Selaa lähdekoodia

[Improve][DM30][DW30][UART tranceive]: Import new tranceive function tranceiveRelDelayTime().

2020.06.16 / TC Hsu

Actions: Add tranceiveRelDelayTime() function which base on tranceive(), but with new argument _delay, it will using the _delay argument to decide the read delay time after write.

Image version    : N/A
Image checksum   : N/A

Hardware PWB P/N : N/A
Hardware Version : N/A

Files:

	modified:   EVSE/Projects/DM30/Apps/internalComm.c
	modified:   EVSE/Projects/DW30/Apps/internalComm.c
TC_Hsu 4 vuotta sitten
vanhempi
commit
b52992a94a
2 muutettua tiedostoa jossa 44 lisäystä ja 0 poistoa
  1. 22 0
      EVSE/Projects/DM30/Apps/internalComm.c
  2. 22 0
      EVSE/Projects/DW30/Apps/internalComm.c

+ 22 - 0
EVSE/Projects/DM30/Apps/internalComm.c

@@ -42,11 +42,33 @@ struct Address Addr={0x01,0x02,0x03,0x05,0x06,0xFF};
 struct Command Cmd={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x24,0x27,0x28,0x29,0x2C,0x81,0x83,
                     0x85,0x86,0x87,0x88,0x089,0x8A,0x8B,0x8C,0x90,0x93,0xe0,0xe1,0xe2,0xe3};
 
+int tranceiveRelDelayTime(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx, unsigned short _delay)
+{
+    int len;
+    //sleep(2); //required to make flush work, for some reason
+    tcflush(fd,TCIOFLUSH);
+
+    if(write(fd, cmd, cmd_len) >= cmd_len)
+    {
+        usleep(_delay * 1000);
+        len = read(fd, rx, 512);
+    }
+    else
+    {
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("Serial command %s response fail.\n", cmd);
+        #endif
+    }
+
+    return len;
+}
+
 int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
 {
     int len;
     //sleep(2); //required to make flush work, for some reason
     tcflush(fd,TCIOFLUSH);
+
     if(write(fd, cmd, cmd_len) >= cmd_len)
     {
         usleep(15000);

+ 22 - 0
EVSE/Projects/DW30/Apps/internalComm.c

@@ -42,11 +42,33 @@ struct Address Addr={0x01,0x02,0x03,0x05,0x06,0xFF};
 struct Command Cmd={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x24,0x27,0x28,0x29,0x2C,0x81,0x83,
                     0x85,0x86,0x87,0x88,0x089,0x8A,0x8B,0x8C,0x90,0x93,0xe0,0xe1,0xe2,0xe3};
 
+int tranceiveRelDelayTime(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx, unsigned short _delay)
+{
+    int len;
+    //sleep(2); //required to make flush work, for some reason
+    tcflush(fd,TCIOFLUSH);
+
+    if(write(fd, cmd, cmd_len) >= cmd_len)
+    {
+        usleep(_delay * 1000);
+        len = read(fd, rx, 512);
+    }
+    else
+    {
+        #ifdef SystemLogMessage
+        DEBUG_ERROR("Serial command %s response fail.\n", cmd);
+        #endif
+    }
+
+    return len;
+}
+
 int tranceive(int fd, unsigned char* cmd, unsigned char cmd_len, unsigned char* rx)
 {
     int len;
     //sleep(2); //required to make flush work, for some reason
     tcflush(fd,TCIOFLUSH);
+
     if(write(fd, cmd, cmd_len) >= cmd_len)
     {
         usleep(15000);