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 4:e17cc31660ad, committed 2017-02-28
- Comitter:
- Eric Matte
- Date:
- Tue Feb 28 21:37:11 2017 -0500
- Parent:
- 3:664dfa189c79
- Child:
- 5:0a7810520b9e
- Commit message:
- Added Ethernet to library.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/include/EthernetInterface.hpp Tue Feb 28 21:37:11 2017 -0500
@@ -0,0 +1,27 @@
+/**
+@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() {}
+};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/include/EthernetMagJack.hpp Tue Feb 28 21:37:11 2017 -0500
@@ -0,0 +1,38 @@
+/**
+@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/source/EthernetMagJack.cpp Tue Feb 28 21:37:11 2017 -0500
@@ -0,0 +1,34 @@
+/**
+@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