123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890 |
- /*
- * lcmComm.c
- *
- * Created on: 2019年5月8日
- * Author: foluswen
- */
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <math.h>
- #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<len;idx++)
- {
- sprintf((char*)output, "%s%02x ", output, data[idx]);
- }
- DEBUG_INFO("%s\n", output);
- }
- uint16_t crc16(uint8_t* data, uint16_t length)
- {
- uint16_t reg_crc = 0xFFFF;
- while(length--)
- {
- reg_crc ^= *data++;
- for(uint8_t j=0;j<8;j++)
- {
- if(reg_crc& 0x01) /* LSB(b0)=1 */
- reg_crc=(reg_crc>>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;
- }
|