123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- /*
- * lcmComm_dgus.c
- *
- * Created on : 2020-10-20
- * Update on : 2022-03-01
- * Author : Folus Wen, Eason Yang
- * Version : V0.27
- *
- */
- #include "lcmComm_dgus.h"
- //#define isDebugPrint
- //=======================================
- // Basic routine
- //=======================================
- void displayMessageDgus(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]);
- }
- //printf("%s\n", output);
- }
- //=======================================
- // Call function (Transmit message into LCD)
- //=======================================
- int transceiverDgus(int32_t fd, uint8_t *tx, uint16_t tx_len, uint8_t *rx, uint16_t rx_len)
- {
- int result = FAIL;
- int len;
- tcflush(fd,TCIOFLUSH);
- displayMessageDgus(tx, tx_len, NO);
- if(write(fd, tx, tx_len) >= ARRAY_SIZE(tx))
- {
- usleep(100);
- len = read(fd, rx, rx_len);
- if(len > 0)
- {
- if((rx[0] == CMD_ACK_VALUE_1) && (rx[1] == CMD_ACK_VALUE_2))
- {
- displayMessageDgus(rx, len, YES);
- result = PASS;
- }
- }
- }
- else
- {}
- return result;
- }
- //=======================================
- // Call function (Write register value function)
- //=======================================
- int8_t lcdRegisterWrite(int32_t fd, uint16_t address, uint8_t *data, uint8_t dataLen)
- {
- int8_t result = FAIL;
- uint8_t tx[5 + dataLen];
- uint8_t rx[128];
- memset(tx, 0x00, sizeof(tx));
- memset(rx, 0x00, sizeof(rx));
- tx[0] = CMD_HEADER_1;
- tx[1] = CMD_HEADER_2;
- tx[2] = (2 + dataLen);
- tx[3] = CMD_REG_WRITE;
- tx[4] = (address & 0xff);
- memcpy(&tx[5], data, dataLen);
- if(fd > 0)
- {
- if(transceiverDgus(fd, tx, ARRAY_SIZE(tx), rx, ARRAY_SIZE(rx)) == PASS)
- {
- result = PASS;
- }
- else
- {}
- }
- else
- {}
- return result;
- }
|