Program the control the fischertechnik robo interface or intelligent interface via tcp socket or via a java gui.

Dependencies:   mbed ConfigFile

Committer:
networker
Date:
Wed May 04 15:42:13 2011 +0000
Revision:
1:2c9d412ad471
Parent:
0:7f26f0680202
first publication (mbed challenge submission)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
networker 0:7f26f0680202 1
networker 0:7f26f0680202 2 /*
networker 0:7f26f0680202 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
networker 0:7f26f0680202 4
networker 0:7f26f0680202 5 Permission is hereby granted, free of charge, to any person obtaining a copy
networker 0:7f26f0680202 6 of this software and associated documentation files (the "Software"), to deal
networker 0:7f26f0680202 7 in the Software without restriction, including without limitation the rights
networker 0:7f26f0680202 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
networker 0:7f26f0680202 9 copies of the Software, and to permit persons to whom the Software is
networker 0:7f26f0680202 10 furnished to do so, subject to the following conditions:
networker 0:7f26f0680202 11
networker 0:7f26f0680202 12 The above copyright notice and this permission notice shall be included in
networker 0:7f26f0680202 13 all copies or substantial portions of the Software.
networker 0:7f26f0680202 14
networker 0:7f26f0680202 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
networker 0:7f26f0680202 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
networker 0:7f26f0680202 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
networker 0:7f26f0680202 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
networker 0:7f26f0680202 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
networker 0:7f26f0680202 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
networker 0:7f26f0680202 21 THE SOFTWARE.
networker 0:7f26f0680202 22 */
networker 0:7f26f0680202 23
networker 0:7f26f0680202 24 /** \file
networker 0:7f26f0680202 25 UDP Socket header file
networker 0:7f26f0680202 26 */
networker 0:7f26f0680202 27
networker 0:7f26f0680202 28 #ifndef UDPSOCKET_H
networker 0:7f26f0680202 29 #define UDPSOCKET_H
networker 0:7f26f0680202 30
networker 0:7f26f0680202 31 #include "core/net.h"
networker 0:7f26f0680202 32 #include "core/host.h"
networker 0:7f26f0680202 33 //Essentially it is a safe interface to NetUdpSocket
networker 0:7f26f0680202 34
networker 0:7f26f0680202 35 ///UDP Socket error codes
networker 0:7f26f0680202 36 enum UDPSocketErr
networker 0:7f26f0680202 37 {
networker 0:7f26f0680202 38 __UDPSOCKET_MIN = -0xFFFF,
networker 0:7f26f0680202 39 UDPSOCKET_SETUP, ///<UDPSocket not properly configured
networker 0:7f26f0680202 40 UDPSOCKET_IF, ///<Interface has problems, does not exist or is not initialized
networker 0:7f26f0680202 41 UDPSOCKET_MEM, ///<Not enough mem
networker 0:7f26f0680202 42 UDPSOCKET_INUSE, ///<Interface / Port is in use
networker 0:7f26f0680202 43 //...
networker 0:7f26f0680202 44 UDPSOCKET_OK = 0 ///<Success
networker 0:7f26f0680202 45 };
networker 0:7f26f0680202 46
networker 0:7f26f0680202 47 ///UDP Socket Event(s)
networker 0:7f26f0680202 48 enum UDPSocketEvent //Only one event here for now, but keeps that model in case we need to implement some others
networker 0:7f26f0680202 49 {
networker 0:7f26f0680202 50 UDPSOCKET_READABLE, ///<Data in buf
networker 0:7f26f0680202 51 };
networker 0:7f26f0680202 52
networker 0:7f26f0680202 53 class NetUdpSocket;
networker 0:7f26f0680202 54 enum NetUdpSocketEvent;
networker 0:7f26f0680202 55
networker 0:7f26f0680202 56 ///This is a simple UDP Socket class
networker 0:7f26f0680202 57 /**
networker 0:7f26f0680202 58 This class exposes an API to deal with UDP Sockets
networker 0:7f26f0680202 59 */
networker 0:7f26f0680202 60 class UDPSocket
networker 0:7f26f0680202 61 {
networker 0:7f26f0680202 62 public:
networker 0:7f26f0680202 63 ///Creates a new socket
networker 0:7f26f0680202 64 UDPSocket();
networker 0:7f26f0680202 65
networker 0:7f26f0680202 66 ///Closes and destroys socket
networker 0:7f26f0680202 67 ~UDPSocket(); //close()
networker 0:7f26f0680202 68
networker 0:7f26f0680202 69 ///Binds the socket to local host or a multicast address
networker 0:7f26f0680202 70 UDPSocketErr bind(const Host& me);
networker 0:7f26f0680202 71
networker 0:7f26f0680202 72 ///Sends data
networker 0:7f26f0680202 73 /*
networker 0:7f26f0680202 74 @param pHost : host to send data to
networker 0:7f26f0680202 75 @return a negative error code or the number of bytes transmitted
networker 0:7f26f0680202 76 */
networker 0:7f26f0680202 77 int /*if < 0 : UDPSocketErr*/ sendto(const char* buf, int len, Host* pHost);
networker 0:7f26f0680202 78
networker 0:7f26f0680202 79 ///Receives data
networker 0:7f26f0680202 80 /*
networker 0:7f26f0680202 81 @param pHost : host from which this piece of data comes from
networker 0:7f26f0680202 82 @return a negative error code or the number of bytes received
networker 0:7f26f0680202 83 */
networker 0:7f26f0680202 84 int /*if < 0 : UDPSocketErr*/ recvfrom(char* buf, int len, Host* pHost);
networker 0:7f26f0680202 85
networker 0:7f26f0680202 86 /* TODO NTH : printf / scanf helpers that call send/recv */
networker 0:7f26f0680202 87
networker 0:7f26f0680202 88 ///Closes socket
networker 0:7f26f0680202 89 UDPSocketErr close();
networker 0:7f26f0680202 90
networker 0:7f26f0680202 91 //Callbacks
networker 0:7f26f0680202 92 ///Setups callback
networker 0:7f26f0680202 93 /**
networker 0:7f26f0680202 94 @param pMethod : callback function
networker 0:7f26f0680202 95 */
networker 0:7f26f0680202 96 void setOnEvent( void (*pMethod)(UDPSocketEvent) );
networker 0:7f26f0680202 97
networker 0:7f26f0680202 98 class CDummy;
networker 0:7f26f0680202 99 ///Setups callback
networker 0:7f26f0680202 100 /**
networker 0:7f26f0680202 101 @param pItem : instance of class on which to execute the callback method
networker 0:7f26f0680202 102 @param pMethod : callback method
networker 0:7f26f0680202 103 */
networker 0:7f26f0680202 104 template<class T>
networker 0:7f26f0680202 105 void setOnEvent( T* pItem, void (T::*pMethod)(UDPSocketEvent) )
networker 0:7f26f0680202 106 {
networker 0:7f26f0680202 107 m_pCbItem = (CDummy*) pItem;
networker 0:7f26f0680202 108 m_pCbMeth = (void (CDummy::*)(UDPSocketEvent)) pMethod;
networker 0:7f26f0680202 109 }
networker 0:7f26f0680202 110
networker 0:7f26f0680202 111 ///Disables callback
networker 0:7f26f0680202 112 void resetOnEvent();
networker 0:7f26f0680202 113
networker 0:7f26f0680202 114 protected:
networker 0:7f26f0680202 115 void onNetUdpSocketEvent(NetUdpSocketEvent e);
networker 0:7f26f0680202 116 UDPSocketErr checkInst();
networker 0:7f26f0680202 117
networker 0:7f26f0680202 118 private:
networker 0:7f26f0680202 119 NetUdpSocket* m_pNetUdpSocket;
networker 0:7f26f0680202 120
networker 0:7f26f0680202 121 CDummy* m_pCbItem;
networker 0:7f26f0680202 122 void (CDummy::*m_pCbMeth)(UDPSocketEvent);
networker 0:7f26f0680202 123
networker 0:7f26f0680202 124 void (*m_pCb)(UDPSocketEvent);
networker 0:7f26f0680202 125
networker 0:7f26f0680202 126 };
networker 0:7f26f0680202 127
networker 0:7f26f0680202 128 #endif