[concordance-commit] concordance/libconcord Makefile.am, 1.11.2.6, 1.11.2.7 lc_internal.h, 1.2.2.2,
Brought to you by:
jaymzh,
kevin_timmerman
From: Phil D. <ja...@us...> - 2013-04-03 06:13:58
|
Update of /cvsroot/concordance/concordance/libconcord In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv1137/libconcord Modified Files: Tag: zwave_work_branch Makefile.am lc_internal.h libconcord.cpp operationfile.cpp remote.cpp remote.h remote_info.h remote_z.cpp web.cpp web.h Log Message: From: Scott Talbert <sw...@te...> Initial support for Harmony 300 in libconcord. Added a new remote type, MH (MyHarmony, after the alternate web site used). Modified UpdateConfig method to allow the XML file to be passed in - MH remotes need some information from the XML in order to perform a configuration update. Added some XML parsing methods to extract this information. GetIdentity, UpdateConfiguration, LearnIR, and Reset operations are supported. Signed-off-by: Scott Talbert <sw...@te...> Signed-off-by: Phil Dibowitz <ph...@ip...> Index: operationfile.cpp =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/Attic/operationfile.cpp,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -d -r1.1.2.4 -r1.1.2.5 --- operationfile.cpp 12 Jan 2013 23:54:55 -0000 1.1.2.4 +++ operationfile.cpp 3 Apr 2013 06:13:55 -0000 1.1.2.5 @@ -97,7 +97,8 @@ ZZIP_DIRENT dirent; while (zzip_dir_read(dir, &dirent)) { ZZIP_FILE *fh = zzip_file_open(dir, dirent.d_name, 0); - if (strcmp(dirent.d_name, "Data.xml") == 0) { + if ((strcmp(dirent.d_name, "Data.xml") == 0) || + (strcmp(dirent.d_name, "Description.xml") == 0)) { debug("Internal file is %s", dirent.d_name); debug("Size is %d", dirent.st_size); xml_size = dirent.st_size; Index: lc_internal.h =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/lc_internal.h,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -u -d -r1.2.2.2 -r1.2.2.3 --- lc_internal.h 22 Mar 2012 08:50:20 -0000 1.2.2.2 +++ lc_internal.h 3 Apr 2013 06:13:55 -0000 1.2.2.3 @@ -60,5 +60,6 @@ /* NOTE: 1 for yes, 0 for no, unlike some other functions. */ int is_z_remote(); int is_usbnet_remote(); +int is_mh_remote(); #endif // ifndef LC_INTERNAL_H Index: libconcord.cpp =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/libconcord.cpp,v retrieving revision 1.42.2.26 retrieving revision 1.42.2.27 diff -u -d -r1.42.2.26 -r1.42.2.27 --- libconcord.cpp 29 Mar 2013 20:44:01 -0000 1.42.2.26 +++ libconcord.cpp 3 Apr 2013 06:13:55 -0000 1.42.2.27 @@ -220,6 +220,22 @@ return rmt->IsUSBNet() ? 1 : 0; } +int is_mh_remote() +{ + return rmt->IsMHRemote() ? 1 : 0; +} + +int is_mh_pid(unsigned int pid) +{ + switch (pid) { + case 0xC124: /* Harmony 300 */ + case 0xC125: /* Harmony 200 */ + return 1; + default: + return 0; + } +} + int get_time_second() { return rtime.second; @@ -634,7 +650,7 @@ uint32_t *base_stages; int num_base_stages; - if (is_z_remote()) { + if (is_z_remote() || is_mh_remote()) { base_stages = (uint32_t*)update_configuration_zwave_mh_stages; num_base_stages = update_configuration_zwave_mh_num_stages; } else { @@ -724,6 +740,8 @@ hid_info.pid <= ZWAVE_HID_PID_MAX) { // 890, Monstor, etc. rmt = new CRemoteZ_HID; + } else if (is_mh_pid(hid_info.pid)) { + rmt = new CRemoteMH; } else { rmt = new CRemote; } @@ -1006,9 +1024,10 @@ cb_arg = (void *)true; } - if (is_z_remote()) { + if (is_z_remote() || is_mh_remote()) { if ((err = rmt->UpdateConfig(of->GetDataSize(), of->GetData(), - cb, cb_arg, cb_stage))) + cb, cb_arg, cb_stage, of->GetXmlSize(), + of->GetXml()))) return LC_ERROR_WRITE; } else { if ((err = rmt->WriteFlash(ri.arch->config_base, @@ -1149,6 +1168,17 @@ return 0; } +int _update_configuration_mh(lc_callback cb, void *cb_arg) +{ + int err; + + if ((err = _write_config_to_remote(cb, cb_arg, 0))) { + return err; + } + + return 0; +} + int _update_configuration_hid(lc_callback cb, void *cb_arg) { int err; int cb_count = 0; @@ -1197,6 +1227,8 @@ if (is_z_remote()) { err = _update_configuration_zwave(cb, cb_arg); + } else if (is_mh_remote()) { + err = _update_configuration_mh(cb, cb_arg); } else { err = _update_configuration_hid(cb, cb_arg); } Index: remote.h =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/remote.h,v retrieving revision 1.20.2.12 retrieving revision 1.20.2.13 diff -u -d -r1.20.2.12 -r1.20.2.13 --- remote.h 29 Mar 2013 19:47:17 -0000 1.20.2.12 +++ remote.h 3 Apr 2013 06:13:55 -0000 1.20.2.13 @@ -151,6 +151,8 @@ void setup_ri_pointers(TRemoteInfo &ri); void make_serial(uint8_t *ser, TRemoteInfo &ri); +int LearnIRInnerLoop(uint32_t *freq, uint32_t **ir_signal, + uint32_t *ir_signal_length, uint8_t seq); class CRemoteBase // Base class for all remotes { @@ -185,7 +187,8 @@ void *cb_arg=NULL, uint32_t cb_stage=0)=0; virtual int UpdateConfig(const uint32_t len, const uint8_t *wr, lc_callback cb, void *cb_arg, - uint32_t cb_stage)=0; + uint32_t cb_stage, uint32_t xml_size=0, + uint8_t *xml=NULL)=0; virtual int GetTime(const TRemoteInfo &ri, THarmonyTime &ht)=0; virtual int SetTime(const TRemoteInfo &ri, const THarmonyTime &ht, lc_callback cb=NULL, void *cb_arg=NULL, @@ -195,6 +198,7 @@ void *cb_arg=NULL, uint32_t cb_stage=0)=0; virtual int IsZRemote()=0; virtual int IsUSBNet()=0; + virtual int IsMHRemote()=0; }; class CRemote : public CRemoteBase // All non-Z-Wave remotes @@ -238,7 +242,8 @@ void *cb_arg=NULL, uint32_t cb_stage=0); virtual int UpdateConfig(const uint32_t len, const uint8_t *wr, lc_callback cb, void *cb_arg, - uint32_t cb_stage=0) {}; + uint32_t cb_stage=0, uint32_t xml_size=0, + uint8_t *xml=NULL) {}; int GetTime(const TRemoteInfo &ri, THarmonyTime &ht); int SetTime(const TRemoteInfo &ri, const THarmonyTime &ht, @@ -249,6 +254,7 @@ void *cb_arg=NULL, uint32_t cb_stage=0); int IsZRemote() {return false;} int IsUSBNet() {return false;} + int IsMHRemote() {return false;} }; // Base class for all Z-Wave remotes @@ -304,6 +310,7 @@ uint32_t *ir_signal_length, lc_callback cb=NULL, void *cb_arg=NULL, uint32_t cb_stage=0); int IsZRemote() {return true;} + int IsMHRemote() {return false;} }; // 890, 890Pro, AVL-300, RF Extender @@ -333,7 +340,8 @@ CRemoteZ_HID() {}; virtual ~CRemoteZ_HID() {}; int UpdateConfig(const uint32_t len, const uint8_t *wr, - lc_callback cb, void *cb_arg, uint32_t cb_stage); + lc_callback cb, void *cb_arg, uint32_t cb_stage, + uint32_t xml_size=0, uint8_t *xml=NULL); 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); @@ -359,11 +367,70 @@ CRemoteZ_USBNET() {}; virtual ~CRemoteZ_USBNET() {}; int UpdateConfig(const uint32_t len, const uint8_t *wr, - lc_callback cb, void *cb_arg, uint32_t cb_stage); + lc_callback cb, void *cb_arg, uint32_t cb_stage, + uint32_t xml_size=0, uint8_t *xml=NULL); 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); int IsUSBNet() {return true;} }; +class CRemoteMH : public CRemoteBase // "My Harmony" remotes +{ +private: + int ReadMiscByte(uint8_t addr, uint32_t len, uint8_t kind, + uint8_t *rd); + int ReadMiscWord(uint16_t addr, uint32_t len, uint8_t kind, + uint16_t *rd); + int WriteMiscByte(uint8_t addr, uint32_t len, uint8_t kind, + uint8_t *wr); + int WriteMiscWord(uint16_t addr, uint32_t len, uint8_t kind, + uint16_t *wr); + +public: + CRemoteMH() {}; + virtual ~CRemoteMH() {}; + int Reset(uint8_t kind); + int GetIdentity(struct TRemoteInfo &ri, struct THIDINFO &hid, + lc_callback cb=NULL, void *cb_arg=NULL, uint32_t cb_stage=0); + + 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 InvalidateFlash(lc_callback cb=NULL, void *cb_arg=NULL, + uint32_t cb_stage=0); + int EraseFlash(uint32_t addr, uint32_t len, const TRemoteInfo &ri, + lc_callback cb=NULL, void *cb_arg=NULL, uint32_t cb_stage=0); + int WriteFlash(uint32_t addr, const uint32_t len, const uint8_t *wr, + unsigned int protocol, lc_callback cb=NULL, void *cb_arg=NULL, + uint32_t cb_stage=0); + 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, lc_callback cb=NULL, + void *cb_arg=NULL, uint32_t cb_stage=0); + int FinishFirmware(const TRemoteInfo &ri, lc_callback cb=NULL, + void *cb_arg=NULL, uint32_t cb_stage=0); + int PrepConfig(const TRemoteInfo &ri, lc_callback cb=NULL, + void *cb_arg=NULL, uint32_t cb_stage=0); + int FinishConfig(const TRemoteInfo &ri, lc_callback cb=NULL, + void *cb_arg=NULL, uint32_t cb_stage=0); + virtual int UpdateConfig(const uint32_t len, + const uint8_t *wr, lc_callback cb, void *cb_arg, + uint32_t cb_stage=0) {}; + virtual int UpdateConfig(const uint32_t len, const uint8_t *wr, + lc_callback cb, void *cb_arg, uint32_t cb_stage=0, + uint32_t xml_size=0, uint8_t *xml=NULL); + + 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); + + int LearnIR(uint32_t *freq, uint32_t **ir_signal, + uint32_t *ir_signal_length, lc_callback cb=NULL, + void *cb_arg=NULL, uint32_t cb_stage=0); + int IsZRemote() {return false;} + int IsUSBNet() {return false;} + int IsMHRemote() {return true;} +}; + #endif //REMOTE_H Index: Makefile.am =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/Makefile.am,v retrieving revision 1.11.2.6 retrieving revision 1.11.2.7 diff -u -d -r1.11.2.6 -r1.11.2.7 --- Makefile.am 29 Mar 2012 03:15:05 -0000 1.11.2.6 +++ Makefile.am 3 Apr 2013 06:13:55 -0000 1.11.2.7 @@ -4,7 +4,7 @@ libconcord_la_SOURCES = remote.cpp remote_z.cpp libconcord.cpp binaryfile.cpp \ web.cpp libusb/libusbhid.cpp usblan.cpp binaryfile.h hid.h protocol_z.h \ remote_info.h web.h protocol.h remote.h usblan.h xml_headers.h \ - operationfile.cpp + operationfile.cpp remote_mh.cpp include_HEADERS = libconcord.h libconcord_la_LDFLAGS = -version-info 2:0:0 -lusb -lzzip Index: web.cpp =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/web.cpp,v retrieving revision 1.27.2.4 retrieving revision 1.27.2.5 diff -u -d -r1.27.2.4 -r1.27.2.5 --- web.cpp 22 Mar 2012 08:50:20 -0000 1.27.2.4 +++ web.cpp 3 Apr 2013 06:13:56 -0000 1.27.2.5 @@ -154,9 +154,21 @@ return 0; } +// If find_attributes is set to true, finds an XML tag with attributes and will +// return the attributes. For example, if you have: <ELEMENT A="B" C="D"/> and +// you search for a tag called "ELEMENT" the function will return A="B" C="D". int GetTag(const char *find, uint8_t* data, uint32_t data_size, - uint8_t *&found, string *s=NULL) + uint8_t *&found, string *s=NULL, bool find_attributes=false) { + char tag_name_end = '>'; + char tag_start = '<'; + char tag_end = '>'; + if (find_attributes) { + tag_name_end = ' '; + tag_start = '/'; + tag_end = '/'; + } + const size_t find_len = strlen(find); uint8_t * search = data; @@ -181,7 +193,7 @@ // Point past <, at tag name search++; // Check to see if this is the tag we want - if (search[find_len] == '>' + if (search[find_len] == tag_name_end && !strnicmp(find, reinterpret_cast<const char*>(search), find_len)) { // Point past >, at tag content search += find_len + 1; @@ -198,7 +210,7 @@ * Here we keep adding chars until the next tag * which, in theory, should be the end-tag. */ - while (*search && *search != '<') { + while (*search && *search != tag_start) { *s += *search; search++; if (search >= data + data_size) { @@ -211,7 +223,7 @@ // Loop searching for end of tag character while (1) { - if (*search == '>') { + if (*search == tag_end) { break; } if (search >= data + data_size) { @@ -222,6 +234,31 @@ } } +// Given a set of XML attributes, e.g., ATTR1="VALUE1" ATTR2="VALUE2", this +// function will find a given attribute and return its value. +int GetAttribute(const char *find, string data, string *result) +{ + if ((find == NULL) || (result == NULL)) + return -1; + + size_t start_pos; + size_t end_pos; + string to_find = find; + to_find.append("=\""); + + start_pos = data.find(to_find); + if (start_pos == string::npos) + return -1; + start_pos += to_find.length(); + + end_pos = data.find("\"", start_pos); + if (end_pos == string::npos) + return -1; + + *result = data.substr(start_pos, end_pos - start_pos); + return 0; +} + int encode_ir_signal(uint32_t carrier_clock, uint32_t *ir_signal, uint32_t ir_signal_length, string *learn_seq) Index: web.h =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/web.h,v retrieving revision 1.11.2.2 retrieving revision 1.11.2.3 diff -u -d -r1.11.2.2 -r1.11.2.3 --- web.h 13 Sep 2010 00:02:25 -0000 1.11.2.2 +++ web.h 3 Apr 2013 06:13:56 -0000 1.11.2.3 @@ -26,7 +26,9 @@ #include "remote.h" int GetTag(const char *find, uint8_t* data, uint32_t data_size, - uint8_t *&found, string *s = NULL); + uint8_t *&found, string *s = NULL, bool find_attributes = false); + +int GetAttribute(const char *find, string data, string *result); int encode_ir_signal(uint32_t carrier_clock, uint32_t *ir_signal, uint32_t ir_signal_length, Index: remote_info.h =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/remote_info.h,v retrieving revision 1.12.2.6 retrieving revision 1.12.2.7 diff -u -d -r1.12.2.6 -r1.12.2.7 --- remote_info.h 29 Mar 2013 20:46:09 -0000 1.12.2.6 +++ remote_info.h 3 Apr 2013 06:13:55 -0000 1.12.2.7 @@ -97,7 +97,34 @@ { MFG_HAR, "Harmony 1100", NULL }, { MFG_UNK, "Unknown", NULL }, { MFG_UNK, "Unknown", NULL }, - { MFG_HAR, "Harmony 700", "Molson" } + { MFG_HAR, "Harmony 700", "Molson" }, + { MFG_UNK, "Unknown", NULL }, + { MFG_UNK, "Unknown", NULL }, + { MFG_HAR, "Harmony 700i", NULL }, + { MFG_UNK, "Unknown", NULL }, +// 70 + { MFG_HAR, "Harmony 600", NULL }, + { MFG_HAR, "Harmony 650", NULL }, + { MFG_HAR, "Harmony 600i", NULL }, + { MFG_HAR, "Harmony 650i", NULL }, + { MFG_UNK, "Unknown", NULL }, + { MFG_UNK, "Unknown", NULL }, + { MFG_UNK, "Unknown", NULL }, + { MFG_HAR, "Harmony 300", NULL }, + { MFG_HAR, "Harmony 300i", NULL }, + { MFG_HAR, "Harmony 200", NULL }, +// 80 + { MFG_HAR, "Harmony 200i", NULL }, + { MFG_HAR, "Harmony Link", NULL }, + { MFG_HAR, "Harmony Link (EMEA)", NULL }, + { MFG_UNK, "Unknown", NULL }, + { MFG_UNK, "Unknown", NULL }, + { MFG_UNK, "Unknown", NULL }, + { MFG_UNK, "Unknown", NULL }, + { MFG_UNK, "Unknown", NULL }, + { MFG_UNK, "Unknown", NULL }, + { MFG_UNK, "Unknown", NULL } +// 90 }; static const unsigned int max_model=sizeof(ModelList)/sizeof(TModel)-1; @@ -449,6 +476,24 @@ 0, // ram_size 0, // eeprom_size "", // usb + }, + /* arch 16: 300 */ + { + 0, // serial_location + 0, // serial_address + 0, // flash_base + 0, // firmware_base + 0, // config_base + 0, // firmware_update_base + 0, // firmware_4847_offset + 0x4D505347, // cookie + 0, // cookie_size + 0, // end_vector + "", // micro + 0, // flash_size + 0, // ram_size + 0, // eeprom_size + "", // usb } }; Index: remote_z.cpp =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/remote_z.cpp,v retrieving revision 1.25.2.18 retrieving revision 1.25.2.19 diff -u -d -r1.25.2.18 -r1.25.2.19 --- remote_z.cpp 29 Mar 2013 19:47:17 -0000 1.25.2.18 +++ remote_z.cpp 3 Apr 2013 06:13:56 -0000 1.25.2.19 @@ -381,7 +381,8 @@ } int CRemoteZ_USBNET::UpdateConfig(const uint32_t len, const uint8_t *wr, - lc_callback cb, void *cb_arg, uint32_t cb_stage) + lc_callback cb, void *cb_arg, uint32_t cb_stage, uint32_t xml_size, + uint8_t *xml) { int err = 0; int cb_count = 0; @@ -1248,7 +1249,8 @@ } int CRemoteZ_HID::UpdateConfig(const uint32_t len, const uint8_t *wr, - lc_callback cb, void *cb_arg, uint32_t cb_stage) + lc_callback cb, void *cb_arg, uint32_t cb_stage, uint32_t xml_size, + uint8_t *xml) { int err = 0; int cb_count = 0; Index: remote.cpp =================================================================== RCS file: /cvsroot/concordance/concordance/libconcord/remote.cpp,v retrieving revision 1.40.2.11 retrieving revision 1.40.2.12 diff -u -d -r1.40.2.11 -r1.40.2.12 --- remote.cpp 29 Jan 2013 07:22:39 -0000 1.40.2.11 +++ remote.cpp 3 Apr 2013 06:13:55 -0000 1.40.2.12 @@ -55,7 +55,7 @@ { char x[48]; // usbnet remotes seem to use a more normal byte ordering for serial #'s - if (is_usbnet_remote()) { + if (is_usbnet_remote() || is_mh_remote()) { sprintf(x, "{%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X}", in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7], @@ -960,26 +960,14 @@ return 0; } - -int CRemote::LearnIR(uint32_t *freq, uint32_t **ir_signal, - uint32_t *ir_signal_length, lc_callback cb, void *cb_arg, - uint32_t cb_stage) +// This section of IR learning code is common between pure HID and MH remotes. +// 'seq' is the starting sequence number, which differs between HID and MH. +int LearnIRInnerLoop(uint32_t *freq, uint32_t **ir_signal, + uint32_t *ir_signal_length, uint8_t seq) { int err = 0; uint8_t rsp[68]; - static const uint8_t start_ir_learn[64] = { COMMAND_START_IRCAP }; - static const uint8_t stop_ir_learn[64] = { COMMAND_STOP_IRCAP }; - - if (cb) { - cb(cb_stage, 0, 0, 1, LC_CB_COUNTER_TYPE_STEPS, cb_arg, NULL); - } - - if (HID_WriteReport(start_ir_learn) != 0) { - return LC_ERROR_WRITE; - } - - uint8_t seq = 0; // Count of how man IR words we've received. uint32_t ir_word = 0; // Time button is on and off @@ -1045,6 +1033,29 @@ } } + return err; +} + +int CRemote::LearnIR(uint32_t *freq, uint32_t **ir_signal, + uint32_t *ir_signal_length, lc_callback cb, void *cb_arg, + uint32_t cb_stage) +{ + int err = 0; + uint8_t rsp[68]; + + static const uint8_t start_ir_learn[64] = { COMMAND_START_IRCAP }; + static const uint8_t stop_ir_learn[64] = { COMMAND_STOP_IRCAP }; + + if (cb) { + cb(cb_stage, 0, 0, 1, LC_CB_COUNTER_TYPE_STEPS, cb_arg, NULL); + } + + if (HID_WriteReport(start_ir_learn) != 0) { + return LC_ERROR_WRITE; + } + + err = LearnIRInnerLoop(freq, ir_signal, ir_signal_length, 0); + if (HID_WriteReport(stop_ir_learn) != 0) { err = LC_ERROR_WRITE; } |