On Sat, 12 Jan 2013, Phil Dibowitz wrote:
Also, looking in my 'pending patches' directory, there are still a couple
there that haven't been merged: the Harmony 300 patch (v4) and the patch
to do config dumping for zwave (v6). Although, these probably aren't
super critical to get into a release, although the 300 support would be
nice.
Oh... I'll look for those, sorry.
Here's the config dumping patch. The Harmony 300 one is too big to email
for the mailing list, so it's here:
https://sourceforge.net/tracker/?func=detail&aid=3559622&group_id=201579&atid=978130
Scott
Implemented config dumping for zwave-hid remotes. Implemented the ReadRegion
function for zwave-hid, based on the usbnet version and the zwave-hid
UpdateConfig function.
Signed-off-by: Scott Talbert <s...@techie.net>
Index: libconcord/libconcord.cpp
===================================================================
RCS file: /cvsroot/concordance/concordance/libconcord/libconcord.cpp,v
retrieving revision 1.42.2.22
diff -u -p -r1.42.2.22 libconcord.cpp
--- libconcord/libconcord.cpp 15 Jul 2012 07:17:08 -0000 1.42.2.22
+++ libconcord/libconcord.cpp 23 Oct 2012 00:00:49 -0000
@@ -564,7 +564,7 @@ int _fix_magic_bytes(uint8_t *in, uint32
*/
int is_config_dump_supported()
{
- return (is_z_remote() && !is_usbnet_remote()) ? LC_ERROR_UNSUPP: 0;
+ return 0;
}
int is_config_update_supported()
@@ -871,6 +871,16 @@ int read_config_from_remote(uint8_t **ou
cb_arg = (void *)true;
}
+ // For zwave-hid remotes, need to read the config once to get the size
+ // For usbnet we do this in GetIdentity, but for hid it takes too long
+ if (is_z_remote() && !is_usbnet_remote()) {
+ if (err = ((CRemoteZ_HID*)rmt)->ReadRegion(REGION_USER_CONFIG,
+ ri.config_bytes_used, NULL, cb,
+ cb_arg, LC_CB_STAGE_READ_CONFIG)) {
+ return err;
+ }
+ }
+
*size = ri.config_bytes_used;
*out = new uint8_t[*size];
Index: libconcord/remote.h
===================================================================
RCS file: /cvsroot/concordance/concordance/libconcord/remote.h,v
retrieving revision 1.20.2.11
diff -u -p -r1.20.2.11 remote.h
--- libconcord/remote.h 4 Jun 2012 07:09:49 -0000 1.20.2.11
+++ libconcord/remote.h 23 Oct 2012 00:00:49 -0000
@@ -326,8 +326,6 @@ protected:
virtual int ParseParams(uint32_t len, uint8_t *data,
TParamList &pl);
virtual uint16_t GetWord(uint8_t *x) { return x[1]<<8 | x[0]; };
- virtual int ReadRegion(uint8_t region, uint32_t &len, uint8_t *rd,
- lc_callback cb, void *cb_arg, uint32_t cb_stage) {return 0;};
public:
CRemoteZ_HID() {};
@@ -335,6 +333,8 @@ public:
int UpdateConfig(const uint32_t len, const uint8_t *wr,
lc_callback cb, void *cb_arg, uint32_t cb_stage);
int IsUSBNet() {return false;}
+ virtual int ReadRegion(uint8_t region, uint32_t &len, uint8_t *rd,
+ lc_callback cb, void *cb_arg, uint32_t cb_stage);
};
// 1000, 1000i
@@ -358,9 +358,6 @@ public:
virtual ~CRemoteZ_USBNET() {};
int UpdateConfig(const uint32_t len, const uint8_t *wr,
lc_callback cb, void *cb_arg, uint32_t cb_stage);
- int ReadFlash(uint32_t addr, const uint32_t len, uint8_t *rd,
- unsigned int protocol, bool verify=false,
- lc_callback cb=NULL, void *cb_arg=NULL, uint32_t cb_stage=0);
int GetTime(const TRemoteInfo &ri, THarmonyTime &ht);
int SetTime(const TRemoteInfo &ri, const THarmonyTime &ht,
lc_callback cb=NULL, void *cb_arg=NULL, uint32_t cb_stage=0);
Index: libconcord/remote_info.h
===================================================================
RCS file: /cvsroot/concordance/concordance/libconcord/remote_info.h,v
retrieving revision 1.12.2.4
diff -u -p -r1.12.2.4 remote_info.h
--- libconcord/remote_info.h 4 Jun 2012 07:09:49 -0000 1.12.2.4
+++ libconcord/remote_info.h 23 Oct 2012 00:00:49 -0000
@@ -348,7 +348,7 @@ static const TArchInfo ArchList[]={
0x000110, // serial_address
0x000000, // flash_base
0x010000, // firmware_base
- 0x020000, // config_base
+ REGION_USER_CONFIG, // config_base
0, // firmware_update_base
0, // firmware_4847_offset
0x1, /* hack */ // cookie
Index: libconcord/remote_z.cpp
===================================================================
RCS file: /cvsroot/concordance/concordance/libconcord/remote_z.cpp,v
retrieving revision 1.25.2.16
diff -u -p -r1.25.2.16 remote_z.cpp
--- libconcord/remote_z.cpp 4 Jun 2012 07:09:49 -0000 1.25.2.16
+++ libconcord/remote_z.cpp 23 Oct 2012 00:00:49 -0000
@@ -207,13 +207,17 @@ int CRemoteZ_HID::TCP_Read(uint8_t &stat
if (pkt[0] < 3) {
return LC_ERROR;
}
- len = pkt[0] - 4;
+ /*
+ * Subtract both TCP (4) and UDP (2) headers from pkt[0] which is
+ * len - 1. (len = pkt[0] + 1 - 6)
+ */
+ len = pkt[0] - 5;
last_seq = pkt[2];
last_ack = pkt[3];
- last_payload_bytes = len + 1; // tcp payload size
+ last_payload_bytes = len + 2; // tcp payload size
//if(!len) return 0;
//memcpy(data, pkt + 6, len);
- memcpy(data, pkt + 1, len+3);
+ memcpy(data, pkt + 1, len+5); // include headers, minus the size
return 0;
}
@@ -577,14 +581,6 @@ int CRemoteZ_USBNET::SetTime(const TRemo
return 0;
}
-int CRemoteZ_USBNET::ReadFlash(uint32_t addr, const uint32_t len, uint8_t *rd,
- unsigned int protocol, bool verify, lc_callback cb,
- void *cb_arg, uint32_t cb_stage)
-{
- uint32_t tmp;
- return ReadRegion(addr, tmp, rd, cb, cb_arg, cb_stage);
-}
-
int CRemoteZ_USBNET::ReadRegion(uint8_t region, uint32_t &rgn_len, uint8_t *rd,
lc_callback cb, void *cb_arg, uint32_t cb_stage)
{
@@ -909,6 +905,163 @@ int CRemoteZ_Base::ReadFlash(uint32_t ad
unsigned int protocol, bool verify, lc_callback cb,
void *cb_arg, uint32_t cb_stage)
{
+ uint32_t tmp;
+ return ReadRegion(addr, tmp, rd, cb, cb_arg, cb_stage);
+}
+
+// Searches for the "end of file" sequence in a set of two packets. Returns
+// the number of bytes in the second packet up to and including the sequence.
+// Returns 0 if not found. Parameters point to the data section of the
packets.
+// Note for the first packet, only the last 3 bytes are provided.
+int FindEndSeq(uint8_t *pkt_1, uint8_t *pkt_2)
+{
+ uint8_t end_seq[4] = { 0x44, 0x4B, 0x44, 0x4B }; // end of file sequence
+ uint8_t tmp[57]; // 3 bytes from the 1st packet, 54 bytes from the 2nd
+ memcpy(&tmp, pkt_1, 3);
+ memcpy(&tmp[3], pkt_2, 54);
+ for (int i=0; i<54; i++) {
+ if (memcmp(&end_seq, &tmp[i], 4) == 0) {
+ return i + 1;
+ }
+ }
+ return 0;
+}
+
+int CRemoteZ_HID::ReadRegion(uint8_t region, uint32_t &rgn_len, uint8_t *rd,
+ lc_callback cb, void *cb_arg, uint32_t cb_stage)
+{
+ int err = 0;
+ int cb_count = 0;
+ uint8_t rsp[60];
+ unsigned int rlen;
+ uint8_t status;
+ CRemoteZ_Base::TParamList pl;
+
+ /* Start a TCP transfer */
+ if ((err = Write(TYPE_REQUEST, COMMAND_INITIATE_UPDATE_TCP_CHANNEL))) {
+ debug("Failed to write to remote");
+ return LC_ERROR_WRITE;
+ }
+
+ /* Make sure the remote is ready to start the TCP transfer */
+ if ((err = Read(status, rlen, rsp))) {
+ debug("Failed to read from remote");
+ return LC_ERROR_READ;
+ }
+
+ if (rsp[1] != TYPE_RESPONSE || rsp[2] !=
+ COMMAND_INITIATE_UPDATE_TCP_CHANNEL) {
+ return LC_ERROR;
+ }
+
+ /* Look for a SYN packet */
+ debug("Looking for syn");
+ if ((err = TCP_Read(status, rlen, rsp))) {
+ debug("Failed to read syn from remote");
+ return LC_ERROR_READ;
+ }
+
+ if (rsp[0] != TYPE_TCP_SYN) {
+ debug("Not a SYN packet!");
+ return LC_ERROR;
+ }
+
+ /* ACK it with a command to read a region */
+ debug("READ_REGION");
+ // 1 parameters, 1 byte, region to read.
+ uint8_t cmd[60] = { region };
+ if ((err = TCP_Write(TYPE_REQUEST, COMMAND_READ_REGION, 1, cmd))) {
+ debug("Failed to write to remote");
+ return LC_ERROR_WRITE;
+ }
+ if ((err = TCP_Read(status, rlen, rsp))) {
+ debug("Failed to read to remote");
+ return LC_ERROR_READ;
+ }
+ if (rsp[0] != TYPE_TCP_ACK || rsp[3] != TYPE_RESPONSE ||
+ rsp[4] != COMMAND_READ_REGION) {
+ debug("Incorrect response type from remote");
+ return LC_ERROR_INVALID_DATA_FROM_REMOTE;
+ }
+
+ rgn_len = 0;
+
+ debug("READ_REGION_DATA");
+ int data_read = 0;
+ uint8_t *rd_ptr = rd;
+ cmd[0] = region;
+ int eof_found = 0;
+ uint8_t prev_pkt_tail[3] = { 0x00, 0x00, 0x00 };
+
+ while (1) {
+ if ((err = TCP_Write(TYPE_REQUEST, COMMAND_READ_REGION_DATA, 1,
+ cmd))) {
+ debug("Failed to write to remote");
+ return LC_ERROR_WRITE;
+ }
+ if ((err = TCP_Read(status, rlen, rsp))) {
+ debug("Failed to read to remote");
+ return LC_ERROR_READ;
+ }
+ if (rsp[0] != TYPE_TCP_ACK || rsp[3] != TYPE_RESPONSE ||
+ ((rsp[4] != COMMAND_READ_REGION_DATA) &&
+ (rsp[4] != COMMAND_READ_REGION_DONE))) {
+ debug("Incorrect response type from remote");
+ return LC_ERROR_INVALID_DATA_FROM_REMOTE;
+ }
+ if (rsp[4] == COMMAND_READ_REGION_DONE) {
+ break;
+ }
+ data_read += rlen;
+
+ if (!eof_found) {
+ eof_found = FindEndSeq(prev_pkt_tail, &rsp[5]);
+ if (eof_found) {
+ rlen = eof_found;
+ }
+ rgn_len += rlen;
+ memcpy(&prev_pkt_tail, &rsp[56], 3);
+
+ if (rd) {
+ memcpy(rd_ptr, &rsp[5], rlen);
+ rd_ptr += rlen;
+ }
+ }
+
+ debug("DATA %d, read %d bytes, %d bytes total", cb_count,
+ rlen, data_read);
+
+ if (cb) {
+ cb(cb_stage, cb_count++, data_read,
+ data_read+1, LC_CB_COUNTER_TYPE_BYTES, cb_arg);
+ }
+ }
+
+ debug("FIN-ACK");
+ if ((err = TCP_Ack(false, true))) {
+ debug("Failed to send fin-ack");
+ return LC_ERROR_WRITE;
+ }
+
+ if ((err = TCP_Read(status, rlen, rsp))) {
+ debug("Failed to read from remote");
+ return LC_ERROR_READ;
+ }
+
+ /* Make sure we got an ack */
+ if (rsp[0] != (TYPE_TCP_ACK | TYPE_TCP_FIN)) {
+ debug("Failed to read finish-update ack");
+ return LC_ERROR;
+ }
+
+ if ((err = TCP_Ack(true, false))) {
+ debug("Failed to ack the ack of our fin-ack");
+ return LC_ERROR_WRITE;
+ }
+
+ /* Return TCP state to initial conditions */
+ SYN_ACKED = false;
+
return 0;
}
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
_______________________________________________
concordance-devel mailing list
concordance-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/concordance-devel