Skip to content

Commit 136a63a

Browse files
authored
Add SmartPort command to get heap size (#895)
* Prevent divide by zero error when switching to a track of zero length. * [appleii] adds 0xC1 status command to get current heap size
1 parent 2100e64 commit 136a63a

File tree

3 files changed

+151
-138
lines changed

3 files changed

+151
-138
lines changed

lib/device/iwm/fuji.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ iwmFuji::iwmFuji()
130130
{ FUJICMD_SCAN_NETWORKS, [this]() { this->iwm_stat_net_scan_networks(); }}, // 0xFD
131131
{ FUJICMD_QRCODE_LENGTH, [this]() { this->iwm_stat_qrcode_length(); }}, // 0xBE
132132
{ FUJICMD_QRCODE_OUTPUT, [this]() { this->iwm_stat_qrcode_output(); }}, // 0xBE
133-
{ FUJICMD_STATUS, [this]() { this->iwm_stat_fuji_status(); }} // 0x53
133+
{ FUJICMD_STATUS, [this]() { this->iwm_stat_fuji_status(); }}, // 0x53
134+
{ FUJICMD_GET_HEAP, [this]() { this->iwm_stat_get_heap(); }}, // 0xC1
134135
};
135136

136137
}
@@ -953,6 +954,16 @@ void iwmFuji::iwm_stat_fuji_status()
953954
data_len = 4;
954955
}
955956

957+
void iwmFuji::iwm_stat_get_heap()
958+
{
959+
uint32_t avail = esp_get_free_internal_heap_size();
960+
961+
962+
memcpy(data_buffer, &avail, sizeof(avail));
963+
data_len = sizeof(avail);
964+
return;
965+
}
966+
956967
// Get network adapter configuration
957968
void iwmFuji::iwm_stat_get_adapter_config()
958969
{

lib/device/iwm/fuji.h

Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -148,75 +148,76 @@ class iwmFuji : public iwmDevice
148148
bool hash_is_hex_output = false;
149149

150150
protected:
151-
void iwm_dummy_command(); // control 0xAA
152-
void iwm_hello_world(); // status 0xAA
153-
void iwm_ctrl_reset_fujinet(); // control 0xFF
154-
void iwm_stat_net_get_ssid(); // status 0xFE
155-
void iwm_stat_net_scan_networks(); // status 0xFD
156-
void iwm_ctrl_net_scan_result(); // control 0xFC
157-
void iwm_stat_net_scan_result(); // status 0xFC
158-
void iwm_ctrl_net_set_ssid(); // control 0xFB
159-
void iwm_stat_net_get_wifi_status(); // status 0xFA
160-
void iwm_ctrl_mount_host(); // 0xF9
161-
uint8_t iwm_ctrl_disk_image_mount(); // 0xF8
162-
uint8_t iwm_ctrl_open_directory(); // 0xF7
163-
void iwm_ctrl_read_directory_entry(); // 0xF6
164-
void iwm_stat_read_directory_entry(); // 0xF6
165-
166-
void iwm_ctrl_close_directory(); // 0xF5
167-
void iwm_stat_read_host_slots(); // 0xF4
168-
void iwm_ctrl_write_host_slots(); // 0xF3
169-
void iwm_stat_read_device_slots(); // 0xF2
170-
void iwm_ctrl_write_device_slots(); // 0xF1
171-
void iwm_stat_get_wifi_enabled(); // 0xEA
172-
void iwm_ctrl_disk_image_umount(); // 0xE9
173-
void iwm_stat_get_adapter_config(); // 0xE8
174-
void iwm_stat_get_adapter_config_extended(); // 0xE8 (additional cmd data)
175-
void iwm_ctrl_new_disk(); // 0xE7
176-
void iwm_ctrl_unmount_host(); // 0xE6
177-
178-
void iwm_stat_get_directory_position(); // 0xE5
179-
void iwm_ctrl_set_directory_position(); // 0xE4
151+
void iwm_dummy_command(); // control 0xAA
152+
void iwm_hello_world(); // status 0xAA
153+
void iwm_ctrl_reset_fujinet(); // control 0xFF
154+
void iwm_stat_net_get_ssid(); // status 0xFE
155+
void iwm_stat_net_scan_networks(); // status 0xFD
156+
void iwm_ctrl_net_scan_result(); // control 0xFC
157+
void iwm_stat_net_scan_result(); // status 0xFC
158+
void iwm_ctrl_net_set_ssid(); // control 0xFB
159+
void iwm_stat_net_get_wifi_status(); // status 0xFA
160+
void iwm_ctrl_mount_host(); // 0xF9
161+
uint8_t iwm_ctrl_disk_image_mount(); // 0xF8
162+
uint8_t iwm_ctrl_open_directory(); // 0xF7
163+
void iwm_ctrl_read_directory_entry(); // 0xF6
164+
void iwm_stat_read_directory_entry(); // 0xF6
165+
166+
void iwm_ctrl_close_directory(); // 0xF5
167+
void iwm_stat_read_host_slots(); // 0xF4
168+
void iwm_ctrl_write_host_slots(); // 0xF3
169+
void iwm_stat_read_device_slots(); // 0xF2
170+
void iwm_ctrl_write_device_slots(); // 0xF1
171+
void iwm_stat_get_wifi_enabled(); // 0xEA
172+
void iwm_ctrl_disk_image_umount(); // 0xE9
173+
void iwm_stat_get_adapter_config(); // 0xE8
174+
void iwm_stat_get_adapter_config_extended(); // 0xC4 (additional cmd data)
175+
void iwm_ctrl_new_disk(); // 0xE7
176+
void iwm_ctrl_unmount_host(); // 0xE6
177+
178+
void iwm_stat_get_directory_position(); // 0xE5
179+
void iwm_ctrl_set_directory_position(); // 0xE4
180180
/*
181-
void adamnet_set_hadamnet_index(); // 0xE3
181+
void adamnet_set_hadamnet_index(); // 0xE3
182182
*/
183-
uint8_t iwm_ctrl_set_device_filename(); // 0xE2
183+
uint8_t iwm_ctrl_set_device_filename(); // 0xE2
184184

185-
void iwm_ctrl_set_host_prefix(); // 0xE1
186-
void iwm_stat_get_host_prefix(); // 0xE0
185+
void iwm_ctrl_set_host_prefix(); // 0xE1
186+
void iwm_stat_get_host_prefix(); // 0xE0
187187
/*
188-
void adamnet_set_adamnet_external_clock(); // 0xDF
188+
void adamnet_set_adamnet_external_clock(); // 0xDF
189189
*/
190-
void iwm_ctrl_write_app_key(); // 0xDE
191-
void iwm_ctrl_read_app_key(); // 0xDD - control
192-
void iwm_stat_read_app_key(); // 0xDD - status
193-
void iwm_ctrl_open_app_key(); // 0xDC
190+
void iwm_ctrl_write_app_key(); // 0xDE
191+
void iwm_ctrl_read_app_key(); // 0xDD - control
192+
void iwm_stat_read_app_key(); // 0xDD - status
193+
void iwm_ctrl_open_app_key(); // 0xDC
194194

195-
/* void adamnet_close_app_key(); // 0xDB
195+
/* void adamnet_close_app_key(); // 0xDB
196196
*/
197-
void iwm_stat_get_device_filename(uint8_t s); // 0xDA, 0xA0 thru 0xA7
198-
199-
void iwm_ctrl_set_boot_config(); // 0xD9
200-
void iwm_ctrl_copy_file(); // 0xD8
201-
void iwm_ctrl_set_boot_mode(); // 0xD6
202-
void iwm_ctrl_enable_device(); // 0xD5
203-
void iwm_ctrl_disable_device(); // 0xD4
204-
void send_stat_get_enable(); // 0xD1
205-
206-
void iwm_ctrl_hash_input(); // 0xC8
207-
void iwm_ctrl_hash_compute(bool clear_data); // 0xC7, 0xC3
208-
void iwm_stat_hash_length(); // 0xC6
209-
void iwm_ctrl_hash_output(); // 0xC5 set hash_is_hex_output
210-
void iwm_stat_hash_output(); // 0xC5 write response
211-
void iwm_ctrl_hash_clear(); // 0xC2
212-
213-
void iwm_ctrl_qrcode_input(); // 0xBC
214-
void iwm_ctrl_qrcode_encode(); // 0xBD
215-
void iwm_stat_qrcode_length(); // OxBE
216-
void iwm_ctrl_qrcode_output(); // 0xBF
217-
void iwm_stat_qrcode_output(); // 0xBF
218-
219-
void iwm_stat_fuji_status(); // 0x53
197+
void iwm_stat_get_device_filename(uint8_t s); // 0xDA, 0xA0 thru 0xA7
198+
199+
void iwm_ctrl_set_boot_config(); // 0xD9
200+
void iwm_ctrl_copy_file(); // 0xD8
201+
void iwm_ctrl_set_boot_mode(); // 0xD6
202+
void iwm_ctrl_enable_device(); // 0xD5
203+
void iwm_ctrl_disable_device(); // 0xD4
204+
void send_stat_get_enable(); // 0xD1
205+
206+
void iwm_ctrl_hash_input(); // 0xC8
207+
void iwm_ctrl_hash_compute(bool clear_data); // 0xC7, 0xC3
208+
void iwm_stat_hash_length(); // 0xC6
209+
void iwm_ctrl_hash_output(); // 0xC5 set hash_is_hex_output
210+
void iwm_stat_hash_output(); // 0xC5 write response
211+
void iwm_ctrl_hash_clear(); // 0xC2
212+
void iwm_stat_get_heap(); // 0xC1
213+
214+
void iwm_ctrl_qrcode_input(); // 0xBC
215+
void iwm_ctrl_qrcode_encode(); // 0xBD
216+
void iwm_stat_qrcode_length(); // OxBE
217+
void iwm_ctrl_qrcode_output(); // 0xBF
218+
void iwm_stat_qrcode_output(); // 0xBF
219+
220+
void iwm_stat_fuji_status(); // 0x53
220221

221222
void shutdown() override;
222223
void process(iwm_decoded_cmd_t cmd) override;
@@ -268,8 +269,8 @@ class iwmFuji : public iwmDevice
268269
DEVICE_TYPE *get_disk_dev(int i) {
269270
#ifndef DEV_RELAY_SLIP
270271
return i < MAX_SP_DEVICES
271-
? (DEVICE_TYPE *) &_fnDisks[i].disk_dev
272-
: (DEVICE_TYPE *) &_fnDisk2s[i - MAX_SP_DEVICES];
272+
? (DEVICE_TYPE *) &_fnDisks[i].disk_dev
273+
: (DEVICE_TYPE *) &_fnDisk2s[i - MAX_SP_DEVICES];
273274
#else
274275
return &_fnDisks[i].disk_dev;
275276
#endif

lib/fuji/fujiCmd.h

Lines changed: 74 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,79 +4,80 @@
44
* Fuji Device Command Definitions
55
*/
66

7-
#define FUJICMD_RESET 0xFF
8-
#define FUJICMD_GET_SSID 0xFE
9-
#define FUJICMD_SCAN_NETWORKS 0xFD
10-
#define FUJICMD_GET_SCAN_RESULT 0xFC
11-
#define FUJICMD_SET_SSID 0xFB
12-
#define FUJICMD_GET_WIFISTATUS 0xFA
13-
#define FUJICMD_MOUNT_HOST 0xF9
14-
#define FUJICMD_MOUNT_IMAGE 0xF8
15-
#define FUJICMD_OPEN_DIRECTORY 0xF7
16-
#define FUJICMD_READ_DIR_ENTRY 0xF6
17-
#define FUJICMD_CLOSE_DIRECTORY 0xF5
18-
#define FUJICMD_READ_HOST_SLOTS 0xF4
19-
#define FUJICMD_WRITE_HOST_SLOTS 0xF3
20-
#define FUJICMD_READ_DEVICE_SLOTS 0xF2
21-
#define FUJICMD_WRITE_DEVICE_SLOTS 0xF1
22-
#define FUJICMD_GET_WIFI_ENABLED 0xEA
23-
#define FUJICMD_UNMOUNT_IMAGE 0xE9
24-
#define FUJICMD_GET_ADAPTERCONFIG 0xE8
25-
#define FUJICMD_NEW_DISK 0xE7
26-
#define FUJICMD_UNMOUNT_HOST 0xE6
27-
#define FUJICMD_GET_DIRECTORY_POSITION 0xE5
28-
#define FUJICMD_SET_DIRECTORY_POSITION 0xE4
29-
#define FUJICMD_SET_HSIO_INDEX 0xE3
30-
#define FUJICMD_SET_DEVICE_FULLPATH 0xE2
31-
#define FUJICMD_SET_HOST_PREFIX 0xE1
32-
#define FUJICMD_GET_HOST_PREFIX 0xE0
33-
#define FUJICMD_SET_SIO_EXTERNAL_CLOCK 0xDF
34-
#define FUJICMD_WRITE_APPKEY 0xDE
35-
#define FUJICMD_READ_APPKEY 0xDD
36-
#define FUJICMD_OPEN_APPKEY 0xDC
37-
#define FUJICMD_CLOSE_APPKEY 0xDB
38-
#define FUJICMD_GET_DEVICE_FULLPATH 0xDA
39-
#define FUJICMD_GET_DEVICE1_FULLPATH 0xA0
40-
#define FUJICMD_GET_DEVICE2_FULLPATH 0xA1
41-
#define FUJICMD_GET_DEVICE3_FULLPATH 0xA2
42-
#define FUJICMD_GET_DEVICE4_FULLPATH 0xA3
43-
#define FUJICMD_GET_DEVICE5_FULLPATH 0xA4
44-
#define FUJICMD_GET_DEVICE6_FULLPATH 0xA5
45-
#define FUJICMD_GET_DEVICE7_FULLPATH 0xA6
46-
#define FUJICMD_GET_DEVICE8_FULLPATH 0xA7
47-
#define FUJICMD_CONFIG_BOOT 0xD9
48-
#define FUJICMD_COPY_FILE 0xD8
49-
#define FUJICMD_MOUNT_ALL 0xD7
50-
#define FUJICMD_SET_BOOT_MODE 0xD6
51-
#define FUJICMD_STATUS 0x53
52-
#define FUJICMD_HSIO_INDEX 0x3F
53-
#define FUJICMD_ENABLE_UDPSTREAM 0xF0
54-
#define FUJICMD_ENABLE_DEVICE 0xD5
55-
#define FUJICMD_DISABLE_DEVICE 0xD4
56-
#define FUJICMD_RANDOM_NUMBER 0xD3
57-
#define FUJICMD_GET_TIME 0xD2
58-
#define FUJICMD_DEVICE_ENABLE_STATUS 0xD1
59-
#define FUJICMD_QRCODE_INPUT 0xBC
60-
#define FUJICMD_QRCODE_ENCODE 0xBD
61-
#define FUJICMD_QRCODE_LENGTH 0xBE
62-
#define FUJICMD_QRCODE_OUTPUT 0xBF
63-
#define FUJICMD_BASE64_ENCODE_INPUT 0xD0
64-
#define FUJICMD_BASE64_ENCODE_COMPUTE 0xCF
65-
#define FUJICMD_BASE64_ENCODE_LENGTH 0xCE
66-
#define FUJICMD_BASE64_ENCODE_OUTPUT 0xCD
67-
#define FUJICMD_BASE64_DECODE_INPUT 0xCC
68-
#define FUJICMD_BASE64_DECODE_COMPUTE 0xCB
69-
#define FUJICMD_BASE64_DECODE_LENGTH 0xCA
70-
#define FUJICMD_BASE64_DECODE_OUTPUT 0xC9
71-
#define FUJICMD_HASH_INPUT 0xC8
72-
#define FUJICMD_HASH_COMPUTE 0xC7
73-
#define FUJICMD_HASH_LENGTH 0xC6
74-
#define FUJICMD_HASH_OUTPUT 0xC5
7+
#define FUJICMD_RESET 0xFF
8+
#define FUJICMD_GET_SSID 0xFE
9+
#define FUJICMD_SCAN_NETWORKS 0xFD
10+
#define FUJICMD_GET_SCAN_RESULT 0xFC
11+
#define FUJICMD_SET_SSID 0xFB
12+
#define FUJICMD_GET_WIFISTATUS 0xFA
13+
#define FUJICMD_MOUNT_HOST 0xF9
14+
#define FUJICMD_MOUNT_IMAGE 0xF8
15+
#define FUJICMD_OPEN_DIRECTORY 0xF7
16+
#define FUJICMD_READ_DIR_ENTRY 0xF6
17+
#define FUJICMD_CLOSE_DIRECTORY 0xF5
18+
#define FUJICMD_READ_HOST_SLOTS 0xF4
19+
#define FUJICMD_WRITE_HOST_SLOTS 0xF3
20+
#define FUJICMD_READ_DEVICE_SLOTS 0xF2
21+
#define FUJICMD_WRITE_DEVICE_SLOTS 0xF1
22+
#define FUJICMD_ENABLE_UDPSTREAM 0xF0
23+
#define FUJICMD_GET_WIFI_ENABLED 0xEA
24+
#define FUJICMD_UNMOUNT_IMAGE 0xE9
25+
#define FUJICMD_GET_ADAPTERCONFIG 0xE8
26+
#define FUJICMD_NEW_DISK 0xE7
27+
#define FUJICMD_UNMOUNT_HOST 0xE6
28+
#define FUJICMD_GET_DIRECTORY_POSITION 0xE5
29+
#define FUJICMD_SET_DIRECTORY_POSITION 0xE4
30+
#define FUJICMD_SET_HSIO_INDEX 0xE3
31+
#define FUJICMD_SET_DEVICE_FULLPATH 0xE2
32+
#define FUJICMD_SET_HOST_PREFIX 0xE1
33+
#define FUJICMD_GET_HOST_PREFIX 0xE0
34+
#define FUJICMD_SET_SIO_EXTERNAL_CLOCK 0xDF
35+
#define FUJICMD_WRITE_APPKEY 0xDE
36+
#define FUJICMD_READ_APPKEY 0xDD
37+
#define FUJICMD_OPEN_APPKEY 0xDC
38+
#define FUJICMD_CLOSE_APPKEY 0xDB
39+
#define FUJICMD_GET_DEVICE_FULLPATH 0xDA
40+
#define FUJICMD_CONFIG_BOOT 0xD9
41+
#define FUJICMD_COPY_FILE 0xD8
42+
#define FUJICMD_MOUNT_ALL 0xD7
43+
#define FUJICMD_SET_BOOT_MODE 0xD6
44+
#define FUJICMD_ENABLE_DEVICE 0xD5
45+
#define FUJICMD_DISABLE_DEVICE 0xD4
46+
#define FUJICMD_RANDOM_NUMBER 0xD3
47+
#define FUJICMD_GET_TIME 0xD2
48+
#define FUJICMD_DEVICE_ENABLE_STATUS 0xD1
49+
#define FUJICMD_BASE64_ENCODE_INPUT 0xD0
50+
#define FUJICMD_BASE64_ENCODE_COMPUTE 0xCF
51+
#define FUJICMD_BASE64_ENCODE_LENGTH 0xCE
52+
#define FUJICMD_BASE64_ENCODE_OUTPUT 0xCD
53+
#define FUJICMD_BASE64_DECODE_INPUT 0xCC
54+
#define FUJICMD_BASE64_DECODE_COMPUTE 0xCB
55+
#define FUJICMD_BASE64_DECODE_LENGTH 0xCA
56+
#define FUJICMD_BASE64_DECODE_OUTPUT 0xC9
57+
#define FUJICMD_HASH_INPUT 0xC8
58+
#define FUJICMD_HASH_COMPUTE 0xC7
59+
#define FUJICMD_HASH_LENGTH 0xC6
60+
#define FUJICMD_HASH_OUTPUT 0xC5
7561
#define FUJICMD_GET_ADAPTERCONFIG_EXTENDED 0xC4
76-
#define FUJICMD_HASH_COMPUTE_NO_CLEAR 0xC3
77-
#define FUJICMD_HASH_CLEAR 0xC2
78-
#define FUJICMD_SEND_ERROR 0x02
79-
#define FUJICMD_SEND_RESPONSE 0x01
80-
#define FUJICMD_DEVICE_READY 0x00
62+
#define FUJICMD_HASH_COMPUTE_NO_CLEAR 0xC3
63+
#define FUJICMD_HASH_CLEAR 0xC2
64+
#define FUJICMD_GET_HEAP 0xC1
65+
#define FUJICMD_QRCODE_OUTPUT 0xBF
66+
#define FUJICMD_QRCODE_LENGTH 0xBE
67+
#define FUJICMD_QRCODE_ENCODE 0xBD
68+
#define FUJICMD_QRCODE_INPUT 0xBC
69+
#define FUJICMD_GET_DEVICE8_FULLPATH 0xA7
70+
#define FUJICMD_GET_DEVICE7_FULLPATH 0xA6
71+
#define FUJICMD_GET_DEVICE6_FULLPATH 0xA5
72+
#define FUJICMD_GET_DEVICE5_FULLPATH 0xA4
73+
#define FUJICMD_GET_DEVICE4_FULLPATH 0xA3
74+
#define FUJICMD_GET_DEVICE3_FULLPATH 0xA2
75+
#define FUJICMD_GET_DEVICE2_FULLPATH 0xA1
76+
#define FUJICMD_GET_DEVICE1_FULLPATH 0xA0
77+
#define FUJICMD_STATUS 0x53
78+
#define FUJICMD_HSIO_INDEX 0x3F
79+
#define FUJICMD_SEND_ERROR 0x02
80+
#define FUJICMD_SEND_RESPONSE 0x01
81+
#define FUJICMD_DEVICE_READY 0x00
8182

8283
#endif

0 commit comments

Comments
 (0)