diff --git a/Dhcp.cpp b/Dhcp.cpp index c3c744f..acbc919 100644 --- a/Dhcp.cpp +++ b/Dhcp.cpp @@ -4,7 +4,14 @@ #include #include #include "Dhcp.h" -#include "Arduino.h" +#if defined(ARDUINO) + #include +#endif +#if defined(__MBED__) + #include + #include "mbed/millis.h" + #define delay(x) wait_ms(x) +#endif #include "utility/logging.h" #include "utility/uip.h" @@ -26,20 +33,25 @@ int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long return request_DHCP_lease(); } -void DhcpClass::reset_DHCP_lease(){ +void DhcpClass::reset_DHCP_lease(void){ // zero out _dhcpSubnetMask, _dhcpGatewayIp, _dhcpLocalIp, _dhcpDhcpServerIp, _dhcpDnsServerIp memset(_dhcpLocalIp, 0, 20); } //return:0 on error, 1 if request is sent and response is received -int DhcpClass::request_DHCP_lease(){ +int DhcpClass::request_DHCP_lease(void){ uint8_t messageType = 0; // Pick an initial transaction ID - _dhcpTransactionId = random(1UL, 2000UL); + #if defined(ARDUINO) + _dhcpTransactionId = random(1UL, 2000UL); + #endif + #if defined(__MBED__) + _dhcpTransactionId = (rand() % 2000UL) + 1; + #endif _dhcpInitialTransactionId = _dhcpTransactionId; _dhcpUdpSocket.stop(); @@ -127,7 +139,7 @@ int DhcpClass::request_DHCP_lease(){ return result; } -void DhcpClass::presend_DHCP() +void DhcpClass::presend_DHCP(void) { } @@ -266,7 +278,7 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr } // start reading in the packet RIP_MSG_FIXED fixedMsg; - _dhcpUdpSocket.read((uint8_t*)&fixedMsg, sizeof(RIP_MSG_FIXED)); + _dhcpUdpSocket.read((char*)&fixedMsg, sizeof(RIP_MSG_FIXED)); if(fixedMsg.op == DHCP_BOOTREPLY && _dhcpUdpSocket.remotePort() == DHCP_SERVER_PORT) { @@ -305,12 +317,12 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr case subnetMask : opt_len = _dhcpUdpSocket.read(); - _dhcpUdpSocket.read(_dhcpSubnetMask, 4); + _dhcpUdpSocket.read((char*)_dhcpSubnetMask, 4); break; case routersOnSubnet : opt_len = _dhcpUdpSocket.read(); - _dhcpUdpSocket.read(_dhcpGatewayIp, 4); + _dhcpUdpSocket.read((char*)_dhcpGatewayIp, 4); for (int i = 0; i < opt_len-4; i++) { _dhcpUdpSocket.read(); @@ -319,7 +331,7 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr case dns : opt_len = _dhcpUdpSocket.read(); - _dhcpUdpSocket.read(_dhcpDnsServerIp, 4); + _dhcpUdpSocket.read((char*)_dhcpDnsServerIp, 4); for (int i = 0; i < opt_len-4; i++) { _dhcpUdpSocket.read(); @@ -331,7 +343,7 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr if( *((uint32_t*)_dhcpDhcpServerIp) == 0 || IPAddress(_dhcpDhcpServerIp) == _dhcpUdpSocket.remoteIP() ) { - _dhcpUdpSocket.read(_dhcpDhcpServerIp, sizeof(_dhcpDhcpServerIp)); + _dhcpUdpSocket.read((char*)_dhcpDhcpServerIp, sizeof(_dhcpDhcpServerIp)); } else { @@ -345,19 +357,19 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr case dhcpT1value : opt_len = _dhcpUdpSocket.read(); - _dhcpUdpSocket.read((uint8_t*)&_dhcpT1, sizeof(_dhcpT1)); + _dhcpUdpSocket.read((char*)&_dhcpT1, sizeof(_dhcpT1)); _dhcpT1 = ntohl(_dhcpT1); break; case dhcpT2value : opt_len = _dhcpUdpSocket.read(); - _dhcpUdpSocket.read((uint8_t*)&_dhcpT2, sizeof(_dhcpT2)); + _dhcpUdpSocket.read((char*)&_dhcpT2, sizeof(_dhcpT2)); _dhcpT2 = ntohl(_dhcpT2); break; case dhcpIPaddrLeaseTime : opt_len = _dhcpUdpSocket.read(); - _dhcpUdpSocket.read((uint8_t*)&_dhcpLeaseTime, sizeof(_dhcpLeaseTime)); + _dhcpUdpSocket.read((char*)&_dhcpLeaseTime, sizeof(_dhcpLeaseTime)); _dhcpLeaseTime = ntohl(_dhcpLeaseTime); _renewInSec = _dhcpLeaseTime; break; @@ -389,7 +401,7 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr 3/DHCP_CHECK_REBIND_FAIL: rebind fail 4/DHCP_CHECK_REBIND_OK: rebind success */ -int DhcpClass::checkLease(){ +int DhcpClass::checkLease(void){ //this uses a signed / unsigned trick to deal with millis overflow unsigned long now = millis(); signed long snow = (long)now; @@ -442,27 +454,27 @@ int DhcpClass::checkLease(){ return rc; } -IPAddress DhcpClass::getLocalIp() +IPAddress DhcpClass::getLocalIp(void) { return IPAddress(_dhcpLocalIp); } -IPAddress DhcpClass::getSubnetMask() +IPAddress DhcpClass::getSubnetMask(void) { return IPAddress(_dhcpSubnetMask); } -IPAddress DhcpClass::getGatewayIp() +IPAddress DhcpClass::getGatewayIp(void) { return IPAddress(_dhcpGatewayIp); } -IPAddress DhcpClass::getDhcpServerIp() +IPAddress DhcpClass::getDhcpServerIp(void) { return IPAddress(_dhcpDhcpServerIp); } -IPAddress DhcpClass::getDnsServerIp() +IPAddress DhcpClass::getDnsServerIp(void) { return IPAddress(_dhcpDnsServerIp); } diff --git a/Dhcp.h b/Dhcp.h index cc3cd35..7aea262 100644 --- a/Dhcp.h +++ b/Dhcp.h @@ -157,22 +157,22 @@ class DhcpClass { uint8_t _dhcp_state; UIPUDP _dhcpUdpSocket; - int request_DHCP_lease(); - void reset_DHCP_lease(); - void presend_DHCP(); + int request_DHCP_lease(void); + void reset_DHCP_lease(void); + void presend_DHCP(void); void send_DHCP_MESSAGE(uint8_t, uint16_t); void printByte(char *, uint8_t); uint8_t parseDHCPResponse(unsigned long responseTimeout, uint32_t& transactionId); public: - IPAddress getLocalIp(); - IPAddress getSubnetMask(); - IPAddress getGatewayIp(); - IPAddress getDhcpServerIp(); - IPAddress getDnsServerIp(); + IPAddress getLocalIp(void); + IPAddress getSubnetMask(void); + IPAddress getGatewayIp(void); + IPAddress getDhcpServerIp(void); + IPAddress getDnsServerIp(void); int beginWithDHCP(uint8_t *, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); - int checkLease(); + int checkLease(void); }; #endif diff --git a/Dns.cpp b/Dns.cpp index 3e77164..92accbb 100644 --- a/Dns.cpp +++ b/Dns.cpp @@ -2,12 +2,19 @@ // (c) Copyright 2009-2010 MCQN Ltd. // Released under Apache License, version 2.0 -#include "Udp.h" - #include "Dns.h" #include //#include -#include "Arduino.h" +#if defined(ARDUINO) + #include "Arduino.h" + #include "Udp.h" +#endif +#if defined(__MBED__) + #include + #include "mbed/Udp.h" + #include "mbed/millis.h" + #define delay(x) wait_ms(x) +#endif #include "utility/logging.h" #include "utility/uip.h" @@ -82,7 +89,7 @@ int DNSClient::inet_aton(const char* aIPAddrString, IPAddress& aResult) } else { - aResult[segment] = (byte)segmentValue; + aResult[segment] = (uint8_t)segmentValue; segment++; segmentValue = 0; } @@ -104,7 +111,7 @@ int DNSClient::inet_aton(const char* aIPAddrString, IPAddress& aResult) } else { - aResult[segment] = (byte)segmentValue; + aResult[segment] = (uint8_t)segmentValue; return 1; } } @@ -279,7 +286,7 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress) { return TRUNCATED; } - iUdp.read(header, DNS_HEADER_SIZE); + iUdp.read((char*)header, DNS_HEADER_SIZE); uint16_t header_flags = htons(*((uint16_t*)&header[2])); // Check that it's a response to this request @@ -315,7 +322,7 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress) uint8_t len; do { - iUdp.read(&len, sizeof(len)); + iUdp.read((char*)&len, sizeof(len)); if (len > 0) { // Don't need to actually read the data out for the string, just @@ -345,7 +352,7 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress) uint8_t len; do { - iUdp.read(&len, sizeof(len)); + iUdp.read((char*)&len, sizeof(len)); if ((len & LABEL_COMPRESSION_MASK) == 0) { // It's just a normal label @@ -378,8 +385,8 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress) // Check the type and class uint16_t answerType; uint16_t answerClass; - iUdp.read((uint8_t*)&answerType, sizeof(answerType)); - iUdp.read((uint8_t*)&answerClass, sizeof(answerClass)); + iUdp.read((char*)&answerType, sizeof(answerType)); + iUdp.read((char*)&answerClass, sizeof(answerClass)); // Ignore the Time-To-Live as we don't do any caching for (int i =0; i < TTL_SIZE; i++) @@ -389,7 +396,7 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress) // And read out the length of this answer // Don't need header_flags anymore, so we can reuse it here - iUdp.read((uint8_t*)&header_flags, sizeof(header_flags)); + iUdp.read((char*)&header_flags, sizeof(header_flags)); if ( (htons(answerType) == TYPE_A) && (htons(answerClass) == CLASS_IN) ) { @@ -400,7 +407,7 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress) iUdp.flush(); return -9;//INVALID_RESPONSE; } - iUdp.read(aAddress.raw_address(), 4); + iUdp.read((char*)aAddress.raw_address(), 4); return SUCCESS; } else diff --git a/Dns.h b/Dns.h index 4ccb1e1..1346841 100644 --- a/Dns.h +++ b/Dns.h @@ -5,7 +5,7 @@ #ifndef DNSClient_h #define DNSClient_h -#include +#include "UIPUdp.h" class DNSClient { diff --git a/UIPClient.cpp b/UIPClient.cpp index 428f006..7fd42fe 100644 --- a/UIPClient.cpp +++ b/UIPClient.cpp @@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include "utility/logging.h" extern "C" { @@ -24,7 +25,6 @@ extern "C" #include "utility/uip_arp.h" #include "string.h" } -#include "utility/logging.h" #include "UIPEthernet.h" #include "UIPClient.h" #include "Dns.h" @@ -33,6 +33,10 @@ extern "C" #include #endif +#if defined(__MBED__) + #include "mbed/millis.h" +#endif + #define UIP_TCP_PHYH_LEN UIP_LLH_LEN+UIP_IPTCPH_LEN uip_userdata_t UIPClient::all_data[UIP_CONNS]; @@ -51,7 +55,7 @@ int UIPClient::connect(IPAddress ip, uint16_t port) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::connect(IPAddress ip, uint16_t port) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::connect(IPAddress ip, uint16_t port) DEBUG_V3:Function started")); #endif stop(); uip_ipaddr_t ipaddr; @@ -69,10 +73,10 @@ UIPClient::connect(IPAddress ip, uint16_t port) { data = (uip_userdata_t*) conn->appstate; #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("UIPClient::connect DEBUG:connected, state: ")); - LogObject.print(data->state); - LogObject.print(F(", first packet in: ")); - LogObject.println(data->packets_in[0]); + LogObject.uart_send_str(F("UIPClient::connect DEBUG:connected, state: ")); + LogObject.uart_send_dec(data->state); + LogObject.uart_send_str(F(", first packet in: ")); + LogObject.uart_send_decln(data->packets_in[0]); #endif return 1; } @@ -92,7 +96,7 @@ int UIPClient::connect(const char *host, uint16_t port) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::connect(const char *host, uint16_t port) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::connect(const char *host, uint16_t port) DEBUG_V3:Function started")); #endif // Look up the host first int ret = 0; @@ -113,12 +117,12 @@ void UIPClient::stop() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::stop() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::stop() DEBUG_V3:Function started")); #endif if (data && data->state) { #if ACTLOGLEVEL>=LOG_DEBUG_V2 - LogObject.println(F("UIPClient::stop() DEBUG_V2:Before stop(), with data")); + LogObject.uart_send_strln(F("UIPClient::stop() DEBUG_V2:Before stop(), with data")); _dumpAllData(); #endif _flushBlocks(&data->packets_in[0]); @@ -131,14 +135,14 @@ UIPClient::stop() data->state |= UIP_CLIENT_CLOSE; } #if ACTLOGLEVEL>=LOG_DEBUG_V2 - LogObject.println(F("UIPClient::stop() DEBUG_V2:after stop()")); + LogObject.uart_send_strln(F("UIPClient::stop() DEBUG_V2:after stop()")); _dumpAllData(); #endif } #if ACTLOGLEVEL>=LOG_DEBUG else { - LogObject.println(F("UIPClient::stop() DEBUG:stop(), data: NULL")); + LogObject.uart_send_strln(F("UIPClient::stop() DEBUG:stop(), data: NULL")); } #endif data = NULL; @@ -149,7 +153,7 @@ uint8_t UIPClient::connected() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::connected() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::connected() DEBUG_V3:Function started")); #endif return (data && (data->packets_in[0] != NOBLOCK || (data->state & UIP_CLIENT_CONNECTED))) ? 1 : 0; } @@ -158,7 +162,7 @@ bool UIPClient::operator==(const UIPClient& rhs) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::operator==(const UIPClient& rhs) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::operator==(const UIPClient& rhs) DEBUG_V3:Function started")); #endif return data && rhs.data && (data == rhs.data); } @@ -166,7 +170,7 @@ UIPClient::operator==(const UIPClient& rhs) UIPClient::operator bool() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::operator bool() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::operator bool() DEBUG_V3:Function started")); #endif UIPEthernetClass::tick(); return data && (!(data->state & UIP_CLIENT_REMOTECLOSED) || data->packets_in[0] != NOBLOCK); @@ -176,7 +180,7 @@ size_t UIPClient::write(uint8_t c) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::write(uint8_t c) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::write(uint8_t c) DEBUG_V3:Function started")); #endif return _write(data, &c, 1); } @@ -185,7 +189,7 @@ size_t UIPClient::write(const uint8_t *buf, size_t size) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::write(const uint8_t *buf, size_t size) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::write(const uint8_t *buf, size_t size) DEBUG_V3:Function started")); #endif return _write(data, buf, size); } @@ -194,7 +198,7 @@ size_t UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size) DEBUG_V3:Function started")); #endif int remain = size; uint16_t written; @@ -223,17 +227,25 @@ UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size) u->out_pos = 0; } #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("UIPClient::_write DEBUG:writePacket(")); - LogObject.print(u->packets_out[p]); - LogObject.print(F(") pos: ")); - LogObject.print(u->out_pos); - LogObject.print(F(", buf[")); - LogObject.print(size-remain); - LogObject.print(F("-")); - LogObject.print(remain); - LogObject.print(F("]: '")); - LogObject.write((uint8_t*)buf+size-remain,remain); - LogObject.println(F("'")); + LogObject.uart_send_str(F("UIPClient::_write DEBUG:writePacket(")); + LogObject.uart_send_dec(u->packets_out[p]); + LogObject.uart_send_str(F(") pos: ")); + LogObject.uart_send_dec(u->out_pos); + LogObject.uart_send_str(F(", buf[")); + LogObject.uart_send_dec(size-remain); + LogObject.uart_send_str(F("-")); + LogObject.uart_send_dec(remain); + LogObject.uart_send_str(F("]: '")); + #if defined(ARDUINO) + LogObject.uart_send_buf_len((uint8_t*)buf+size-remain,remain); + #endif + #if defined(__MBED__) + for(int i=0; ipackets_out[p],u->out_pos,(uint8_t*)buf+size-remain,remain); remain -= written; @@ -266,7 +278,7 @@ int UIPClient::available() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::available() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::available() DEBUG_V3:Function started")); #endif if (*this) return _available(data); @@ -277,7 +289,7 @@ int UIPClient::_available(uip_userdata_t *u) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::_available(uip_userdata_t *u) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::_available(uip_userdata_t *u) DEBUG_V3:Function started")); #endif int len = 0; for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++) @@ -291,7 +303,7 @@ int UIPClient::read(uint8_t *buf, size_t size) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::read(uint8_t *buf, size_t size) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::read(uint8_t *buf, size_t size) DEBUG_V3:Function started")); #endif if (*this) { @@ -334,7 +346,7 @@ int UIPClient::read() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::read() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::read() DEBUG_V3:Function started")); #endif uint8_t c; if (read(&c,1) < 0) @@ -346,7 +358,7 @@ int UIPClient::peek() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::peek() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::peek() DEBUG_V3:Function started")); #endif if (*this) { @@ -364,7 +376,7 @@ void UIPClient::flush() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::flush() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::flush() DEBUG_V3:Function started")); #endif if (*this) { @@ -376,14 +388,14 @@ void uipclient_appcall(void) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("uipclient_appcall(void) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG_V3:Function started")); #endif uint16_t send_len = 0; uip_userdata_t *u = (uip_userdata_t*)uip_conn->appstate; if (!u && uip_connected()) { #if ACTLOGLEVEL>=LOG_DEBUG_V2 - LogObject.println(F("uipclient_appcall(void) DEBUG_V2:UIPClient uip_connected")); + LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG_V2:UIPClient uip_connected")); UIPClient::_dumpAllData(); #endif u = (uip_userdata_t*) UIPClient::_allocateData(); @@ -391,13 +403,13 @@ uipclient_appcall(void) { uip_conn->appstate = u; #if ACTLOGLEVEL>=LOG_DEBUG_V1 - LogObject.print(F("uipclient_appcall(void) DEBUG_V1:UIPClient allocated state: ")); - LogObject.println(u->state,BIN); + LogObject.uart_send_str(F("uipclient_appcall(void) DEBUG_V1:UIPClient allocated state: ")); + LogObject.uart_send_binln(u->state); #endif } #if ACTLOGLEVEL>=LOG_ERR else - LogObject.println(F("uipclient_appcall(void) ERROR:UIPClient allocation failed")); + LogObject.uart_send_strln(F("uipclient_appcall(void) ERROR:UIPClient allocation failed")); #endif } if (u) @@ -405,8 +417,8 @@ uipclient_appcall(void) if (uip_newdata()) { #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("uipclient_appcall(void) DEBUG:UIPClient uip_newdata, uip_len:")); - LogObject.println(uip_len); + LogObject.uart_send_str(F("uipclient_appcall(void) DEBUG:UIPClient uip_newdata, uip_len:")); + LogObject.uart_send_decln(uip_len); #endif if (uip_len && !(u->state & (UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED))) { @@ -438,7 +450,7 @@ uipclient_appcall(void) if (uip_closed() || uip_timedout()) { #if ACTLOGLEVEL>=LOG_DEBUG_V2 - LogObject.println(F("uipclient_appcall(void) DEBUG_V2:UIPClient uip_closed")); + LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG_V2:UIPClient uip_closed")); UIPClient::_dumpAllData(); #endif // drop outgoing packets not sent yet: @@ -452,7 +464,7 @@ uipclient_appcall(void) u->state = 0; // disassociate appdata. #if ACTLOGLEVEL>=LOG_DEBUG_V2 - LogObject.println(F("uipclient_appcall(void) DEBUG_V2:After UIPClient uip_closed")); + LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG_V2:After UIPClient uip_closed")); UIPClient::_dumpAllData(); #endif uip_conn->appstate = NULL; @@ -461,14 +473,14 @@ uipclient_appcall(void) if (uip_acked()) { #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.println(F("uipclient_appcall(void) DEBUG:UIPClient uip_acked")); + LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG:UIPClient uip_acked")); #endif UIPClient::_eatBlock(&u->packets_out[0]); } if (uip_poll() || uip_rexmit()) { #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.println(F("uipclient_appcall(void) DEBUG:UIPClient uip_poll ||uip_remix")); + LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG:UIPClient uip_poll ||uip_remix")); #endif if (u->packets_out[0] != NOBLOCK) { @@ -499,7 +511,7 @@ uipclient_appcall(void) if (u->state & UIP_CLIENT_CLOSE) { #if ACTLOGLEVEL>=LOG_DEBUG_V2 - LogObject.println(F("uipclient_appcall(void) DEBUG_V2:UIPClient state UIP_CLIENT_CLOSE")); + LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG_V2:UIPClient state UIP_CLIENT_CLOSE")); UIPClient::_dumpAllData(); #endif if (u->packets_out[0] == NOBLOCK) @@ -508,7 +520,7 @@ uipclient_appcall(void) uip_conn->appstate = NULL; uip_close(); #if ACTLOGLEVEL>=LOG_DEBUG_V2 - LogObject.println(F("uipclient_appcall(void) DEBUG_V2:no blocks out -> free userdata")); + LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG_V2:no blocks out -> free userdata")); UIPClient::_dumpAllData(); #endif } @@ -516,7 +528,7 @@ uipclient_appcall(void) { uip_stop(); #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.println(F("uipclient_appcall(void) DEBUG:blocks outstanding transfer -> uip_stop()")); + LogObject.uart_send_strln(F("uipclient_appcall(void) DEBUG:blocks outstanding transfer -> uip_stop()")); #endif } } @@ -530,7 +542,7 @@ uip_userdata_t * UIPClient::_allocateData() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::_allocateData() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::_allocateData() DEBUG_V3:Function started")); #endif for ( uint8_t sock = 0; sock < UIP_CONNS; sock++ ) { @@ -549,7 +561,7 @@ uint8_t UIPClient::_currentBlock(memhandle* block) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::_currentBlock(memhandle* block) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::_currentBlock(memhandle* block) DEBUG_V3:Function started")); #endif for (uint8_t i = 1; i < UIP_SOCKET_NUMPACKETS; i++) { @@ -563,19 +575,19 @@ void UIPClient::_eatBlock(memhandle* block) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::_eatBlock(memhandle* block) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::_eatBlock(memhandle* block) DEBUG_V3:Function started")); #endif #if ACTLOGLEVEL>=LOG_DEBUG memhandle* start = block; - LogObject.print(F("UIPClient::_eatBlock DEBUG:eatblock(")); - LogObject.print(*block); - LogObject.print(F("): ")); + LogObject.uart_send_str(F("UIPClient::_eatBlock DEBUG:eatblock(")); + LogObject.uart_send_dec(*block); + LogObject.uart_send_str(F("): ")); for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++) { - LogObject.print(start[i]); - LogObject.print(F(" ")); + LogObject.uart_send_dec(start[i]); + LogObject.uart_send_str(F(" ")); } - LogObject.print(F("-> ")); + LogObject.uart_send_str(F("-> ")); #endif Enc28J60Network::freeBlock(block[0]); for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS-1; i++) @@ -586,10 +598,10 @@ UIPClient::_eatBlock(memhandle* block) #if ACTLOGLEVEL>=LOG_DEBUG for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++) { - LogObject.print(start[i]); - LogObject.print(F(" ")); + LogObject.uart_send_dec(start[i]); + LogObject.uart_send_str(F(" ")); } - LogObject.println(); + LogObject.uart_send_strln(F("")); #endif } @@ -597,7 +609,7 @@ void UIPClient::_flushBlocks(memhandle* block) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPClient::_flushBlocks(memhandle* block) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPClient::_flushBlocks(memhandle* block) DEBUG_V3:Function started")); #endif for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++) { @@ -608,36 +620,36 @@ UIPClient::_flushBlocks(memhandle* block) #if ACTLOGLEVEL>=LOG_DEBUG_V2 void -UIPClient::_dumpAllData() { +UIPClient::_dumpAllData(void) { for (uint8_t i=0; i < UIP_CONNS; i++) { - LogObject.print(F("UIPClient::_dumpAllData() DEBUG_V2:UIPClient::all_data[")); - LogObject.print(i); - LogObject.print(F("], state:")); - LogObject.println(all_data[i].state, BIN); - LogObject.print(F("packets_in: ")); + LogObject.uart_send_str(F("UIPClient::_dumpAllData() DEBUG_V2:UIPClient::all_data[")); + LogObject.uart_send_dec(i); + LogObject.uart_send_str(F("], state:")); + LogObject.uart_send_binln(all_data[i].state); + LogObject.uart_send_str(F("packets_in: ")); for (uint8_t j=0; j < UIP_SOCKET_NUMPACKETS; j++) { - LogObject.print(all_data[i].packets_in[j]); - LogObject.print(F(" ")); + LogObject.uart_send_dec(all_data[i].packets_in[j]); + LogObject.uart_send_str(F(" ")); } - LogObject.println(); + LogObject.uart_send_strln(F("")); if (all_data[i].state & UIP_CLIENT_REMOTECLOSED) { - LogObject.print(F("state remote closed, local port: ")); - LogObject.println(htons(((uip_userdata_closed_t *)(&all_data[i]))->lport)); + LogObject.uart_send_str(F("state remote closed, local port: ")); + LogObject.uart_send_decln(htons(((uip_userdata_closed_t *)(&all_data[i]))->lport)); } else { - LogObject.print(F("packets_out: ")); + LogObject.uart_send_str(F("packets_out: ")); for (uint8_t j=0; j < UIP_SOCKET_NUMPACKETS; j++) { - LogObject.print(all_data[i].packets_out[j]); - LogObject.print(F(" ")); + LogObject.uart_send_dec(all_data[i].packets_out[j]); + LogObject.uart_send_str(F(" ")); } - LogObject.println(); - LogObject.print(F("out_pos: ")); - LogObject.println(all_data[i].out_pos); + LogObject.uart_send_strln(F("")); + LogObject.uart_send_str(F("out_pos: ")); + LogObject.uart_send_decln(all_data[i].out_pos); } } } diff --git a/UIPClient.h b/UIPClient.h index ecec8c9..ef926f8 100644 --- a/UIPClient.h +++ b/UIPClient.h @@ -21,8 +21,13 @@ #define UIPCLIENT_H #include "ethernet_comp.h" -#include "Print.h" -#include "Client.h" +#if defined(ARDUINO) + #include "Print.h" + #include "Client.h" +#endif +#if defined(__MBED__) + #include "mbed/Client.h" +#endif #include "utility/mempool.h" #include "utility/logging.h" @@ -81,7 +86,9 @@ class UIPClient : public Client { int peek(); void flush(); - using Print::write; + #if defined(ARDUINO) + using Print::write; + #endif private: UIPClient(struct uip_conn *_conn); @@ -100,7 +107,7 @@ class UIPClient : public Client { static void _flushBlocks(memhandle* blocks); #if ACTLOGLEVEL>=LOG_DEBUG_V2 - static void _dumpAllData(); + static void _dumpAllData(void); #endif friend class UIPEthernetClass; diff --git a/UIPEthernet.cpp b/UIPEthernet.cpp index 4650eba..16b3a8a 100644 --- a/UIPEthernet.cpp +++ b/UIPEthernet.cpp @@ -17,7 +17,13 @@ along with this program. If not, see . */ -#include +#if defined(ARDUINO) + #include +#endif +#if defined(__MBED__) + #include + #include "mbed/millis.h" +#endif #include "UIPEthernet.h" #include "utility/logging.h" #include "utility/Enc28J60Network.h" @@ -59,7 +65,7 @@ int UIPEthernetClass::begin(const uint8_t* mac) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::begin(const uint8_t* mac) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::begin(const uint8_t* mac) DEBUG_V3:Function started")); #endif //static DhcpClass s_dhcp; // <-- this is a bug ! // I leave it there commented for history. It is bring all GCC "new" memory allocation code, making the *.bin almost 40K bigger. I've move it globally. @@ -83,7 +89,7 @@ void UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip) DEBUG_V3:Function started")); #endif IPAddress dns = ip; dns[3] = 1; @@ -94,7 +100,7 @@ void UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns) DEBUG_V3:Function started")); #endif IPAddress gateway = ip; gateway[3] = 1; @@ -105,7 +111,7 @@ void UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway) DEBUG_V3:Function started")); #endif IPAddress subnet(255, 255, 255, 0); begin(mac, ip, dns, gateway, subnet); @@ -115,7 +121,7 @@ void UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) DEBUG_V3:Function started")); #endif init(mac); configure(ip,dns,gateway,subnet); @@ -123,7 +129,7 @@ UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddre int UIPEthernetClass::maintain(){ #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::maintain() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::maintain() DEBUG_V3:Function started")); #endif tick(); int rc = DHCP_CHECK_NONE; @@ -152,7 +158,7 @@ int UIPEthernetClass::maintain(){ IPAddress UIPEthernetClass::localIP() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::localIP() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::localIP() DEBUG_V3:Function started")); #endif IPAddress ret; uip_ipaddr_t a; @@ -163,7 +169,7 @@ IPAddress UIPEthernetClass::localIP() IPAddress UIPEthernetClass::subnetMask() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::subnetMask() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::subnetMask() DEBUG_V3:Function started")); #endif IPAddress ret; uip_ipaddr_t a; @@ -174,7 +180,7 @@ IPAddress UIPEthernetClass::subnetMask() IPAddress UIPEthernetClass::gatewayIP() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::gatewayIP() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::gatewayIP() DEBUG_V3:Function started")); #endif IPAddress ret; uip_ipaddr_t a; @@ -185,7 +191,7 @@ IPAddress UIPEthernetClass::gatewayIP() IPAddress UIPEthernetClass::dnsServerIP() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::dnsServerIP() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::dnsServerIP() DEBUG_V3:Function started")); #endif return _dnsServerAddress; } @@ -194,12 +200,12 @@ void UIPEthernetClass::tick() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::tick() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::tick() DEBUG_V3:Function started")); #endif if (Enc28J60Network::geterevid()==0) { #if ACTLOGLEVEL>=LOG_ERR - LogObject.println(F("UIPEthernetClass::tick() ERROR:EREVID=0 -> Not found ENC28j60 device !!! Function ended !!!")); + LogObject.uart_send_strln(F("UIPEthernetClass::tick() ERROR:EREVID=0 -> Not found ENC28j60 device !!! Function ended !!!")); #endif return; } @@ -212,8 +218,8 @@ if (Enc28J60Network::geterevid()==0) #if ACTLOGLEVEL>=LOG_DEBUG if (in_packet != NOBLOCK) { - LogObject.print(F("UIPEthernetClass::tick() DEBUG:receivePacket: ")); - LogObject.println(in_packet); + LogObject.uart_send_str(F("UIPEthernetClass::tick() DEBUG:receivePacket: ")); + LogObject.uart_send_decln(in_packet); } #endif } @@ -228,8 +234,8 @@ if (Enc28J60Network::geterevid()==0) { uip_packet = in_packet; //required for upper_layer_checksum of in_packet! #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("UIPEthernetClass::tick() DEBUG:readPacket type IP, uip_len: ")); - LogObject.println(uip_len); + LogObject.uart_send_str(F("UIPEthernetClass::tick() DEBUG:readPacket type IP, uip_len: ")); + LogObject.uart_send_decln(uip_len); #endif uip_arp_ipin(); uip_input(); @@ -242,8 +248,8 @@ if (Enc28J60Network::geterevid()==0) else if (ETH_HDR ->type == HTONS(UIP_ETHTYPE_ARP)) { #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("UIPEthernetClass::tick() DEBUG:readPacket type ARP, uip_len: ")); - LogObject.println(uip_len); + LogObject.uart_send_str(F("UIPEthernetClass::tick() DEBUG:readPacket type ARP, uip_len: ")); + LogObject.uart_send_decln(uip_len); #endif uip_arp_arpin(); if (uip_len > 0) @@ -255,8 +261,8 @@ if (Enc28J60Network::geterevid()==0) if (in_packet != NOBLOCK && (packetstate & UIPETHERNET_FREEPACKET)) { #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("UIPEthernetClass::tick() DEBUG:freeing packet: ")); - LogObject.println(in_packet); + LogObject.uart_send_str(F("UIPEthernetClass::tick() DEBUG:freeing packet: ")); + LogObject.uart_send_decln(in_packet); #endif Enc28J60Network::freePacket(); in_packet = NOBLOCK; @@ -308,7 +314,7 @@ if (Enc28J60Network::geterevid()==0) else { #if ACTLOGLEVEL>=LOG_DEBUG_V1 - LogObject.println(F("UIPEthernetClass::tick() DEBUG_V1:((uip_userdata_t*)uip_conn->appstate) is NULL")); + LogObject.uart_send_strln(F("UIPEthernetClass::tick() DEBUG_V1:((uip_userdata_t*)uip_conn->appstate) is NULL")); #endif if ((long)( now - ((uip_userdata_t*)uip_conn)->timer) >= 0) { @@ -323,7 +329,7 @@ if (Enc28J60Network::geterevid()==0) else { #if ACTLOGLEVEL>=LOG_ERR - LogObject.println(F("UIPEthernetClass::tick() ERROR:uip_conn is NULL")); + LogObject.uart_send_strln(F("UIPEthernetClass::tick() ERROR:uip_conn is NULL")); #endif continue; } @@ -362,15 +368,15 @@ if (Enc28J60Network::geterevid()==0) bool UIPEthernetClass::network_send() { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::network_send() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::network_send() DEBUG_V3:Function started")); #endif if (packetstate & UIPETHERNET_SENDPACKET) { #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("UIPEthernetClass::network_send() DEBUG:uip_packet: ")); - LogObject.print(uip_packet); - LogObject.print(F(", hdrlen: ")); - LogObject.println(uip_hdrlen); + LogObject.uart_send_str(F("UIPEthernetClass::network_send() DEBUG:uip_packet: ")); + LogObject.uart_send_dec(uip_packet); + LogObject.uart_send_str(F(", hdrlen: ")); + LogObject.uart_send_decln(uip_hdrlen); #endif Enc28J60Network::writePacket(uip_packet,0,uip_buf,uip_hdrlen); packetstate &= ~ UIPETHERNET_SENDPACKET; @@ -380,10 +386,10 @@ bool UIPEthernetClass::network_send() if (uip_packet != NOBLOCK) { #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("UIPEthernetClass::network_send() DEBUG:uip_buf (uip_len): ")); - LogObject.print(uip_len); - LogObject.print(F(", packet: ")); - LogObject.println(uip_packet); + LogObject.uart_send_str(F("UIPEthernetClass::network_send() DEBUG:uip_buf (uip_len): ")); + LogObject.uart_send_dec(uip_len); + LogObject.uart_send_str(F(", packet: ")); + LogObject.uart_send_decln(uip_packet); #endif Enc28J60Network::writePacket(uip_packet,0,uip_buf,uip_len); goto sendandfree; @@ -398,7 +404,7 @@ bool UIPEthernetClass::network_send() void UIPEthernetClass::init(const uint8_t* mac) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::init(const uint8_t* mac) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::init(const uint8_t* mac) DEBUG_V3:Function started")); #endif periodic_timer = millis() + UIP_PERIODIC_TIMER; @@ -411,7 +417,7 @@ void UIPEthernetClass::init(const uint8_t* mac) { void UIPEthernetClass::configure(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::configure(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::configure(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) DEBUG_V3:Function started")); #endif uip_ipaddr_t ipaddr; @@ -434,7 +440,7 @@ uint16_t UIPEthernetClass::chksum(uint16_t sum, const uint8_t *data, uint16_t len) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::chksum(uint16_t sum, const uint8_t *data, uint16_t len) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::chksum(uint16_t sum, const uint8_t *data, uint16_t len) DEBUG_V3:Function started")); #endif uint16_t t; const uint8_t *dataptr; @@ -470,7 +476,7 @@ uint16_t UIPEthernetClass::ipchksum(void) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPEthernetClass::ipchksum(void) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::ipchksum(void) DEBUG_V3:Function started")); #endif uint16_t sum; @@ -488,9 +494,9 @@ uip_tcpchksum(void) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 #if UIP_UDP - LogObject.println(F("UIPEthernetClass::upper_layer_chksum(uint8_t proto) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPEthernetClass::upper_layer_chksum(uint8_t proto) DEBUG_V3:Function started")); #else - LogObject.println(F("uip_tcpchksum(void) INFO:Function started")); + LogObject.uart_send_strln(F("uip_tcpchksum(void) INFO:Function started")); #endif #endif uint16_t upper_layer_len; @@ -535,15 +541,15 @@ uip_tcpchksum(void) sum = UIPEthernetClass::chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN], upper_layer_memlen); #if ACTLOGLEVEL>=LOG_DEBUG #if UIP_UDP - LogObject.print(F("UIPEthernetClass::upper_layer_chksum(uint8_t proto) DEBUG:uip_buf[")); + LogObject.uart_send_str(F("UIPEthernetClass::upper_layer_chksum(uint8_t proto) DEBUG:uip_buf[")); #else - LogObject.print(F("uip_tcpchksum(void) DEBUG:uip_buf[")); + LogObject.uart_send_str(F("uip_tcpchksum(void) DEBUG:uip_buf[")); #endif - LogObject.print(UIP_IPH_LEN + UIP_LLH_LEN); - LogObject.print(F("-")); - LogObject.print(UIP_IPH_LEN + UIP_LLH_LEN + upper_layer_memlen); - LogObject.print(F("]: ")); - LogObject.println(htons(sum),HEX); + LogObject.uart_send_dec(UIP_IPH_LEN + UIP_LLH_LEN); + LogObject.uart_send_str(F("-")); + LogObject.uart_send_dec(UIP_IPH_LEN + UIP_LLH_LEN + upper_layer_memlen); + LogObject.uart_send_str(F("]: ")); + LogObject.uart_send_hexln(htons(sum)); #endif if (upper_layer_memlen < upper_layer_len) { @@ -555,17 +561,17 @@ uip_tcpchksum(void) ); #if ACTLOGLEVEL>=LOG_DEBUG #if UIP_UDP - LogObject.print(F("UIPEthernetClass::upper_layer_chksum(uint8_t proto) DEBUG:uip_packet(")); + LogObject.uart_send_str(F("UIPEthernetClass::upper_layer_chksum(uint8_t proto) DEBUG:uip_packet(")); #else - LogObject.print(F("uip_tcpchksum(void) DEBUG:uip_packet(")); + LogObject.uart_send_str(F("uip_tcpchksum(void) DEBUG:uip_packet(")); #endif - LogObject.print(uip_packet); - LogObject.print(F(")[")); - LogObject.print(UIP_IPH_LEN + UIP_LLH_LEN + upper_layer_memlen); - LogObject.print(F("-")); - LogObject.print(UIP_IPH_LEN + UIP_LLH_LEN + upper_layer_len); - LogObject.print(F("]: ")); - LogObject.println(htons(sum),HEX); + LogObject.uart_send_dec(uip_packet); + LogObject.uart_send_str(F(")[")); + LogObject.uart_send_dec(UIP_IPH_LEN + UIP_LLH_LEN + upper_layer_memlen); + LogObject.uart_send_str(F("-")); + LogObject.uart_send_dec(UIP_IPH_LEN + UIP_LLH_LEN + upper_layer_len); + LogObject.uart_send_str(F("]: ")); + LogObject.uart_send_hexln(htons(sum)); #endif } return (sum == 0) ? 0xffff : htons(sum); diff --git a/UIPEthernet.h b/UIPEthernet.h index 928fb9c..ecbc640 100644 --- a/UIPEthernet.h +++ b/UIPEthernet.h @@ -21,9 +21,14 @@ #define UIPETHERNET_H #include "ethernet_comp.h" -#include +#if defined(__MBED__) + #include +#endif +#if defined(ARDUINO) + #include + #include "IPAddress.h" +#endif #include "Dhcp.h" -#include "IPAddress.h" #include "utility/Enc28J60Network.h" #include "UIPClient.h" #include "UIPServer.h" diff --git a/UIPServer.h b/UIPServer.h index 9b6da7d..31df41e 100644 --- a/UIPServer.h +++ b/UIPServer.h @@ -20,7 +20,12 @@ #define UIPSERVER_H #include "ethernet_comp.h" -#include "Server.h" +#if defined(ARDUINO) + #include "Server.h" +#endif +#if defined(__MBED__) + #include "mbed/Server.h" +#endif #include "UIPClient.h" class UIPServer : public Server { @@ -31,7 +36,9 @@ class UIPServer : public Server { void begin(); size_t write(uint8_t); size_t write(const uint8_t *buf, size_t size); - using Print::write; + #if defined(ARDUINO) + using Print::write; + #endif private: uint16_t _port; diff --git a/UIPUdp.cpp b/UIPUdp.cpp index 5eb88cc..c8ac503 100644 --- a/UIPUdp.cpp +++ b/UIPUdp.cpp @@ -33,7 +33,7 @@ extern "C" { #define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) // Constructor -UIPUDP::UIPUDP() : +UIPUDP::UIPUDP(void) : _uip_udp_conn(NULL) { memset(&appdata,0,sizeof(appdata)); @@ -44,7 +44,7 @@ uint8_t UIPUDP::begin(uint16_t port) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::begin(uint16_t port) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::begin(uint16_t port) DEBUG_V3:Function started")); #endif if (!_uip_udp_conn) { @@ -61,10 +61,10 @@ UIPUDP::begin(uint16_t port) // Finish with the UDP socket void -UIPUDP::stop() +UIPUDP::stop(void) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::stop() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::stop(void) DEBUG_V3:Function started")); #endif if (_uip_udp_conn) { @@ -86,7 +86,7 @@ int UIPUDP::beginPacket(IPAddress ip, uint16_t port) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::beginPacket(IPAddress ip, uint16_t port) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::beginPacket(IPAddress ip, uint16_t port) DEBUG_V3:Function started")); #endif UIPEthernetClass::tick(); if (ip && port) @@ -94,7 +94,7 @@ UIPUDP::beginPacket(IPAddress ip, uint16_t port) uip_ipaddr_t ripaddr; uip_ip_addr(&ripaddr, ip); #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("UIPUDP::beginPacket DEBUG:udp beginPacket, ")); + LogObject.uart_send_str(F("UIPUDP::beginPacket DEBUG:udp beginPacket, ")); #endif if (_uip_udp_conn) { @@ -107,23 +107,23 @@ UIPUDP::beginPacket(IPAddress ip, uint16_t port) if (_uip_udp_conn) { #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("new connection, ")); + LogObject.uart_send_str(F("new connection, ")); #endif _uip_udp_conn->appstate = &appdata; } else { #if ACTLOGLEVEL>=LOG_ERR - LogObject.println(F("\nUIPUDP::beginPacket ERROR:failed to allocate new connection")); + LogObject.uart_send_strln(F("\nUIPUDP::beginPacket ERROR:failed to allocate new connection")); #endif return 0; } } #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("rip: ")); - LogObject.print(ip); - LogObject.print(F(", port: ")); - LogObject.println(port); + LogObject.uart_send_str(F("rip: ")); + LogObject.uart_send_dec(ip); + LogObject.uart_send_str(F(", port: ")); + LogObject.uart_send_decln(port); #endif } if (_uip_udp_conn) @@ -136,12 +136,12 @@ UIPUDP::beginPacket(IPAddress ip, uint16_t port) return 1; #if ACTLOGLEVEL>=LOG_ERR else - LogObject.println(F("\nUIPUDP::beginPacket ERROR:Failed to allocate memory for packet")); + LogObject.uart_send_strln(F("\nUIPUDP::beginPacket ERROR:Failed to allocate memory for packet")); #endif } #if ACTLOGLEVEL>=LOG_WARNING else - LogObject.println(F("\nUIPUDP::beginPacket WARNING:Previous packet on that connection not sent yet")); + LogObject.uart_send_strln(F("\nUIPUDP::beginPacket WARNING:Previous packet on that connection not sent yet")); #endif } return 0; @@ -153,7 +153,7 @@ int UIPUDP::beginPacket(const char *host, uint16_t port) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::beginPacket(const char *host, uint16_t port) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::beginPacket(const char *host, uint16_t port) DEBUG_V3:Function started")); #endif // Look up the host first int ret = 0; @@ -172,10 +172,10 @@ UIPUDP::beginPacket(const char *host, uint16_t port) // Finish off this packet and send it // Returns 1 if the packet was sent successfully, 0 if there was an error int -UIPUDP::endPacket() +UIPUDP::endPacket(void) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::endPacket() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::endPacket(void) DEBUG_V3:Function started")); #endif if (_uip_udp_conn && appdata.packet_out != NOBLOCK) { @@ -184,7 +184,7 @@ UIPUDP::endPacket() uip_udp_periodic_conn(_uip_udp_conn); if (uip_len > 0) { - _send(&appdata); + _send(&appdata); return 1; } } @@ -196,7 +196,7 @@ size_t UIPUDP::write(uint8_t c) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::write(uint8_t c) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::write(uint8_t c) DEBUG_V3:Function started")); #endif return write(&c,1); } @@ -206,7 +206,7 @@ size_t UIPUDP::write(const uint8_t *buffer, size_t size) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::write(const uint8_t *buffer, size_t size) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::write(const uint8_t *buffer, size_t size) DEBUG_V3:Function started")); #endif if (appdata.packet_out != NOBLOCK) { @@ -220,17 +220,17 @@ UIPUDP::write(const uint8_t *buffer, size_t size) // Start processing the next available incoming packet // Returns the size of the packet in bytes, or 0 if no packets are available int -UIPUDP::parsePacket() +UIPUDP::parsePacket(void) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::parsePacket() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::parsePacket(void) DEBUG_V3:Function started")); #endif UIPEthernetClass::tick(); if (appdata.packet_in != NOBLOCK) { #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("UIPUDP::parsePacket() DEBUG:udp parsePacket freeing previous packet: ")); - LogObject.println(appdata.packet_in); + LogObject.uart_send_str(F("UIPUDP::parsePacket(void) DEBUG:udp parsePacket freeing previous packet: ")); + LogObject.uart_send_decln(appdata.packet_in); #endif Enc28J60Network::freeBlock(appdata.packet_in); } @@ -241,16 +241,16 @@ UIPUDP::parsePacket() #if ACTLOGLEVEL>=LOG_DEBUG if (appdata.packet_in != NOBLOCK) { - LogObject.print(F("UIPUDP::parsePacket() DEBUG:udp parsePacket received packet: ")); - LogObject.print(appdata.packet_in); + LogObject.uart_send_str(F("UIPUDP::parsePacket(void) DEBUG:udp parsePacket received packet: ")); + LogObject.uart_send_dec(appdata.packet_in); } #endif int size = Enc28J60Network::blockSize(appdata.packet_in); #if ACTLOGLEVEL>=LOG_DEBUG if (appdata.packet_in != NOBLOCK) { - LogObject.print(F(", size: ")); - LogObject.println(size); + LogObject.uart_send_str(F(", size: ")); + LogObject.uart_send_decln(size); } #endif return size; @@ -258,10 +258,10 @@ UIPUDP::parsePacket() // Number of bytes remaining in the current packet int -UIPUDP::available() +UIPUDP::available(void) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::available() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::available(void) DEBUG_V3:Function started")); #endif UIPEthernetClass::tick(); return Enc28J60Network::blockSize(appdata.packet_in); @@ -269,10 +269,10 @@ UIPUDP::available() // Read a single byte from the current packet int -UIPUDP::read() +UIPUDP::read(void) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::read() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::read(void) DEBUG_V3:Function started")); #endif unsigned char c; if (read(&c,1) > 0) @@ -288,12 +288,12 @@ int UIPUDP::read(unsigned char* buffer, size_t len) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::read(unsigned char* buffer, size_t len) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::read(unsigned char* buffer, size_t len) DEBUG_V3:Function started")); #endif UIPEthernetClass::tick(); if (appdata.packet_in != NOBLOCK) { - memaddress read = Enc28J60Network::readPacket(appdata.packet_in,0,buffer,len); + memaddress read = Enc28J60Network::readPacket(appdata.packet_in,0,(uint8_t*)buffer,(uint16_t)len); if (read == Enc28J60Network::blockSize(appdata.packet_in)) { Enc28J60Network::freeBlock(appdata.packet_in); @@ -308,16 +308,16 @@ UIPUDP::read(unsigned char* buffer, size_t len) // Return the next byte from the current packet without moving on to the next byte int -UIPUDP::peek() +UIPUDP::peek(void) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::peek() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::peek(void) DEBUG_V3:Function started")); #endif UIPEthernetClass::tick(); if (appdata.packet_in != NOBLOCK) { unsigned char c; - if (Enc28J60Network::readPacket(appdata.packet_in,0,&c,1) == 1) + if (Enc28J60Network::readPacket(appdata.packet_in,0,(uint8_t*)&c,1) == 1) return c; } return -1; @@ -325,10 +325,10 @@ UIPUDP::peek() // Finish reading the current packet void -UIPUDP::flush() +UIPUDP::flush(void) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::flush() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::flush(void) DEBUG_V3:Function started")); #endif UIPEthernetClass::tick(); Enc28J60Network::freeBlock(appdata.packet_in); @@ -337,20 +337,20 @@ UIPUDP::flush() // Return the IP address of the host who sent the current incoming packet IPAddress -UIPUDP::remoteIP() +UIPUDP::remoteIP(void) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::remoteIP() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::remoteIP(void) DEBUG_V3:Function started")); #endif return _uip_udp_conn ? ip_addr_uip(_uip_udp_conn->ripaddr) : IPAddress(); } // Return the port of the host who sent the current incoming packet uint16_t -UIPUDP::remotePort() +UIPUDP::remotePort(void) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::remotePort() DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::remotePort(void) DEBUG_V3:Function started")); #endif return _uip_udp_conn ? ntohs(_uip_udp_conn->rport) : 0; } @@ -360,7 +360,7 @@ UIPUDP::remotePort() void uipudp_appcall(void) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("uipudp_appcall(void) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("uipudp_appcall(void) DEBUG_V3:Function started")); #endif if (uip_udp_userdata_t *data = (uip_udp_userdata_t *)(uip_udp_conn->appstate)) { @@ -377,10 +377,10 @@ uipudp_appcall(void) { //discard Linklevel and IP and udp-header and any trailing bytes: Enc28J60Network::copyPacket(data->packet_next,0,UIPEthernetClass::in_packet,UIP_UDP_PHYH_LEN,Enc28J60Network::blockSize(data->packet_next)); #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("uipudp_appcall(void) DEBUG:udp, uip_newdata received packet: ")); - LogObject.print(data->packet_next); - LogObject.print(F(", size: ")); - LogObject.println(Enc28J60Network::blockSize(data->packet_next)); + LogObject.uart_send_str(F("uipudp_appcall(void) DEBUG:udp, uip_newdata received packet: ")); + LogObject.uart_send_dec(data->packet_next); + LogObject.uart_send_str(F(", size: ")); + LogObject.uart_send_decln(Enc28J60Network::blockSize(data->packet_next)); #endif } } @@ -389,10 +389,10 @@ uipudp_appcall(void) { { //set uip_slen (uip private) by calling uip_udp_send #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("uipudp_appcall(void) DEBUG:udp, uip_poll preparing packet to send: ")); - LogObject.print(data->packet_out); - LogObject.print(F(", size: ")); - LogObject.println(Enc28J60Network::blockSize(data->packet_out)); + LogObject.uart_send_str(F("uipudp_appcall(void) DEBUG:udp, uip_poll preparing packet to send: ")); + LogObject.uart_send_dec(data->packet_out); + LogObject.uart_send_str(F(", size: ")); + LogObject.uart_send_decln(Enc28J60Network::blockSize(data->packet_out)); #endif UIPEthernetClass::uip_packet = data->packet_out; UIPEthernetClass::uip_hdrlen = UIP_UDP_PHYH_LEN; @@ -404,7 +404,7 @@ uipudp_appcall(void) { void UIPUDP::_send(uip_udp_userdata_t *data) { #if ACTLOGLEVEL>=LOG_DEBUG_V3 - LogObject.println(F("UIPUDP::_send(uip_udp_userdata_t *data) DEBUG_V3:Function started")); + LogObject.uart_send_strln(F("UIPUDP::_send(uip_udp_userdata_t *data) DEBUG_V3:Function started")); #endif uip_arp_out(); //add arp if (uip_len == UIP_ARPHDRSIZE) @@ -412,7 +412,7 @@ UIPUDP::_send(uip_udp_userdata_t *data) { UIPEthernetClass::uip_packet = NOBLOCK; UIPEthernetClass::packetstate &= ~UIPETHERNET_SENDPACKET; #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.println(F("UIPUDP::_send() DEBUG:udp, uip_poll results in ARP-packet")); + LogObject.uart_send_strln(F("UIPUDP::_send() DEBUG:udp, uip_poll results in ARP-packet")); #endif } else @@ -422,8 +422,8 @@ UIPUDP::_send(uip_udp_userdata_t *data) { data->packet_out = NOBLOCK; UIPEthernetClass::packetstate |= UIPETHERNET_SENDPACKET; #if ACTLOGLEVEL>=LOG_DEBUG - LogObject.print(F("UIPUDP::_send() DEBUG:udp, uip_packet to send: ")); - LogObject.println(UIPEthernetClass::uip_packet); + LogObject.uart_send_str(F("UIPUDP::_send() DEBUG:udp, uip_packet to send: ")); + LogObject.uart_send_decln(UIPEthernetClass::uip_packet); #endif } UIPEthernetClass::network_send(); diff --git a/UIPUdp.h b/UIPUdp.h index 93118b0..02db2ba 100644 --- a/UIPUdp.h +++ b/UIPUdp.h @@ -1,5 +1,5 @@ /* - UIPUdp.h - Arduino implementation of a uIP wrapper class. + UIPUdp.h - Arduino implementation of a uIP wrapper class Copyright (c) 2013 Norbert Truchsess All rights reserved. @@ -21,8 +21,14 @@ #define UIPUDP_H #include "ethernet_comp.h" -#include "Arduino.h" -#include +#if defined(__MBED__) + #include + #include "mbed/Udp.h" +#endif +#if defined(ARDUINO) + #include + #include +#endif #include "utility/mempool.h" extern "C" { #include "utility/uip.h" @@ -49,11 +55,11 @@ class UIPUDP : public UDP uip_udp_userdata_t appdata; public: - UIPUDP(); // Constructor + UIPUDP(void); // Constructor uint8_t begin(uint16_t);// initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use void - stop(); // Finish with the UDP socket + stop(void); // Finish with the UDP socket // Sending UDP packets @@ -68,7 +74,7 @@ class UIPUDP : public UDP // Finish off this packet and send it // Returns 1 if the packet was sent successfully, 0 if there was an error int - endPacket(); + endPacket(void); // Write a single byte into the packet size_t write(uint8_t); @@ -76,18 +82,19 @@ class UIPUDP : public UDP size_t write(const uint8_t *buffer, size_t size); - using Print::write; - + #if defined(ARDUINO) + using Print::write; + #endif // Start processing the next available incoming packet // Returns the size of the packet in bytes, or 0 if no packets are available int - parsePacket(); + parsePacket(void); // Number of bytes remaining in the current packet int - available(); + available(void); // Read a single byte from the current packet int - read(); + read(void); // Read up to len bytes from the current packet and place them into buffer // Returns the number of bytes read, or 0 if none are available int @@ -102,17 +109,17 @@ class UIPUDP : public UDP ; // Return the next byte from the current packet without moving on to the next byte int - peek(); + peek(void); void - flush(); // Finish reading the current packet + flush(void); // Finish reading the current packet // Return the IP address of the host who sent the current incoming packet IPAddress - remoteIP(); + remoteIP(void); // Return the port of the host who sent the current incoming packet uint16_t - remotePort(); + remotePort(void); private: