Simplify using of UnbufferedSerial(Serial), USBCDC, TCP, SMTP, NTP Fork : https://github.com/YSI-LPS/lib_Transmission

Dependents:   lib_Transmission_Serial_example 2022_TICE_Electrolyse lib_Transmission_TCP_example

Committer:
YSI
Date:
Fri Jul 17 07:51:57 2020 +0000
Revision:
5:4d87504e9257
Parent:
4:9a4ab4f406ab
Child:
6:d6a07fd1548a
fix clientTCP send

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YSI 0:2fc6fc3b5e15 1 #include "lib_Transmission.h"
YSI 0:2fc6fc3b5e15 2
YSI 1:27f6baabb15e 3 Transmission::Transmission(UnbufferedSerial *serial, EthernetInterface *eth, EventQueue *queue, void(*_init)(void), void(*_processing)(string, const enumTRANSMISSION&))
YSI 0:2fc6fc3b5e15 4 {
YSI 0:2fc6fc3b5e15 5 _serial = serial;
YSI 0:2fc6fc3b5e15 6 _eth = eth;
YSI 0:2fc6fc3b5e15 7 _queue = queue;
YSI 1:27f6baabb15e 8 fn_init = _init;
YSI 1:27f6baabb15e 9 fn_processing = _processing;
YSI 0:2fc6fc3b5e15 10 }
YSI 0:2fc6fc3b5e15 11
YSI 3:7e15bf0a71f4 12 void Transmission::set(bool TCP, const char* IP, uint16_t PORT)
YSI 3:7e15bf0a71f4 13 {
YSI 3:7e15bf0a71f4 14 if(message.TCP && TCP)
YSI 3:7e15bf0a71f4 15 {
YSI 3:7e15bf0a71f4 16 if(message.PORT != PORT)
YSI 3:7e15bf0a71f4 17 {
YSI 3:7e15bf0a71f4 18 message.CONNECT = false;
YSI 3:7e15bf0a71f4 19 _serverTCP.sigio(NULL);
YSI 3:7e15bf0a71f4 20 eth_error("serverTCP_close", _serverTCP.close());
YSI 3:7e15bf0a71f4 21 }
YSI 3:7e15bf0a71f4 22 eth_error("Ethernet_disconnect", _eth->disconnect());
YSI 3:7e15bf0a71f4 23 }
YSI 3:7e15bf0a71f4 24 message.TCP = TCP;
YSI 3:7e15bf0a71f4 25 message.IP = IP;
YSI 3:7e15bf0a71f4 26 message.PORT = PORT;
YSI 3:7e15bf0a71f4 27 message.DHCP = message.IP.empty();
YSI 3:7e15bf0a71f4 28 }
YSI 3:7e15bf0a71f4 29
YSI 3:7e15bf0a71f4 30 string Transmission::get(void)
YSI 3:7e15bf0a71f4 31 {
YSI 3:7e15bf0a71f4 32 SocketAddress ip;
YSI 3:7e15bf0a71f4 33 _eth->get_ip_address(&ip);
YSI 3:7e15bf0a71f4 34 string address(ip.get_ip_address()?ip.get_ip_address():"0.0.0.0");
YSI 3:7e15bf0a71f4 35 address += ":" + to_string(message.PORT);
YSI 3:7e15bf0a71f4 36 return address;
YSI 3:7e15bf0a71f4 37 }
YSI 3:7e15bf0a71f4 38
YSI 0:2fc6fc3b5e15 39 bool Transmission::eth_connect(void)
YSI 0:2fc6fc3b5e15 40 {
YSI 0:2fc6fc3b5e15 41 if(message.TCP)
YSI 0:2fc6fc3b5e15 42 {
YSI 0:2fc6fc3b5e15 43 switch(_eth->get_connection_status())
YSI 0:2fc6fc3b5e15 44 {
YSI 0:2fc6fc3b5e15 45 case NSAPI_STATUS_DISCONNECTED:
YSI 1:27f6baabb15e 46 if(message.status == RED_DISCONNECTED)
YSI 0:2fc6fc3b5e15 47 {
YSI 0:2fc6fc3b5e15 48 eth_error("Ethernet_blocking", _eth->set_blocking(false));
YSI 3:7e15bf0a71f4 49 eth_error("Ethernet_dhcp", _eth->set_dhcp(message.DHCP));
YSI 3:7e15bf0a71f4 50 if(!message.DHCP) eth_error("Ethernet_static", _eth->set_network(SocketAddress(message.IP.c_str()), SocketAddress("255.255.255.0"), SocketAddress("192.168.1.1")));
YSI 0:2fc6fc3b5e15 51 eth_error("Ethernet_connect", _eth->connect());
YSI 0:2fc6fc3b5e15 52 }
YSI 0:2fc6fc3b5e15 53 break;
YSI 0:2fc6fc3b5e15 54 case NSAPI_STATUS_CONNECTING:
YSI 1:27f6baabb15e 55 if(message.status == RED_DISCONNECTED)
YSI 0:2fc6fc3b5e15 56 {
YSI 0:2fc6fc3b5e15 57 eth_status("Ethernet_connect", NSAPI_STATUS_CONNECTING);
YSI 1:27f6baabb15e 58 message.status = YELLOW_CONNECTING;
YSI 0:2fc6fc3b5e15 59 _eth->attach(callback(this, &Transmission::eth_event));
YSI 0:2fc6fc3b5e15 60 }
YSI 0:2fc6fc3b5e15 61 break;
YSI 4:9a4ab4f406ab 62 case NSAPI_STATUS_GLOBAL_UP: return message.CONNECT; break;
YSI 4:9a4ab4f406ab 63 default: break;
YSI 0:2fc6fc3b5e15 64 }
YSI 0:2fc6fc3b5e15 65 }
YSI 0:2fc6fc3b5e15 66 else if(_eth->get_connection_status() != NSAPI_STATUS_DISCONNECTED) eth_error("Ethernet_disconnect", _eth->disconnect());
YSI 0:2fc6fc3b5e15 67 return false;
YSI 0:2fc6fc3b5e15 68 }
YSI 0:2fc6fc3b5e15 69
YSI 0:2fc6fc3b5e15 70 void Transmission::eth_event(nsapi_event_t status, intptr_t param)
YSI 0:2fc6fc3b5e15 71 {
YSI 0:2fc6fc3b5e15 72 eth_status("Ethernet_event", param);
YSI 0:2fc6fc3b5e15 73 switch(param)
YSI 0:2fc6fc3b5e15 74 {
YSI 1:27f6baabb15e 75 case NSAPI_STATUS_DISCONNECTED: message.status = RED_DISCONNECTED; break;
YSI 4:9a4ab4f406ab 76 case NSAPI_STATUS_CONNECTING:if(message.status == BLUE_CLIENT) eth_error("clientTCP_disconnect", _clientTCP->close());
YSI 1:27f6baabb15e 77 message.status = YELLOW_CONNECTING; break;
YSI 3:7e15bf0a71f4 78 case NSAPI_STATUS_GLOBAL_UP: message.status = GREEN_GLOBAL_UP;
YSI 3:7e15bf0a71f4 79 if(message.CONNECT)
YSI 3:7e15bf0a71f4 80 serverTCP_event();
YSI 3:7e15bf0a71f4 81 else serverTCP_connect(); break;
YSI 1:27f6baabb15e 82 default: break;
YSI 1:27f6baabb15e 83 }
YSI 1:27f6baabb15e 84 }
YSI 1:27f6baabb15e 85
YSI 1:27f6baabb15e 86 bool Transmission::serverTCP_connect(void)
YSI 1:27f6baabb15e 87 {
YSI 3:7e15bf0a71f4 88 if(!message.CONNECT)
YSI 3:7e15bf0a71f4 89 if(eth_error("serverTCP_open", _serverTCP.open(_eth)) == NSAPI_ERROR_OK)
YSI 3:7e15bf0a71f4 90 if(eth_error("serverTCP_bind", _serverTCP.bind(message.PORT)) == NSAPI_ERROR_OK)
YSI 3:7e15bf0a71f4 91 if(eth_error("serverTCP_listen", _serverTCP.listen()) == NSAPI_ERROR_OK)
YSI 1:27f6baabb15e 92 {
YSI 3:7e15bf0a71f4 93 _serverTCP.set_blocking(false);
YSI 3:7e15bf0a71f4 94 _serverTCP.sigio(callback(this, &Transmission::serverTCP_event));
YSI 3:7e15bf0a71f4 95 message.CONNECT = true;
YSI 3:7e15bf0a71f4 96 _queue->call(fn_init);
YSI 1:27f6baabb15e 97 }
YSI 3:7e15bf0a71f4 98 return message.CONNECT;
YSI 1:27f6baabb15e 99 }
YSI 1:27f6baabb15e 100
YSI 1:27f6baabb15e 101 void Transmission::serverTCP_event(void)
YSI 1:27f6baabb15e 102 {
YSI 1:27f6baabb15e 103 _queue->call(this, &Transmission::serverTCP_accept);
YSI 1:27f6baabb15e 104 }
YSI 1:27f6baabb15e 105
YSI 1:27f6baabb15e 106 void Transmission::serverTCP_accept(void)
YSI 1:27f6baabb15e 107 {
YSI 1:27f6baabb15e 108 if(message.status == GREEN_GLOBAL_UP)
YSI 1:27f6baabb15e 109 {
YSI 1:27f6baabb15e 110 nsapi_error_t ack = NSAPI_ERROR_WOULD_BLOCK;
YSI 1:27f6baabb15e 111 message.status = MAGENTA_ACCEPT;
YSI 3:7e15bf0a71f4 112 _clientTCP = _serverTCP.accept(&ack);
YSI 1:27f6baabb15e 113 switch(ack)
YSI 1:27f6baabb15e 114 {
YSI 1:27f6baabb15e 115 case NSAPI_ERROR_OK:
YSI 3:7e15bf0a71f4 116 _clientTCP->set_timeout(TCP_CLIENT_TIMEOUT);
YSI 1:27f6baabb15e 117 message.status = BLUE_CLIENT;
YSI 1:27f6baabb15e 118 break;
YSI 1:27f6baabb15e 119 case NSAPI_ERROR_NO_CONNECTION:
YSI 4:9a4ab4f406ab 120 eth_state();
YSI 3:7e15bf0a71f4 121 serverTCP_event();
YSI 1:27f6baabb15e 122 break;
YSI 1:27f6baabb15e 123 default:
YSI 4:9a4ab4f406ab 124 eth_state();
YSI 4:9a4ab4f406ab 125 if(ack < NSAPI_ERROR_WOULD_BLOCK) eth_error("serverTCP_accept", ack);
YSI 1:27f6baabb15e 126 break;
YSI 1:27f6baabb15e 127 }
YSI 1:27f6baabb15e 128 }
YSI 1:27f6baabb15e 129 }
YSI 1:27f6baabb15e 130
YSI 4:9a4ab4f406ab 131 void Transmission::eth_state(void)
YSI 4:9a4ab4f406ab 132 {
YSI 4:9a4ab4f406ab 133 switch(_eth->get_connection_status())
YSI 4:9a4ab4f406ab 134 {
YSI 4:9a4ab4f406ab 135 case NSAPI_STATUS_DISCONNECTED: message.status = RED_DISCONNECTED; break;
YSI 4:9a4ab4f406ab 136 case NSAPI_STATUS_CONNECTING: message.status = YELLOW_CONNECTING; break;
YSI 4:9a4ab4f406ab 137 case NSAPI_STATUS_GLOBAL_UP: message.status = GREEN_GLOBAL_UP; break;
YSI 4:9a4ab4f406ab 138 default: break;
YSI 4:9a4ab4f406ab 139 }
YSI 4:9a4ab4f406ab 140 }
YSI 4:9a4ab4f406ab 141
YSI 2:ec88f3f8b619 142 enumTRANSTATUS Transmission::recv(void)
YSI 1:27f6baabb15e 143 {
YSI 1:27f6baabb15e 144 if(eth_connect())
YSI 1:27f6baabb15e 145 {
YSI 1:27f6baabb15e 146 char buffer[1024] = {0};
YSI 1:27f6baabb15e 147 nsapi_error_t ack = NSAPI_ERROR_WOULD_BLOCK;
YSI 1:27f6baabb15e 148 if(message.status == BLUE_CLIENT)
YSI 3:7e15bf0a71f4 149 if((ack = _clientTCP->recv(buffer, 1024)) < NSAPI_ERROR_WOULD_BLOCK)
YSI 1:27f6baabb15e 150 eth_error("clientTCP_recv", ack);
YSI 4:9a4ab4f406ab 151 if((ack == NSAPI_ERROR_OK) || (ack == NSAPI_ERROR_NO_CONNECTION)) message.BREAK = true;
YSI 1:27f6baabb15e 152 for(int i = 0; i < ack; i++) if(buffer[i] == '\n') buffer[i] = ';';
YSI 1:27f6baabb15e 153 fn_processing(message.buffer[TCP] = buffer, TCP);
YSI 1:27f6baabb15e 154 message.buffer[TCP].clear();
YSI 0:2fc6fc3b5e15 155 }
YSI 1:27f6baabb15e 156 if(_serial->readable())
YSI 1:27f6baabb15e 157 {
YSI 1:27f6baabb15e 158 char caractere;
YSI 1:27f6baabb15e 159 _serial->read(&caractere, 1);
YSI 4:9a4ab4f406ab 160 if((caractere == '\n') || (caractere == '\r'))
YSI 1:27f6baabb15e 161 {
YSI 4:9a4ab4f406ab 162 fn_processing(message.buffer[SERIAL], SERIAL);
YSI 4:9a4ab4f406ab 163 message.buffer[SERIAL].clear();
YSI 1:27f6baabb15e 164 }
YSI 4:9a4ab4f406ab 165 else if((caractere > 31) && (caractere < 127)) message.buffer[SERIAL] += caractere;
YSI 1:27f6baabb15e 166 }
YSI 1:27f6baabb15e 167 return message.status;
YSI 1:27f6baabb15e 168 }
YSI 1:27f6baabb15e 169
YSI 1:27f6baabb15e 170 nsapi_error_t Transmission::send(const string& buff, const enumTRANSMISSION& type)
YSI 1:27f6baabb15e 171 {
YSI 1:27f6baabb15e 172 nsapi_error_t ack = NSAPI_ERROR_WOULD_BLOCK;
YSI 1:27f6baabb15e 173 string ssend(buff+"\n");
YSI 4:9a4ab4f406ab 174
YSI 4:9a4ab4f406ab 175 if((type != TCP) && !buff.empty()) ack = _serial->write(ssend.c_str(), ssend.length());
YSI 4:9a4ab4f406ab 176 if(type != SERIAL)
YSI 1:27f6baabb15e 177 {
YSI 5:4d87504e9257 178 if(!message.BREAK && !buff.empty() && (message.status == BLUE_CLIENT))
YSI 4:9a4ab4f406ab 179 eth_error("clientTCP_send", ack = _clientTCP->send(ssend.c_str(), ssend.size()));
YSI 4:9a4ab4f406ab 180 if(message.BREAK || message.HTTP)
YSI 4:9a4ab4f406ab 181 {
YSI 4:9a4ab4f406ab 182 message.BREAK = message.HTTP = false;
YSI 4:9a4ab4f406ab 183 eth_error("clientTCP_disconnect", _clientTCP->close());
YSI 4:9a4ab4f406ab 184 eth_state();
YSI 4:9a4ab4f406ab 185 serverTCP_event();
YSI 4:9a4ab4f406ab 186 }
YSI 1:27f6baabb15e 187 }
YSI 1:27f6baabb15e 188 return ack;
YSI 1:27f6baabb15e 189 }
YSI 1:27f6baabb15e 190
YSI 1:27f6baabb15e 191 bool Transmission::smtp(const char* MAIL, const char* FROM, const char* SUBJECT, const char* DATA)
YSI 1:27f6baabb15e 192 {
YSI 3:7e15bf0a71f4 193 if(!message.DHCP) return false;
YSI 1:27f6baabb15e 194 TCPSocket clientSMTP;
YSI 1:27f6baabb15e 195 clientSMTP.set_timeout(5000);
YSI 1:27f6baabb15e 196 const string sMAIL(MAIL), sFROM(FROM), sSUBJECT(SUBJECT), sDATA(DATA);
YSI 1:27f6baabb15e 197 const string smtpParams[][7] = {{ "", "HELO Mbed " + sFROM + "\r\n", "MAIL FROM: <Mbed." + sFROM + "@U-PSUD.FR>\r\n", "RCPT TO: <" + sMAIL + ">\r\n", "DATA\r\n", "From: \"Mbed " + sFROM + "\" <Mbed." + sFROM + "@U-PSUD.FR>\r\nTo: \"DESTINATAIRE\" <" + sMAIL + ">\r\nSubject:" + sSUBJECT + "\r\n" + sDATA + "\r\n.\r\n", "QUIT\r\n" },
YSI 1:27f6baabb15e 198 { "", "HELO Mbed\r\n", "MAIL FROM: <Mbed>\r\n","RCPT TO: <" + sMAIL + ">\r\n", "QUIT\r\n" }};
YSI 1:27f6baabb15e 199 string code;
YSI 1:27f6baabb15e 200 if(eth_error("clientSMTP_open", clientSMTP.open(_eth)) == NSAPI_ERROR_OK)
YSI 1:27f6baabb15e 201 {
YSI 1:27f6baabb15e 202 for(const string ssend : smtpParams[(sFROM.empty())?1:0])
YSI 1:27f6baabb15e 203 {
YSI 1:27f6baabb15e 204 char buffer[256] = {0};
YSI 1:27f6baabb15e 205 if(code.empty()) { if(eth_error("clientSMTP_connect", clientSMTP.connect(SocketAddress(SMTP_SERVER, 25))) < NSAPI_ERROR_OK) break; }
YSI 1:27f6baabb15e 206 else if(eth_error("clientSMTP_send", clientSMTP.send(ssend.c_str(), ssend.size())) < NSAPI_ERROR_OK) break;
YSI 1:27f6baabb15e 207 if(eth_error("clientSMTP_recv", clientSMTP.recv(buffer, 256)) < NSAPI_ERROR_OK) break;
YSI 1:27f6baabb15e 208 buffer[3] = 0;
YSI 1:27f6baabb15e 209 code += buffer;
YSI 1:27f6baabb15e 210 if(ssend == "QUIT\r\n") break;
YSI 1:27f6baabb15e 211 }
YSI 1:27f6baabb15e 212 eth_error("clientSMTP_close", clientSMTP.close());
YSI 1:27f6baabb15e 213 }
YSI 1:27f6baabb15e 214 if(sFROM.empty()) return code == "220250250250221";
YSI 1:27f6baabb15e 215 else if(code != "220250250250354250221") _queue->call_in(60s, this, &Transmission::smtp, MAIL, FROM, SUBJECT, DATA);
YSI 1:27f6baabb15e 216 return code == "220250250250354250221";
YSI 0:2fc6fc3b5e15 217 }
YSI 0:2fc6fc3b5e15 218
YSI 3:7e15bf0a71f4 219 void Transmission::http(void)
YSI 3:7e15bf0a71f4 220 {
YSI 3:7e15bf0a71f4 221 message.HTTP = true;
YSI 3:7e15bf0a71f4 222 }
YSI 3:7e15bf0a71f4 223
YSI 0:2fc6fc3b5e15 224 intptr_t Transmission::eth_status(const string& source, const intptr_t& code)
YSI 0:2fc6fc3b5e15 225 {
YSI 0:2fc6fc3b5e15 226 stringstream message;
YSI 0:2fc6fc3b5e15 227 message << "\n" << source << "[" << code;
YSI 0:2fc6fc3b5e15 228 switch(code)
YSI 0:2fc6fc3b5e15 229 {
YSI 0:2fc6fc3b5e15 230 case NSAPI_STATUS_LOCAL_UP: message << "] NSAPI_STATUS_LOCAL_UP < local IP address set >"; break;
YSI 0:2fc6fc3b5e15 231 case NSAPI_STATUS_GLOBAL_UP: message << "] NSAPI_STATUS_GLOBAL_UP < global IP address set >"; break;
YSI 0:2fc6fc3b5e15 232 case NSAPI_STATUS_DISCONNECTED: message << "] NSAPI_STATUS_DISCONNECTED < no connection to network >"; break;
YSI 0:2fc6fc3b5e15 233 case NSAPI_STATUS_CONNECTING: message << "] NSAPI_STATUS_CONNECTING < connecting to network >"; break;
YSI 0:2fc6fc3b5e15 234 case NSAPI_STATUS_ERROR_UNSUPPORTED: message << "] NSAPI_STATUS_ERROR_UNSUPPORTED < unsupported functionality >";break;
YSI 0:2fc6fc3b5e15 235 }
YSI 1:27f6baabb15e 236 #ifndef NDEBUG
YSI 1:27f6baabb15e 237 _serial->write(message.str().c_str(), message.str().size());
YSI 1:27f6baabb15e 238 #endif
YSI 0:2fc6fc3b5e15 239 return code;
YSI 0:2fc6fc3b5e15 240 }
YSI 0:2fc6fc3b5e15 241
YSI 0:2fc6fc3b5e15 242 nsapi_error_t Transmission::eth_error(const string& source, const nsapi_error_t& code)
YSI 0:2fc6fc3b5e15 243 {
YSI 0:2fc6fc3b5e15 244 stringstream message;
YSI 0:2fc6fc3b5e15 245 message << "\n" << source << "[" << code;
YSI 0:2fc6fc3b5e15 246 switch(code)
YSI 0:2fc6fc3b5e15 247 {
YSI 0:2fc6fc3b5e15 248 case NSAPI_ERROR_OK: message << "] NSAPI_ERROR_OK < no error >"; break;
YSI 0:2fc6fc3b5e15 249 case NSAPI_ERROR_WOULD_BLOCK: message << "] NSAPI_ERROR_WOULD_BLOCK < no data is not available but call is non-blocking >";break;
YSI 0:2fc6fc3b5e15 250 case NSAPI_ERROR_UNSUPPORTED: message << "] NSAPI_ERROR_UNSUPPORTED < unsupported functionality >"; break;
YSI 0:2fc6fc3b5e15 251 case NSAPI_ERROR_PARAMETER: message << "] NSAPI_ERROR_PARAMETER < invalid configuration >"; break;
YSI 0:2fc6fc3b5e15 252 case NSAPI_ERROR_NO_CONNECTION: message << "] NSAPI_ERROR_NO_CONNECTION < not connected to a network >"; break;
YSI 0:2fc6fc3b5e15 253 case NSAPI_ERROR_NO_SOCKET: message << "] NSAPI_ERROR_NO_SOCKET < socket not available for use >"; break;
YSI 0:2fc6fc3b5e15 254 case NSAPI_ERROR_NO_ADDRESS: message << "] NSAPI_ERROR_NO_ADDRESS < IP address is not known >"; break;
YSI 0:2fc6fc3b5e15 255 case NSAPI_ERROR_NO_MEMORY: message << "] NSAPI_ERROR_NO_MEMORY < memory resource not available >"; break;
YSI 0:2fc6fc3b5e15 256 case NSAPI_ERROR_NO_SSID: message << "] NSAPI_ERROR_NO_SSID < ssid not found >"; break;
YSI 0:2fc6fc3b5e15 257 case NSAPI_ERROR_DNS_FAILURE: message << "] NSAPI_ERROR_DNS_FAILURE < DNS failed to complete successfully >"; break;
YSI 0:2fc6fc3b5e15 258 case NSAPI_ERROR_DHCP_FAILURE: message << "] NSAPI_ERROR_DHCP_FAILURE < DHCP failed to complete successfully >"; break;
YSI 0:2fc6fc3b5e15 259 case NSAPI_ERROR_AUTH_FAILURE: message << "] NSAPI_ERROR_AUTH_FAILURE < connection to access point failed >"; break;
YSI 0:2fc6fc3b5e15 260 case NSAPI_ERROR_DEVICE_ERROR: message << "] NSAPI_ERROR_DEVICE_ERROR < failure interfacing with the network processor >"; break;
YSI 0:2fc6fc3b5e15 261 case NSAPI_ERROR_IN_PROGRESS: message << "] NSAPI_ERROR_IN_PROGRESS < operation (eg connect) in progress >"; break;
YSI 0:2fc6fc3b5e15 262 case NSAPI_ERROR_ALREADY: message << "] NSAPI_ERROR_ALREADY < operation (eg connect) already in progress >"; break;
YSI 0:2fc6fc3b5e15 263 case NSAPI_ERROR_IS_CONNECTED: message << "] NSAPI_ERROR_IS_CONNECTED < socket is already connected >"; break;
YSI 0:2fc6fc3b5e15 264 case NSAPI_ERROR_CONNECTION_LOST: message << "] NSAPI_ERROR_CONNECTION_LOST < connection lost >"; break;
YSI 0:2fc6fc3b5e15 265 case NSAPI_ERROR_CONNECTION_TIMEOUT: message << "] NSAPI_ERROR_CONNECTION_TIMEOUT < connection timed out >"; break;
YSI 0:2fc6fc3b5e15 266 case NSAPI_ERROR_ADDRESS_IN_USE: message << "] NSAPI_ERROR_ADDRESS_IN_USE < Address already in use >"; break;
YSI 0:2fc6fc3b5e15 267 case NSAPI_ERROR_TIMEOUT: message << "] NSAPI_ERROR_TIMEOUT < operation timed out >"; break;
YSI 0:2fc6fc3b5e15 268 case NSAPI_ERROR_BUSY: message << "] NSAPI_ERROR_BUSY < device is busy and cannot accept new operation >"; break;
YSI 0:2fc6fc3b5e15 269 default: message << "] NSAPI_ERROR < unknow code >"; break;
YSI 0:2fc6fc3b5e15 270 }
YSI 1:27f6baabb15e 271 #ifndef NDEBUG
YSI 1:27f6baabb15e 272 if(code < NSAPI_ERROR_OK) _serial->write(message.str().c_str(), message.str().size());
YSI 1:27f6baabb15e 273 #endif
YSI 0:2fc6fc3b5e15 274 return code;
YSI 0:2fc6fc3b5e15 275 }