/* * lcmComm.c * * Created on: 2019年5月8日 * Author: foluswen */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /*標準輸入輸出定義*/ #include /*標準函數庫定義*/ #include /*Unix 標準函數定義*/ #include /*檔控制定義*/ #include /*PPSIX 終端控制定義*/ #include /*錯誤號定義*/ #include #include #include #include #include #include #include "lcmComm.h" #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0])) #define PASS 1 #define FAIL -1 #define YES 1 #define NO 0 SYS_FLAG sysFlag; //================================ // Basic routine //================================ void displayMessage(uint8_t *data, uint16_t len, uint8_t isRX) { uint8_t output[8192]; memset(output, 0x00, ARRAY_SIZE(output)); sprintf((char*)output, "%s", (isRX?"RX: ":"TX: ")); for(uint16_t idx = 0;idx>1) ^ 0xA001; else reg_crc=reg_crc>>1; } } return reg_crc; } int tranceive(int32_t fd, uint8_t *tx, uint16_t tx_len) { int result = FAIL; uint8_t rx[5]; uint8_t rx_len; uint16_t chksum; memset(rx, 0x00, ARRAY_SIZE(rx)); tcflush(fd,TCIOFLUSH); displayMessage(tx, tx_len, NO); if(write(fd, tx, tx_len) >= ARRAY_SIZE(tx)) { rx_len = read(fd, rx, ARRAY_SIZE(rx)); if(rx_len > 0) displayMessage(rx, rx_len, YES); else DEBUG_INFO("RX: NULL\n"); chksum=crc16(&rx[0], ARRAY_SIZE(rx)-2); if((rx_len >= 5) && (((chksum>>0)&0xff) == rx[3]) && (((chksum>>8)&0xff) == rx[4]) && (rx[1] == 0x00)) { result = PASS; } else { DEBUG_WARN("Serial command read fail, checksum: 0x%04x.\n", chksum); } } else { DEBUG_WARN("Serial command write fail.\n"); } return result; } //================================ // Application routine //================================ int8_t clearScreen(int32_t fd, uint8_t isPartial, uint16_t startX, uint16_t startY, uint16_t width, uint16_t height) { int8_t result = FAIL; uint8_t tx[(isPartial?10:12)]; uint16_t chksum; if(isPartial) { tx[0] = 0xa1; tx[1] = (startX>>0)&0xff; tx[2] = (startX>>8)&0xff; tx[3] = (startY>>0)&0xff; tx[4] = (startY>>8)&0xff; tx[5] = (width>>0)&0xff; tx[6] = (width>>8)&0xff; tx[7] = (height>>0)&0xff; tx[8] = (height>>8)&0xff; tx[9] = (isPartial?0x01:0x00); chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; } else { tx[0] = 0xa1; tx[1] = (startX>>0)&0xff; tx[2] = (startX>>8)&0xff; tx[3] = (startY>>0)&0xff; tx[4] = (startY>>8)&0xff; tx[5] = (width>>0)&0xff; tx[6] = (width>>8)&0xff; tx[7] = (height>>0)&0xff; tx[8] = (height>>8)&0xff; tx[9] = (isPartial?0x01:0x00); chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; } result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t setContrast(int32_t fd, uint8_t startBrightness, uint8_t stopBrightness, uint8_t interval) { int8_t result = FAIL; uint8_t tx[6]; uint16_t chksum; tx[0] = 0xa2; tx[1] = startBrightness; tx[2] = stopBrightness; tx[3] = interval; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t setPower(int32_t fd, uint8_t isOn) { int8_t result = FAIL; uint8_t tx[4]; uint16_t chksum; tx[0] = 0xa3; tx[1] = (isOn?0x01:0x00); chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t dispGraphic(int32_t fd, uint8_t isCover, uint16_t startX, uint16_t startY, uint8_t graphicID) { int8_t result = FAIL; uint8_t tx[10]; uint16_t chksum; tx[0] = 0xb1; tx[1] = (startX>>0)&0xff; tx[2] = (startX>>8)&0xff; tx[3] = (startY>>0)&0xff; tx[4] = (startY>>8)&0xff; tx[5] = (graphicID>>0)&0xff; tx[6] = (graphicID>>8)&0xff; tx[7] = (isCover?0x01:0x00); chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t dispGraphicConfig(int32_t fd, uint8_t areaId, uint8_t isCover, uint16_t startX, uint16_t startY, uint16_t endXX, uint16_t endY) { int8_t result = FAIL; uint8_t tx[29]; uint16_t chksum; tx[0] = 0xb4; tx[1] = 0xf3; tx[2] = (areaId>=19?19:areaId); tx[3] = (startX>>0)&0xff; tx[4] = (startX>>8)&0xff; tx[5] = (startY>>0)&0xff; tx[6] = (startY>>8)&0xff; tx[7] = (endXX>>0)&0xff; tx[8] = (endXX>>8)&0xff; tx[9] = (endY>>0)&0xff; tx[10] = (endY>>8)&0xff; tx[11] = 0x09; tx[12] = 0x24; tx[13] = 0xff; tx[14] = 0xff; tx[15] = 0xff; tx[16] = 0xff; tx[17] = 0x00; tx[18] = 0x00; tx[19] = 0x00; tx[20] = 0x00; tx[21] = 0x00; tx[22] = 0x00; tx[23] = 0x00; tx[24] = 0x00; tx[25] = 0x00; tx[26] = (isCover?0x01:0x00); chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); //usleep(30000); return result; } int8_t dispGraphicArea(int32_t fd, uint8_t areaId, uint8_t isCover, uint16_t startX, uint16_t startY, uint16_t endXX, uint16_t endY, uint8_t graphicID) { int8_t result = FAIL; uint8_t tx[31]; uint16_t chksum; tx[0] = 0xb4; tx[1] = 0xf2; tx[2] = (areaId>=19?19:areaId); tx[3] = (startX>>0)&0xff; tx[4] = (startX>>8)&0xff; tx[5] = (startY>>0)&0xff; tx[6] = (startY>>8)&0xff; tx[7] = (endXX>>0)&0xff; tx[8] = (endXX>>8)&0xff; tx[9] = (endY>>0)&0xff; tx[10] = (endY>>8)&0xff; tx[11] = 0x49; tx[12] = 0x24; tx[13] = 0xff; tx[14] = 0xff; tx[15] = 0xff; tx[16] = 0xff; tx[17] = 0x00; tx[18] = 0x00; tx[19] = 0x00; tx[20] = 0x00; tx[21] = 0x00; tx[22] = 0x00; tx[23] = 0x00; tx[24] = 0x00; tx[25] = 0x00; tx[26] = (graphicID>>0)&0xff; tx[27] = (graphicID>>8)&0xff; tx[28] = (isCover?0x01:0x00); chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); //usleep(30000); return result; } int8_t dispGraphicPartial(int32_t fd, uint8_t areaId, uint8_t isCover, uint16_t startX, uint16_t startY, uint16_t bmpX, uint16_t bmpY, uint16_t bmpW, uint16_t bmpH, uint8_t graphicID) { int8_t result = FAIL; uint8_t tx[20]; uint16_t chksum; tx[0] = 0xb4; tx[1] = 0x45; tx[2] = (areaId>=19?19:areaId); tx[3] = (startX>>0)&0xff; tx[4] = (startX>>8)&0xff; tx[5] = (startY>>0)&0xff; tx[6] = (startY>>8)&0xff; tx[7] = (bmpX>>0)&0xff; tx[8] = (bmpX>>8)&0xff; tx[9] = (bmpY>>0)&0xff; tx[10] = (bmpY>>8)&0xff; tx[11] = (bmpW>>0)&0xff; tx[12] = (bmpW>>8)&0xff; tx[13] = (bmpH>>0)&0xff; tx[14] = (bmpH>>8)&0xff; tx[15] = (graphicID>>0)&0xff; tx[16] = (graphicID>>8)&0xff; tx[17] = (isCover?0x01:0x00); chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); //usleep(30000); return result; } int8_t dispCharacter(int32_t fd, uint16_t startX, uint16_t startY, uint16_t font, uint8_t *data, uint8_t msgLen) { int8_t result = FAIL; uint8_t tx[9+msgLen]; uint16_t chksum; tx[0] = 0xc1; tx[1] = (startX>>0)&0xff; tx[2] = (startX>>8)&0xff; tx[3] = (startY>>0)&0xff; tx[4] = (startY>>8)&0xff; tx[5] = (font>>0)&0xff; memcpy(&tx[6], &data[0], msgLen); tx[ARRAY_SIZE(tx)-3] = 0x00; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t dispCharacterConfig(int32_t fd, uint8_t areaId, uint8_t isCover, uint16_t startX, uint16_t startY, uint16_t endXX, uint16_t endY) { int8_t result = FAIL; uint8_t tx[29]; uint16_t chksum; tx[0] = 0xc4; tx[1] = 0xf3; tx[2] = (areaId>=19?19:areaId); tx[3] = (startX>>0)&0xff; tx[4] = (startX>>8)&0xff; tx[5] = (startY>>0)&0xff; tx[6] = (startY>>8)&0xff; tx[7] = (endXX>>0)&0xff; tx[8] = (endXX>>8)&0xff; tx[9] = (endY>>0)&0xff; tx[10] = (endY>>8)&0xff; tx[11] = 0x09; tx[12] = 0x24; tx[13] = 0xff; tx[14] = 0xff; tx[15] = 0xff; tx[16] = 0xff; tx[17] = 0x00; tx[18] = 0x00; tx[19] = 0x00; tx[20] = 0x00; tx[21] = 0x00; tx[22] = 0x00; tx[23] = 0x00; tx[24] = 0x00; tx[25] = 0x00; tx[26] = (isCover?0x01:0x00); chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; //result = tranceive(fd, tx, ARRAY_SIZE(tx)); //usleep(30000); return result; } int8_t dispCharacterArea(int32_t fd, uint8_t areaId, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY, uint16_t font, uint8_t *data, uint8_t msgLen) { int8_t result = FAIL; uint8_t tx[30+msgLen]; uint16_t chksum; tx[0] = 0xc4; tx[1] = 0xf2; tx[2] = (areaId>=19?19:areaId); tx[3] = (startX>>0)&0xff; tx[4] = (startX>>8)&0xff; tx[5] = (startY>>0)&0xff; tx[6] = (startY>>8)&0xff; tx[7] = (endX>>0)&0xff; tx[8] = (endX>>8)&0xff; tx[9] = (endY>>0)&0xff; tx[10] = (endY>>8)&0xff; tx[11] = 0x49; tx[12] = 0x24; tx[13] = 0xff; tx[14] = 0xff; tx[15] = 0xff; tx[16] = 0xff; tx[17] = 0x00; tx[18] = 0x00; tx[19] = 0x00; tx[20] = 0x00; tx[21] = 0x00; tx[22] = 0x00; tx[23] = 0x00; tx[24] = 0x00; tx[25] = 0x00; tx[26] = (font>>0)&0xff; memcpy(&tx[27], &data[0], msgLen); tx[ARRAY_SIZE(tx)-3] = 0x00; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); //usleep(25000); return result; } int8_t dispCharacterScroll(int32_t fd, uint8_t areaId, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY, uint16_t font, uint8_t isToRight, uint8_t speed, uint8_t *data, uint8_t msgLen) { int8_t result = FAIL; uint8_t tx[31+msgLen]; uint16_t chksum; tx[0] = 0xc5; tx[1] = 0xf2; tx[2] = (areaId>=19?19:areaId); tx[3] = (startX>>0)&0xff; tx[4] = (startX>>8)&0xff; tx[5] = (startY>>0)&0xff; tx[6] = (startY>>8)&0xff; tx[7] = (endX>>0)&0xff; tx[8] = (endX>>8)&0xff; tx[9] = (endY>>0)&0xff; tx[10] = (endY>>8)&0xff; tx[11] = 0x49; tx[12] = 0x24; tx[13] = 0xff; tx[14] = 0xff; tx[15] = 0xff; tx[16] = 0xff; tx[17] = 0x00; tx[18] = 0x00; tx[19] = 0x00; tx[20] = 0x00; tx[21] = 0x00; tx[22] = 0x00; tx[23] = 0x00; tx[24] = 0x00; tx[25] = 0x00; tx[26] = (isToRight?0x01:0x00); tx[27] = ((speed<25)?25:speed); tx[28] = (font>>0)&0xff; memcpy(&tx[30], &data[0], msgLen); chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t dispCharacterBlink(int32_t fd, uint8_t areaId, uint16_t startX, uint16_t startY, uint16_t font, uint8_t type, uint16_t time, uint8_t *data, uint8_t msgLen) { int8_t result = FAIL; uint8_t tx[12+msgLen]; uint16_t chksum; tx[0] = 0xc3; tx[1] = (areaId>=19?19:areaId); tx[2] = (startX>>0)&0xff; tx[3] = (startX>>8)&0xff; tx[4] = (startY>>0)&0xff; tx[5] = (startY>>8)&0xff; tx[6] = (font>>0)&0xff; tx[7] = type; tx[8] = (time>>0)&0xff; tx[9] = (time>>8)&0xff; memcpy(&tx[10], &data[0], msgLen); chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t drawAll(int32_t fd) { int8_t result = FAIL; uint8_t tx[7]; uint16_t chksum; tx[0] = 0xd0; tx[1] = 0xff; tx[2] = 0xff; tx[3] = 0xff; tx[4] = 0xff; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t drawPoint(int32_t fd, uint16_t startX, uint16_t startY) { int8_t result = FAIL; uint8_t tx[7]; uint16_t chksum; tx[0] = 0xd6; tx[1] = (startX>>0)&0xff; tx[2] = (startX>>8)&0xff; tx[3] = (startY>>0)&0xff; tx[4] = (startY>>8)&0xff; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t drawRect(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY, uint8_t isFill) { int8_t result = FAIL; uint8_t tx[11]; uint16_t chksum; tx[0] = (isFill?0xd1:0xd4); tx[1] = (startX>>0)&0xff; tx[2] = (startX>>8)&0xff; tx[3] = (startY>>0)&0xff; tx[4] = (startY>>8)&0xff; tx[5] = (endX>>0)&0xff; tx[6] = (endX>>8)&0xff; tx[7] = (endY>>0)&0xff; tx[8] = (endY>>8)&0xff; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t drawRectCorner(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY, uint8_t radius, uint8_t isFill) { int8_t result = FAIL; uint8_t tx[12]; uint16_t chksum; tx[0] = (isFill?0xd2:0xd5); tx[1] = (startX>>0)&0xff; tx[2] = (startX>>8)&0xff; tx[3] = (startY>>0)&0xff; tx[4] = (startY>>8)&0xff; tx[5] = (endX>>0)&0xff; tx[6] = (endX>>8)&0xff; tx[7] = (endY>>0)&0xff; tx[8] = (endY>>8)&0xff; tx[9] = (radius>15?15:radius); tx[6] = 0xff; tx[7] = 0xff; tx[8] = 0xff; tx[9] = 0xff; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t drawRectMesh(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY) { int8_t result = FAIL; uint8_t tx[11]; uint16_t chksum; tx[0] = 0xd3; tx[1] = (startX>>0)&0xff; tx[2] = (startX>>8)&0xff; tx[3] = (startY>>0)&0xff; tx[4] = (startY>>8)&0xff; tx[5] = (endX>>0)&0xff; tx[6] = (endX>>8)&0xff; tx[7] = (endY>>0)&0xff; tx[8] = (endY>>8)&0xff; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t drawLine(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY) { int8_t result = FAIL; uint8_t tx[11]; uint16_t chksum; tx[0] = 0xda; tx[1] = (startX>>0)&0xff; tx[2] = (startX>>8)&0xff; tx[3] = (startY>>0)&0xff; tx[4] = (startY>>8)&0xff; tx[5] = (endX>>0)&0xff; tx[6] = (endX>>8)&0xff; tx[7] = (endY>>0)&0xff; tx[8] = (endY>>8)&0xff; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t drawRfSignal(int32_t fd, uint8_t strength, uint8_t is4G) { int8_t result = PASS; uint16_t startX = (is4G?109:(sysFlag.isEnable4G?83:109)); uint16_t startY = 0; dispGraphic(fd, YES, startX, startY, IMG_ADDR_RF_0+strength); dispCharacter(fd, startX-5, startY+2, FONT_ASCII_4X6, (uint8_t*)(is4G?"T":"W"), strlen((is4G?"T":"W"))); return result; } int8_t bgConfig(int32_t fd, uint16_t startX, uint16_t startY, uint16_t idxPic) { int8_t result = FAIL; uint8_t tx[9]; uint16_t chksum; tx[0] = 0xb5; tx[1] = (startX>>0)&0xff; tx[2] = (startX>>8)&0xff; tx[3] = (startY>>0)&0xff; tx[4] = (startY>>8)&0xff; tx[5] = (idxPic>>0)&0xff; tx[6] = (idxPic>>8)&0xff; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t bgOperation(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY, uint8_t isRestore) { int8_t result = FAIL; uint8_t tx[12]; uint16_t chksum; tx[0] = 0xb6; tx[1] = (startX>>0)&0xff; tx[2] = (startX>>8)&0xff; tx[3] = (startY>>0)&0xff; tx[4] = (startY>>8)&0xff; tx[5] = (endX>>0)&0xff; tx[6] = (endX>>8)&0xff; tx[7] = (endY>>0)&0xff; tx[8] = (endY>>8)&0xff; tx[9] = isRestore; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; } int8_t picUploadStart(int32_t fd, uint16_t imgIdx, uint16_t width, uint16_t height) { int8_t result = FAIL; uint8_t tx[11]; uint16_t chksum; tx[0] = 0xe1; tx[1] = (imgIdx>>0)&0xff; tx[2] = (imgIdx>>8)&0xff; tx[3] = (width>>0)&0xff; tx[4] = (width>>8)&0xff; tx[5] = (height>>0)&0xff; tx[6] = (height>>8)&0xff; tx[7] = 0x01; tx[8] = 0x01; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); //usleep(100000); return result; } int8_t picUploadData(int32_t fd, uint16_t imgIdx, uint32_t startAddress, uint8_t *data, uint16_t length) { int8_t result = FAIL; uint8_t tx[11+length]; uint16_t chksum; tx[0] = 0xe2; tx[1] = (imgIdx>>0)&0xff; tx[2] = (imgIdx>>8)&0xff; tx[3] = (startAddress>>0)&0xff; tx[4] = (startAddress>>8)&0xff; tx[5] = (startAddress>>16)&0xff; tx[6] = (startAddress>>24)&0xff; tx[7] = (length>>0)&0xff; tx[8] = (length>>8)&0xff; memcpy(&tx[9], &data[0], length); chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); //usleep(100000); return result; } int8_t graphicSave(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY) { int8_t result = FAIL; uint8_t tx[12]; uint16_t chksum; tx[0] = 0xae; tx[1] = 0x02; tx[2] = (startX>>0)&0xff; tx[3] = (startX>>8)&0xff; tx[4] = (startY>>0)&0xff; tx[5] = (startY>>8)&0xff; tx[6] = (endX>>0)&0xff; tx[7] = (endX>>8)&0xff; tx[8] = (endY>>0)&0xff; tx[9] = (endY>>8)&0xff; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); //usleep(50000); return result; } int8_t graphicLoad(int32_t fd, uint16_t startX, uint16_t startY) { int8_t result = FAIL; uint8_t tx[8]; uint16_t chksum; tx[0] = 0xae; tx[1] = 0x04; tx[2] = (startX>>0)&0xff; tx[3] = (startX>>8)&0xff; tx[4] = (startY>>0)&0xff; tx[5] = (startY>>8)&0xff; chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); //usleep(50000); return result; } int8_t qrCodeOperation(int32_t fd, uint16_t startX, uint16_t startY, uint8_t *data, uint16_t msgLen) { int8_t result = FAIL; uint8_t tx[15+msgLen]; uint16_t chksum; tx[0] = 0xdc; tx[1] = 0x01; tx[2] = (startX>>0)&0xff; tx[3] = (startX>>8)&0xff; tx[4] = (startY>>0)&0xff; tx[5] = (startY>>8)&0xff; tx[6] = 0x03; tx[7] = 0x09; tx[8] = 0xff; tx[9] = 0x00; tx[10] = 0x00; tx[11] = (msgLen>>0)&0xff; tx[12] = (msgLen>>8)&0xff; memcpy(&tx[13], &data[0], msgLen); chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2); tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff; tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff; result = tranceive(fd, tx, ARRAY_SIZE(tx)); return result; }