#define HMUARTLGW_INIT_TIMEOUT 10000
-#define HMUARTLGW_SETTLE_TIME 2
+#define HMUARTLGW_SETTLE_TIME 1
static int debug = 0;
switch(rdata->state) {
case HMUARTLGW_QUERY_APPSTATE:
- if ((buf[0] == 0x04) && (buf[1] == 0x02)) {
+ if ((buf[0] == HMUARTLGW_OS_ACK) && (buf[1] == 0x02)) {
if (!strncmp(((char*)buf)+2, "Co_CPU_BL", 9)) {
rdata->state = HMUARTLGW_BOOTLOADER;
} else if (!strncmp(((char*)buf)+2, "Co_CPU_App", 10)) {
break;
case HMUARTLGW_ENTER_BOOTLOADER:
if ((buf_len == 2) &&
- (buf[0] == 0x04) &&
+ (buf[0] == HMUARTLGW_OS_ACK) &&
(buf[1] == 0x01)) {
rdata->state = HMUARTLGW_ENTER_BOOTLOADER_ACK;
}
break;
case HMUARTLGW_ENTER_APPLICATION:
if ((buf_len == 2) &&
- (buf[0] == 0x04) &&
+ (buf[0] == HMUARTLGW_OS_ACK) &&
(buf[1] == 0x01)) {
rdata->state = HMUARTLGW_ENTER_APPLICATION_ACK;
}
return 1;
}
-struct hmuartlgw_dev *hmuart_init(char *device, hmuartlgw_cb_fn cb, void *data)
+struct hmuartlgw_dev *hmuart_init(char *device, hmuartlgw_cb_fn cb, void *data, int app)
{
struct hmuartlgw_dev *dev = NULL;
struct termios oldtio, tio;
hmuartlgw_flush(dev);
- hmuartlgw_enter_app(dev);
+ if (app) {
+ hmuartlgw_enter_app(dev);
+ } else {
+ hmuartlgw_enter_bootloader(dev);
+ }
dev->cb = cb;
dev->cb_data = data;
int hmuartlgw_send(struct hmuartlgw_dev *dev, uint8_t *cmd, int cmdlen, enum hmuartlgw_dst dst)
{
static uint8_t cnt = 0;
- uint8_t frame[1024] = { 0 };
+ uint8_t frame[4096] = { 0 };
uint16_t crc;
frame[0] = 0xfd;
return -1;
}
- crc = crc16(dev->buf, dev->pos - 2);
- if ((((crc >> 8) & 0xff) == dev->buf[dev->pos - 2]) &&
- ((crc & 0xff) == dev->buf[dev->pos - 1])) {
-
+ crc = crc16(dev->buf, dev->pos);
+ if (crc == 0x0000) {
if (debug)
hexdump(dev->buf, dev->pos, "UARTLGW > ");