Cellular library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems
Dependents: mtsas mtsas mtsas mtsas
Utils/Terminal.cpp@4:1f63354b8d1b, 2014-05-20 (annotated)
- Committer:
- Mike Fiore
- Date:
- Tue May 20 16:11:38 2014 -0500
- Revision:
- 4:1f63354b8d1b
- Parent:
- 1:f155d94d6f3a
use MTSLog, put mbed.h in cpp files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
4:1f63354b8d1b | 1 | #include "mbed.h" |
Mike Fiore |
1:f155d94d6f3a | 2 | #include "Terminal.h" |
Mike Fiore |
4:1f63354b8d1b | 3 | #include "MTSLog.h" |
Mike Fiore |
1:f155d94d6f3a | 4 | |
Mike Fiore |
1:f155d94d6f3a | 5 | using namespace mts; |
Mike Fiore |
1:f155d94d6f3a | 6 | |
Mike Fiore |
1:f155d94d6f3a | 7 | Terminal::Terminal(MTSBufferedIO* io) : io(io), index(0) |
Mike Fiore |
1:f155d94d6f3a | 8 | { |
Mike Fiore |
1:f155d94d6f3a | 9 | terminal = new MTSSerial(USBTX, USBRX); |
Mike Fiore |
1:f155d94d6f3a | 10 | } |
Mike Fiore |
1:f155d94d6f3a | 11 | |
Mike Fiore |
1:f155d94d6f3a | 12 | Terminal::~Terminal() |
Mike Fiore |
1:f155d94d6f3a | 13 | { |
Mike Fiore |
1:f155d94d6f3a | 14 | delete terminal; |
Mike Fiore |
1:f155d94d6f3a | 15 | } |
Mike Fiore |
1:f155d94d6f3a | 16 | |
Mike Fiore |
1:f155d94d6f3a | 17 | void Terminal::start() |
Mike Fiore |
1:f155d94d6f3a | 18 | { |
Mike Fiore |
1:f155d94d6f3a | 19 | //Setup terminal session |
Mike Fiore |
4:1f63354b8d1b | 20 | logInfo("Starting Terminal Mode.\n\r"); |
Mike Fiore |
1:f155d94d6f3a | 21 | char buffer[256]; |
Mike Fiore |
1:f155d94d6f3a | 22 | bool running = true; |
Mike Fiore |
1:f155d94d6f3a | 23 | |
Mike Fiore |
1:f155d94d6f3a | 24 | //Run terminal session |
Mike Fiore |
1:f155d94d6f3a | 25 | while (running) { |
Mike Fiore |
1:f155d94d6f3a | 26 | //Write terminal data to interface |
Mike Fiore |
1:f155d94d6f3a | 27 | int terminalRead = terminal->readable(); |
Mike Fiore |
1:f155d94d6f3a | 28 | terminal->read(buffer, terminalRead); |
Mike Fiore |
1:f155d94d6f3a | 29 | io->write(buffer, terminalRead); |
Mike Fiore |
1:f155d94d6f3a | 30 | |
Mike Fiore |
1:f155d94d6f3a | 31 | //Check for exit condition |
Mike Fiore |
1:f155d94d6f3a | 32 | for (int i = 0; i < terminalRead; i++) { |
Mike Fiore |
1:f155d94d6f3a | 33 | if (index < (exitMsg.size() - 1)) { |
Mike Fiore |
1:f155d94d6f3a | 34 | if(buffer[i] == exitMsg[index]) { |
Mike Fiore |
1:f155d94d6f3a | 35 | index++; |
Mike Fiore |
1:f155d94d6f3a | 36 | } else { |
Mike Fiore |
1:f155d94d6f3a | 37 | index = 0; |
Mike Fiore |
1:f155d94d6f3a | 38 | } |
Mike Fiore |
1:f155d94d6f3a | 39 | } else { |
Mike Fiore |
1:f155d94d6f3a | 40 | running = false; |
Mike Fiore |
1:f155d94d6f3a | 41 | wait(.1); |
Mike Fiore |
1:f155d94d6f3a | 42 | } |
Mike Fiore |
1:f155d94d6f3a | 43 | } |
Mike Fiore |
1:f155d94d6f3a | 44 | |
Mike Fiore |
1:f155d94d6f3a | 45 | //Write interface data to the terminal |
Mike Fiore |
1:f155d94d6f3a | 46 | int ioRead = io->readable(); |
Mike Fiore |
1:f155d94d6f3a | 47 | io->read(buffer, ioRead); |
Mike Fiore |
1:f155d94d6f3a | 48 | terminal->write(buffer, ioRead); |
Mike Fiore |
1:f155d94d6f3a | 49 | } |
Mike Fiore |
1:f155d94d6f3a | 50 | |
Mike Fiore |
1:f155d94d6f3a | 51 | //Cleanup and return |
Mike Fiore |
1:f155d94d6f3a | 52 | io->txClear(); |
Mike Fiore |
1:f155d94d6f3a | 53 | io->rxClear(); |
Mike Fiore |
4:1f63354b8d1b | 54 | logInfo("\n\rExited Terminal Mode.\n\r"); |
Mike Fiore |
4:1f63354b8d1b | 55 | } |