for hank

Dependencies:   mbed-STM32F103C8T6_new

Committer:
hankzhang
Date:
Sat Apr 18 13:02:03 2020 +0000
Revision:
4:864bb8bde75c
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hankzhang 4:864bb8bde75c 1 #include "mbed.h"
hankzhang 4:864bb8bde75c 2 #include "stm32f103c8t6.h"
hankzhang 4:864bb8bde75c 3 #include "string.h"
hankzhang 4:864bb8bde75c 4 #include "main.h"
hankzhang 4:864bb8bde75c 5
hankzhang 4:864bb8bde75c 6 #if 0
hankzhang 4:864bb8bde75c 7 DigitalOut led1(PC_13);
hankzhang 4:864bb8bde75c 8
hankzhang 4:864bb8bde75c 9 //Serial pc(PB_10,PB_11);
hankzhang 4:864bb8bde75c 10
hankzhang 4:864bb8bde75c 11 UARTSerial *_serial;
hankzhang 4:864bb8bde75c 12
hankzhang 4:864bb8bde75c 13 UARTSerial debug_uart(PB_10, PB_11, 115200);
hankzhang 4:864bb8bde75c 14 UARTSerial wifi_uart(PA_2, PA_3, 115200);
hankzhang 4:864bb8bde75c 15
hankzhang 4:864bb8bde75c 16 char rxBuf[32];
hankzhang 4:864bb8bde75c 17 char wifi_rxBuf[32];
hankzhang 4:864bb8bde75c 18 int i = 0;
hankzhang 4:864bb8bde75c 19
hankzhang 4:864bb8bde75c 20 ATCmdParser *_parser;
hankzhang 4:864bb8bde75c 21
hankzhang 4:864bb8bde75c 22 void led1_thread() {
hankzhang 4:864bb8bde75c 23 int length;
hankzhang 4:864bb8bde75c 24 while (true) {
hankzhang 4:864bb8bde75c 25 wifi_uart.write("get_down\r", 9);
hankzhang 4:864bb8bde75c 26 if(wifi_uart.readable())
hankzhang 4:864bb8bde75c 27 {
hankzhang 4:864bb8bde75c 28 length = wifi_uart.read(wifi_rxBuf, sizeof(wifi_rxBuf));
hankzhang 4:864bb8bde75c 29 debug_uart.write(wifi_rxBuf, length);
hankzhang 4:864bb8bde75c 30 }
hankzhang 4:864bb8bde75c 31 thread_sleep_for(400);
hankzhang 4:864bb8bde75c 32 }
hankzhang 4:864bb8bde75c 33 }
hankzhang 4:864bb8bde75c 34
hankzhang 4:864bb8bde75c 35
hankzhang 4:864bb8bde75c 36 void led0_thread() {
hankzhang 4:864bb8bde75c 37 int length;
hankzhang 4:864bb8bde75c 38 while (1) {
hankzhang 4:864bb8bde75c 39 if(debug_uart.readable())
hankzhang 4:864bb8bde75c 40 {
hankzhang 4:864bb8bde75c 41 length = debug_uart.read(rxBuf, sizeof(rxBuf));
hankzhang 4:864bb8bde75c 42 debug_uart.write(rxBuf, length);
hankzhang 4:864bb8bde75c 43 wifi_uart.write(rxBuf, length);
hankzhang 4:864bb8bde75c 44 debug_uart.write("111\r",4);
hankzhang 4:864bb8bde75c 45 }
hankzhang 4:864bb8bde75c 46 if(wifi_uart.readable())
hankzhang 4:864bb8bde75c 47 {
hankzhang 4:864bb8bde75c 48 length = wifi_uart.read(rxBuf, sizeof(rxBuf));
hankzhang 4:864bb8bde75c 49 debug_uart.write(rxBuf, length);
hankzhang 4:864bb8bde75c 50 debug_uart.write("222\r",4);
hankzhang 4:864bb8bde75c 51
hankzhang 4:864bb8bde75c 52 }
hankzhang 4:864bb8bde75c 53 wait(0.5);
hankzhang 4:864bb8bde75c 54 }
hankzhang 4:864bb8bde75c 55 }
hankzhang 4:864bb8bde75c 56
hankzhang 4:864bb8bde75c 57
hankzhang 4:864bb8bde75c 58 int main() {
hankzhang 4:864bb8bde75c 59 int length;
hankzhang 4:864bb8bde75c 60 led1 = 1;
hankzhang 4:864bb8bde75c 61
hankzhang 4:864bb8bde75c 62 wait(2);
hankzhang 4:864bb8bde75c 63
hankzhang 4:864bb8bde75c 64 //debug_uart.printf("hello world\r\n");
hankzhang 4:864bb8bde75c 65 debug_uart.write("hello world",11);
hankzhang 4:864bb8bde75c 66
hankzhang 4:864bb8bde75c 67 WIFI_PWREN = 1;
hankzhang 4:864bb8bde75c 68 #if 0
hankzhang 4:864bb8bde75c 69 while(1){
hankzhang 4:864bb8bde75c 70 if(debug_uart.readable())
hankzhang 4:864bb8bde75c 71 {
hankzhang 4:864bb8bde75c 72 length = debug_uart.read(rxBuf, sizeof(rxBuf));
hankzhang 4:864bb8bde75c 73 debug_uart.write(rxBuf, length);
hankzhang 4:864bb8bde75c 74 debug_uart.write("test",4);
hankzhang 4:864bb8bde75c 75 }
hankzhang 4:864bb8bde75c 76 wait(0.5);
hankzhang 4:864bb8bde75c 77 }
hankzhang 4:864bb8bde75c 78 //wifi_debug();
hankzhang 4:864bb8bde75c 79
hankzhang 4:864bb8bde75c 80
hankzhang 4:864bb8bde75c 81 _serial = new UARTSerial(PA_2, PA_3, 115200);
hankzhang 4:864bb8bde75c 82 _parser = new ATCmdParser(_serial);
hankzhang 4:864bb8bde75c 83 _parser->debug_on( 1 );
hankzhang 4:864bb8bde75c 84 _parser->set_delimiter("\r\n");
hankzhang 4:864bb8bde75c 85
hankzhang 4:864bb8bde75c 86 debug_uart.printf("\nATCmdParser: Retrieving model");
hankzhang 4:864bb8bde75c 87 _parser->send("model\\r");
hankzhang 4:864bb8bde75c 88
hankzhang 4:864bb8bde75c 89 _parser->recv("%s", model);
hankzhang 4:864bb8bde75c 90 debug_uart.printf("model:%s", model);
hankzhang 4:864bb8bde75c 91 #endif
hankzhang 4:864bb8bde75c 92
hankzhang 4:864bb8bde75c 93 Thread thread0(osPriorityNormal, 512, nullptr, nullptr);
hankzhang 4:864bb8bde75c 94 Thread thread1(osPriorityNormal, 512, nullptr, nullptr);
hankzhang 4:864bb8bde75c 95 //Thread thread2(osPriorityNormal, 512, nullptr, nullptr);
hankzhang 4:864bb8bde75c 96
hankzhang 4:864bb8bde75c 97 thread0.start(led0_thread);
hankzhang 4:864bb8bde75c 98 thread1.start(led1_thread);
hankzhang 4:864bb8bde75c 99
hankzhang 4:864bb8bde75c 100 //wifi_serial.printf("model\r\n");
hankzhang 4:864bb8bde75c 101 //thread1.start(led1_thread);
hankzhang 4:864bb8bde75c 102 //thread2.start(led2_thread);
hankzhang 4:864bb8bde75c 103 while(1)
hankzhang 4:864bb8bde75c 104 {
hankzhang 4:864bb8bde75c 105 debug_uart.write("--main--\r\n",10);
hankzhang 4:864bb8bde75c 106 wait(3);
hankzhang 4:864bb8bde75c 107 }
hankzhang 4:864bb8bde75c 108
hankzhang 4:864bb8bde75c 109 }
hankzhang 4:864bb8bde75c 110
hankzhang 4:864bb8bde75c 111 #endif