Socket interface for C027Interface. Implements the NetworkSocketAPI

Dependencies:   C027_Support

Dependents:   HelloC027Interface U_Blox_DeviceConnector U_Blox_DeviceConnector U-Blox_Client

Fork of LWIPInterface by NetworkSocketAPI

Revision:
15:21d4f56eb172
Parent:
14:3d1845f5cd81
Child:
16:eaf31bd133f0
--- a/C027Interface.cpp	Thu Apr 21 06:53:31 2016 -0500
+++ b/C027Interface.cpp	Tue Apr 26 20:34:29 2016 +0000
@@ -18,11 +18,6 @@
 #include "mbed.h"
 
 
-static void ipToString(MDMParser::IP ip, char *buffer) {
-    sprintf(buffer, IPSTR, IPNUM(ip));
-}
-
-
 // C027Interface implementation
 C027Interface::C027Interface(const char *simpin, bool debug)
     : _debug(debug)
@@ -59,7 +54,7 @@
     if (mdmOk) {
         // join the internet connection 
         MDMParser::IP ip = _mdm->join(apn, username, password);
-        ipToString(ip, _ip_address);
+        _ip_address.set_ip_bytes(&ip, NSAPI_IPv4);
         mdmOk = (ip != NOIP);
     }
     
@@ -77,7 +72,7 @@
 
 const char *C027Interface::get_ip_address()
 {
-    return _ip_address;
+    return _ip_address.get_ip_address();
 }
 
 const char *C027Interface::get_mac_address()
@@ -178,10 +173,10 @@
 {
     struct c027_socket *socket = (struct c027_socket *)handle;
 
-    MDMParser::IP ip = _mdm->gethostbyname(addr.get_ip_address());
-    uint16_t port = addr.get_port();
-
-    int sent = _mdm->socketSendTo(socket->socket, ip, port, (const char *)data, size);
+    int sent = _mdm->socketSendTo(socket->socket,
+            *(MDMParser::IP *)addr.get_ip_bytes(), addr.get_port(),
+            (const char *)data, size);
+            
     if (sent == SOCKET_ERROR) {
         return NSAPI_ERROR_DEVICE_ERROR;
     }
@@ -205,9 +200,7 @@
     }
 
     if (addr) {
-        char buffer[NSAPI_IP_SIZE];
-        ipToString(ip, buffer);
-        addr->set_ip_address(buffer);
+        addr->set_ip_bytes(&ip, NSAPI_IPv4);
         addr->set_port(port);
     }