diff options
author | root <root@no.no.james.local> | 2015-09-01 16:49:20 +0100 |
---|---|---|
committer | root <root@no.no.james.local> | 2015-09-01 16:49:20 +0100 |
commit | b92a20c60e5a4409179efc5b659411d3c0c7b6f6 (patch) | |
tree | fe257f8ae2547dbcbbdf603b33e4715d9d9d471a | |
parent | 88d098d6b3f85f70c9cde405a0d2ff70997fe706 (diff) | |
download | nrfdfu-b92a20c60e5a4409179efc5b659411d3c0c7b6f6.tar.gz nrfdfu-b92a20c60e5a4409179efc5b659411d3c0c7b6f6.tar.bz2 nrfdfu-b92a20c60e5a4409179efc5b659411d3c0c7b6f6.zip |
fix bugs, and better end handling
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | ble.c | 17 | ||||
-rw-r--r-- | dfu.c | 41 | ||||
-rw-r--r-- | prototypes.h | 1 |
4 files changed, 41 insertions, 20 deletions
diff --git a/Makefile.am b/Makefile.am index c7fe645..480e6d5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -72,6 +72,6 @@ AM_CFLAGS=-g -Wall protos: echo > prototypes.h - ${CPROTO} ${CPPFLAGS} -e -v ${CSRCS} > prototypes.new + ${CPROTO} ${AM_CPPFLAGS} -e -v ${CSRCS} > prototypes.new mv prototypes.new prototypes.h @@ -553,6 +553,23 @@ ble_send_cp (BLE * ble, uint8_t * buf, size_t len) } + +int +ble_send_cp_noresp (BLE * ble, uint8_t * buf, size_t len) +{ + printf ("Sending control:\n"); + hexdump (buf, len); + + if (!bt_gatt_client_write_without_response + (ble->gatt, ble->cp_handle, false, buf, len)) + { + printf ("Failed to initiate write procedure\n"); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} + + #if 0 int ble_send_data (BLE * ble, uint8_t * buf, size_t len) @@ -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); diff --git a/prototypes.h b/prototypes.h index 0fba901..8489d3d 100644 --- a/prototypes.h +++ b/prototypes.h @@ -13,6 +13,7 @@ extern void ble_init(void); extern BLE *ble_open(const char *bdaddr); extern int ble_register_notify(BLE *ble); extern int ble_send_cp(BLE *ble, uint8_t *buf, size_t len); +extern int ble_send_cp_noresp(BLE *ble, uint8_t *buf, size_t len); extern int ble_send_data(BLE *ble, uint8_t *buf, size_t len); extern int ble_send_data_noresp(BLE *ble, uint8_t *buf, size_t len); extern void ble_wait_setup(BLE *ble, uint8_t op); |