From b92a20c60e5a4409179efc5b659411d3c0c7b6f6 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 1 Sep 2015 16:49:20 +0100 Subject: fix bugs, and better end handling --- dfu.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'dfu.c') diff --git a/dfu.c b/dfu.c index 89b2b10..29dc4cd 100644 --- a/dfu.c +++ b/dfu.c @@ -100,27 +100,30 @@ dfu (const char *bdaddr, const char *type, const char *version, uint8_t * dat, { BLE *b; uint8_t buf[32]; - uint32_t u32; uint16_t u16; - uint32_t start_data[3]; - uint8_t dfu_type; + uint32_t start_data[3]; + uint8_t dfu_type; if (!strcmp (type, "application")) { - dfu_type=DFU_UPDATE_APP; /*bit field */ - start_data[0]=0; - start_data[1]=0; - start_data[2]=bin_sz; - - }else if (!strcmp (type, "bootloader")) { - dfu_type=DFU_UPDATE_BL; /*bit field */ - start_data[0]=0; - start_data[1]=bin_sz; - start_data[2]=0; - } else { - fprintf("No idea how to upload %s\n",type); - exit(EXIT_FAILURE); + dfu_type = DFU_UPDATE_APP; /*bit field */ + start_data[0] = 0; + start_data[1] = 0; + start_data[2] = bin_sz; + + } + else if (!strcmp (type, "bootloader")) + { + dfu_type = DFU_UPDATE_BL; /*bit field */ + start_data[0] = 0; + start_data[1] = bin_sz; + start_data[2] = 0; + } + else + { + fprintf (stderr, "No idea how to upload %s\n", type); + exit (EXIT_FAILURE); } ble_init (); @@ -138,7 +141,7 @@ dfu (const char *bdaddr, const char *type, const char *version, uint8_t * dat, break; buf[0] = OP_CODE_START_DFU; - buf[1] = dfu_type; /*bit field */ + buf[1] = dfu_type; /*bit field */ ble_wait_setup (b, OP_CODE_START_DFU); @@ -148,7 +151,7 @@ dfu (const char *bdaddr, const char *type, const char *version, uint8_t * dat, /*4 bytes sd size, 4 bytes bl size, 4 bytes app size */ - if (ble_send_data (b, start_data, sizeof(start_data))) + if (ble_send_data (b, (uint8_t *) start_data, sizeof (start_data))) break; if (ble_wait_run (b) != BLE_DFU_RESP_VAL_SUCCESS) @@ -222,7 +225,7 @@ dfu (const char *bdaddr, const char *type, const char *version, uint8_t * dat, break; buf[0] = OP_CODE_ACTIVATE_N_RESET; - if (ble_send_cp (b, buf, 1)) + if (ble_send_cp_noresp (b, buf, 1)) break; ble_close (b); -- cgit v1.2.3