Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of cc3000_hostdriver_mbedsocket by
Revision 17:14b6a3a2b622, committed 2013-10-02
- Comitter:
- Kojto
- Date:
- Wed Oct 02 20:29:31 2013 +0200
- Parent:
- 16:f3676ae62f96
- Child:
- 18:7e22775eadb9
- Commit message:
- Hci print internal, Endpoint - unix ending lines
- hci internal print function
- endpoint correction with ending lines (was PC)
Changed in this revision
--- a/Socket/Endpoint.cpp Wed Oct 02 16:00:41 2013 +0000
+++ b/Socket/Endpoint.cpp Wed Oct 02 20:29:31 2013 +0200
@@ -1,132 +1,132 @@
-/* Copyright (C) 2013 mbed.org, MIT License
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-#include "Socket/Socket.h"
-#include "Socket/Endpoint.h"
-#include "Helper/def.h"
-#include <cstring>
-
- #include "cc3000.h"
-
-/* Copied from lwip */
-static char *inet_ntoa_r(const in_addr addr, char *buf, int buflen)
-{
- uint32_t s_addr;
- char inv[3];
- char *rp;
- uint8_t *ap;
- uint8_t rem;
- uint8_t n;
- uint8_t i;
- int len = 0;
-
- s_addr = addr.s_addr;
-
- rp = buf;
- ap = (uint8_t *)&s_addr;
- for(n = 0; n < 4; n++) {
- i = 0;
- do {
- rem = *ap % (uint8_t)10;
- *ap /= (uint8_t)10;
- inv[i++] = '0' + rem;
- } while(*ap);
- while(i--) {
- if (len++ >= buflen) {
- return NULL;
- }
- *rp++ = inv[i];
- }
- if (len++ >= buflen) {
- return NULL;
- }
- *rp++ = '.';
- ap++;
- }
- *--rp = 0;
- return buf;
-}
-
-Endpoint::Endpoint() {
- _cc3000_module = cc3000::get_instance();
- if (_cc3000_module == NULL) {
- error("Endpoint constructor error: no cc3000 instance available!\r\n");
- }
- reset_address();
-}
-Endpoint::~Endpoint() {}
-
-void Endpoint::reset_address(void) {
- _ipAddress[0] = '\0';
- std::memset(&_remote_host, 0, sizeof(sockaddr_in));
-}
-
-int Endpoint::set_address(const char* host, const int port) {
- reset_address();
-
- char address[5];
- char *p_address = address;
-
- signed int add[5];
-
- // Dot-decimal notation
- int result = std::sscanf(host, "%3u.%3u.%3u.%3u", &add[0], &add[1], &add[2], &add[3]);
- for (int i=0;i<4;i++) {
- address[i] = add[i];
- }
- std::memset(_ipAddress,0,sizeof(_ipAddress));
-
- if (result != 4) {
- //Resolve DNS address or populate hard-coded IP address
- uint32_t address_integer;
- _cc3000_module->_socket.gethostbyname((uint8_t *)host, strlen(host) , &address_integer);
-
- uint32_t ip = 0;
- ip = (ip | (address_integer >> 24));
- ip = (ip | ((address_integer & 0x00FF0000) >> 8));
- ip = (ip | ((address_integer & 0x0000FF00) << 8));
- ip = (ip | ((address_integer & 0x000000FF) << 24));
- _remote_host.sin_addr.s_addr = ip;
- inet_ntoa_r(_remote_host.sin_addr, _ipAddress, sizeof(_ipAddress));
- } else {
- std::memcpy((char*)&_remote_host.sin_addr.s_addr, p_address, 4);
- }
-
- _remote_host.sin_family = AF_INET;
- _remote_host.sin_port = htons(port);
-
- DBG_SOCKET("remote host address (string): %s",get_address());
- DBG_SOCKET("remote host address from s_addr : %d.%d.%d.%d",
- 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));
- DBG_SOCKET("port: %d", port);
-
- return 0;
-}
-
-char* Endpoint::get_address() {
- if ((_ipAddress[0] == '\0') && (_remote_host.sin_addr.s_addr != 0))
- inet_ntoa_r(_remote_host.sin_addr, _ipAddress, sizeof(_ipAddress));
- return _ipAddress;
-}
-
-
-int Endpoint::get_port() {
- return ntohs(_remote_host.sin_port);
-}
+/* Copyright (C) 2013 mbed.org, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include "Socket/Socket.h"
+#include "Socket/Endpoint.h"
+#include "Helper/def.h"
+#include <cstring>
+
+ #include "cc3000.h"
+
+/* Copied from lwip */
+static char *inet_ntoa_r(const in_addr addr, char *buf, int buflen)
+{
+ uint32_t s_addr;
+ char inv[3];
+ char *rp;
+ uint8_t *ap;
+ uint8_t rem;
+ uint8_t n;
+ uint8_t i;
+ int len = 0;
+
+ s_addr = addr.s_addr;
+
+ rp = buf;
+ ap = (uint8_t *)&s_addr;
+ for(n = 0; n < 4; n++) {
+ i = 0;
+ do {
+ rem = *ap % (uint8_t)10;
+ *ap /= (uint8_t)10;
+ inv[i++] = '0' + rem;
+ } while(*ap);
+ while(i--) {
+ if (len++ >= buflen) {
+ return NULL;
+ }
+ *rp++ = inv[i];
+ }
+ if (len++ >= buflen) {
+ return NULL;
+ }
+ *rp++ = '.';
+ ap++;
+ }
+ *--rp = 0;
+ return buf;
+}
+
+Endpoint::Endpoint() {
+ _cc3000_module = cc3000::get_instance();
+ if (_cc3000_module == NULL) {
+ error("Endpoint constructor error: no cc3000 instance available!\r\n");
+ }
+ reset_address();
+}
+Endpoint::~Endpoint() {}
+
+void Endpoint::reset_address(void) {
+ _ipAddress[0] = '\0';
+ std::memset(&_remote_host, 0, sizeof(sockaddr_in));
+}
+
+int Endpoint::set_address(const char* host, const int port) {
+ reset_address();
+
+ char address[5];
+ char *p_address = address;
+
+ signed int add[5];
+
+ // Dot-decimal notation
+ int result = std::sscanf(host, "%3u.%3u.%3u.%3u", &add[0], &add[1], &add[2], &add[3]);
+ for (int i=0;i<4;i++) {
+ address[i] = add[i];
+ }
+ std::memset(_ipAddress,0,sizeof(_ipAddress));
+
+ if (result != 4) {
+ //Resolve DNS address or populate hard-coded IP address
+ uint32_t address_integer;
+ _cc3000_module->_socket.gethostbyname((uint8_t *)host, strlen(host) , &address_integer);
+
+ uint32_t ip = 0;
+ ip = (ip | (address_integer >> 24));
+ ip = (ip | ((address_integer & 0x00FF0000) >> 8));
+ ip = (ip | ((address_integer & 0x0000FF00) << 8));
+ ip = (ip | ((address_integer & 0x000000FF) << 24));
+ _remote_host.sin_addr.s_addr = ip;
+ inet_ntoa_r(_remote_host.sin_addr, _ipAddress, sizeof(_ipAddress));
+ } else {
+ std::memcpy((char*)&_remote_host.sin_addr.s_addr, p_address, 4);
+ }
+
+ _remote_host.sin_family = AF_INET;
+ _remote_host.sin_port = htons(port);
+
+ DBG_SOCKET("remote host address (string): %s",get_address());
+ DBG_SOCKET("remote host address from s_addr : %d.%d.%d.%d",
+ 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));
+ DBG_SOCKET("port: %d", port);
+
+ return 0;
+}
+
+char* Endpoint::get_address() {
+ if ((_ipAddress[0] == '\0') && (_remote_host.sin_addr.s_addr != 0))
+ inet_ntoa_r(_remote_host.sin_addr, _ipAddress, sizeof(_ipAddress));
+ return _ipAddress;
+}
+
+
+int Endpoint::get_port() {
+ return ntohs(_remote_host.sin_port);
+}
--- a/Socket/Socket.cpp Wed Oct 02 16:00:41 2013 +0000
+++ b/Socket/Socket.cpp Wed Oct 02 20:29:31 2013 +0200
@@ -71,7 +71,7 @@
int ret = _cc3000_module->_socket.select(_sock_fd+1, readset, writeset, NULL, timeout);
- DBG_SOCKET("Select on sock_fd: %d, returns %d. fdSet: %d", _sock_fd, ret, fdSet);
+ DBG_SOCKET("Select on sock_fd: %d, returns %d. fdSet: %d", _sock_fd, ret, FD_ISSET(_sock_fd, &fdSet));
// TODO
//return (ret <= 0 || !FD_ISSET(_sock_fd, &fdSet)) ? (-1) : (0);
--- a/cc3000.h Wed Oct 02 16:00:41 2013 +0000
+++ b/cc3000.h Wed Oct 02 20:29:31 2013 +0200
@@ -58,15 +58,15 @@
#if CC3000_DEBUG == 1
// DBG_SOCKET, mbed socket specific debug messages
- #define DBG_SOCKET(x, ...) std::printf("[CC3000 : SOCKET] "x"\r\n", ##__VA_ARGS__);
-
+ #define DBG_SOCKET(x, ...) std::printf("[CC3000 : SOCKET] "x"\r\n", ##__VA_ARGS__);
+
// DBG_HCI, prints a message for every recieved HCI event, quite a lot of debug
- #define DBG_HCI(x, ...) std::printf("[CC3000 : HCI] "x"\r\n", ##__VA_ARGS__);
-
+ #define DBG_HCI(x, ...) std::printf("[CC3000 : HCI] "x"\r\n", ##__VA_ARGS__);
+
// DBG_CC, General cc3000 debug messages
- #define DBG_CC(x, ...) std::printf("[CC3000] "x"\r\n", ##__VA_ARGS__);
+ #define DBG_CC(x, ...) std::printf("[CC3000] "x"\r\n", ##__VA_ARGS__);
#else
- #define DBG_SOCKET(x, ...)
+ #define DBG_SOCKET(x, ...)
#define DBG_HCI(x, ...)
#define DBG_CC(x, ...)
#endif
@@ -216,7 +216,6 @@
~cc3000_event();
void hci_unsol_handle_patch_request(uint8_t *event_hdr);
- void hci_event_debug_print ( uint16_t hciEventNo );
uint8_t *hci_event_handler(void *ret_param, uint8_t *from, uint8_t *fromlen);
int32_t hci_unsol_event_handler(uint8_t *event_hdr);
int32_t hci_unsolicited_event_handler(void);
--- a/cc3000_event.cpp Wed Oct 02 16:00:41 2013 +0000
+++ b/cc3000_event.cpp Wed Oct 02 20:29:31 2013 +0200
@@ -176,10 +176,10 @@
}
}
-void cc3000_event::hci_event_debug_print ( uint16_t hciEventNo )
+static void hci_event_debug_print(uint16_t hciEventNo)
{
#if CC3000_DEBUG == 1
- if (( hciEventNo > HCI_CMND_SOCKET_BASE) && ( hciEventNo <= HCI_CMND_MDNS_ADVERTISE))
+ if ((hciEventNo > HCI_CMND_SOCKET_BASE) && ( hciEventNo <= HCI_CMND_MDNS_ADVERTISE))
{
DBG_HCI("Event Received : 0x%04X - %s", hciEventNo, HCI_EVENT_STR[hciEventNo-HCI_CMND_SOCKET]);
}
@@ -226,7 +226,7 @@
STREAM_TO_UINT8(received_data, HCI_DATA_LENGTH_OFFSET, length);
hci_event_debug_print( received_op_code );
-
+
switch(received_op_code)
{
case HCI_CMND_READ_BUFFER_SIZE:
