aa

Dependencies:   mbed TrapezoidControl QEI

Revision:
21:1f1e9c585da8
Parent:
0:669ef71cba68
--- a/Communication/RS485/RS485.cpp	Sun Sep 01 01:33:36 2019 +0000
+++ b/Communication/RS485/RS485.cpp	Fri Sep 13 01:36:42 2019 +0000
@@ -1,24 +1,35 @@
 #include "RS485.h"
 #include "mbed.h"
 #include "ActuatorHub/ActuatorHub.h"
+#include "LineHub/LineHub.h"
 #include "../../LED/LED.h"
 #include "../../System/Using.h"
 
 namespace RS485 {
-    DigitalOut selectBit(SELECTBIT_PIN);
+    
+    DigitalOut selectBitT(SELECTBIT_T_PIN);
+//  DigitalOut selectBitR(SELECTBIT_R_PIN);
     Serial RS485Uart(RS485UART_TX, RS485UART_RX);
+    Serial RS485Line(RS485LINE_TX, RS485LINE_RX);
+    
+    bool readFase = 0;
+    char buffer[RS485_BUFFER_LINE] = {0};
 
     void Transmit();
+    void Recieve();
 
     void RS485::Initialize() {
-        selectBit = 1;  //送信固定
+        selectBitT = 1;  //送信固定
+//      selectBitR = 0;  //受信固定
         RS485Uart.baud(38400);
-        RS485Uart.attach(Transmit, Serial::TxIrq);
+        RS485Uart.attach(Transmit, Serial::TxIrq);  //送信割り込み
+        RS485Line.baud(9600);
+        RS485Line.attach(Recieve, Serial::RxIrq);  //受信割り込み
     }
 
     void Transmit() {
+//        __disable_irq();
         static uint8_t count = 0;
-        __disable_irq();
         RS485Uart.putc(RS485SendBuffer.GetData());
         if(count >= 200) {
             #ifdef USE_MOTOR
@@ -29,4 +40,33 @@
         } else count++;
         __enable_irq();
     }
-}
+    
+    void Recieve() {
+        __disable_irq();
+        static uint8_t time = 0;
+        static uint8_t count = 0;
+        char data = RS485Line.getc();
+        if (data == 'S') {
+            readFase = true;
+            time = 0;
+        } else if(data == 'F') {
+            readFase = false;
+            for(int i = 0; i < 8; i++) {
+                lineData[i] = buffer[i];
+            }
+            time = 0;
+        } else if(readFase) {
+            RS485LineBuffer.PutData(data);
+            buffer[time] = data;
+            time++;
+        } else {
+            readFase = false;
+            time = 0;
+        }
+        if(count >= 200) {
+            LED_DEBUG1 = !LED_DEBUG1;
+            count = 0;
+        } else count++;
+        __enable_irq();
+    }
+}
\ No newline at end of file