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:
Tue Oct 13 12:08:04 2020 +0000
Revision:
8:7193327bed34
Parent:
7:98b12722e9e2
Child:
9:abd4a4944399
add Transmission internaly thread

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YSI 0:2fc6fc3b5e15 1 #include "lib_Transmission.h"
YSI 0:2fc6fc3b5e15 2
YSI 8:7193327bed34 3 Transmission::Transmission(UnbufferedSerial *serial, EthernetInterface *eth, void(*init)(void), void(*processing)(string, const enumTRANSMISSION&))
YSI 0:2fc6fc3b5e15 4 {
YSI 8:7193327bed34 5 _queueThread.start(callback(&_queue, &EventQueue::dispatch_forever));
YSI 0:2fc6fc3b5e15 6 _serial = serial;
YSI 0:2fc6fc3b5e15 7 _eth = eth;
YSI 8:7193327bed34 8 _init = init;
YSI 8:7193327bed34 9 _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 8:7193327bed34 96 _queue.call(_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 8:7193327bed34 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 6:d6a07fd1548a 116 _clientTCP->set_timeout(REQUEST_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 8:7193327bed34 153 _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 8:7193327bed34 162 _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 8:7193327bed34 195 clientSMTP.set_timeout(REQUEST_TIMEOUT*20);
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 8:7193327bed34 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 6:d6a07fd1548a 219 time_t Transmission::ntp(void)
YSI 6:d6a07fd1548a 220 {
YSI 6:d6a07fd1548a 221 if(!message.DHCP) return 0;
YSI 6:d6a07fd1548a 222 time_t timeStamp = 0;
YSI 6:d6a07fd1548a 223 UDPSocket clientNTP;
YSI 8:7193327bed34 224 clientNTP.set_timeout(REQUEST_TIMEOUT*20);
YSI 6:d6a07fd1548a 225 if(eth_error("clientNTP_open", clientNTP.open(_eth)) == NSAPI_ERROR_OK)
YSI 6:d6a07fd1548a 226 {
YSI 6:d6a07fd1548a 227 uint32_t buffer[12] = { 0b11011, 0 }; // VN = 3 & Mode = 3
YSI 6:d6a07fd1548a 228 if(eth_error("clientNTP_send", clientNTP.sendto(SocketAddress(NTP_SERVER, 123), (void*)buffer, sizeof(buffer))) > NSAPI_ERROR_OK)
YSI 6:d6a07fd1548a 229 {
YSI 6:d6a07fd1548a 230 if(eth_error("clientNTP_recv", clientNTP.recvfrom(NULL, (void*)buffer, sizeof(buffer))) > NSAPI_ERROR_OK)
YSI 6:d6a07fd1548a 231 {
YSI 6:d6a07fd1548a 232 timeStamp = ((buffer[10] & 0xFF) << 24) | ((buffer[10] & 0xFF00) << 8) | ((buffer[10] & 0xFF0000UL) >> 8) | ((buffer[10] & 0xFF000000UL) >> 24);
YSI 6:d6a07fd1548a 233 timeStamp -= 2208985200U; // 01/01/1970 Europe
YSI 6:d6a07fd1548a 234 struct tm * tmTimeStamp = localtime(&timeStamp);
YSI 7:98b12722e9e2 235 if (((tmTimeStamp->tm_mon > 3) && (tmTimeStamp->tm_mon < 10)) || ((tmTimeStamp->tm_mon == 3) && ((tmTimeStamp->tm_mday - tmTimeStamp->tm_wday) > 24)) || ((tmTimeStamp->tm_mon == 10) && ((tmTimeStamp->tm_mday - tmTimeStamp->tm_wday) < 25)))
YSI 7:98b12722e9e2 236 timeStamp += 3600; // DST starts last Sunday of March; 2am (1am UTC), DST ends last Sunday of october; 3am (2am UTC)
YSI 6:d6a07fd1548a 237 }
YSI 6:d6a07fd1548a 238 }
YSI 6:d6a07fd1548a 239 eth_error("clientNTP_close", clientNTP.close());
YSI 6:d6a07fd1548a 240 }
YSI 6:d6a07fd1548a 241 return timeStamp;
YSI 6:d6a07fd1548a 242 }
YSI 6:d6a07fd1548a 243
YSI 3:7e15bf0a71f4 244 void Transmission::http(void)
YSI 3:7e15bf0a71f4 245 {
YSI 3:7e15bf0a71f4 246 message.HTTP = true;
YSI 3:7e15bf0a71f4 247 }
YSI 3:7e15bf0a71f4 248
YSI 0:2fc6fc3b5e15 249 intptr_t Transmission::eth_status(const string& source, const intptr_t& code)
YSI 0:2fc6fc3b5e15 250 {
YSI 0:2fc6fc3b5e15 251 stringstream message;
YSI 0:2fc6fc3b5e15 252 message << "\n" << source << "[" << code;
YSI 0:2fc6fc3b5e15 253 switch(code)
YSI 0:2fc6fc3b5e15 254 {
YSI 0:2fc6fc3b5e15 255 case NSAPI_STATUS_LOCAL_UP: message << "] NSAPI_STATUS_LOCAL_UP < local IP address set >"; break;
YSI 0:2fc6fc3b5e15 256 case NSAPI_STATUS_GLOBAL_UP: message << "] NSAPI_STATUS_GLOBAL_UP < global IP address set >"; break;
YSI 0:2fc6fc3b5e15 257 case NSAPI_STATUS_DISCONNECTED: message << "] NSAPI_STATUS_DISCONNECTED < no connection to network >"; break;
YSI 0:2fc6fc3b5e15 258 case NSAPI_STATUS_CONNECTING: message << "] NSAPI_STATUS_CONNECTING < connecting to network >"; break;
YSI 0:2fc6fc3b5e15 259 case NSAPI_STATUS_ERROR_UNSUPPORTED: message << "] NSAPI_STATUS_ERROR_UNSUPPORTED < unsupported functionality >";break;
YSI 0:2fc6fc3b5e15 260 }
YSI 1:27f6baabb15e 261 #ifndef NDEBUG
YSI 1:27f6baabb15e 262 _serial->write(message.str().c_str(), message.str().size());
YSI 1:27f6baabb15e 263 #endif
YSI 0:2fc6fc3b5e15 264 return code;
YSI 0:2fc6fc3b5e15 265 }
YSI 0:2fc6fc3b5e15 266
YSI 0:2fc6fc3b5e15 267 nsapi_error_t Transmission::eth_error(const string& source, const nsapi_error_t& code)
YSI 0:2fc6fc3b5e15 268 {
YSI 0:2fc6fc3b5e15 269 stringstream message;
YSI 0:2fc6fc3b5e15 270 message << "\n" << source << "[" << code;
YSI 0:2fc6fc3b5e15 271 switch(code)
YSI 0:2fc6fc3b5e15 272 {
YSI 0:2fc6fc3b5e15 273 case NSAPI_ERROR_OK: message << "] NSAPI_ERROR_OK < no error >"; break;
YSI 0:2fc6fc3b5e15 274 case NSAPI_ERROR_WOULD_BLOCK: message << "] NSAPI_ERROR_WOULD_BLOCK < no data is not available but call is non-blocking >";break;
YSI 0:2fc6fc3b5e15 275 case NSAPI_ERROR_UNSUPPORTED: message << "] NSAPI_ERROR_UNSUPPORTED < unsupported functionality >"; break;
YSI 0:2fc6fc3b5e15 276 case NSAPI_ERROR_PARAMETER: message << "] NSAPI_ERROR_PARAMETER < invalid configuration >"; break;
YSI 0:2fc6fc3b5e15 277 case NSAPI_ERROR_NO_CONNECTION: message << "] NSAPI_ERROR_NO_CONNECTION < not connected to a network >"; break;
YSI 0:2fc6fc3b5e15 278 case NSAPI_ERROR_NO_SOCKET: message << "] NSAPI_ERROR_NO_SOCKET < socket not available for use >"; break;
YSI 0:2fc6fc3b5e15 279 case NSAPI_ERROR_NO_ADDRESS: message << "] NSAPI_ERROR_NO_ADDRESS < IP address is not known >"; break;
YSI 0:2fc6fc3b5e15 280 case NSAPI_ERROR_NO_MEMORY: message << "] NSAPI_ERROR_NO_MEMORY < memory resource not available >"; break;
YSI 0:2fc6fc3b5e15 281 case NSAPI_ERROR_NO_SSID: message << "] NSAPI_ERROR_NO_SSID < ssid not found >"; break;
YSI 0:2fc6fc3b5e15 282 case NSAPI_ERROR_DNS_FAILURE: message << "] NSAPI_ERROR_DNS_FAILURE < DNS failed to complete successfully >"; break;
YSI 0:2fc6fc3b5e15 283 case NSAPI_ERROR_DHCP_FAILURE: message << "] NSAPI_ERROR_DHCP_FAILURE < DHCP failed to complete successfully >"; break;
YSI 0:2fc6fc3b5e15 284 case NSAPI_ERROR_AUTH_FAILURE: message << "] NSAPI_ERROR_AUTH_FAILURE < connection to access point failed >"; break;
YSI 0:2fc6fc3b5e15 285 case NSAPI_ERROR_DEVICE_ERROR: message << "] NSAPI_ERROR_DEVICE_ERROR < failure interfacing with the network processor >"; break;
YSI 0:2fc6fc3b5e15 286 case NSAPI_ERROR_IN_PROGRESS: message << "] NSAPI_ERROR_IN_PROGRESS < operation (eg connect) in progress >"; break;
YSI 0:2fc6fc3b5e15 287 case NSAPI_ERROR_ALREADY: message << "] NSAPI_ERROR_ALREADY < operation (eg connect) already in progress >"; break;
YSI 0:2fc6fc3b5e15 288 case NSAPI_ERROR_IS_CONNECTED: message << "] NSAPI_ERROR_IS_CONNECTED < socket is already connected >"; break;
YSI 0:2fc6fc3b5e15 289 case NSAPI_ERROR_CONNECTION_LOST: message << "] NSAPI_ERROR_CONNECTION_LOST < connection lost >"; break;
YSI 0:2fc6fc3b5e15 290 case NSAPI_ERROR_CONNECTION_TIMEOUT: message << "] NSAPI_ERROR_CONNECTION_TIMEOUT < connection timed out >"; break;
YSI 0:2fc6fc3b5e15 291 case NSAPI_ERROR_ADDRESS_IN_USE: message << "] NSAPI_ERROR_ADDRESS_IN_USE < Address already in use >"; break;
YSI 0:2fc6fc3b5e15 292 case NSAPI_ERROR_TIMEOUT: message << "] NSAPI_ERROR_TIMEOUT < operation timed out >"; break;
YSI 0:2fc6fc3b5e15 293 case NSAPI_ERROR_BUSY: message << "] NSAPI_ERROR_BUSY < device is busy and cannot accept new operation >"; break;
YSI 0:2fc6fc3b5e15 294 default: message << "] NSAPI_ERROR < unknow code >"; break;
YSI 0:2fc6fc3b5e15 295 }
YSI 1:27f6baabb15e 296 #ifndef NDEBUG
YSI 1:27f6baabb15e 297 if(code < NSAPI_ERROR_OK) _serial->write(message.str().c_str(), message.str().size());
YSI 1:27f6baabb15e 298 #endif
YSI 0:2fc6fc3b5e15 299 return code;
YSI 0:2fc6fc3b5e15 300 }