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.
Dependents: NerfUS_cmake_add_library_from_mbed NerfUS NerfUSGameCoordinator
Revision 5:0a7810520b9e, committed 2017-03-01
- Comitter:
- ericmatte
- Date:
- Wed Mar 01 03:53:01 2017 +0000
- Parent:
- 4:e17cc31660ad
- Commit message:
- Working Ethernet communication.
Changed in this revision
--- a/include/EthernetInterface.hpp Tue Feb 28 21:37:11 2017 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/**
-@file EthernetInterface.hpp
-
-@brief Allow communication with a server using a specific websocket.
-
-@poject NerfUS, Team P5
-*/
-class EthernetInterface
-{
- /**
- * Allow to send a buffer of information to the server
- *
- * @param buffer The data to send
- * @returns the number of bytes sent
- */
- virtual int send(char *buffer) = 0;
-
- /**
- * Blocking method to get message back from the server
- *
- * @param buffer Must be a pointer to the buffer to write the message
- * @return true if a websocket frame has been read
- */
- virtual bool onMessage(char *buffer) = 0;
-
- virtual ~EthernetInterface() {}
-};
--- a/include/EthernetMagJack.hpp Tue Feb 28 21:37:11 2017 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-/**
-@file EthernetMagJack.hpp
-
-@brief Allow communication with a server using a specific websocket.
-
-@poject NerfUS, Team P5
-*/
-#ifndef ETHERNET_MAGJACK
-#define ETHERNET_MAGJACK
-
-#include "EthernetInterface.hpp"
-#include "mbed.h"
-#include "EthernetInterface.h"
-#include "Websocket.h"
-
-#define WS_BUFFER_SIZE 32
-
-class EthernetMagJack : public EthernetInterface
-{
- public:
- /**
- * Initialize the communication interface
- *
- * @param url The url to the websocket server (eg. "ws://192.168.137.1:8000/")
- */
- EthernetMagJack(char *url);
-
- // From the interface
- void send(char *buffer);
- void onMessage(char *buffer);
- ~EthernetInterface();
-
- private:
- EthernetInterface eth;
- Websocket ws;
-};
-
-#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/include/WSRequest.hpp Wed Mar 01 03:53:01 2017 +0000
@@ -0,0 +1,38 @@
+/**
+@file WSRequest.hpp
+
+@brief Allow communication with a server using a specific websocket.
+
+@poject NerfUS, Team P5
+*/
+#ifndef ETHERNET_MAGJACK
+#define ETHERNET_MAGJACK
+
+#include "WSRequestInterface.hpp"
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "Websocket.h"
+
+#define WS_BUFFER_SIZE 32
+
+class WSRequest : public WSRequestInterface
+{
+ public:
+ /**
+ * Initialize the communication interface
+ *
+ * @param url The url to the websocket server (eg. "ws://192.168.137.1:8000/")
+ */
+ WSRequest(char *url);
+
+ // From the interface
+ virtual int send(char *buffer);
+ virtual bool onMessage(char *buffer);
+ ~WSRequest();
+
+ private:
+ EthernetInterface eth;
+ Websocket ws;
+};
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/include/WSRequestInterface.hpp Wed Mar 01 03:53:01 2017 +0000
@@ -0,0 +1,25 @@
+/**
+@file WSRequestInterface.hpp
+
+@brief Allow communication with a server using a specific websocket.
+
+@poject NerfUS, Team P5
+*/
+class WSRequestInterface
+{
+ /**
+ * Allow to send a buffer of information to the server
+ *
+ * @param buffer The data to send
+ * @returns the number of bytes sent
+ */
+ virtual int send(char *buffer) = 0;
+
+ /**
+ * Blocking method to get message back from the server
+ *
+ * @param buffer Must be a pointer to the buffer to write the message
+ * @return true if a websocket frame has been read
+ */
+ virtual bool onMessage(char *buffer) = 0;
+};
--- a/source/EthernetMagJack.cpp Tue Feb 28 21:37:11 2017 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-/**
-@file EthernetMagJack.cpp
-
-@brief Allow communication with a server using a specific websocket.
-
-@poject NerfUS, Team P5
-*/
-#include "EthernetMagJack.hpp"
-
-
-EthernetMagJack::EthernetMagJack(char *url) : ws(url)
-{
- eth.init(); //Use DHCP
- eth.connect();
- printf("IP Address is %s\n\r", eth.getIPAddress());
-
- ws.connect();
-}
-
-void EthernetMagJack::send(char *buffer)
-{
- return ws.send(buffer);
-}
-
-void EthernetMagJack::onMessage(char *buffer)
-{
- return ws.read(buffer);
-}
-
-EthernetMagJack::~EthernetInterface()
-{
- ws.close();
- eth.disconnect();
-}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/WSRequest.cpp Wed Mar 01 03:53:01 2017 +0000
@@ -0,0 +1,38 @@
+/**
+@file WSRequest.cpp
+
+@brief Allow communication with a server using a specific websocket.
+
+@poject NerfUS, Team P5
+*/
+#include "WSRequest.hpp"
+
+
+WSRequest::WSRequest(char *url) : ws(url)
+{
+ eth.init(); //Use DHCP
+ eth.connect();
+ printf("IP Address is %s\n\r", eth.getIPAddress());
+
+ ws.connect();
+}
+
+int WSRequest::send(char *buffer)
+{
+ return ws.send(buffer);
+}
+
+bool WSRequest::onMessage(char *buffer)
+{
+ while (!ws.read(buffer))
+ {
+ wait(0.1);
+ }
+ return true;
+}
+
+WSRequest::~WSRequest()
+{
+ ws.close();
+ eth.disconnect();
+}
\ No newline at end of file