v1.0
Dependencies: SDFileSystem mbed
main.cpp@0:0073c8def9f1, 2016-05-09 (annotated)
- Committer:
- jehoon
- Date:
- Mon May 09 00:13:40 2016 +0000
- Revision:
- 0:0073c8def9f1
WiFi Tracker
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jehoon | 0:0073c8def9f1 | 1 | #include "mbed.h" |
jehoon | 0:0073c8def9f1 | 2 | #include "WiFiTracker.h" |
jehoon | 0:0073c8def9f1 | 3 | |
jehoon | 0:0073c8def9f1 | 4 | Serial wifi(P23, P24); |
jehoon | 0:0073c8def9f1 | 5 | |
jehoon | 0:0073c8def9f1 | 6 | int8_t send_command(char*); |
jehoon | 0:0073c8def9f1 | 7 | void init_tracker(); |
jehoon | 0:0073c8def9f1 | 8 | int tracking(); |
jehoon | 0:0073c8def9f1 | 9 | |
jehoon | 0:0073c8def9f1 | 10 | WiFiTracker tracker; |
jehoon | 0:0073c8def9f1 | 11 | |
jehoon | 0:0073c8def9f1 | 12 | int main() { |
jehoon | 0:0073c8def9f1 | 13 | |
jehoon | 0:0073c8def9f1 | 14 | wifi.baud(9600); |
jehoon | 0:0073c8def9f1 | 15 | |
jehoon | 0:0073c8def9f1 | 16 | printf("Start Tracking...\n"); |
jehoon | 0:0073c8def9f1 | 17 | |
jehoon | 0:0073c8def9f1 | 18 | init_tracker(); |
jehoon | 0:0073c8def9f1 | 19 | |
jehoon | 0:0073c8def9f1 | 20 | while(1) |
jehoon | 0:0073c8def9f1 | 21 | { |
jehoon | 0:0073c8def9f1 | 22 | tracking(); |
jehoon | 0:0073c8def9f1 | 23 | } |
jehoon | 0:0073c8def9f1 | 24 | |
jehoon | 0:0073c8def9f1 | 25 | } |
jehoon | 0:0073c8def9f1 | 26 | |
jehoon | 0:0073c8def9f1 | 27 | |
jehoon | 0:0073c8def9f1 | 28 | // 0x4000/04:1b:ba:21:6d:a1/-66 |
jehoon | 0:0073c8def9f1 | 29 | int tracking() |
jehoon | 0:0073c8def9f1 | 30 | { |
jehoon | 0:0073c8def9f1 | 31 | char buf[30] = {0,}; |
jehoon | 0:0073c8def9f1 | 32 | int i=0; |
jehoon | 0:0073c8def9f1 | 33 | |
jehoon | 0:0073c8def9f1 | 34 | while(1) |
jehoon | 0:0073c8def9f1 | 35 | { |
jehoon | 0:0073c8def9f1 | 36 | if(wifi.readable()) |
jehoon | 0:0073c8def9f1 | 37 | { |
jehoon | 0:0073c8def9f1 | 38 | buf[i++] = wifi.getc(); |
jehoon | 0:0073c8def9f1 | 39 | |
jehoon | 0:0073c8def9f1 | 40 | if(strstr(buf,"\r\n")) |
jehoon | 0:0073c8def9f1 | 41 | { |
jehoon | 0:0073c8def9f1 | 42 | tracker.write_sdcard(buf, i); |
jehoon | 0:0073c8def9f1 | 43 | return 0; |
jehoon | 0:0073c8def9f1 | 44 | } |
jehoon | 0:0073c8def9f1 | 45 | } |
jehoon | 0:0073c8def9f1 | 46 | } |
jehoon | 0:0073c8def9f1 | 47 | } |
jehoon | 0:0073c8def9f1 | 48 | |
jehoon | 0:0073c8def9f1 | 49 | |
jehoon | 0:0073c8def9f1 | 50 | void init_tracker() |
jehoon | 0:0073c8def9f1 | 51 | { |
jehoon | 0:0073c8def9f1 | 52 | |
jehoon | 0:0073c8def9f1 | 53 | //char cmd[] = "AT+MWPACKET=3,1,1,0,4000,,11010111"; |
jehoon | 0:0073c8def9f1 | 54 | char cmd[] = "AT+MWPACKET=3,1,3,0,4000,,10010001"; |
jehoon | 0:0073c8def9f1 | 55 | int8_t ret = -1; |
jehoon | 0:0073c8def9f1 | 56 | |
jehoon | 0:0073c8def9f1 | 57 | |
jehoon | 0:0073c8def9f1 | 58 | ret = send_command(cmd); |
jehoon | 0:0073c8def9f1 | 59 | printf("init ret: %d",ret); |
jehoon | 0:0073c8def9f1 | 60 | |
jehoon | 0:0073c8def9f1 | 61 | |
jehoon | 0:0073c8def9f1 | 62 | } |
jehoon | 0:0073c8def9f1 | 63 | |
jehoon | 0:0073c8def9f1 | 64 | int8_t send_command(char* cmd) |
jehoon | 0:0073c8def9f1 | 65 | { |
jehoon | 0:0073c8def9f1 | 66 | int len = strlen(cmd); |
jehoon | 0:0073c8def9f1 | 67 | int i; |
jehoon | 0:0073c8def9f1 | 68 | |
jehoon | 0:0073c8def9f1 | 69 | for(i=0; i<len; i++) |
jehoon | 0:0073c8def9f1 | 70 | wifi.putc(cmd[i]); |
jehoon | 0:0073c8def9f1 | 71 | |
jehoon | 0:0073c8def9f1 | 72 | wifi.putc('\r'); |
jehoon | 0:0073c8def9f1 | 73 | wifi.putc('\n'); |
jehoon | 0:0073c8def9f1 | 74 | |
jehoon | 0:0073c8def9f1 | 75 | return 0; |
jehoon | 0:0073c8def9f1 | 76 | } |
jehoon | 0:0073c8def9f1 | 77 | |
jehoon | 0:0073c8def9f1 | 78 | //int8_t wait_response(char* rsp, uint32_t timeout) |
jehoon | 0:0073c8def9f1 | 79 | //{ |
jehoon | 0:0073c8def9f1 | 80 | // char buf[256] = {0,}; |
jehoon | 0:0073c8def9f1 | 81 | // char c; |
jehoon | 0:0073c8def9f1 | 82 | // Timer t; |
jehoon | 0:0073c8def9f1 | 83 | // uint32_t time; |
jehoon | 0:0073c8def9f1 | 84 | // t.start(); |
jehoon | 0:0073c8def9f1 | 85 | // |
jehoon | 0:0073c8def9f1 | 86 | // while(1) |
jehoon | 0:0073c8def9f1 | 87 | // { |
jehoon | 0:0073c8def9f1 | 88 | // if(wifi.readable()) |
jehoon | 0:0073c8def9f1 | 89 | // tracker.write(wifi.getc()); |
jehoon | 0:0073c8def9f1 | 90 | // |
jehoon | 0:0073c8def9f1 | 91 | // // 수정해야 |
jehoon | 0:0073c8def9f1 | 92 | // |
jehoon | 0:0073c8def9f1 | 93 | // } |
jehoon | 0:0073c8def9f1 | 94 | //} |