easy connect wnc added to http request with debug mode enabled. traces collected for AT%CGEQOS, AT%MEAS, AT%PCONI
Fork of WncControllerLibrary by
Diff: WncController.cpp
- Revision:
- 33:2958e09ad308
- Parent:
- 32:6512f41ac6f0
- Child:
- 35:7c9d0f29ff7a
diff -r 6512f41ac6f0 -r 2958e09ad308 WncController.cpp --- a/WncController.cpp Mon Oct 10 17:02:24 2016 +0000 +++ b/WncController.cpp Thu Nov 17 15:30:42 2016 +0000 @@ -24,6 +24,54 @@ @version 1.0 @date July 2016 @author Fred Kellerman + + + An Example of usage: + + WncControllerK64F mdm(&wncPinList, &mdmUart, &debugUart); + + mdm.enableDebug(true, true); + + if (false == mdm.powerWncOn("m2m.com.attz", 60)) { + while(1); + } + + // ICCID and MSISDN + string iccid; string msisdn; + if (mdm.getICCID(&iccid) == true) { + if (mdm.convertICCIDtoMSISDN(iccid, &msisdn) == true) { + // Send an SMS message (must use 15-digit MISDN number!) + mdm.sendSMSText(msisdn.c_str(), "Hello from WNC Kit -> from WNC"); + } + } + + // Get an IP address setup for the socket #1 (0 indexed)) + if (true == mdm.resolveUrl(0, "www.att.com")) + { + // Report server IP + if (true == mdm.getIpAddr(0, ipAddrStr)) { + debugUart.puts("Server IP: "); + debugUart.puts(ipAddrStr); + debugUart.puts("\r\n"); + } + + // Open Socket #1, TCP=true resolved IP on port 80: + if (true == mdm.openSocket(0, 80, true)) { + // Write some data + const uint8_t * dataStr = "GET /index.html HTTP/1.0\r\nFrom: someuser@someuser.com\r\nUser-Agent: HTTPTool/1.0\r\n\r\n"; + if (true == mdm.write(0, dataStr, strlen((const char *)dataStr))) + { + const uint8_t * myBuf; + mdm.setReadRetries(0, 20); + uint32_t n = mdm.read(0, &myBuf); + if (n > 0) + debugUart.printf("Read %d chars: %s\r\n", n, myBuf); + else + debugUart.puts("No read data!\r\n"); + } + } + } + */ @@ -55,8 +103,7 @@ * C++ version 0.4 char* style "itoa": * Written by Lukás Chmela * Released under GPLv3. -*/ - + */ static char* itoa(int64_t value, char* result, int base) { // check that the base is valid @@ -103,18 +150,6 @@ return (str); } -/** - * \brief Constructor for UART controlled WNC - * - * \param [in] wnc_uart - Reference to a SerialBuffered object which will - * be used as the bus to control the WNC. - * - * \return None. - * - * \details Adding another way to talk to the WNC, like I2C or USB, - * a constructor should be added for each type just like the SerialBuffered - * constructor below. - */ WncController::WncController(void) { for(unsigned i; i<MAX_NUM_WNC_SOCKETS; i++) @@ -127,29 +162,11 @@ m_sMoreDebugEnabled = moreDebugOn; } -/** - * \brief Used internally but also make public for a user of the Class to interrogate state as well. - * - * \param [in] None. - * - * \return The state of the WNC Modem. - * - * \details None. - */ WncController::WncState_e WncController::getWncStatus(void) { return (m_sState); } -/** - * \brief Return signal quality dBm level - * - * \param [in] None. - * - * \return The dBm signal level at the time of the request. - * - * \details This polls (at the time of the call) the cell signal. - */ int16_t WncController::getDbmRssi(void) { int16_t rssi, ber; @@ -168,18 +185,6 @@ return (99); } - -/** - * \brief Power up and down (down not implemented yet) - * - * \param [in] on - set true to power on, otherwise false - * - * \return None. - * - * \details Power-on works but not power-down. This will manipulate WNC Shield hardware - * and bring it to life. It will also initialize the WNC enough to get it to be able to open sockets - * (with AT commands) - */ bool WncController::powerWncOn(const char * const apn, uint8_t powerUpTimeoutSecs) { dbgPuts("Waiting for WNC to Initialize..."); @@ -270,16 +275,6 @@ return (false); } - -/** - * \brief Look-up a URL text string and convert into an IP Address string. - * - * \param [in] url - the URL to lookup. numSock - the socket number to resolve. - * - * \return true - if the IP address has been resolved. false - if the URL could not be resolved. - * - * \details None. - */ bool WncController::resolveUrl(uint16_t numSock, const char * url) { bool cmdRes; @@ -300,16 +295,6 @@ return (false); } -/** - * \brief Set IP Address string - * - * \param [in] numSock - socket reference to set the string for. ipStr - text string of the IP - * address you want to talk to. There is no sanity check - beware!!! - * - * \return true - if the IP address has been set. false - if the IP could not be set. - * - * \details None. - */ bool WncController::setIpAddr(uint16_t numSock, const char * ipStr) { if (numSock < MAX_NUM_WNC_SOCKETS) { @@ -327,17 +312,6 @@ m_sCmdTimeoutMs = toMs; } -/** - * \brief Opens a WNC socket. - * - * \param [in] sockNum - the number of the socket to open. ipAddr - a string containing - * the IP address. port - the IP port number to open the socket connection. - * - * \return true - if the socket is/was opened. false otherwise. - * - * \details None. - */ - bool WncController::openSocketUrl(uint16_t numSock, const char * url, uint16_t port, bool tcp, uint16_t timeOutSec) { if (resolveUrl(numSock, url) == true) @@ -402,19 +376,7 @@ return (m_sSock[numSock].open); } -/** - * \brief Write bytes of data to an open socket - * - * \param [in] sockNum - the number of the socket to write. s - a string containing - * the byte data to send must be less than = 1500. - * - * \return true - if the write was successful. false otherwise. - * - * \details The results of the write do not have anything to do with the data - * arriving at the endpoint. - */ - -bool WncController::sockWrite(const char * const s, uint16_t n, uint16_t numSock, bool isTcp) +bool WncController::sockWrite(const uint8_t * const s, uint16_t n, uint16_t numSock, bool isTcp) { bool result = true; @@ -433,7 +395,7 @@ return (result); } -bool WncController::write(uint16_t numSock, const char * s, uint32_t n) +bool WncController::write(uint16_t numSock, const uint8_t * s, uint32_t n) { bool result; @@ -472,18 +434,6 @@ return (result); } -/** - * \brief Poll and read back data from the WNC (if it has any) - * If auto poll is enabled this read might fail (return with no data). - * - * \param [in] sockNum - the number of the socket to read. result - a string pointer containing - * the byte data readback from the WNC. - * - * \return The number of bytes/chars that are read from the socket. - * - * \details DO NOT use the same string as is passed to the auto poll setup method! - */ - size_t WncController::read(uint16_t numSock, const uint8_t ** readBuf) { static string theBuf; @@ -613,16 +563,6 @@ return (numCopied); } -/** - * \brief Set how many times the above read method will retry if data is not returned. - * - * \param [in] sockNum - the number of the socket to set. retries - how many times to - * poll until data is found. - * - * \return None. - * - * \details None. - */ void WncController::setReadRetries(uint16_t numSock, uint16_t retries) { if (numSock < MAX_NUM_WNC_SOCKETS) @@ -631,16 +571,6 @@ dbgPuts("Bad socket num!"); } -/** - * \brief Set how long between retries to wait. - * - * \param [in] sockNum - the number of the socket to set. readRetryWaitMs - how long to wait - * before doing the read poll (calling read(...)). - * - * \return None. - * - * \details None. - */ void WncController::setReadRetryWait(uint16_t numSock, uint16_t readRetryWaitMs) { if (numSock < MAX_NUM_WNC_SOCKETS) @@ -649,15 +579,6 @@ dbgPuts("Bad socket num!"); } -/** - * \brief Close the socket. - * - * \param [in] sockNum - the number of the socket to close. - * - * \return None. - * - * \details None. - */ bool WncController::closeSocket(uint16_t numSock) { if (numSock < MAX_NUM_WNC_SOCKETS) { @@ -676,8 +597,6 @@ return (m_sSock[numSock].open == false); } -// Note: If you want to make it more portable, create a -// arecharsavailable() and readchar() size_t WncController::mdmGetline(string * buff, int timeout_ms) { char chin = '\0'; @@ -707,7 +626,6 @@ return (len); } -// Eventually this should try to reinstate the sockets open bool WncController::softwareInitMdm(void) { static bool reportStatus = true; @@ -744,8 +662,6 @@ } } - -// Sets a global with failure or success, assumes 1 thread all the time WncController::AtCmdErr_e WncController::sendWncCmd(const char * const s, string ** r, int ms_timeout) { if (checkCellLink() == false) { @@ -883,7 +799,6 @@ } while (m_sSock[numSock].open == false); } - bool WncController::getICCID(string * iccid) { if (at_geticcid_wnc(iccid) == false) { @@ -919,7 +834,6 @@ return (true); } - bool WncController::convertICCIDtoMSISDN(const string & iccid, string * msisdn) { msisdn->erase(); @@ -939,7 +853,6 @@ return (true); } - bool WncController::sendSMSText(const char * const phoneNum, const char * const text) { if (at_sendSMStext_wnc(phoneNum, text) == true) @@ -1628,7 +1541,6 @@ return (true); } - int16_t WncController::at_sockopen_wnc(const char * const ip, uint16_t port, uint16_t numSock, bool tcp, uint16_t timeOutSec) { string * pRespStr; @@ -1748,7 +1660,7 @@ return (false); } -WncController::AtCmdErr_e WncController::at_sockwrite_wnc(const char * s, uint16_t n, uint16_t numSock, bool isTcp) +WncController::AtCmdErr_e WncController::at_sockwrite_wnc(const uint8_t * s, uint16_t n, uint16_t numSock, bool isTcp) { AtCmdErr_e result; @@ -1768,7 +1680,7 @@ cmd_str += ",\""; while(n > 0) { n--; - num2str = _to_hex_string((uint8_t)*s++); + num2str = _to_hex_string(*s++); // Always 2-digit ascii hex: if (num2str[1] == '\0') cmd_str += '0'; @@ -2197,7 +2109,6 @@ puts("\r\n"); } -// WNC used to have troubles handling full speed, seems to not need this now. void WncController::sendCmd(const char * cmd, unsigned n, unsigned wait_uS, bool crLf) { while (n--) { @@ -2212,5 +2123,4 @@ } } - }; // End namespace WncController_fk