Communicate to bluetooth devices or wifi per at-commands
Diff: at.cpp
- Revision:
- 1:ce7fb335aa1b
- Parent:
- 0:413f3c13a00a
- Child:
- 2:b8d28a4f6b02
--- a/at.cpp Mon Aug 13 20:27:21 2018 +0000 +++ b/at.cpp Thu Aug 16 21:09:12 2018 +0000 @@ -13,6 +13,7 @@ atterm at0; atterm at1; +Timer t; void CallBack0() { @@ -66,13 +67,12 @@ } -void atterm::device_init(unsigned long baud) +void atterm::device_init(unsigned long baud, _IRQ interrupt) { atterm::debug_off(1); - atserial0.attach(&CallBack0); + if(interrupt == ON) atserial0.attach(&CallBack0); atserial0.baud(baud); - atserial0.printf("AT\r\n"); - + } void atterm::at_send1(char *format, char *buf) @@ -82,12 +82,45 @@ -void atterm::device_init1(unsigned long baud) +void atterm::device_init1(unsigned long baud, _IRQ interrupt) { atterm::debug_off(1); - atserial1.attach(&CallBack1); + if(interrupt == ON) atserial1.attach(&CallBack1); atserial1.baud(baud); - atserial1.printf("AT\r\n"); + at1.at_send1("AT\r\n", ""); + +} + +char *atterm::getAnswer(uint32_t timeout) +{ + int b = 0; + int t_time = 0; + char sign, sign1; + + memset(read_timed_buffer, 0, sizeof(read_timed_buffer)); + + t.start(); + t_time = t.read(); + while(1) { + if(atserial0.readable()) { + sign = atserial0.getc(); + read_timed_buffer[b] = sign; + b ++; + } + else if(atserial1.readable()) { + sign1 = atserial1.getc(); + read_timed_buffer[b] = sign1; + b ++; + } + if((t.read() - t_time) > timeout) { + t.stop(); + t.reset(); + break; + + } + + } + return read_timed_buffer; } \ No newline at end of file