+ /* Minimally handle DualCopro-Firmware */
+ if (dst == HMUARTLGW_DUAL) {
+ if ((buf_len == 14) && (buf[0] == 0x00) && !strncmp(((char*)buf)+1, "DualCoPro_App", 13)) {
+ rdata->state = HMUARTLGW_DUAL_APPLICATION;
+ return 1;
+ }
+
+ switch (rdata->state) {
+ case HMUARTLGW_QUERY_APPSTATE:
+ if ((buf[0] == 0x05) && (buf[1] == 0x01)) {
+ if (!strncmp(((char*)buf)+2, "DualCoPro_App", 13)) {
+ rdata->state = HMUARTLGW_DUAL_APPLICATION;
+ return 1;
+ }
+ }
+ break;
+ case HMUARTLGW_ENTER_BOOTLOADER:
+ if ((buf_len == 2) &&
+ (buf[0] == 0x05) &&
+ (buf[1] == 0x01)) {
+ rdata->state = HMUARTLGW_ENTER_BOOTLOADER_ACK;
+ return 1;
+ }
+ break;
+ default:
+ fprintf(stderr, "Don't know how to handle this state (%d) for unsupported firmware, giving up!\n", rdata->state);
+ exit(1);
+ break;
+ }
+
+ return 0;
+ }
+
+ /* Re-send commands for DualCopro Firmware */
+ if (dst == HMUARTLGW_DUAL_ERR) {
+ uint8_t buf[128] = { 0 };
+
+ switch(rdata->state) {
+ case HMUARTLGW_QUERY_APPSTATE:
+ if (debug) {
+ printf("Re-sending appstate-query for new firmare\n");
+ }
+
+ buf[0] = HMUARTLGW_DUAL_GET_APP;
+ hmuartlgw_send(rdata->dev, buf, 1, HMUARTLGW_DUAL);
+ break;
+ case HMUARTLGW_ENTER_BOOTLOADER:
+ if (debug) {
+ printf("Re-sending switch to bootloader for new firmare\n");
+ }
+
+ buf[0] = HMUARTLGW_DUAL_CHANGE_APP;
+ hmuartlgw_send(rdata->dev, buf, 1, HMUARTLGW_DUAL);
+ break;
+ default:
+ fprintf(stderr, "Don't know how to handle this error-state (%d) for unsupported firmware, giving up!\n", rdata->state);
+ exit(1);
+ break;
+ }
+
+ return 0;
+ }
+