Support for LISA-N101
Fork of C027_Support by
This is a variant of the C027 driver code for the C027N version, i.e. the one with the Neul/Huawei/u-blox Cellular Internet of Things module on board. The AT command interface for this module is entirely different to the AT interface for the other u-blox modules, hence this fork of the driver. Work is underway to rearchitect the original C027 driver so that a merge can be done.
Diff: MDM.cpp
- Revision:
- 124:a58c1a7c5e18
- Parent:
- 122:c6b2fa1928f2
- Child:
- 125:72ca0c9a5a06
--- a/MDM.cpp Mon Mar 16 13:10:46 2015 +0000 +++ b/MDM.cpp Mon Mar 16 16:28:57 2015 +0000 @@ -38,6 +38,9 @@ #define CYA COL("36m") #define WHY COL("37m") +const char hexTable[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', \ + '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + void dumpAtCmd(const char* buf, int len) { ::printf(" %3d \"", len); @@ -66,6 +69,7 @@ { if (_debugLevel >= level) { + ::printf("_debugPrint %d %d\r\n", _debugLevel, level); va_list args; va_start (args, format); if (color) ::printf(color); @@ -455,7 +459,7 @@ waitFinalResp(NULL, NULL, 1000); #ifdef C027N_USE_NMI // Switch on new message indications - sendFormated("AT+NMI=1\r\n"); + sendFormated("AT+NMI=2\r\n"); if (RESP_OK != waitFinalResp()) goto failure; #else @@ -1512,16 +1516,24 @@ bool MDMParser::datagramSend(int size, const char* buf) { bool ok = false; + int sizeToSend; + char bufToSend[MAX_SIZE]; LOCK(); - sendFormated ("AT+MGS=%d,%.*s\r\n", size / 2, size, buf); - ok = (RESP_OK == waitFinalResp(_cbMGS, &ok)) && ok; - if (ok) { - ok = (RESP_OK == waitFinalResp(NULL)); + + if (size <= (int) (sizeof(bufToSend) / 2)) + { + sizeToSend = bytesToHexString (buf, size, bufToSend, sizeof(bufToSend)); + sendFormated ("AT+MGS=%d,%.*s\r\n", size, sizeToSend, bufToSend); + ok = (RESP_OK == waitFinalResp(_cbMGS, &ok)) && ok; if (ok) { - ok = (RESP_OK == waitFinalResp(_cbSMI, &ok, 30000)) && ok; + ok = (RESP_OK == waitFinalResp(NULL)); + if (ok) { + ok = (RESP_OK == waitFinalResp(_cbSMI, &ok, 30000)) && ok; + } } } + UNLOCK(); return ok; @@ -1683,6 +1695,25 @@ return ok; } +int MDMParser::bytesToHexString (const char * inBuf, int size, char *outBuf, int lenOutBuf) +{ + int x = 0; + int y = 0; + + for (x = 0; (x < size) && (y < lenOutBuf); x++) + { + outBuf[y] = hexTable[(inBuf[x] >> 4) & 0x0f]; // upper nibble + y++; + if (y < lenOutBuf) + { + outBuf[y] = hexTable[inBuf[x] & 0x0f]; // lower nibble + y++; + } + } + + return y; +} + void MDMParser::hexStringToBytes (const char *inBuf, int lenInBuf, char * outBuf, int* lenOutBuf) { int x; @@ -2091,4 +2122,4 @@ int MDMUsb::getLine(char* buffer, int length) { return NOT_FOUND; } -#endif +#endif \ No newline at end of file