lcmComm.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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[9+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. tx[ARRAY_SIZE(tx)-3] = 0x00;
  320. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  321. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  322. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  323. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  324. return result;
  325. }
  326. int8_t dispCharacterConfig(int32_t fd, uint8_t areaId, uint8_t isCover, uint16_t startX, uint16_t startY, uint16_t endXX, uint16_t endY)
  327. {
  328. int8_t result = FAIL;
  329. uint8_t tx[29];
  330. uint16_t chksum;
  331. tx[0] = 0xc4;
  332. tx[1] = 0xf3;
  333. tx[2] = (areaId>=19?19:areaId);
  334. tx[3] = (startX>>0)&0xff;
  335. tx[4] = (startX>>8)&0xff;
  336. tx[5] = (startY>>0)&0xff;
  337. tx[6] = (startY>>8)&0xff;
  338. tx[7] = (endXX>>0)&0xff;
  339. tx[8] = (endXX>>8)&0xff;
  340. tx[9] = (endY>>0)&0xff;
  341. tx[10] = (endY>>8)&0xff;
  342. tx[11] = 0x09;
  343. tx[12] = 0x24;
  344. tx[13] = 0xff;
  345. tx[14] = 0xff;
  346. tx[15] = 0xff;
  347. tx[16] = 0xff;
  348. tx[17] = 0x00;
  349. tx[18] = 0x00;
  350. tx[19] = 0x00;
  351. tx[20] = 0x00;
  352. tx[21] = 0x00;
  353. tx[22] = 0x00;
  354. tx[23] = 0x00;
  355. tx[24] = 0x00;
  356. tx[25] = 0x00;
  357. tx[26] = (isCover?0x01:0x00);
  358. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  359. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  360. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  361. //result = tranceive(fd, tx, ARRAY_SIZE(tx));
  362. //usleep(30000);
  363. return result;
  364. }
  365. 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)
  366. {
  367. int8_t result = FAIL;
  368. uint8_t tx[30+msgLen];
  369. uint16_t chksum;
  370. tx[0] = 0xc4;
  371. tx[1] = 0xf2;
  372. tx[2] = (areaId>=19?19:areaId);
  373. tx[3] = (startX>>0)&0xff;
  374. tx[4] = (startX>>8)&0xff;
  375. tx[5] = (startY>>0)&0xff;
  376. tx[6] = (startY>>8)&0xff;
  377. tx[7] = (endX>>0)&0xff;
  378. tx[8] = (endX>>8)&0xff;
  379. tx[9] = (endY>>0)&0xff;
  380. tx[10] = (endY>>8)&0xff;
  381. tx[11] = 0x49;
  382. tx[12] = 0x24;
  383. tx[13] = 0xff;
  384. tx[14] = 0xff;
  385. tx[15] = 0xff;
  386. tx[16] = 0xff;
  387. tx[17] = 0x00;
  388. tx[18] = 0x00;
  389. tx[19] = 0x00;
  390. tx[20] = 0x00;
  391. tx[21] = 0x00;
  392. tx[22] = 0x00;
  393. tx[23] = 0x00;
  394. tx[24] = 0x00;
  395. tx[25] = 0x00;
  396. tx[26] = (font>>0)&0xff;
  397. memcpy(&tx[27], &data[0], msgLen);
  398. tx[ARRAY_SIZE(tx)-3] = 0x00;
  399. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  400. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  401. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  402. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  403. //usleep(25000);
  404. return result;
  405. }
  406. 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)
  407. {
  408. int8_t result = FAIL;
  409. uint8_t tx[31+msgLen];
  410. uint16_t chksum;
  411. tx[0] = 0xc5;
  412. tx[1] = 0xf2;
  413. tx[2] = (areaId>=19?19:areaId);
  414. tx[3] = (startX>>0)&0xff;
  415. tx[4] = (startX>>8)&0xff;
  416. tx[5] = (startY>>0)&0xff;
  417. tx[6] = (startY>>8)&0xff;
  418. tx[7] = (endX>>0)&0xff;
  419. tx[8] = (endX>>8)&0xff;
  420. tx[9] = (endY>>0)&0xff;
  421. tx[10] = (endY>>8)&0xff;
  422. tx[11] = 0x49;
  423. tx[12] = 0x24;
  424. tx[13] = 0xff;
  425. tx[14] = 0xff;
  426. tx[15] = 0xff;
  427. tx[16] = 0xff;
  428. tx[17] = 0x00;
  429. tx[18] = 0x00;
  430. tx[19] = 0x00;
  431. tx[20] = 0x00;
  432. tx[21] = 0x00;
  433. tx[22] = 0x00;
  434. tx[23] = 0x00;
  435. tx[24] = 0x00;
  436. tx[25] = 0x00;
  437. tx[26] = (isToRight?0x01:0x00);
  438. tx[27] = ((speed<25)?25:speed);
  439. tx[28] = (font>>0)&0xff;
  440. memcpy(&tx[30], &data[0], msgLen);
  441. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  442. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  443. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  444. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  445. return result;
  446. }
  447. 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)
  448. {
  449. int8_t result = FAIL;
  450. uint8_t tx[12+msgLen];
  451. uint16_t chksum;
  452. tx[0] = 0xc3;
  453. tx[1] = (areaId>=19?19:areaId);
  454. tx[2] = (startX>>0)&0xff;
  455. tx[3] = (startX>>8)&0xff;
  456. tx[4] = (startY>>0)&0xff;
  457. tx[5] = (startY>>8)&0xff;
  458. tx[6] = (font>>0)&0xff;
  459. tx[7] = type;
  460. tx[8] = (time>>0)&0xff;
  461. tx[9] = (time>>8)&0xff;
  462. memcpy(&tx[10], &data[0], msgLen);
  463. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  464. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  465. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  466. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  467. return result;
  468. }
  469. int8_t drawAll(int32_t fd)
  470. {
  471. int8_t result = FAIL;
  472. uint8_t tx[7];
  473. uint16_t chksum;
  474. tx[0] = 0xd0;
  475. tx[1] = 0xff;
  476. tx[2] = 0xff;
  477. tx[3] = 0xff;
  478. tx[4] = 0xff;
  479. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  480. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  481. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  482. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  483. return result;
  484. }
  485. int8_t drawPoint(int32_t fd, uint16_t startX, uint16_t startY)
  486. {
  487. int8_t result = FAIL;
  488. uint8_t tx[7];
  489. uint16_t chksum;
  490. tx[0] = 0xd6;
  491. tx[1] = (startX>>0)&0xff;
  492. tx[2] = (startX>>8)&0xff;
  493. tx[3] = (startY>>0)&0xff;
  494. tx[4] = (startY>>8)&0xff;
  495. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  496. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  497. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  498. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  499. return result;
  500. }
  501. int8_t drawRect(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY, uint8_t isFill)
  502. {
  503. int8_t result = FAIL;
  504. uint8_t tx[11];
  505. uint16_t chksum;
  506. tx[0] = (isFill?0xd1:0xd4);
  507. tx[1] = (startX>>0)&0xff;
  508. tx[2] = (startX>>8)&0xff;
  509. tx[3] = (startY>>0)&0xff;
  510. tx[4] = (startY>>8)&0xff;
  511. tx[5] = (endX>>0)&0xff;
  512. tx[6] = (endX>>8)&0xff;
  513. tx[7] = (endY>>0)&0xff;
  514. tx[8] = (endY>>8)&0xff;
  515. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  516. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  517. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  518. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  519. return result;
  520. }
  521. int8_t drawRectCorner(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY, uint8_t radius, uint8_t isFill)
  522. {
  523. int8_t result = FAIL;
  524. uint8_t tx[12];
  525. uint16_t chksum;
  526. tx[0] = (isFill?0xd2:0xd5);
  527. tx[1] = (startX>>0)&0xff;
  528. tx[2] = (startX>>8)&0xff;
  529. tx[3] = (startY>>0)&0xff;
  530. tx[4] = (startY>>8)&0xff;
  531. tx[5] = (endX>>0)&0xff;
  532. tx[6] = (endX>>8)&0xff;
  533. tx[7] = (endY>>0)&0xff;
  534. tx[8] = (endY>>8)&0xff;
  535. tx[9] = (radius>15?15:radius);
  536. tx[6] = 0xff;
  537. tx[7] = 0xff;
  538. tx[8] = 0xff;
  539. tx[9] = 0xff;
  540. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  541. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  542. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  543. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  544. return result;
  545. }
  546. int8_t drawRectMesh(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY)
  547. {
  548. int8_t result = FAIL;
  549. uint8_t tx[11];
  550. uint16_t chksum;
  551. tx[0] = 0xd3;
  552. tx[1] = (startX>>0)&0xff;
  553. tx[2] = (startX>>8)&0xff;
  554. tx[3] = (startY>>0)&0xff;
  555. tx[4] = (startY>>8)&0xff;
  556. tx[5] = (endX>>0)&0xff;
  557. tx[6] = (endX>>8)&0xff;
  558. tx[7] = (endY>>0)&0xff;
  559. tx[8] = (endY>>8)&0xff;
  560. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  561. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  562. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  563. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  564. return result;
  565. }
  566. int8_t drawLine(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY)
  567. {
  568. int8_t result = FAIL;
  569. uint8_t tx[11];
  570. uint16_t chksum;
  571. tx[0] = 0xda;
  572. tx[1] = (startX>>0)&0xff;
  573. tx[2] = (startX>>8)&0xff;
  574. tx[3] = (startY>>0)&0xff;
  575. tx[4] = (startY>>8)&0xff;
  576. tx[5] = (endX>>0)&0xff;
  577. tx[6] = (endX>>8)&0xff;
  578. tx[7] = (endY>>0)&0xff;
  579. tx[8] = (endY>>8)&0xff;
  580. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  581. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  582. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  583. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  584. return result;
  585. }
  586. int8_t drawRfSignal(int32_t fd, uint8_t strength, uint8_t is4G)
  587. {
  588. int8_t result = PASS;
  589. uint16_t startX = (is4G?109:(sysFlag.isEnable4G?83:109));
  590. uint16_t startY = 0;
  591. dispGraphic(fd, YES, startX, startY, IMG_ADDR_RF_0+strength);
  592. dispCharacter(fd, startX-5, startY+2, FONT_ASCII_4X6, (uint8_t*)(is4G?"T":"W"), strlen((is4G?"T":"W")));
  593. return result;
  594. }
  595. int8_t bgConfig(int32_t fd, uint16_t startX, uint16_t startY, uint16_t idxPic)
  596. {
  597. int8_t result = FAIL;
  598. uint8_t tx[9];
  599. uint16_t chksum;
  600. tx[0] = 0xb5;
  601. tx[1] = (startX>>0)&0xff;
  602. tx[2] = (startX>>8)&0xff;
  603. tx[3] = (startY>>0)&0xff;
  604. tx[4] = (startY>>8)&0xff;
  605. tx[5] = (idxPic>>0)&0xff;
  606. tx[6] = (idxPic>>8)&0xff;
  607. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  608. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  609. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  610. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  611. return result;
  612. }
  613. int8_t bgOperation(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY, uint8_t isRestore)
  614. {
  615. int8_t result = FAIL;
  616. uint8_t tx[12];
  617. uint16_t chksum;
  618. tx[0] = 0xb6;
  619. tx[1] = (startX>>0)&0xff;
  620. tx[2] = (startX>>8)&0xff;
  621. tx[3] = (startY>>0)&0xff;
  622. tx[4] = (startY>>8)&0xff;
  623. tx[5] = (endX>>0)&0xff;
  624. tx[6] = (endX>>8)&0xff;
  625. tx[7] = (endY>>0)&0xff;
  626. tx[8] = (endY>>8)&0xff;
  627. tx[9] = isRestore;
  628. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  629. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  630. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  631. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  632. return result;
  633. }
  634. int8_t picUploadStart(int32_t fd, uint16_t imgIdx, uint16_t width, uint16_t height)
  635. {
  636. int8_t result = FAIL;
  637. uint8_t tx[11];
  638. uint16_t chksum;
  639. tx[0] = 0xe1;
  640. tx[1] = (imgIdx>>0)&0xff;
  641. tx[2] = (imgIdx>>8)&0xff;
  642. tx[3] = (width>>0)&0xff;
  643. tx[4] = (width>>8)&0xff;
  644. tx[5] = (height>>0)&0xff;
  645. tx[6] = (height>>8)&0xff;
  646. tx[7] = 0x01;
  647. tx[8] = 0x01;
  648. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  649. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  650. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  651. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  652. //usleep(100000);
  653. return result;
  654. }
  655. int8_t picUploadData(int32_t fd, uint16_t imgIdx, uint32_t startAddress, uint8_t *data, uint16_t length)
  656. {
  657. int8_t result = FAIL;
  658. uint8_t tx[11+length];
  659. uint16_t chksum;
  660. tx[0] = 0xe2;
  661. tx[1] = (imgIdx>>0)&0xff;
  662. tx[2] = (imgIdx>>8)&0xff;
  663. tx[3] = (startAddress>>0)&0xff;
  664. tx[4] = (startAddress>>8)&0xff;
  665. tx[5] = (startAddress>>16)&0xff;
  666. tx[6] = (startAddress>>24)&0xff;
  667. tx[7] = (length>>0)&0xff;
  668. tx[8] = (length>>8)&0xff;
  669. memcpy(&tx[9], &data[0], length);
  670. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  671. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  672. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  673. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  674. //usleep(100000);
  675. return result;
  676. }
  677. int8_t graphicSave(int32_t fd, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY)
  678. {
  679. int8_t result = FAIL;
  680. uint8_t tx[12];
  681. uint16_t chksum;
  682. tx[0] = 0xae;
  683. tx[1] = 0x02;
  684. tx[2] = (startX>>0)&0xff;
  685. tx[3] = (startX>>8)&0xff;
  686. tx[4] = (startY>>0)&0xff;
  687. tx[5] = (startY>>8)&0xff;
  688. tx[6] = (endX>>0)&0xff;
  689. tx[7] = (endX>>8)&0xff;
  690. tx[8] = (endY>>0)&0xff;
  691. tx[9] = (endY>>8)&0xff;
  692. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  693. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  694. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  695. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  696. //usleep(50000);
  697. return result;
  698. }
  699. int8_t graphicLoad(int32_t fd, uint16_t startX, uint16_t startY)
  700. {
  701. int8_t result = FAIL;
  702. uint8_t tx[8];
  703. uint16_t chksum;
  704. tx[0] = 0xae;
  705. tx[1] = 0x04;
  706. tx[2] = (startX>>0)&0xff;
  707. tx[3] = (startX>>8)&0xff;
  708. tx[4] = (startY>>0)&0xff;
  709. tx[5] = (startY>>8)&0xff;
  710. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  711. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  712. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  713. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  714. //usleep(50000);
  715. return result;
  716. }
  717. int8_t qrCodeOperation(int32_t fd, uint16_t startX, uint16_t startY, uint8_t *data, uint16_t msgLen)
  718. {
  719. int8_t result = FAIL;
  720. uint8_t tx[15+msgLen];
  721. uint16_t chksum;
  722. tx[0] = 0xdc;
  723. tx[1] = 0x01;
  724. tx[2] = (startX>>0)&0xff;
  725. tx[3] = (startX>>8)&0xff;
  726. tx[4] = (startY>>0)&0xff;
  727. tx[5] = (startY>>8)&0xff;
  728. tx[6] = 0x03;
  729. tx[7] = 0x09;
  730. tx[8] = 0xff;
  731. tx[9] = 0x00;
  732. tx[10] = 0x00;
  733. tx[11] = (msgLen>>0)&0xff;
  734. tx[12] = (msgLen>>8)&0xff;
  735. memcpy(&tx[13], &data[0], msgLen);
  736. chksum = crc16(&tx[0], ARRAY_SIZE(tx)-2);
  737. tx[ARRAY_SIZE(tx)-2] = (chksum>>0)&0xff;
  738. tx[ARRAY_SIZE(tx)-1] = (chksum>>8)&0xff;
  739. result = tranceive(fd, tx, ARRAY_SIZE(tx));
  740. return result;
  741. }