[concordance-commit] concordance/libconcord libconcord.cpp, 1.42.2.11, 1.42.2.12 libconcord.h, 1.22
Brought to you by:
jaymzh,
kevin_timmerman
Update of /cvsroot/concordance/concordance/libconcord In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv12080/libconcord Modified Files: Tag: zwave_work_branch libconcord.cpp libconcord.h remote.cpp remote.h remote_z.cpp Log Message: Port firmware over to new API Index: libconcord.h =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/libconcord.h,v retrieving revision 1.22.2.9 retrieving revision 1.22.2.10 diff -u -d -r1.22.2.9 -r1.22.2.10 --- libconcord.h 18 Sep 2010 14:14:54 -0000 1.22.2.9 +++ libconcord.h 18 Sep 2010 21:52:06 -0000 1.22.2.10 @@ -214,7 +214,7 @@ /* * Reboot the remote. */ -int reset_remote(); +int reset_remote(lc_callback cb, void *cb_arg); /* * Get the time from the remote. Use the time accessors above to access * the data. @@ -384,13 +384,13 @@ /* * Preps the remote for a firmware upgrade */ -int prep_firmware(); +int prep_firmware(lc_callback cb, void *cb_arg); /* * Tells the remote the firmware upgrade was successful and that it should * copy the firmware from the "staging" area to the live area on next reboot. * Don't forget to reboot. */ -int finish_firmware(); +int finish_firmware(lc_callback cb, void *cb_arg); /* * Make the firmware area of the flash all 1's so you can write * to it. @@ -408,8 +408,7 @@ /* * Same as write_config_to_remote(), but with the firmware instead. */ -int write_firmware_to_remote(uint8_t *in, uint32_t size, int direct, - lc_callback cb, void *cb_arg); +int write_firmware_to_remote(int direct, lc_callback cb, void *cb_arg); /* * Same as write_config_to_file(), but with firmware instead. Note * that unless binary is specified, the firmware is broken into chunks @@ -507,6 +506,7 @@ int post_new_code(char *key_name, char *encoded_signal); int update_configuration(lc_callback cb, void *cb_arg, int noreset); +int update_firmware(lc_callback cb, void *cb_arg, int noreset, int direct); #ifdef __cplusplus } Index: libconcord.cpp =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/libconcord.cpp,v retrieving revision 1.42.2.11 retrieving revision 1.42.2.12 diff -u -d -r1.42.2.11 -r1.42.2.12 --- libconcord.cpp 18 Sep 2010 14:14:54 -0000 1.42.2.11 +++ libconcord.cpp 18 Sep 2010 21:52:06 -0000 1.42.2.12 @@ -57,8 +57,6 @@ #define ZWAVE_HID_PID_MIN 0xC112 #define ZWAVE_HID_PID_MAX 0xC115 -#define FIRMWARE_MAX_SIZE 64*1024 - #define MAX_WAIT_FOR_BOOT 5 #define WAIT_FOR_BOOT_SLEEP 5 @@ -622,12 +620,12 @@ } int _write_fw_to_remote(uint8_t *in, uint32_t size, uint32_t addr, - lc_callback cb, void *cb_arg) + lc_callback cb, void *cb_arg, uint32_t cb_stage) { int err = 0; if ((err = rmt->WriteFlash(addr, size, in, - ri.protocol, cb, cb_arg, NULL))) { + ri.protocol, cb, cb_arg, cb_stage))) { return LC_ERROR_WRITE; } return 0; @@ -711,22 +709,6 @@ return 0; } -/* - * Chunk the hex into words, tack on an '0x', and then throw - * it through strtoul to get binary data (int) back. - */ -int _convert_to_binary(string hex, uint8_t *&ptr) -{ - size_t size = hex.length(); - for (size_t i = 0; i < size; i += 2) { - char tmp[6]; - sprintf(tmp, "0x%s ", hex.substr(i, 2).c_str()); - ptr[0] = (uint8_t)strtoul(tmp, NULL, 16); - ptr++; - } - return 0; -} - /* * GENERAL REMOTE STUFF @@ -820,10 +802,38 @@ _get_identity(cb, cb_arg, LC_CB_STAGE_GET_IDENTITY); } -int reset_remote() +int reset_remote(lc_callback cb, void *cb_arg) { - int err = rmt->Reset(COMMAND_RESET_DEVICE); - return err; + int err; + if (cb) + cb(LC_CB_STAGE_RESET, 0, 0, 2, LC_CB_COUNTER_TYPE_STEPS, cb_arg); + + if ((err = rmt->Reset(COMMAND_RESET_DEVICE))) + return err; + + if (cb) + cb(LC_CB_STAGE_RESET, 1, 1, 2, LC_CB_COUNTER_TYPE_STEPS, cb_arg); + + deinit_concord(); + for (int i = 0; i < MAX_WAIT_FOR_BOOT; i++) { + sleep(WAIT_FOR_BOOT_SLEEP); + err = init_concord(); + if (err == 0) { + err = get_identity(NULL, NULL); + if (err == 0) { + break; + } + deinit_concord(); + } + } + + if (err != 0) + return err; + + if (cb) + cb(LC_CB_STAGE_RESET, 2, 2, 2, LC_CB_COUNTER_TYPE_STEPS, cb_arg); + + return 0; } /* FIXME: This should almost certainly be rolled into prep_config() */ @@ -831,7 +841,7 @@ { int err = 0; - if ((err = rmt->InvalidateFlash())) + if ((err = rmt->InvalidateFlash(cb, cb_arg, cb_stage))) return LC_ERROR_INVALIDATE; return 0; @@ -1191,37 +1201,11 @@ if (err != 0) return err; - if (noreset) { + if (noreset) return 0; - } - - if (cb) - cb(LC_CB_STAGE_RESET, 0, 0, 2, LC_CB_COUNTER_TYPE_STEPS, cb_arg); - - reset_remote(); - - if (cb) - cb(LC_CB_STAGE_RESET, 1, 1, 2, LC_CB_COUNTER_TYPE_STEPS, cb_arg); - - deinit_concord(); - for (int i = 0; i < MAX_WAIT_FOR_BOOT; i++) { - sleep(WAIT_FOR_BOOT_SLEEP); - err = init_concord(); - if (err == 0) { - /* fix lack of callback */ - err = _get_identity(NULL, NULL, NULL); - if (err == 0) { - break; - } - deinit_concord(); - } - } - if (err != 0) { + if ((err = reset_remote(cb, cb_arg))) return err; - } - if (cb) - cb(LC_CB_STAGE_RESET, 2, 2, 2, LC_CB_COUNTER_TYPE_STEPS, cb_arg); return 0; } @@ -1299,49 +1283,53 @@ } } -int prep_firmware() +int prep_firmware(lc_callback cb, void *cb_arg) { int err = 0; - if ((err = rmt->PrepFirmware(ri))) { + if ((err = rmt->PrepFirmware(ri, cb, cb_arg, + LC_CB_STAGE_INITIALIZE_UPDATE))) { return LC_ERROR; } return 0; } -int finish_firmware() +int finish_firmware(lc_callback cb, void *cb_arg) { int err = 0; - if ((err = rmt->FinishFirmware(ri))) { + if ((err = rmt->FinishFirmware(ri, cb, cb_arg, + LC_CB_STAGE_FINALIZE_UPDATE))) { return LC_ERROR; } return 0; } -int erase_firmware(int direct, lc_callback cb, void *cb_arg) +int _erase_firmware(int direct, lc_callback cb, void *cb_arg, uint32_t cb_stage) { int err = 0; - if (!_is_fw_update_supported(direct)) { - return LC_ERROR_UNSUPP; - } - uint32_t addr = ri.arch->firmware_update_base; if (direct) { debug("Writing direct"); addr = ri.arch->firmware_base; } - if ((err = rmt->EraseFlash(addr, FIRMWARE_MAX_SIZE, ri, cb, cb_arg))) { + if ((err = rmt->EraseFlash(addr, FIRMWARE_MAX_SIZE, ri, cb, cb_arg, + cb_stage))) { return LC_ERROR_ERASE; } return 0; } +int erase_firmware(int direct, lc_callback cb, void *cb_arg) +{ + _erase_firmware(direct, cb, cb_arg, LC_CB_STAGE_ERASE_FLASH); +} + int read_firmware_from_remote(uint8_t **out, uint32_t *size, lc_callback cb, void *cb_arg) { @@ -1350,17 +1338,13 @@ cb_arg); } -int write_firmware_to_remote(uint8_t *in, uint32_t size, int direct, - lc_callback cb, void *cb_arg) +int _write_firmware_to_remote(int direct, lc_callback cb, void *cb_arg, + uint32_t cb_stage) { uint32_t addr = ri.arch->firmware_update_base; int err = 0; - if (!_is_fw_update_supported(direct)) { - return LC_ERROR_UNSUPP; - } - - if (size > FIRMWARE_MAX_SIZE) { + if (of->GetDataSize() > FIRMWARE_MAX_SIZE) { return LC_ERROR; } @@ -1369,11 +1353,18 @@ addr = ri.arch->firmware_base; } - if ((err = _fix_magic_bytes(in, size))) { + if ((err = _fix_magic_bytes(of->GetData(), of->GetDataSize()))) { return LC_ERROR_READ; } - return _write_fw_to_remote(in, size, addr, cb, cb_arg); + return _write_fw_to_remote(of->GetData(), of->GetDataSize(), addr, cb, + cb_arg, cb_stage); +} + +int write_firmware_to_remote(int direct, lc_callback cb, void *cb_arg) +{ + return _write_firmware_to_remote(direct, cb, cb_arg, + LC_CB_STAGE_WRITE_FIRMWARE); } int write_firmware_to_file(uint8_t *in, uint32_t size, char *file_name, @@ -1428,30 +1419,40 @@ return 0; } -int extract_firmware_binary(uint8_t *xml, uint32_t xml_size, uint8_t **out, - uint32_t *size) +int update_firmware(lc_callback cb, void *cb_arg, int noreset, int direct) { - uint32_t o_size = FIRMWARE_MAX_SIZE; - *out = new uint8_t[o_size]; - uint8_t *o = *out; + int err; - uint8_t *x = xml; - uint32_t x_size = xml_size; + if (!_is_fw_update_supported(direct)) { + return LC_ERROR_UNSUPP; + } - string hex; - while (GetTag("DATA", x, x_size, x, &hex) == 0) { - uint32_t hex_size = hex.length() / 2; - if (hex_size > o_size) { - return LC_ERROR; - } + if (!direct) { + if ((err = prep_firmware(cb, cb_arg))) + return err; + } - _convert_to_binary(hex, o); + if ((err = invalidate_flash(cb, cb_arg))) + return err; - x_size = xml_size - (x - xml); - o_size -= hex_size; + if ((err = erase_firmware(direct, cb, cb_arg))) + return err; + + if ((err = write_firmware_to_remote(direct, cb, cb_arg))) + return err; + + if (!direct) { + if ((err = finish_firmware(cb, cb_arg))) + return err; } - *size = o - *out; + if (noreset) + return 0; + + reset_remote(cb, cb_arg); + + if ((err = set_time(cb, cb_arg))) + return err; return 0; } Index: remote.h =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/remote.h,v retrieving revision 1.20.2.5 retrieving revision 1.20.2.6 diff -u -d -r1.20.2.5 -r1.20.2.6 --- remote.h 18 Sep 2010 14:14:54 -0000 1.20.2.5 +++ remote.h 18 Sep 2010 21:52:06 -0000 1.20.2.6 @@ -25,6 +25,8 @@ #define REMOTE_H #define SERIAL_SIZE 48 +#define FIRMWARE_MAX_SIZE 64*1024 + /* * limits for IR signal learning, stop when any is reached: * timeouts in milliseconds, length in number of mark/space durations @@ -153,12 +155,14 @@ void *cb_arg=NULL, uint32_t cb_stage=NULL)=0; virtual int WriteRam(uint32_t addr, const uint32_t len, uint8_t *wr)=0; virtual int ReadRam(uint32_t addr, const uint32_t len, uint8_t *rd)=0; - virtual int PrepFirmware(const TRemoteInfo &ri) = 0; - virtual int FinishFirmware(const TRemoteInfo &ri) = 0; + virtual int PrepFirmware(const TRemoteInfo &ri, lc_callback cb=NULL, + void *cb_arg=NULL, uint32_t cb_stage=NULL) = 0; + virtual int FinishFirmware(const TRemoteInfo &ri, lc_callback cb=NULL, + void *cb_arg=NULL, uint32_t cb_stage=NULL) = 0; virtual int PrepConfig(const TRemoteInfo &ri, lc_callback cb=NULL, void *cb_arg=NULL, uint32_t cb_stage=NULL)=0; virtual int FinishConfig(const TRemoteInfo &ri, lc_callback cb=NULL, - void *cb_arg=NULL, uint32_t cb_stage=NULL)=0; + void *cb_arg=NULL, uint32_t cb_stage=NULL)=0; virtual int UpdateConfig(const uint32_t len, const uint8_t *wr, lc_callback cb, void *cb_arg, uint32_t cb_stage)=0; @@ -202,8 +206,10 @@ uint32_t cb_stage=NULL); int WriteRam(uint32_t addr, const uint32_t len, uint8_t *wr); int ReadRam(uint32_t addr, const uint32_t len, uint8_t *rd); - int PrepFirmware(const TRemoteInfo &ri); - int FinishFirmware(const TRemoteInfo &ri); + int PrepFirmware(const TRemoteInfo &ri, lc_callback cb=NULL, + void *cb_arg=NULL, uint32_t cb_stage=NULL); + int FinishFirmware(const TRemoteInfo &ri, lc_callback cb=NULL, + void *cb_arg=NULL, uint32_t cb_stage=NULL); int PrepConfig(const TRemoteInfo &ri, lc_callback cb=NULL, void *cb_arg=NULL, uint32_t cb_stage=NULL); int FinishConfig(const TRemoteInfo &ri, lc_callback cb=NULL, @@ -255,8 +261,10 @@ uint32_t cb_stage=NULL); int WriteRam(uint32_t addr, const uint32_t len, uint8_t *wr); int ReadRam(uint32_t addr, const uint32_t len, uint8_t *rd); - int PrepFirmware(const TRemoteInfo &ri); - int FinishFirmware(const TRemoteInfo &ri); + int PrepFirmware(const TRemoteInfo &ri, lc_callback cb=NULL, + void *cb_arg=NULL, uint32_t cb_stage=NULL); + int FinishFirmware(const TRemoteInfo &ri, lc_callback cb=NULL, + void *cb_arg=NULL, uint32_t cb_stage=NULL); int PrepConfig(const TRemoteInfo &ri, lc_callback cb=NULL, void *cb_arg=NULL, uint32_t cb_stage=NULL); int FinishConfig(const TRemoteInfo &ri, lc_callback cb=NULL, Index: remote_z.cpp =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/remote_z.cpp,v retrieving revision 1.25.2.11 retrieving revision 1.25.2.12 diff -u -d -r1.25.2.11 -r1.25.2.12 --- remote_z.cpp 18 Sep 2010 14:14:54 -0000 1.25.2.11 +++ remote_z.cpp 18 Sep 2010 21:52:06 -0000 1.25.2.12 @@ -531,12 +531,14 @@ return 0; } -int CRemoteZ_Base::PrepFirmware(const TRemoteInfo &ri) +int CRemoteZ_Base::PrepFirmware(const TRemoteInfo &ri, lc_callback cb, + void *cb_arg, uint32_t cb_stage) { return 0; } -int CRemoteZ_Base::FinishFirmware(const TRemoteInfo &ri) +int CRemoteZ_Base::FinishFirmware(const TRemoteInfo &ri, lc_callback cb, + void *cb_arg, uint32_t cb_stage) { return 0; } Index: remote.cpp =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/remote.cpp,v retrieving revision 1.40.2.3 retrieving revision 1.40.2.4 diff -u -d -r1.40.2.3 -r1.40.2.4 --- remote.cpp 18 Sep 2010 14:14:54 -0000 1.40.2.3 +++ remote.cpp 18 Sep 2010 21:52:06 -0000 1.40.2.4 @@ -370,11 +370,15 @@ return err; } -int CRemote::PrepFirmware(const TRemoteInfo &ri) +int CRemote::PrepFirmware(const TRemoteInfo &ri, lc_callback cb, void *cb_arg, + uint32_t cb_stage) { int err = 0; uint8_t data[1] = { 0x00 }; + if (cb) + cb(cb_stage, 0, 0, 2, LC_CB_COUNTER_TYPE_STEPS, cb_arg); + if (ri.arch->firmware_update_base == ri.arch->firmware_base) { /* * The preperation for where the staging area IS the config @@ -382,8 +386,13 @@ * restart config * write "1" to flash addr 200000 */ - if ((err = WriteMiscByte(0x09, 1, COMMAND_MISC_RESTART_CONFIG, data))) + if ((err = WriteMiscByte(0x09, 1, COMMAND_MISC_RESTART_CONFIG, + data))) return LC_ERROR; + + if (cb) + cb(cb_stage, 1, 1, 2, LC_CB_COUNTER_TYPE_STEPS, cb_arg); + if ((err = WriteFlash(0x200000, 1, data, ri.protocol, NULL, NULL, NULL))) return LC_ERROR; @@ -395,41 +404,59 @@ */ if ((err = WriteRam(0, 1, data))) return LC_ERROR_WRITE; + + if (cb) + cb(cb_stage, 1, 1, 2, LC_CB_COUNTER_TYPE_STEPS, cb_arg); + if ((err = ReadRam(0, 1, data))) return LC_ERROR_WRITE; if (data[0] != 0) return LC_ERROR_VERIFY; } + if (cb) + cb(cb_stage, 2, 2, 2, LC_CB_COUNTER_TYPE_STEPS, cb_arg); return 0; } -int CRemote::FinishFirmware(const TRemoteInfo &ri) +int CRemote::FinishFirmware(const TRemoteInfo &ri, lc_callback cb, void *cb_arg, + uint32_t cb_stage) { int err = 0; + if (cb) + cb(cb_stage, 0, 0, 3, LC_CB_COUNTER_TYPE_STEPS, cb_arg); + uint8_t data[1]; if (ri.arch->firmware_update_base == ri.arch->firmware_base) { data[0] = 0x02; if ((err = WriteFlash(0x200000, 1, data, ri.protocol, NULL, NULL, NULL))) return LC_ERROR; + if (cb) + cb(cb_stage, 1, 1, 3, LC_CB_COUNTER_TYPE_STEPS, cb_arg); } else { data[0] = 0x02; if ((err = WriteRam(0, 1, data))) { debug("Failed to write 2 to RAM 0"); return LC_ERROR_WRITE; } + if (cb) + cb(cb_stage, 1, 1, 3, LC_CB_COUNTER_TYPE_STEPS, cb_arg); if ((err = ReadRam(0, 1, data))) { debug("Failed to from RAM 0"); return LC_ERROR_WRITE; } + if (cb) + cb(cb_stage, 2, 2, 3, LC_CB_COUNTER_TYPE_STEPS, cb_arg); if (data[0] != 2) { printf("byte is %d\n",data[0]); debug("Finalize byte didn't match"); return LC_ERROR_VERIFY; } } + if (cb) + cb(cb_stage, 3, 3, 3, LC_CB_COUNTER_TYPE_STEPS, cb_arg); return 0; } |