lcmComm.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. /*
  2. * lcmComm.c
  3. *
  4. * Created on: 2019年5月8日
  5. * Author: foluswen
  6. */
  7. #include <sys/time.h>
  8. #include <sys/timeb.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <sys/types.h>
  12. #include <sys/ioctl.h>
  13. #include <sys/socket.h>
  14. #include <sys/ipc.h>
  15. #include <sys/shm.h>
  16. #include <sys/shm.h>
  17. #include <sys/mman.h>
  18. #include <linux/wireless.h>
  19. #include <arpa/inet.h>
  20. #include <netinet/in.h>
  21. #include <unistd.h>
  22. #include <stdarg.h>
  23. #include <stdio.h> /*標準輸入輸出定義*/
  24. #include <stdlib.h> /*標準函數庫定義*/
  25. #include <unistd.h> /*Unix 標準函數定義*/
  26. #include <fcntl.h> /*檔控制定義*/
  27. #include <termios.h> /*PPSIX 終端控制定義*/
  28. #include <errno.h> /*錯誤號定義*/
  29. #include <errno.h>
  30. #include <string.h>
  31. #include <time.h>
  32. #include <ctype.h>
  33. #include <ifaddrs.h>
  34. #include <math.h>
  35. #include "lcmComm.h"
  36. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  37. #define PASS 1
  38. #define FAIL -1
  39. #define YES 1
  40. #define NO 0
  41. SYS_FLAG sysFlag;
  42. //================================
  43. // Basic routine
  44. //================================
  45. void displayMessage(uint8_t *data, uint16_t len, uint8_t isRX)
  46. {
  47. uint8_t output[8192];
  48. memset(output, 0x00, ARRAY_SIZE(output));
  49. sprintf((char*)output, "%s", (isRX?"RX: ":"TX: "));
  50. for(uint16_t idx = 0;idx<len;idx++)
  51. {
  52. sprintf((char*)output, "%s%02x ", output, data[idx]);
  53. }
  54. DEBUG_INFO("%s\n", output);
  55. }
  56. uint16_t crc16(uint8_t* data, uint16_t length)
  57. {
  58. uint16_t reg_crc = 0xFFFF;
  59. while(length--)
  60. {
  61. reg_crc ^= *data++;
  62. for(uint8_t j=0;j<8;j++)
  63. {
  64. if(reg_crc& 0x01) /* LSB(b0)=1 */
  65. reg_crc=(reg_crc>>1) ^ 0xA001;
  66. else
  67. reg_crc=reg_crc>>1;
  68. }
  69. }
  70. return reg_crc;
  71. }
  72. int tranceive(int32_t fd, uint8_t *tx, uint16_t tx_len)
  73. {
  74. int result = FAIL;
  75. uint8_t rx[5];
  76. uint8_t rx_len;
  77. uint16_t chksum;
  78. memset(rx, 0x00, ARRAY_SIZE(rx));
  79. tcflush(fd,TCIOFLUSH);
  80. displayMessage(tx, tx_len, NO);
  81. if(write(fd, tx, tx_len) >= ARRAY_SIZE(tx))
  82. {
  83. rx_len = read(fd, rx, ARRAY_SIZE(rx));
  84. if(rx_len > 0)
  85. displayMessage(rx, rx_len, YES);
  86. else
  87. DEBUG_INFO("RX: NULL\n");
  88. chksum=crc16(&rx[0], ARRAY_SIZE(rx)-2);
  89. if((rx_len >= 5) &&
  90. (((chksum>>0)&0xff) == rx[3]) &&
  91. (((chksum>>8)&0xff) == rx[4]) &&
  92. (rx[1] == 0x00))
  93. {
  94. result = PASS;
  95. }
  96. else
  97. {
  98. DEBUG_WARN("Serial command read fail, checksum: 0x%04x.\n", chksum);
  99. }
  100. }
  101. else
  102. {
  103. DEBUG_WARN("Serial command write fail.\n");
  104. }
  105. return result;
  106. }
  107. //================================
  108. // Application routine
  109. //================================
  110. int8_t clearScreen(int32_t fd, uint8_t isPartial, uint16_t startX, uint16_t startY, uint16_t width, uint16_t height)
  111. {
  112. int8_t result = FAIL;
  113. uint8_t tx[(isPartial?10:12)];
  114. uint16_t chksum;
  115. if(isPartial)
  116. {
  117. tx[0] = 0xa1;
  118. tx[1] = (startX>>0)&0xff;
  119. tx[2] = (startX>>8)&0xff;
  120. tx[3] = (startY>>0)&0xff;
  121. tx[4] = (startY>>8)&0xff;
  122. tx[5] = (width>>0)&0xff;
  123. tx[6] = (width>>8)&0xff;
  124. tx[7] = (height>>0)&0xff;
  125. tx[8] = (height>>8)&0xff;
  126. tx[9] = (isPartial?0x01:0x00);
  127. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  128. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  129. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  130. }
  131. else
  132. {
  133. tx[0] = 0xa1;
  134. tx[1] = (startX>>0)&0xff;
  135. tx[2] = (startX>>8)&0xff;
  136. tx[3] = (startY>>0)&0xff;
  137. tx[4] = (startY>>8)&0xff;
  138. tx[5] = (width>>0)&0xff;
  139. tx[6] = (width>>8)&0xff;
  140. tx[7] = (height>>0)&0xff;
  141. tx[8] = (height>>8)&0xff;
  142. tx[9] = (isPartial?0x01:0x00);
  143. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  144. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  145. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  146. }
  147. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  148. return result;
  149. }
  150. int8_t setContrast(int32_t fd, uint8_t startBrightness, uint8_t stopBrightness, uint8_t interval)
  151. {
  152. int8_t result = FAIL;
  153. uint8_t tx[6];
  154. uint16_t chksum;
  155. tx[0] = 0xa2;
  156. tx[1] = startBrightness;
  157. tx[2] = stopBrightness;
  158. tx[3] = interval;
  159. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  160. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  161. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  162. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  163. return result;
  164. }
  165. int8_t setPower(int32_t fd, uint8_t isOn)
  166. {
  167. int8_t result = FAIL;
  168. uint8_t tx[4];
  169. uint16_t chksum;
  170. tx[0] = 0xa3;
  171. tx[1] = (isOn?0x01:0x00);
  172. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  173. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  174. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  175. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  176. return result;
  177. }
  178. int8_t dispGraphic(int32_t fd, uint8_t isCover, uint16_t startX, uint16_t startY, uint8_t graphicID)
  179. {
  180. int8_t result = FAIL;
  181. uint8_t tx[10];
  182. uint16_t chksum;
  183. tx[0] = 0xb1;
  184. tx[1] = (startX>>0)&0xff;
  185. tx[2] = (startX>>8)&0xff;
  186. tx[3] = (startY>>0)&0xff;
  187. tx[4] = (startY>>8)&0xff;
  188. tx[5] = (graphicID>>0)&0xff;
  189. tx[6] = (graphicID>>8)&0xff;
  190. tx[7] = (isCover?0x01:0x00);
  191. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  192. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  193. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  194. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  195. return result;
  196. }
  197. int8_t dispGraphicConfig(int32_t fd, uint8_t areaId, uint8_t isCover, uint16_t startX, uint16_t startY, uint16_t endXX, uint16_t endY)
  198. {
  199. int8_t result = FAIL;
  200. uint8_t tx[29];
  201. uint16_t chksum;
  202. tx[0] = 0xb4;
  203. tx[1] = 0xf3;
  204. tx[2] = (areaId>=19?19:areaId);
  205. tx[3] = (startX>>0)&0xff;
  206. tx[4] = (startX>>8)&0xff;
  207. tx[5] = (startY>>0)&0xff;
  208. tx[6] = (startY>>8)&0xff;
  209. tx[7] = (endXX>>0)&0xff;
  210. tx[8] = (endXX>>8)&0xff;
  211. tx[9] = (endY>>0)&0xff;
  212. tx[10] = (endY>>8)&0xff;
  213. tx[11] = 0x09;
  214. tx[12] = 0x24;
  215. tx[13] = 0xff;
  216. tx[14] = 0xff;
  217. tx[15] = 0xff;
  218. tx[16] = 0xff;
  219. tx[17] = 0x00;
  220. tx[18] = 0x00;
  221. tx[19] = 0x00;
  222. tx[20] = 0x00;
  223. tx[21] = 0x00;
  224. tx[22] = 0x00;
  225. tx[23] = 0x00;
  226. tx[24] = 0x00;
  227. tx[25] = 0x00;
  228. tx[26] = (isCover?0x01:0x00);
  229. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  230. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  231. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  232. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  233. //usleep(30000);
  234. return result;
  235. }
  236. 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)
  237. {
  238. int8_t result = FAIL;
  239. uint8_t tx[31];
  240. uint16_t chksum;
  241. tx[0] = 0xb4;
  242. tx[1] = 0xf2;
  243. tx[2] = (areaId>=19?19:areaId);
  244. tx[3] = (startX>>0)&0xff;
  245. tx[4] = (startX>>8)&0xff;
  246. tx[5] = (startY>>0)&0xff;
  247. tx[6] = (startY>>8)&0xff;
  248. tx[7] = (endXX>>0)&0xff;
  249. tx[8] = (endXX>>8)&0xff;
  250. tx[9] = (endY>>0)&0xff;
  251. tx[10] = (endY>>8)&0xff;
  252. tx[11] = 0x49;
  253. tx[12] = 0x24;
  254. tx[13] = 0xff;
  255. tx[14] = 0xff;
  256. tx[15] = 0xff;
  257. tx[16] = 0xff;
  258. tx[17] = 0x00;
  259. tx[18] = 0x00;
  260. tx[19] = 0x00;
  261. tx[20] = 0x00;
  262. tx[21] = 0x00;
  263. tx[22] = 0x00;
  264. tx[23] = 0x00;
  265. tx[24] = 0x00;
  266. tx[25] = 0x00;
  267. tx[26] = (graphicID>>0)&0xff;
  268. tx[27] = (graphicID>>8)&0xff;
  269. tx[28] = (isCover?0x01:0x00);
  270. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  271. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  272. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  273. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  274. //usleep(30000);
  275. return result;
  276. }
  277. 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)
  278. {
  279. int8_t result = FAIL;
  280. uint8_t tx[20];
  281. uint16_t chksum;
  282. tx[0] = 0xb4;
  283. tx[1] = 0x45;
  284. tx[2] = (areaId>=19?19:areaId);
  285. tx[3] = (startX>>0)&0xff;
  286. tx[4] = (startX>>8)&0xff;
  287. tx[5] = (startY>>0)&0xff;
  288. tx[6] = (startY>>8)&0xff;
  289. tx[7] = (bmpX>>0)&0xff;
  290. tx[8] = (bmpX>>8)&0xff;
  291. tx[9] = (bmpY>>0)&0xff;
  292. tx[10] = (bmpY>>8)&0xff;
  293. tx[11] = (bmpW>>0)&0xff;
  294. tx[12] = (bmpW>>8)&0xff;
  295. tx[13] = (bmpH>>0)&0xff;
  296. tx[14] = (bmpH>>8)&0xff;
  297. tx[15] = (graphicID>>0)&0xff;
  298. tx[16] = (graphicID>>8)&0xff;
  299. tx[17] = (isCover?0x01:0x00);
  300. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  301. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  302. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  303. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  304. //usleep(30000);
  305. return result;
  306. }
  307. int8_t dispCharacter(int32_t fd, uint16_t startX, uint16_t startY, uint16_t font, uint8_t *data, uint8_t msgLen)
  308. {
  309. int8_t result = FAIL;
  310. uint8_t tx[8+msgLen];
  311. uint16_t chksum;
  312. tx[0] = 0xc1;
  313. tx[1] = (startX>>0)&0xff;
  314. tx[2] = (startX>>8)&0xff;
  315. tx[3] = (startY>>0)&0xff;
  316. tx[4] = (startY>>8)&0xff;
  317. tx[5] = (font>>0)&0xff;
  318. memcpy(&tx[6], &data[0], msgLen);
  319. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  320. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  321. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  322. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  323. return result;
  324. }
  325. int8_t dispCharacterConfig(int32_t fd, uint8_t areaId, uint8_t isCover, uint16_t startX, uint16_t startY, uint16_t endXX, uint16_t endY)
  326. {
  327. int8_t result = FAIL;
  328. uint8_t tx[29];
  329. uint16_t chksum;
  330. tx[0] = 0xc4;
  331. tx[1] = 0xf3;
  332. tx[2] = (areaId>=19?19:areaId);
  333. tx[3] = (startX>>0)&0xff;
  334. tx[4] = (startX>>8)&0xff;
  335. tx[5] = (startY>>0)&0xff;
  336. tx[6] = (startY>>8)&0xff;
  337. tx[7] = (endXX>>0)&0xff;
  338. tx[8] = (endXX>>8)&0xff;
  339. tx[9] = (endY>>0)&0xff;
  340. tx[10] = (endY>>8)&0xff;
  341. tx[11] = 0x09;
  342. tx[12] = 0x24;
  343. tx[13] = 0xff;
  344. tx[14] = 0xff;
  345. tx[15] = 0xff;
  346. tx[16] = 0xff;
  347. tx[17] = 0x00;
  348. tx[18] = 0x00;
  349. tx[19] = 0x00;
  350. tx[20] = 0x00;
  351. tx[21] = 0x00;
  352. tx[22] = 0x00;
  353. tx[23] = 0x00;
  354. tx[24] = 0x00;
  355. tx[25] = 0x00;
  356. tx[26] = (isCover?0x01:0x00);
  357. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  358. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  359. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  360. //result = tranceive(fd, tx, ARRAY_SIZE(tx));
  361. //usleep(30000);
  362. return result;
  363. }
  364. 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)
  365. {
  366. int8_t result = FAIL;
  367. uint8_t tx[29+msgLen];
  368. uint16_t chksum;
  369. tx[0] = 0xc4;
  370. tx[1] = 0xf2;
  371. tx[2] = (areaId>=19?19:areaId);
  372. tx[3] = (startX>>0)&0xff;
  373. tx[4] = (startX>>8)&0xff;
  374. tx[5] = (startY>>0)&0xff;
  375. tx[6] = (startY>>8)&0xff;
  376. tx[7] = (endX>>0)&0xff;
  377. tx[8] = (endX>>8)&0xff;
  378. tx[9] = (endY>>0)&0xff;
  379. tx[10] = (endY>>8)&0xff;
  380. tx[11] = 0x49;
  381. tx[12] = 0x24;
  382. tx[13] = 0xff;
  383. tx[14] = 0xff;
  384. tx[15] = 0xff;
  385. tx[16] = 0xff;
  386. tx[17] = 0x00;
  387. tx[18] = 0x00;
  388. tx[19] = 0x00;
  389. tx[20] = 0x00;
  390. tx[21] = 0x00;
  391. tx[22] = 0x00;
  392. tx[23] = 0x00;
  393. tx[24] = 0x00;
  394. tx[25] = 0x00;
  395. tx[26] = (font>>0)&0xff;
  396. memcpy(&tx[27], &data[0], msgLen);
  397. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  398. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  399. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  400. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  401. //usleep(25000);
  402. return result;
  403. }
  404. 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)
  405. {
  406. int8_t result = FAIL;
  407. uint8_t tx[31+msgLen];
  408. uint16_t chksum;
  409. tx[0] = 0xc5;
  410. tx[1] = 0xf2;
  411. tx[2] = (areaId>=19?19:areaId);
  412. tx[3] = (startX>>0)&0xff;
  413. tx[4] = (startX>>8)&0xff;
  414. tx[5] = (startY>>0)&0xff;
  415. tx[6] = (startY>>8)&0xff;
  416. tx[7] = (endX>>0)&0xff;
  417. tx[8] = (endX>>8)&0xff;
  418. tx[9] = (endY>>0)&0xff;
  419. tx[10] = (endY>>8)&0xff;
  420. tx[11] = 0x49;
  421. tx[12] = 0x24;
  422. tx[13] = 0xff;
  423. tx[14] = 0xff;
  424. tx[15] = 0xff;
  425. tx[16] = 0xff;
  426. tx[17] = 0x00;
  427. tx[18] = 0x00;
  428. tx[19] = 0x00;
  429. tx[20] = 0x00;
  430. tx[21] = 0x00;
  431. tx[22] = 0x00;
  432. tx[23] = 0x00;
  433. tx[24] = 0x00;
  434. tx[25] = 0x00;
  435. tx[26] = (isToRight?0x01:0x00);
  436. tx[27] = ((speed<25)?25:speed);
  437. tx[28] = (font>>0)&0xff;
  438. memcpy(&tx[30], &data[0], msgLen);
  439. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  440. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  441. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  442. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  443. return result;
  444. }
  445. 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)
  446. {
  447. int8_t result = FAIL;
  448. uint8_t tx[12+msgLen];
  449. uint16_t chksum;
  450. tx[0] = 0xc3;
  451. tx[1] = (areaId>=19?19:areaId);
  452. tx[2] = (startX>>0)&0xff;
  453. tx[3] = (startX>>8)&0xff;
  454. tx[4] = (startY>>0)&0xff;
  455. tx[5] = (startY>>8)&0xff;
  456. tx[6] = (font>>0)&0xff;
  457. tx[7] = type;
  458. tx[8] = (time>>0)&0xff;
  459. tx[9] = (time>>8)&0xff;
  460. memcpy(&tx[10], &data[0], msgLen);
  461. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  462. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  463. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  464. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  465. return result;
  466. }
  467. int8_t drawAll(int32_t fd)
  468. {
  469. int8_t result = FAIL;
  470. uint8_t tx[7];
  471. uint16_t chksum;
  472. tx[0] = 0xd0;
  473. tx[1] = 0xff;
  474. tx[2] = 0xff;
  475. tx[3] = 0xff;
  476. tx[4] = 0xff;
  477. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  478. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  479. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  480. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  481. return result;
  482. }
  483. int8_t drawPoint(int32_t fd, uint16_t startX, uint16_t startY)
  484. {
  485. int8_t result = FAIL;
  486. uint8_t tx[7];
  487. uint16_t chksum;
  488. tx[0] = 0xd6;
  489. tx[1] = (startX>>0)&0xff;
  490. tx[2] = (startX>>8)&0xff;
  491. tx[3] = (startY>>0)&0xff;
  492. tx[4] = (startY>>8)&0xff;
  493. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  494. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  495. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  496. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  497. return result;
  498. }
  499. int8_t drawRect(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY, uint8_t isFill)
  500. {
  501. int8_t result = FAIL;
  502. uint8_t tx[11];
  503. uint16_t chksum;
  504. tx[0] = (isFill?0xd1:0xd4);
  505. tx[1] = (startX>>0)&0xff;
  506. tx[2] = (startX>>8)&0xff;
  507. tx[3] = (startY>>0)&0xff;
  508. tx[4] = (startY>>8)&0xff;
  509. tx[5] = (endX>>0)&0xff;
  510. tx[6] = (endX>>8)&0xff;
  511. tx[7] = (endY>>0)&0xff;
  512. tx[8] = (endY>>8)&0xff;
  513. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  514. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  515. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  516. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  517. return result;
  518. }
  519. int8_t drawRectCorner(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY, uint8_t radius, uint8_t isFill)
  520. {
  521. int8_t result = FAIL;
  522. uint8_t tx[12];
  523. uint16_t chksum;
  524. tx[0] = (isFill?0xd2:0xd5);
  525. tx[1] = (startX>>0)&0xff;
  526. tx[2] = (startX>>8)&0xff;
  527. tx[3] = (startY>>0)&0xff;
  528. tx[4] = (startY>>8)&0xff;
  529. tx[5] = (endX>>0)&0xff;
  530. tx[6] = (endX>>8)&0xff;
  531. tx[7] = (endY>>0)&0xff;
  532. tx[8] = (endY>>8)&0xff;
  533. tx[9] = (radius>15?15:radius);
  534. tx[6] = 0xff;
  535. tx[7] = 0xff;
  536. tx[8] = 0xff;
  537. tx[9] = 0xff;
  538. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  539. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  540. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  541. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  542. return result;
  543. }
  544. int8_t drawRectMesh(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY)
  545. {
  546. int8_t result = FAIL;
  547. uint8_t tx[11];
  548. uint16_t chksum;
  549. tx[0] = 0xd3;
  550. tx[1] = (startX>>0)&0xff;
  551. tx[2] = (startX>>8)&0xff;
  552. tx[3] = (startY>>0)&0xff;
  553. tx[4] = (startY>>8)&0xff;
  554. tx[5] = (endX>>0)&0xff;
  555. tx[6] = (endX>>8)&0xff;
  556. tx[7] = (endY>>0)&0xff;
  557. tx[8] = (endY>>8)&0xff;
  558. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  559. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  560. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  561. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  562. return result;
  563. }
  564. int8_t drawLine(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY)
  565. {
  566. int8_t result = FAIL;
  567. uint8_t tx[11];
  568. uint16_t chksum;
  569. tx[0] = 0xda;
  570. tx[1] = (startX>>0)&0xff;
  571. tx[2] = (startX>>8)&0xff;
  572. tx[3] = (startY>>0)&0xff;
  573. tx[4] = (startY>>8)&0xff;
  574. tx[5] = (endX>>0)&0xff;
  575. tx[6] = (endX>>8)&0xff;
  576. tx[7] = (endY>>0)&0xff;
  577. tx[8] = (endY>>8)&0xff;
  578. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  579. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  580. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  581. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  582. return result;
  583. }
  584. int8_t drawRfSignal(int32_t fd, uint8_t strength, uint8_t is4G)
  585. {
  586. int8_t result = PASS;
  587. uint16_t startX = (is4G?109:(sysFlag.isEnable4G?83:109));
  588. uint16_t startY = 0;
  589. dispGraphic(fd, YES, startX, startY, IMG_ADDR_RF_0+strength);
  590. dispCharacter(fd, startX-5, startY+2, FONT_ASCII_4X6, (uint8_t*)(is4G?"T":"W"), strlen((is4G?"T":"W")));
  591. return result;
  592. }
  593. int8_t bgConfig(int32_t fd, uint16_t startX, uint16_t startY, uint16_t idxPic)
  594. {
  595. int8_t result = FAIL;
  596. uint8_t tx[9];
  597. uint16_t chksum;
  598. tx[0] = 0xb5;
  599. tx[1] = (startX>>0)&0xff;
  600. tx[2] = (startX>>8)&0xff;
  601. tx[3] = (startY>>0)&0xff;
  602. tx[4] = (startY>>8)&0xff;
  603. tx[5] = (idxPic>>0)&0xff;
  604. tx[6] = (idxPic>>8)&0xff;
  605. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  606. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  607. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  608. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  609. return result;
  610. }
  611. int8_t bgOperation(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY, uint8_t isRestore)
  612. {
  613. int8_t result = FAIL;
  614. uint8_t tx[12];
  615. uint16_t chksum;
  616. tx[0] = 0xb6;
  617. tx[1] = (startX>>0)&0xff;
  618. tx[2] = (startX>>8)&0xff;
  619. tx[3] = (startY>>0)&0xff;
  620. tx[4] = (startY>>8)&0xff;
  621. tx[5] = (endX>>0)&0xff;
  622. tx[6] = (endX>>8)&0xff;
  623. tx[7] = (endY>>0)&0xff;
  624. tx[8] = (endY>>8)&0xff;
  625. tx[9] = isRestore;
  626. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  627. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  628. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  629. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  630. return result;
  631. }
  632. int8_t picUploadStart(int32_t fd, uint16_t imgIdx, uint16_t width, uint16_t height)
  633. {
  634. int8_t result = FAIL;
  635. uint8_t tx[11];
  636. uint16_t chksum;
  637. tx[0] = 0xe1;
  638. tx[1] = (imgIdx>>0)&0xff;
  639. tx[2] = (imgIdx>>8)&0xff;
  640. tx[3] = (width>>0)&0xff;
  641. tx[4] = (width>>8)&0xff;
  642. tx[5] = (height>>0)&0xff;
  643. tx[6] = (height>>8)&0xff;
  644. tx[7] = 0x01;
  645. tx[8] = 0x01;
  646. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  647. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  648. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  649. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  650. //usleep(100000);
  651. return result;
  652. }
  653. int8_t picUploadData(int32_t fd, uint16_t imgIdx, uint32_t startAddress, uint8_t *data, uint16_t length)
  654. {
  655. int8_t result = FAIL;
  656. uint8_t tx[11+length];
  657. uint16_t chksum;
  658. tx[0] = 0xe2;
  659. tx[1] = (imgIdx>>0)&0xff;
  660. tx[2] = (imgIdx>>8)&0xff;
  661. tx[3] = (startAddress>>0)&0xff;
  662. tx[4] = (startAddress>>8)&0xff;
  663. tx[5] = (startAddress>>16)&0xff;
  664. tx[6] = (startAddress>>24)&0xff;
  665. tx[7] = (length>>0)&0xff;
  666. tx[8] = (length>>8)&0xff;
  667. memcpy(&tx[9], &data[0], length);
  668. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  669. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  670. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  671. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  672. //usleep(100000);
  673. return result;
  674. }
  675. int8_t graphicSave(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY)
  676. {
  677. int8_t result = FAIL;
  678. uint8_t tx[12];
  679. uint16_t chksum;
  680. tx[0] = 0xae;
  681. tx[1] = 0x02;
  682. tx[2] = (startX>>0)&0xff;
  683. tx[3] = (startX>>8)&0xff;
  684. tx[4] = (startY>>0)&0xff;
  685. tx[5] = (startY>>8)&0xff;
  686. tx[6] = (endX>>0)&0xff;
  687. tx[7] = (endX>>8)&0xff;
  688. tx[8] = (endY>>0)&0xff;
  689. tx[9] = (endY>>8)&0xff;
  690. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  691. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  692. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  693. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  694. //usleep(50000);
  695. return result;
  696. }
  697. int8_t graphicLoad(int32_t fd, uint16_t startX, uint16_t startY)
  698. {
  699. int8_t result = FAIL;
  700. uint8_t tx[8];
  701. uint16_t chksum;
  702. tx[0] = 0xae;
  703. tx[1] = 0x04;
  704. tx[2] = (startX>>0)&0xff;
  705. tx[3] = (startX>>8)&0xff;
  706. tx[4] = (startY>>0)&0xff;
  707. tx[5] = (startY>>8)&0xff;
  708. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  709. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  710. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  711. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  712. //usleep(50000);
  713. return result;
  714. }