Axeda Ready Demo for Freescale FRDM-KL46Z as accident alert system

Dependencies:   FRDM_MMA8451Q KL46Z-USBHost MAG3110 SocketModem TSI mbed FATFileSystem

Fork of AxedaGo-Freescal_FRDM-KL46Z revert by Axeda Corp

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Wifi.cpp Source File

Wifi.cpp

00001 /* Universal Socket Modem Interface Library
00002 * Copyright (c) 2013 Multi-Tech Systems
00003 *
00004 * Licensed under the Apache License, Version 2.0 (the "License");
00005 * you may not use this file except in compliance with the License.
00006 * You may obtain a copy of the License at
00007 *
00008 *     http://www.apache.org/licenses/LICENSE-2.0
00009 *
00010 * Unless required by applicable law or agreed to in writing, software
00011 * distributed under the License is distributed on an "AS IS" BASIS,
00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013 * See the License for the specific language governing permissions and
00014 * limitations under the License.
00015 */
00016 
00017 #include "Wifi.h"
00018 #include "MTSText.h"
00019 
00020 #if 0
00021 //Enable debug
00022 #include <cstdio>
00023 #define DBG(x, ...) std::printf("Line: %d %s \t[Wifi : DBG]"x"\r\n", __LINE__, __FILE__, ##__VA_ARGS__);
00024 #else
00025 #define DBG(x, ...)
00026 #endif
00027 
00028 Wifi* Wifi::instance = NULL;
00029 
00030 Wifi* Wifi::getInstance()
00031 {
00032     if(instance == NULL) {
00033         instance = new Wifi(NULL);
00034     }
00035     return instance;
00036 }
00037 
00038 bool Wifi::sortInterfaceMode(void)
00039 {
00040     //Check initial state of command mode
00041     std::string response = sendCommand("", 1000, ">");
00042     if(response.find(">") != string::npos) {
00043         cmdOn = true;
00044     }
00045 
00046     //Set device into command mode
00047     if (!setCmdMode(true)) {
00048         return false;
00049     }
00050 
00051     return true;
00052 }
00053 
00054 bool Wifi::init(MTSBufferedIO* io)
00055 {
00056     if (io == NULL) {
00057         return false;
00058     }
00059     instance->io = io;
00060 
00061     // start from the same place each time
00062     reset();
00063 
00064     //Secure interface mode
00065     if(!sortInterfaceMode()) {
00066         return false;
00067     }
00068 
00069     //Set device to non-echo mode
00070     while (sendBasicCommand("set uart mode 1", 1000) != SUCCESS) {
00071         printf("[ERROR] Failed to set to non-echo mode\n\r");
00072         //return false;
00073     }
00074     // do this twice because the module response doesnt seem to always take
00075     while (sendBasicCommand("set uart mode 1", 1000) != SUCCESS) {
00076         printf("[ERROR] Failed to set to non-echo mode\n\r");
00077         //return false;
00078     }
00079 
00080     //Set device to manual infrastructure mode
00081     if (sendBasicCommand("set wlan join 0", 1000) != SUCCESS) {
00082         printf("[ERROR] Failed to set join mode\n\r");
00083         return false;
00084     }
00085 
00086     //Set device to channel auto-scanning mode
00087     if (sendBasicCommand("set wlan channel 0", 1000) != SUCCESS) {
00088         printf("[ERROR] Failed to set auto-scanning mode\n\r");
00089         return false;
00090     }
00091 
00092     //Set device so no data is transmitted immediately following a socket connection
00093     if (sendBasicCommand("set comm remote 0", 1000) != SUCCESS) {
00094         printf("[ERROR] Failed to set remote transmit mode\n\r");
00095         return false;
00096     }
00097 
00098     //Set device into DHCP mode by default
00099     if (sendBasicCommand("set ip dhcp 1", 1000) != SUCCESS) {
00100         printf("[ERROR] Failed to set to default DHCP mode\n\r");
00101         return false;
00102     }
00103 
00104     return true;
00105 }
00106 
00107 Wifi::Wifi(MTSBufferedIO* io)
00108     : io(io)
00109     , wifiConnected(false)
00110     , _ssid("")
00111     , mode(TCP)
00112     , socketOpened(false)
00113     , socketCloseable(true)
00114     , local_port(0)
00115     , local_address("")
00116     , host_port(0)
00117     , cmdOn(false)
00118 {
00119 
00120 }
00121 
00122 Wifi::~Wifi()
00123 {
00124 }
00125 
00126 bool Wifi::connect()
00127 {
00128     //Check if socket is open
00129     if(socketOpened) {
00130         return true;
00131     }
00132 
00133     //Run Test first to validate a good state
00134     if(isConnected()) {
00135         return true;
00136     }
00137 
00138     if (_ssid.size() == 0) {
00139         printf("[ERROR] No SSID has been set\n\r");
00140         return false;
00141     }
00142 
00143     if(!setCmdMode(true)) {
00144         return false;
00145     }
00146 
00147     //Possibly add a scan command here and look for the network....
00148 
00149     //join my_network
00150     printf("[DEBUG] Making SSID Connection Attempt. SSID[%s]\r\n", _ssid.c_str());
00151     std::string result = sendCommand("join " + _ssid, 15000, "GW=");
00152     //printf("Connect Status: %s\n\r", result.c_str());
00153 
00154     //Check whether connection was successful
00155     if(result.find("Associated!") != string::npos) {
00156         if(result.find("Static") == string::npos) {
00157             int start = result.find("IP=");
00158             int stop = result.find(":", start);
00159             local_address = result.substr(start + 3, stop - start - 3);
00160         }
00161         printf("[INFO] WiFi Connection Established: IP[%s]\r\n", local_address.c_str());
00162         wifiConnected = true;
00163 
00164         //Report Signal Strength of new connection
00165         wait(1); //Needed for signal strength to be available
00166         int rssi = getSignalStrength();
00167         printf("[DEBUG] Signal strength (dBm): %d\r\n", rssi);
00168     } else {
00169         wifiConnected = false;
00170     }
00171 
00172     return wifiConnected;
00173 }
00174 
00175 void Wifi::disconnect()
00176 {
00177     wait(5.0f);
00178     printf("[DEBUG] Disconnecting from network\r\n");
00179 
00180     if(socketOpened) {
00181         close();
00182     }
00183 
00184     if(!setCmdMode(true)) {
00185         printf("[ERROR] Failed in disconnecting from network.  Continuing ...\r\n");
00186     }
00187 
00188     std::string response = sendCommand("leave", 10000, "<4.00>");
00189     response = sendCommand("show net", 5000, "Links");
00190     //printf("Response: %s\n\r", response.c_str());
00191     if (response.find("Assoc=FAIL") != string::npos) {
00192         printf("[DEBUG] Successfully disconnected from network\r\n");
00193     } else {
00194         printf("[ERROR] Failed in disconnecting from network.  Continuing ...\r\n");
00195     }
00196 
00197     wifiConnected = false;
00198 }
00199 
00200 bool Wifi::isConnected()
00201 {
00202     //1) Check if SSID was set
00203     if(_ssid.size() == 0) {
00204         printf("[DEBUG] SSID is not set\r\n");
00205         return false;
00206     }
00207 
00208     //1) Check that we do not have a live connection up
00209     if(isOpen()) {
00210         printf("[DEBUG] Socket is opened\r\n");
00211         return true;
00212     }
00213 
00214     //Check command mode.
00215     if(!setCmdMode(true)) {
00216         return false;
00217     }
00218 
00219     //2) Query the wifi module
00220     wifiConnected = false;
00221     std::string result = sendCommand("show net", 5000, "Links");
00222     //printf("netResult: %s\n\r", result);
00223     if(result.find("Assoc=OK") != std::string::npos) {
00224         wifiConnected = true;
00225     }
00226 
00227     return wifiConnected;
00228 }
00229 
00230 bool Wifi::bind(unsigned int port)
00231 {
00232     if(socketOpened) {
00233         printf("[ERROR] socket is open. Can not set local port\r\n");
00234         return false;
00235     }
00236     if(port > 65535) {
00237         printf("[ERROR] port out of range (0-65535)\r\n");
00238         return false;
00239     }
00240     local_port = port;
00241     return true;
00242 }
00243 
00244 bool Wifi::open(const std::string& address, unsigned int port, Mode mode)
00245 {
00246     char buffer[256] = {0};
00247     printf("[DEBUG] Attempting to Open Socket\r\n");
00248 
00249     //1) Check that we do not have a live connection up
00250     if(socketOpened) {
00251         //Check that the address, port, and mode match
00252         if(host_address != address || host_port != port || this->mode != mode) {
00253             if(this->mode == TCP) {
00254                 printf("[ERROR] TCP socket already opened (%s:%d)\r\n", host_address.c_str(), host_port);
00255             } else {
00256                 printf("[ERROR] UDP socket already opened (%s:%d)\r\n", host_address.c_str(), host_port);
00257             }
00258             return false;
00259         }
00260 
00261         printf("[DEBUG] Socket already opened\r\n");
00262         return true;
00263     }
00264 
00265     //2) Check Parameters
00266     if(port > 65535) {
00267         printf("[ERROR] port out of range (0-65535)\r\n");
00268         return false;
00269     }
00270 
00271 
00272     //3) Check Wifi network connection
00273     if(!isConnected()) {
00274         printf("[ERROR] Wifi network not connected.  Attempting to connect\r\n");
00275         if(!connect()) {
00276             printf("[ERROR] Wifi network connection failed\r\n");
00277             return false;
00278         } else {
00279             printf("[DEBUG] Wifi connection established\r\n");
00280         }
00281     }
00282 
00283     //Check command mode
00284     if(!setCmdMode(true)) {
00285         return false;
00286     }
00287 
00288     //Set Local Port
00289     if(local_port != 0) {
00290         //Attempt to set local port
00291         sprintf(buffer, "set ip localport %d", local_port);
00292         Code code = sendBasicCommand(buffer, 1000);
00293         if(code != SUCCESS) {
00294             printf("[WARNING] Unable to set local port (%d) [%d]. Continuing...\r\n", local_port, (int) code);
00295         }
00296     }
00297 
00298     //Set TCP/UDP parameters
00299     sprintf(buffer, "set ip remote %d", port);
00300     if(sendBasicCommand(buffer, 1000) == SUCCESS) {
00301         host_port = port;
00302     } else {
00303         printf("[ERROR] Host port could not be set\r\n");
00304     }
00305 
00306     //Check if address of URL
00307     std::vector<std::string> tmp = Text::split(address, '.');
00308     if(tmp.size() != 4) {
00309         std::string ip = getHostByName(address);
00310         if(ip.size() != 0) {
00311             host_address = ip;
00312         } else {
00313             return false;
00314         }
00315     } else {
00316         host_address = address;
00317     }
00318 
00319     //Set Address
00320     printf("[DEBUG] Host address: %s\n\r", host_address.c_str());
00321     if(sendBasicCommand("set ip host " + host_address, 1000) != SUCCESS) {
00322         printf("[ERROR] Host address could not be set\r\n");
00323         return false;
00324     }
00325 
00326     if(sendBasicCommand("set ip protocol 8", 1000) != SUCCESS) {
00327         printf("[ERROR] Failed to set TCP mode\r\n");
00328         return false;
00329     }
00330 
00331     // Try and Connect
00332     std::string sMode;
00333     std::string sOpenSocketCmd;
00334     if(mode == TCP) {
00335         sOpenSocketCmd = "open";
00336         sMode = "TCP";
00337     } else {
00338         //TODO
00339         //sOpenSocketCmd = "AT#OUDP";
00340         //sMode = "UDP";
00341     }
00342     string response = sendCommand(sOpenSocketCmd, 10000, "OPEN");
00343     if (response.find("OPEN") != string::npos) {
00344         printf("[INFO] Opened %s Socket [%s:%d]\r\n", sMode.c_str(), host_address.c_str(), port);
00345         socketOpened = true;
00346         cmdOn = false;
00347     } else {
00348         printf("[WARNING] Unable to open %s Socket [%s:%d]\r\n", sMode.c_str(),  host_address.c_str(), port);
00349         socketOpened = false;
00350     }
00351 
00352     return socketOpened;
00353 }
00354 
00355 bool Wifi::isOpen()
00356 {
00357     if(io->readable()) {
00358         printf("[DEBUG] Assuming open, data available to read.\n\r");
00359         return true;
00360     }
00361     if(!setCmdMode(true)) {
00362         printf("[ERROR] Failed to properly check if TCP connection is open.\r\n");
00363         return socketOpened;
00364     }
00365     std::string response = sendCommand("show connection", 2000, "\n");
00366     int start = response.find("f");
00367     if(start != string::npos && response.size() >= (start + 3)) {
00368         if(response[start + 3] == '1') {
00369             socketOpened = true;
00370         } else {
00371             socketOpened = false;
00372         }
00373     } else {
00374         printf("[WARNING] Trouble checking TCP Connection status.\n\r");
00375     }
00376     return socketOpened;
00377 }
00378 
00379 bool Wifi::close()
00380 {
00381     wait(1);
00382     if(io == NULL) {
00383         printf("[ERROR] MTSBufferedIO not set\r\n");
00384         return false;
00385     }
00386 
00387     if(!socketOpened) {
00388         printf("[WARNING] Socket close() called, but socket was not open\r\n");
00389         return true;
00390     }
00391 
00392     if(!setCmdMode(true)) {
00393         printf("[ERROR] Failed to close socket\r\n");
00394         return false;
00395     }
00396 
00397     if(isOpen()) {
00398         std::string response = sendCommand("close", 3000, "CLOS");
00399         if(response.find("CLOS") == string::npos) {
00400             printf("[WARNING] Failed to successfully close socket...\r\n");
00401             return false;
00402         }
00403     }
00404 
00405     wait(1); //Wait so the subsequent isOpen calls return correctly.
00406     io->rxClear();
00407     io->txClear();
00408 
00409     return true;
00410 }
00411 
00412 int Wifi::read(char* data, int max, int timeout)
00413 {
00414     if(io == NULL) {
00415         printf("[ERROR] MTSBufferedIO not set\r\n");
00416         return -1;
00417     }
00418 
00419     //Check that nothing is in the rx buffer
00420     if(!socketOpened && !io->readable()) {
00421         printf("[ERROR] Socket is not open\r\n");
00422         return -1;
00423     }
00424 
00425     //Check for data mode
00426     if(!setCmdMode(false)) {
00427         printf("[ERROR] Failed to read data due to mode\r\n");
00428         return -1;
00429     }
00430 
00431     int bytesRead = 0;
00432 
00433     if(timeout >= 0) {
00434         bytesRead = io->read(data, max, static_cast<unsigned int>(timeout));
00435     } else {
00436         bytesRead = io->read(data, max);
00437     }
00438 
00439     return bytesRead;
00440 }
00441 
00442 int Wifi::write(const char* data, int length, int timeout)
00443 {
00444     if(io == NULL) {
00445         printf("[ERROR] MTSBufferedIO not set\r\n");
00446         return -1;
00447     }
00448 
00449     if(!socketOpened) {
00450         printf("[ERROR] Socket is not open\r\n");
00451         return -1;
00452     }
00453 
00454     //Check for data mode
00455     if(!setCmdMode(false)) {
00456         printf("[ERROR] Failed to write data due to mode\r\n");
00457         return -1;
00458     }
00459 
00460     int bytesWritten = 0;
00461 
00462     if(timeout >= 0) {
00463         bytesWritten = io->write(data, length, static_cast<unsigned int>(timeout));
00464     } else {
00465         bytesWritten = io->write(data, length);
00466     }
00467 
00468     return bytesWritten;
00469 }
00470 
00471 unsigned int Wifi::readable()
00472 {
00473     if(io == NULL) {
00474         printf("[ERROR] MTSBufferedIO not set\r\n");
00475         return 0;
00476     }
00477     if(!socketOpened) {
00478         printf("[ERROR] Socket is not open\r\n");
00479         return 0;
00480     }
00481     return io->readable();
00482 }
00483 
00484 unsigned int Wifi::writeable()
00485 {
00486     if(io == NULL) {
00487         printf("[ERROR] MTSBufferedIO not set\r\n");
00488         return 0;
00489     }
00490     if(!socketOpened) {
00491         printf("[ERROR] Socket is not open\r\n");
00492         return 0;
00493     }
00494 
00495     return io->writeable();
00496 }
00497 
00498 void Wifi::reset()
00499 {
00500     if(!sortInterfaceMode()) {
00501         return;
00502     }
00503 
00504     sendCommand("factory RESET", 2000, "Set Factory Default"); // <ver> comes out about 1 sec later
00505     wait(0.5f);
00506     sendCommand("reboot", 2000, "*READY*");
00507 
00508     wifiConnected = false;
00509     _ssid = "";
00510     mode = TCP;
00511     socketOpened = false;
00512     socketCloseable = true;
00513     local_port = 0;
00514     local_address = "";
00515     host_port = 0;
00516     cmdOn = false;
00517     wait(1);
00518 //    if(!init(io)) {
00519 //        printf("[ERROR] Failed to reinitialize after reset.\n\r");
00520 //    }
00521 }
00522 
00523 Code Wifi::setDeviceIP(std::string address)
00524 {
00525     //Check for command mode
00526     if(!setCmdMode(true)) {
00527         printf("[ERROR] Failed to set IP due to mode issue\r\n");
00528         return FAILURE;
00529     }
00530 
00531     //Set to DHCP mode
00532     if(address.compare("DHCP") == 0) {
00533         return sendBasicCommand("set ip dhcp 1", 1000);
00534     }
00535 
00536     //Set to static mode and set address
00537     Code code = sendBasicCommand("set ip address " + address, 1000);
00538     if(code != SUCCESS) {
00539         return code;
00540     }
00541     code = sendBasicCommand("set ip dhcp 0", 1000);
00542     if(code != SUCCESS) {
00543         return code;
00544     }
00545     local_address = address;
00546     return SUCCESS;
00547 }
00548 
00549 std::string Wifi::getDeviceIP()
00550 {
00551     return local_address;
00552 }
00553 
00554 Code Wifi::setNetwork(const std::string& ssid, SecurityType type, const std::string& key)
00555 {
00556     //Check the command mode
00557     if(!setCmdMode(true)) {
00558         return FAILURE;
00559     }
00560 
00561     Code code;
00562 
00563     //Set the appropraite SSID
00564     code = sendBasicCommand("set wlan ssid " + ssid, 1000);
00565     if (code != SUCCESS) {
00566         return code;
00567     }
00568 
00569     //Set the security key
00570     if (type == WEP64 || type == WEP128) {
00571         //Set the WEP key if using WEP encryption
00572         code = sendBasicCommand("set wlan key " + key, 1000);
00573         if (code != SUCCESS) {
00574             return code;
00575         }
00576     } else if (type == WPA || type == WPA2) {
00577         //Set the WPA key if using WPA encryption
00578         code = sendBasicCommand("set wlan phrase " + key, 1000);
00579         if (code != SUCCESS) {
00580             return code;
00581         }
00582     }
00583 
00584     _ssid = ssid;
00585     return SUCCESS;
00586 }
00587 
00588 Code Wifi::setDNS(const std::string& dnsName)
00589 {
00590     //Check the command mode
00591     if(!setCmdMode(true)) {
00592         return FAILURE;
00593     }
00594 
00595     return sendBasicCommand("set dns name " + dnsName, 1000);
00596 }
00597 
00598 int Wifi::getSignalStrength()
00599 {
00600     //Signal strength does not report correctly if not connected
00601     if(!wifiConnected) {
00602         printf("[ERROR] Could not get RSSI, Wifi network not connected.\n\r");
00603         return 99;
00604     }
00605 
00606     //Check the command mode
00607     if(!setCmdMode(true)) {
00608         printf("[ERROR] Could not get RSSI\n\r");
00609         return 99;
00610     }
00611 
00612     string response = sendCommand("show rssi", 2000, "dBm");
00613     if (response.find("RSSI") == string::npos) {
00614         printf("[ERROR] Could not get RSSI\n\r");
00615         return 99;
00616     }
00617     int start = response.find('(');
00618     int stop = response.find(')', start);
00619     string signal = response.substr(start + 1, stop - start - 1);
00620     int value;
00621     sscanf(signal.c_str(), "%d", &value);
00622     return value;
00623 }
00624 
00625 bool Wifi::ping(const std::string& address)
00626 {
00627     //Check the command mode
00628     if(!setCmdMode(true)) {
00629         printf("[ERROR] Could not send ping command\n\r");
00630         return false;
00631     }
00632 
00633     std::string response;
00634     for (int i = 0; i < PINGNUM; i++) {
00635         response = sendCommand("ping " + address, PINGDELAY * 1000, "reply");
00636         if (response.find("reply") != std::string::npos) {
00637             return true;
00638         }
00639     }
00640     return false;
00641 }
00642 
00643 bool Wifi::setCmdMode(bool on)
00644 {
00645     if (on) {
00646         if (cmdOn) {
00647             return true;
00648         }
00649         wait(.5);
00650         std::string response = sendCommand("$$", 2000, "CMD", '$');
00651         if (response.find("CMD") != string::npos) {
00652             cmdOn = true;
00653             wait(.5);
00654             return true;
00655         }
00656         printf("[ERROR] Failed to enter command mode\n\r");
00657         return false;
00658     } else {
00659         if (!cmdOn) {
00660             return true;
00661         }
00662         std::string response = sendCommand("exit", 2000, "EXIT");
00663         if (response.find("EXIT") != string::npos) {
00664             cmdOn = false;
00665             return true;
00666         }
00667         printf("[ERROR] Failed to exit command mode\n\r");
00668         return false;
00669     }
00670 }
00671 
00672 std::string Wifi::getHostByName(std::string url)
00673 {
00674     std::string response = sendCommand("lookup " + url, 3000, "<4.00>");
00675     int start = response.find("=");
00676     int stop = response.find("\r");
00677     if(start == string::npos || stop == string::npos) {
00678         printf("[ERROR] Failed to resolve URL [%s]", response.c_str());
00679         return "";
00680     }
00681     std::string ip = response.substr(start + 1, stop - start - 1);
00682     //printf("Data: %s\n\r", ip);
00683     return ip;
00684 }
00685 
00686 Code Wifi::sendBasicCommand(string command, int timeoutMillis, char esc)
00687 {
00688     if(socketOpened) {
00689         printf("[ERROR] socket is open. Can not send AT commands\r\n");
00690         return ERROR;
00691     }
00692 
00693     string response = sendCommand(command, timeoutMillis, "AOK", esc);
00694     //printf("Response: %s\n\r", response.c_str());
00695     if (response.size() == 0) {
00696         return NO_RESPONSE;
00697     } else if (response.find("AOK") != string::npos) {
00698         return SUCCESS;
00699     } else if (response.find("ERR") != string::npos) {
00700         return ERROR;
00701     } else {
00702         return FAILURE;
00703     }
00704 }
00705 
00706 string Wifi::sendCommand(string command, int timeoutMillis, std::string response, char esc)
00707 {
00708     if(io == NULL) {
00709         printf("[ERROR] MTSBufferedIO not set\r\n");
00710         return "";
00711     }
00712     //if(socketOpened && command.compare("$$") != 0 && command.compare("exit") != 0 && command.compare("close") != 0) {
00713     //    printf("[ERROR] socket is open. Can not send AT commands\r\n");
00714     //    return "";
00715     //}
00716 
00717     io->rxClear();
00718     io->txClear();
00719     std::string result;
00720 
00721     //Attempt to write command
00722     if(io->write(command.data(), command.size(), timeoutMillis) != command.size()) {
00723         //Failed to write command
00724         printf("[ERROR] failed to send command to radio within %d milliseconds\r\n", timeoutMillis);
00725         return "";
00726     }
00727     //Send Escape Character
00728     if (esc != 0x00) {
00729         if(io->write(esc, timeoutMillis) != 1) {
00730             printf("[ERROR] failed to send '%c' to radio within %d milliseconds\r\n", esc, timeoutMillis);
00731             return "";
00732         }
00733     }
00734     DBG("Sending: %s%c", command.data(), esc);
00735 
00736     int timer = 0;
00737     size_t previous = 0;
00738     char tmp[256];
00739     tmp[255] = 0;
00740     bool done = false;
00741     do {
00742         wait(.2);
00743         timer = timer + 200;
00744         previous = result.size();
00745         int size = io->read(tmp, 255, 0);    //1 less than allocated
00746         if(size > 0) {
00747             result.append(tmp, size);
00748             if (response.size() != 0) {
00749                 if (result.find(response) != string::npos) {
00750                     goto exit_func;
00751                     //return result;
00752                 }
00753             } else {
00754                 done =  (result.size() == previous);
00755             }
00756         }
00757         if(timer >= timeoutMillis) {
00758             if(!(command.compare("reboot") == 0 || command.compare("") == 0)) {
00759                 printf("[WARNING] sendCommand [%s] timed out after %d milliseconds\r\n", command.c_str(), timeoutMillis);
00760             }
00761             done = true;
00762         }
00763     } while (!done);
00764 
00765 exit_func:
00766     DBG("Result: %s\n\r", result.c_str());
00767     return result;
00768 }
00769