NerfUS / HardwareInterface

Dependents:   NerfUS_cmake_add_library_from_mbed NerfUS NerfUSGameCoordinator

Committer:
Eric Matte
Date:
Tue Feb 28 21:37:11 2017 -0500
Revision:
4:e17cc31660ad
Added Ethernet to library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Eric Matte 4:e17cc31660ad 1 /**
Eric Matte 4:e17cc31660ad 2 @file EthernetMagJack.cpp
Eric Matte 4:e17cc31660ad 3
Eric Matte 4:e17cc31660ad 4 @brief Allow communication with a server using a specific websocket.
Eric Matte 4:e17cc31660ad 5
Eric Matte 4:e17cc31660ad 6 @poject NerfUS, Team P5
Eric Matte 4:e17cc31660ad 7 */
Eric Matte 4:e17cc31660ad 8 #include "EthernetMagJack.hpp"
Eric Matte 4:e17cc31660ad 9
Eric Matte 4:e17cc31660ad 10
Eric Matte 4:e17cc31660ad 11 EthernetMagJack::EthernetMagJack(char *url) : ws(url)
Eric Matte 4:e17cc31660ad 12 {
Eric Matte 4:e17cc31660ad 13 eth.init(); //Use DHCP
Eric Matte 4:e17cc31660ad 14 eth.connect();
Eric Matte 4:e17cc31660ad 15 printf("IP Address is %s\n\r", eth.getIPAddress());
Eric Matte 4:e17cc31660ad 16
Eric Matte 4:e17cc31660ad 17 ws.connect();
Eric Matte 4:e17cc31660ad 18 }
Eric Matte 4:e17cc31660ad 19
Eric Matte 4:e17cc31660ad 20 void EthernetMagJack::send(char *buffer)
Eric Matte 4:e17cc31660ad 21 {
Eric Matte 4:e17cc31660ad 22 return ws.send(buffer);
Eric Matte 4:e17cc31660ad 23 }
Eric Matte 4:e17cc31660ad 24
Eric Matte 4:e17cc31660ad 25 void EthernetMagJack::onMessage(char *buffer)
Eric Matte 4:e17cc31660ad 26 {
Eric Matte 4:e17cc31660ad 27 return ws.read(buffer);
Eric Matte 4:e17cc31660ad 28 }
Eric Matte 4:e17cc31660ad 29
Eric Matte 4:e17cc31660ad 30 EthernetMagJack::~EthernetInterface()
Eric Matte 4:e17cc31660ad 31 {
Eric Matte 4:e17cc31660ad 32 ws.close();
Eric Matte 4:e17cc31660ad 33 eth.disconnect();
Eric Matte 4:e17cc31660ad 34 }