CPS_Lab*
/
Lab9
initial
main.cpp@0:d382db2d4a0f, 2018-04-03 (annotated)
- Committer:
- youngs2
- Date:
- Tue Apr 03 14:43:43 2018 +0000
- Revision:
- 0:d382db2d4a0f
- Child:
- 1:1c928ac1083f
initial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
youngs2 | 0:d382db2d4a0f | 1 | #include "mbed.h" |
youngs2 | 0:d382db2d4a0f | 2 | #include "ATParser.h" |
youngs2 | 0:d382db2d4a0f | 3 | //#define my_assert(b) if (!b) error("ASSERT FAILED at %s, line %d.\n", __FILE__, __LINE__); |
youngs2 | 0:d382db2d4a0f | 4 | #include "assert.h" |
youngs2 | 0:d382db2d4a0f | 5 | |
youngs2 | 0:d382db2d4a0f | 6 | Serial pc(SERIAL_TX, SERIAL_RX, 115200); |
youngs2 | 0:d382db2d4a0f | 7 | Serial device(PA_9, PA_10, 115200); // tx, rx |
youngs2 | 0:d382db2d4a0f | 8 | DigitalOut myled(LED1); |
youngs2 | 0:d382db2d4a0f | 9 | |
youngs2 | 0:d382db2d4a0f | 10 | ATParser at = ATParser(serial, "\r\n"); |
youngs2 | 0:d382db2d4a0f | 11 | |
youngs2 | 0:d382db2d4a0f | 12 | int connect() |
youngs2 | 0:d382db2d4a0f | 13 | { |
youngs2 | 0:d382db2d4a0f | 14 | char buffer[100] |
youngs2 | 0:d382db2d4a0f | 15 | assert(at.send("AT") && at.send("OK")); |
youngs2 | 0:d382db2d4a0f | 16 | assert(at.send("AT+N1=1,MTCDT-19400691") && at.recv("Set Network Name: MTCDT-19400691") && at.recv("OK")); |
youngs2 | 0:d382db2d4a0f | 17 | assert(at.send("AT+NK=1,MTCDT-19400691") && at.recv("Set Network Passphrase: MTCDT-19400691") && at.recv("OK")); |
youngs2 | 0:d382db2d4a0f | 18 | assert(at.send("AT+FSB=1") && at.recv("OK")); |
youngs2 | 0:d382db2d4a0f | 19 | assert(at.send("AT+JOIN") && at.recv("Successfully joined network") && at.recv("OK")); |
youngs2 | 0:d382db2d4a0f | 20 | assert(at.send("AT+DI") && at.recv("%s\r\nOK", buffer)); |
youngs2 | 0:d382db2d4a0f | 21 | return(0); |
youngs2 | 0:d382db2d4a0f | 22 | } |
youngs2 | 0:d382db2d4a0f | 23 | |
youngs2 | 0:d382db2d4a0f | 24 | int main() { |
youngs2 | 0:d382db2d4a0f | 25 | while(1) { |
youngs2 | 0:d382db2d4a0f | 26 | if(pc.readable()) { |
youngs2 | 0:d382db2d4a0f | 27 | device.putc(pc.getc()); |
youngs2 | 0:d382db2d4a0f | 28 | myled = !myled; |
youngs2 | 0:d382db2d4a0f | 29 | } |
youngs2 | 0:d382db2d4a0f | 30 | if(device.readable()) { |
youngs2 | 0:d382db2d4a0f | 31 | pc.putc(device.getc()); |
youngs2 | 0:d382db2d4a0f | 32 | myled = !myled; |
youngs2 | 0:d382db2d4a0f | 33 | } |
youngs2 | 0:d382db2d4a0f | 34 | } |
youngs2 | 0:d382db2d4a0f | 35 | } |