Fix handling buffers with text
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
parent
06911014f8
commit
1a307252da
|
|
@ -239,7 +239,7 @@ device3_type* device3_open(device3_event_callback callback) {
|
||||||
|
|
||||||
uint32_t calibration_len = 0;
|
uint32_t calibration_len = 0;
|
||||||
if (recv_payload_msg(device, DEVICE3_MSG_GET_CAL_DATA_LENGTH, 4, (uint8_t*) &calibration_len)) {
|
if (recv_payload_msg(device, DEVICE3_MSG_GET_CAL_DATA_LENGTH, 4, (uint8_t*) &calibration_len)) {
|
||||||
char* calibration_data = malloc(calibration_len);
|
char* calibration_data = malloc(calibration_len + 1);
|
||||||
|
|
||||||
uint32_t position = 0;
|
uint32_t position = 0;
|
||||||
while (position < calibration_len) {
|
while (position < calibration_len) {
|
||||||
|
|
@ -257,6 +257,8 @@ device3_type* device3_open(device3_event_callback callback) {
|
||||||
|
|
||||||
position += next;
|
position += next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
calibration_data[calibration_len] = '\0';
|
||||||
|
|
||||||
struct json_tokener* tokener = json_tokener_new();
|
struct json_tokener* tokener = json_tokener_new();
|
||||||
struct json_object* root = json_tokener_parse_ex(tokener, calibration_data, calibration_len);
|
struct json_object* root = json_tokener_parse_ex(tokener, calibration_data, calibration_len);
|
||||||
|
|
|
||||||
|
|
@ -111,16 +111,19 @@ static bool recv_payload_msg(device4_type* device, uint16_t msgid, uint8_t len,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet.head != PACKET_HEAD) {
|
if (packet.head != PACKET_HEAD) {
|
||||||
|
perror("ERROR: invalid payload received\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet.msgid != msgid) {
|
if (packet.msgid != msgid) {
|
||||||
|
perror("ERROR: unexpected payload received\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t status = packet.data[0];
|
|
||||||
|
|
||||||
|
const uint8_t status = packet.data[0];
|
||||||
|
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
|
perror("ERROR: payload status failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,6 +156,7 @@ static bool do_payload_action(device4_type* device, uint16_t msgid, uint8_t len,
|
||||||
attempts--;
|
attempts--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
perror("ERROR: payload status failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -483,6 +487,22 @@ bool device4_update_mcu_firmware(device4_type* device, const char* path) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!send_payload_action(device, DEVICE4_MSG_R_ACTIVATION_TIME, 0, NULL)) {
|
||||||
|
perror("Requesting activation time failed!\n");
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t activated;
|
||||||
|
if (!recv_payload_msg(device, DEVICE4_MSG_R_ACTIVATION_TIME, 1, &activated)) {
|
||||||
|
perror("Receiving activation time failed!\n");
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!activated) {
|
||||||
|
perror("Device is not activated!\n");
|
||||||
|
goto jump_to_app;
|
||||||
|
}
|
||||||
|
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
|
|
||||||
while (offset < firmware_len) {
|
while (offset < firmware_len) {
|
||||||
|
|
@ -500,10 +520,12 @@ bool device4_update_mcu_firmware(device4_type* device, const char* path) {
|
||||||
msgid = DEVICE4_MSG_W_UPDATE_MCU_APP_FW_TRANSMIT;
|
msgid = DEVICE4_MSG_W_UPDATE_MCU_APP_FW_TRANSMIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!do_payload_action(device, msgid, len, firmware)) {
|
if (!do_payload_action(device, msgid, len, firmware + offset)) {
|
||||||
perror("Failed sending firmware upload!\n");
|
perror("Failed sending firmware upload!\n");
|
||||||
goto jump_to_app;
|
goto jump_to_app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
offset += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Finish upload!\n");
|
printf("Finish upload!\n");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue