test

Dependencies:   mbed-STM32F103C8T6 mbed-rtos mbed-dev

Revision:
3:30d61fa10b98
Parent:
2:f48b0967b6cc
Child:
4:864bb8bde75c
--- a/main.cpp	Thu Apr 16 07:15:00 2020 +0000
+++ b/main.cpp	Sat Apr 18 06:31:52 2020 +0000
@@ -1,46 +1,104 @@
 #include "mbed.h"
 #include "stm32f103c8t6.h"
+#include "string.h"
+#include "main.h"
 
 DigitalOut led1(PC_13);
 
-Serial pc(PA_9,PA_10);
+//Serial pc(PB_10,PB_11);
+
+UARTSerial *_serial;
 
+UARTSerial debug_uart(PB_10, PB_11, 115200);
+UARTSerial wifi_uart(PA_2, PA_3, 115200);
+
+char      rxBuf[64];
+int       i = 0;
+
+ATCmdParser *_parser;
  
 void led2_thread() {
     while (true) {
-        pc.printf("led2_thread\r\n");
+        debug_uart.write("led2+++", 6);
         thread_sleep_for(4000);
     }
 }
 
-void led1_thread() {
-    while (true) {
-        pc.printf("led1_thread\r\n");
-        thread_sleep_for(3000);
-    }
+void debug_uart_recv() {
+    //rxBuf[i++] = debug_uart.getc();
+    debug_uart.read(rxBuf, 5);
 } 
 
 void led0_thread() {
-    while (true) {
-        pc.printf("led0_thread\r\n");
-        thread_sleep_for(2000);
+    int length;
+    while (1) {
+        if(debug_uart.readable())
+        {
+              length = debug_uart.read(rxBuf, sizeof(rxBuf)); 
+              debug_uart.write(rxBuf, length); 
+              wifi_uart.write(rxBuf, length);
+              debug_uart.write("111\r",4);
+        }
+        if(wifi_uart.readable())
+        {
+            length = wifi_uart.read(rxBuf, sizeof(rxBuf));
+            debug_uart.write(rxBuf, length); 
+            debug_uart.write("222\r",4);
+              
+        }
+        wait(0.5);
     }
 }
+
+
 int main() {
-    pc.baud(115200);
-    pc.printf("hello world\r\n");
+    int length;
+    led1 = 1;
+    
+    wait(2);
+    
+    //debug_uart.printf("hello world\r\n");
+    debug_uart.write("hello world",11);
     
+    WIFI_PWREN = 1;
+#if 0  
+    while(1){
+        if(debug_uart.readable())
+        {
+              length = debug_uart.read(rxBuf, sizeof(rxBuf)); 
+              debug_uart.write(rxBuf, length); 
+              debug_uart.write("test",4);
+        }
+        wait(0.5);
+   }
+    //wifi_debug();
+    
+
+    _serial = new UARTSerial(PA_2, PA_3, 115200);
+    _parser = new ATCmdParser(_serial);
+    _parser->debug_on( 1 );
+    _parser->set_delimiter("\r\n");
+    
+    debug_uart.printf("\nATCmdParser: Retrieving model");
+    _parser->send("model\\r");
+    
+    _parser->recv("%s", model);
+    debug_uart.printf("model:%s", model);
+ #endif   
+ 
     Thread thread0(osPriorityNormal, 512, nullptr, nullptr);
-    Thread thread1(osPriorityNormal, 512, nullptr, nullptr);
-    Thread thread2(osPriorityNormal, 512, nullptr, nullptr);
+    //Thread thread1(osPriorityNormal, 512, nullptr, nullptr);
+    //Thread thread2(osPriorityNormal, 512, nullptr, nullptr);
     
     thread0.start(led0_thread);
-    thread1.start(led1_thread);
-    thread2.start(led2_thread);
     
-    while (true) {
-        //led1 = !led1;
-        thread_sleep_for(5000);
-        pc.printf("+++++main task++++++\r\n");
+    //wifi_serial.printf("model\r\n");
+    //thread1.start(led1_thread);
+    //thread2.start(led2_thread);
+    while(1)
+    {
+        debug_uart.write("--main--\r\n",10);
+        wait(3);
     }
+
 }
\ No newline at end of file