cc3000 hostdriver with the mbed socket interface

Dependents:   cc3000_hello_world_demo cc3000_simple_socket_demo cc3000_ntp_demo cc3000_ping_demo ... more

Files at this revision

API Documentation at this revision

Comitter:
SolderSplashLabs
Date:
Tue Oct 01 21:17:44 2013 +0000
Parent:
10:7069c5f1e6f4
Child:
12:1c2a856c618a
Child:
13:5e36c267e62f
Commit message:
Added \r\n to all debug messages; Fixed debug message displaying the port no incorrectly

Changed in this revision

Socket/Endpoint.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/Socket.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketConnection.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/UDPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
cc3000.cpp Show annotated file Show diff for this revision Revisions of this file
cc3000.h Show annotated file Show diff for this revision Revisions of this file
cc3000_socket.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Socket/Endpoint.cpp	Tue Oct 01 04:41:47 2013 +0000
+++ b/Socket/Endpoint.cpp	Tue Oct 01 21:17:44 2013 +0000
@@ -110,13 +110,13 @@
     _remote_host.sin_port = htons(port);
 
 #if (CC3000_DEBUG == 1)
-    printf("DEBUG: remote host address (string): %s\n",get_address());
-    printf("DEBUG: remote host address from s_addr : %d.%d.%d.%d\n",
+    printf("DEBUG: remote host address (string): %s\r\n",get_address());
+    printf("DEBUG: remote host address from s_addr : %d.%d.%d.%d\r\n",
             int(_remote_host.sin_addr.s_addr & 0xFF),
             int((_remote_host.sin_addr.s_addr & 0xFF00) >> 8),
             int((_remote_host.sin_addr.s_addr & 0xFF0000) >> 16),
             int((_remote_host.sin_addr.s_addr & 0xFF000000) >> 24));
-    printf("DEBUG: port: %x \n", _remote_host.sin_port);
+   printf("DEBUG: port: %d \r\n", port);
 #endif
     return 0;
 }
--- a/Socket/Socket.cpp	Tue Oct 01 04:41:47 2013 +0000
+++ b/Socket/Socket.cpp	Tue Oct 01 21:17:44 2013 +0000
@@ -29,7 +29,7 @@
 int Socket::init_socket(int type, int protocol) {
     if (_sock_fd != -1) {
 #if (CC3000_DEBUG == 1)
-        printf("DEBUG: Socket was initialized previously.\n");
+        printf("DEBUG: Socket was initialized previously.\r\n");
 #endif
         return -1;
     }
@@ -37,12 +37,12 @@
     int fd = _cc3000_module->_socket.socket(AF_INET, type, protocol);
     if (fd < -1) {
 #if (CC3000_DEBUG == 1)
-        printf("DEBUG: Failed to create new socket (type: %d, protocol: %d).\n",type, protocol);
+        printf("DEBUG: Failed to create new socket (type: %d, protocol: %d).\r\n",type, protocol);
 #endif
         return -1;
     }
 #if (CC3000_DEBUG == 1)
-        printf("DEBUG: Socket created (fd: %d type: %d, protocol: %d).\n",fd, type, protocol);
+        printf("DEBUG: Socket created (fd: %d type: %d, protocol: %d).\r\n",fd, type, protocol);
 #endif
     _sock_fd = fd;
 
@@ -76,7 +76,7 @@
 
     int ret = _cc3000_module->_socket.select(_sock_fd+1, readset, writeset, NULL, timeout);
 #if (CC3000_DEBUG == 1)
-    printf("DEBUG: Select on sock_fd: %d, returns %d. fdSet: %d\n",_sock_fd, ret, fdSet);
+    printf("DEBUG: Select on sock_fd: %d, returns %d. fdSet: %d\r\n",_sock_fd, ret, fdSet);
 #endif
     // TODO
     //return (ret <= 0 || !FD_ISSET(_sock_fd, &fdSet)) ? (-1) : (0);
--- a/Socket/TCPSocketConnection.cpp	Tue Oct 01 04:41:47 2013 +0000
+++ b/Socket/TCPSocketConnection.cpp	Tue Oct 01 21:17:44 2013 +0000
@@ -29,21 +29,21 @@
 int TCPSocketConnection::connect(const char *host, const int port) {
     if (init_socket(SOCK_STREAM, IPPROTO_TCP) < 0) {
 #if (CC3000_DEBUG == 1)
-        printf("DEBUG: Failed to create tcp socket.\n");
+        printf("DEBUG: Failed to create tcp socket.\r\n");
 #endif
         return -1;
     }
 
     if (set_address(host, port) != 0) {
 #if (CC3000_DEBUG == 1)
-        printf("DEBUG: Failed to set address (tcp).\n");
+        printf("DEBUG: Failed to set address (tcp).\r\n");
 #endif
         return -1;
     }
 
     if (_cc3000_module->_socket.connect(_sock_fd, (const sockaddr *)&_remote_host, sizeof(_remote_host)) < 0) {
 #if (CC3000_DEBUG == 1)
-        printf("DEBUG: Failed to connect (tcp).\n");
+        printf("DEBUG: Failed to connect (tcp).\r\n");
 #endif
         close();
         return -1;
--- a/Socket/UDPSocket.cpp	Tue Oct 01 04:41:47 2013 +0000
+++ b/Socket/UDPSocket.cpp	Tue Oct 01 21:17:44 2013 +0000
@@ -43,7 +43,7 @@
 
     if (_cc3000_module->_socket.bind(_sock_fd, (sockaddr *)&localHost, sizeof(sockaddr_in)) != 0) {
 #if (CC3000_DEBUG == 1)
-        printf("DEBUG: Failed to bind a socket (udp). Closing socket.\n");
+        printf("DEBUG: Failed to bind a socket (udp). Closing socket.\r\n");
 #endif
         _cc3000_module->_socket.closesocket(_sock_fd);
         _sock_fd = -1;
@@ -82,7 +82,7 @@
         TimeInterval timeout(_timeout);
         if (wait_readable(timeout) != 0) {
 #if (CC3000_DEBUG == 1)
-            printf("DEBUG: The socket is not readable. _sock_fd: %d.\n", _sock_fd);
+            printf("DEBUG: The socket is not readable. _sock_fd: %d.\r\n", _sock_fd);
 #endif
             return 0;
         }
--- a/cc3000.cpp	Tue Oct 01 04:41:47 2013 +0000
+++ b/cc3000.cpp	Tue Oct 01 21:17:44 2013 +0000
@@ -417,11 +417,11 @@
 
     /* known issue of cc3000 - sent number is send + received */
 #if (CC3000_DEBUG == 1)
-    printf("DEBUG: Sent: %d \n",_ping_report.packets_sent);
-    printf("DEBUG: Received: %d \n",_ping_report.packets_received);
-    printf("DEBUG: Min time: %d \n",_ping_report.min_round_time);
-    printf("DEBUG: Max time: %d \n",_ping_report.max_round_time);
-    printf("DEBUG: Avg time: %d \n",_ping_report.avg_round_time);
+    printf("DEBUG: Sent: %d \r\n",_ping_report.packets_sent);
+    printf("DEBUG: Received: %d \r\n",_ping_report.packets_received);
+    printf("DEBUG: Min time: %d \r\n",_ping_report.min_round_time);
+    printf("DEBUG: Max time: %d \r\n",_ping_report.max_round_time);
+    printf("DEBUG: Avg time: %d \r\n",_ping_report.avg_round_time);
 #endif
 
     return _ping_report.packets_received;
--- a/cc3000.h	Tue Oct 01 04:41:47 2013 +0000
+++ b/cc3000.h	Tue Oct 01 21:17:44 2013 +0000
@@ -267,6 +267,7 @@
     int32_t bind(int32_t sd, const sockaddr *addr, int32_t addrlen);
     int32_t listen(int32_t sd, int32_t backlog);
 #ifndef CC3000_TINY_DRIVER
+    int32_t gethostbyname(uint8_t * hostname, uint16_t name_length, uint32_t* out_ip_addr);
     int32_t get_host_by_name(uint8_t * hostname, uint16_t name_length, uint32_t* out_ip_addr);
     int32_t set_sockopt(int32_t sd, int32_t level, int32_t optname, const void *optval, socklen_t optlen);
 #endif
--- a/cc3000_socket.cpp	Tue Oct 01 04:41:47 2013 +0000
+++ b/cc3000_socket.cpp	Tue Oct 01 21:17:44 2013 +0000
@@ -534,6 +534,11 @@
 
 
 #ifndef CC3000_TINY_DRIVER
+
+int32_t cc3000_socket::gethostbyname(uint8_t *hostname, uint16_t name_length, uint32_t *out_ip_addr) {
+    get_host_by_name(hostname, name_length, out_ip_addr);
+}
+
 int32_t cc3000_socket::get_host_by_name(uint8_t *hostname, uint16_t name_length, uint32_t *out_ip_addr) {
     tBsdGethostbynameParams ret;
     uint8_t *ptr, *args;