Add a bunch of APNs

Fork of C027_Support by Xinlei Cao

Committer:
mazgch
Date:
Mon Mar 24 07:38:05 2014 +0000
Revision:
19:2b5d097ca15d
Parent:
18:e5697801df29
Child:
21:c4d64830bf02
prepare for native C027 platform support; add api to get lat/lon; better separation of mdm libarary from serial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazgch 18:e5697801df29 1 #include "mbed.h"
mazgch 18:e5697801df29 2 #include <ctype.h>
mazgch 18:e5697801df29 3 #include "MDM.h"
mazgch 18:e5697801df29 4
mazgch 18:e5697801df29 5
mazgch 18:e5697801df29 6 int MDMParser::send(const char* buf, int len)
mazgch 18:e5697801df29 7 {
mazgch 18:e5697801df29 8 return _send(buf, len);
mazgch 18:e5697801df29 9 }
mazgch 18:e5697801df29 10
mazgch 18:e5697801df29 11 int MDMParser::_getLine(Pipe<char>* pipe, char* buffer, int length)
mazgch 18:e5697801df29 12 {
mazgch 18:e5697801df29 13 int o = 0;
mazgch 18:e5697801df29 14 int i = 0;
mazgch 18:e5697801df29 15 int l = pipe->start();
mazgch 18:e5697801df29 16 while ((i < l) && (o < length))
mazgch 18:e5697801df29 17 {
mazgch 18:e5697801df29 18 int t = pipe->next();
mazgch 18:e5697801df29 19 i ++;
mazgch 18:e5697801df29 20 if (t == '\r') // terminate commands with carriage return
mazgch 18:e5697801df29 21 {
mazgch 18:e5697801df29 22 pipe->done();
mazgch 18:e5697801df29 23 if (length > o)
mazgch 18:e5697801df29 24 buffer[o] = '\0';
mazgch 18:e5697801df29 25 return o; // if enter send the zero char
mazgch 18:e5697801df29 26 }
mazgch 18:e5697801df29 27 else if (t == '\n') // skip/filter new line
mazgch 18:e5697801df29 28 /* skip */;
mazgch 18:e5697801df29 29 else if (t != '\b') // normal char (no backspace)
mazgch 18:e5697801df29 30 buffer[o++] = t;
mazgch 18:e5697801df29 31 else if (o > 0) // backspace
mazgch 18:e5697801df29 32 o --; // remove it
mazgch 18:e5697801df29 33 }
mazgch 18:e5697801df29 34 o = 0;
mazgch 18:e5697801df29 35 if (length > 0)
mazgch 18:e5697801df29 36 buffer[0] = '\0';
mazgch 18:e5697801df29 37 return WAIT;
mazgch 18:e5697801df29 38 }
mazgch 18:e5697801df29 39
mazgch 18:e5697801df29 40 int MDMParser::_getResp(Pipe<char>* pipe, char* buffer, int length)
mazgch 18:e5697801df29 41 {
mazgch 18:e5697801df29 42 int o = 0;
mazgch 18:e5697801df29 43 int i = 0;
mazgch 18:e5697801df29 44 int l = pipe->start();
mazgch 18:e5697801df29 45 static const char erTxt[] = "ERROR\r\n";
mazgch 18:e5697801df29 46 static const char okTxt[] = "OK\r\n";
mazgch 18:e5697801df29 47 int er = 0;
mazgch 18:e5697801df29 48 int ok = 0;
mazgch 18:e5697801df29 49 while ((i < pipe->size()) && (o < length))
mazgch 18:e5697801df29 50 {
mazgch 18:e5697801df29 51 int t = pipe->next();
mazgch 18:e5697801df29 52 i ++;
mazgch 18:e5697801df29 53 buffer[o++] = t;
mazgch 18:e5697801df29 54 ok = (t == okTxt[ok]) ? ok + 1 : 0;
mazgch 18:e5697801df29 55 er = (t == erTxt[er]) ? er + 1 : 0;
mazgch 18:e5697801df29 56 if ((okTxt[ok] == '\0') || (erTxt[er] == '\0'))
mazgch 18:e5697801df29 57 {
mazgch 18:e5697801df29 58 pipe->done();
mazgch 18:e5697801df29 59 if (length > o)
mazgch 18:e5697801df29 60 buffer[o] = '\0';
mazgch 18:e5697801df29 61 return o;
mazgch 18:e5697801df29 62 }
mazgch 18:e5697801df29 63 }
mazgch 18:e5697801df29 64 o = 0;
mazgch 18:e5697801df29 65 if (length > 0)
mazgch 18:e5697801df29 66 buffer[0] = '\0';
mazgch 18:e5697801df29 67 return WAIT;
mazgch 18:e5697801df29 68 }
mazgch 18:e5697801df29 69
mazgch 18:e5697801df29 70 // ----------------------------------------------------------------
mazgch 18:e5697801df29 71 // Serial Implementation
mazgch 18:e5697801df29 72 // ----------------------------------------------------------------
mazgch 18:e5697801df29 73
mazgch 19:2b5d097ca15d 74 MDMSerial::MDMSerial(PinName tx /*= MDMTXD*/, PinName rx /*= MDMRXD*/,
mazgch 19:2b5d097ca15d 75 int baudrate /*= MDMBAUD*/,
mazgch 19:2b5d097ca15d 76 #if DEVICE_SERIAL_FC
mazgch 19:2b5d097ca15d 77 PinName rts /*= MDMRTS*/, PinName cts /*= MDMCTS*/,
mazgch 19:2b5d097ca15d 78 #endif
mazgch 18:e5697801df29 79 int rxSize /*= 256*/, int txSize /*= 128*/) :
mazgch 19:2b5d097ca15d 80 #if DEVICE_SERIAL_FC
mazgch 19:2b5d097ca15d 81 SerialPipe(tx, rx, rts, cts, rxSize, txSize)
mazgch 19:2b5d097ca15d 82 #else
mazgch 18:e5697801df29 83 SerialPipe(tx, rx, rxSize, txSize)
mazgch 19:2b5d097ca15d 84 #endif
mazgch 18:e5697801df29 85 {
mazgch 18:e5697801df29 86 baud(baudrate);
mazgch 18:e5697801df29 87 }
mazgch 18:e5697801df29 88
mazgch 18:e5697801df29 89 int MDMSerial::_send(const void* buf, int len)
mazgch 18:e5697801df29 90 {
mazgch 18:e5697801df29 91 return put((const char*)buf, len, true/*=blocking*/);
mazgch 18:e5697801df29 92 }
mazgch 18:e5697801df29 93
mazgch 18:e5697801df29 94 int MDMSerial::getLine(char* buffer, int length)
mazgch 18:e5697801df29 95 {
mazgch 18:e5697801df29 96 return _getLine(&_pipeRx, buffer, length);
mazgch 18:e5697801df29 97 }
mazgch 18:e5697801df29 98
mazgch 18:e5697801df29 99 int MDMSerial::getResp(char* buffer, int length)
mazgch 18:e5697801df29 100 {
mazgch 18:e5697801df29 101 return _getResp(&_pipeRx, buffer, length);
mazgch 18:e5697801df29 102 }
mazgch 18:e5697801df29 103
mazgch 18:e5697801df29 104 // ----------------------------------------------------------------
mazgch 18:e5697801df29 105 // USB Implementation
mazgch 18:e5697801df29 106 // ----------------------------------------------------------------
mazgch 18:e5697801df29 107
mazgch 18:e5697801df29 108 #ifdef HAVE_MDMUSB
mazgch 18:e5697801df29 109 // TODO properly implement with USB
mazgch 18:e5697801df29 110 MDMUsb::MDMUsb(void) { }
mazgch 18:e5697801df29 111 int MDMUsb::_send(const void* buf, int len) { return len; }
mazgch 18:e5697801df29 112 int MDMUsb::getLine(char* buffer, int length) { return NOT_FOUND; }
mazgch 18:e5697801df29 113 int MDMUsb::getResp(char* buffer, int length) { return NOT_FOUND; }
mazgch 18:e5697801df29 114 #endif