UDP comms to ROV

Committer:
inky
Date:
Mon Jan 16 17:17:58 2012 +0000
Revision:
1:f51739cada16
Parent:
0:4a75d653c18c
UDP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inky 0:4a75d653c18c 1 /* ROV communication class
inky 0:4a75d653c18c 2 */
inky 0:4a75d653c18c 3 #ifndef ROVCOMMS_H
inky 0:4a75d653c18c 4 #define ROVCOMMS_H
inky 0:4a75d653c18c 5 #include "mbed.h"
inky 0:4a75d653c18c 6 #include "msg.h"
inky 0:4a75d653c18c 7
inky 1:f51739cada16 8 #include "EthernetNetIf.h"
inky 1:f51739cada16 9 #include "UDPSocket.h"
inky 1:f51739cada16 10
inky 0:4a75d653c18c 11 #define STATIC_IP_ADDR
inky 0:4a75d653c18c 12
inky 0:4a75d653c18c 13 #define MAX_BUFFER_SIZE 10 // max chars in the data stream
inky 0:4a75d653c18c 14
inky 0:4a75d653c18c 15 #define ipGateway IpAddr(10,0,0,1)
inky 0:4a75d653c18c 16 #define ipMask IpAddr(255,255,255,0)
inky 0:4a75d653c18c 17 #define ipDns IpAddr(10,0,0,1)
inky 0:4a75d653c18c 18
inky 0:4a75d653c18c 19 #define RX_TCP_LISTENING_PORT 0xdead // 57005
inky 0:4a75d653c18c 20
inky 0:4a75d653c18c 21 // last digit for the IP address, defining below 100 for below water
inky 0:4a75d653c18c 22 // and above 100 for above water :)
inky 0:4a75d653c18c 23 // The host/server is the ROV, so the handset can send info to the host
inky 0:4a75d653c18c 24 #define ROV_ADDR 50 // ROV as host and below 100 for below water
inky 0:4a75d653c18c 25 #define IPCAMERA_ADDR 60
inky 0:4a75d653c18c 26 #define SURFACE_PC_ADDR 102
inky 0:4a75d653c18c 27 #define HANDSET_ADDR 101
inky 0:4a75d653c18c 28
inky 0:4a75d653c18c 29 class RovComms
inky 0:4a75d653c18c 30 {
inky 0:4a75d653c18c 31 public:
inky 0:4a75d653c18c 32 RovComms(int addr);
inky 1:f51739cada16 33 void InitUDP(int addr);
inky 0:4a75d653c18c 34
inky 1:f51739cada16 35 void CloseSocket(UDPSocket *s, int *state);
inky 0:4a75d653c18c 36
inky 0:4a75d653c18c 37 void CallbackFn( void (*function)(void) ) { _callback.attach(function); }
inky 0:4a75d653c18c 38
inky 1:f51739cada16 39 void onUDPSocketEvent(UDPSocketEvent e);
inky 0:4a75d653c18c 40 void Transmit(int pktType);
inky 0:4a75d653c18c 41 char *Receive(void);
inky 0:4a75d653c18c 42
inky 0:4a75d653c18c 43 void RovPropulsion(int speed, int turn, int vert);
inky 0:4a75d653c18c 44 int RovSpeed() { return iRovSpeed;}
inky 0:4a75d653c18c 45 int RovTurn() { return iRovTurn;}
inky 0:4a75d653c18c 46 int RovVert() { return iRovVert;}
inky 0:4a75d653c18c 47
inky 0:4a75d653c18c 48 void FrontLights(int state);
inky 0:4a75d653c18c 49 int FrontLights() { return ( (iLight & AUX_FN_LIGHT1_ON)==AUX_FN_LIGHT1_ON?1:0); }
inky 0:4a75d653c18c 50 void RearLights(int state);
inky 0:4a75d653c18c 51 int RearLights() { return ( (iLight & AUX_FN_LIGHT2_ON)==AUX_FN_LIGHT2_ON?1:0); }
inky 0:4a75d653c18c 52
inky 0:4a75d653c18c 53 void Camera(int cam);
inky 0:4a75d653c18c 54 int Camera();
inky 0:4a75d653c18c 55
inky 0:4a75d653c18c 56 private:
inky 0:4a75d653c18c 57 void Debug(const char *format, ...);
inky 0:4a75d653c18c 58 void ClearBuffer(char *buf) {int i=MAX_BUFFER_SIZE;while (i>0) buf[i--]=0;}
inky 0:4a75d653c18c 59 void ResetValues();
inky 0:4a75d653c18c 60
inky 0:4a75d653c18c 61 private:
inky 0:4a75d653c18c 62 EthernetNetIf *eth;
inky 1:f51739cada16 63 UDPSocket *UdpSkt;
inky 0:4a75d653c18c 64 IpAddr rovAddr;
inky 0:4a75d653c18c 65 Host server;
inky 0:4a75d653c18c 66
inky 0:4a75d653c18c 67 enum NETWORK_STATE { INIT, OPEN, LISTEN, CONNECTED, ERROR, CLOSED };
inky 0:4a75d653c18c 68 int RxNetworkState;
inky 0:4a75d653c18c 69 int TxNetworkState;
inky 0:4a75d653c18c 70
inky 0:4a75d653c18c 71 char iRxData[MAX_BUFFER_SIZE];
inky 0:4a75d653c18c 72 char iTxData[MAX_BUFFER_SIZE];
inky 0:4a75d653c18c 73 int iState;
inky 0:4a75d653c18c 74
inky 0:4a75d653c18c 75 FunctionPointer _callback; // used to call back into code when data arrives
inky 0:4a75d653c18c 76
inky 0:4a75d653c18c 77 // ROV params
inky 0:4a75d653c18c 78 int iRovSpeed;
inky 0:4a75d653c18c 79 int iRovTurn;
inky 0:4a75d653c18c 80 int iRovVert;
inky 0:4a75d653c18c 81
inky 0:4a75d653c18c 82 int iLight;
inky 0:4a75d653c18c 83 int iWaterSol;
inky 0:4a75d653c18c 84 int iAirSol;
inky 0:4a75d653c18c 85 int iCamera;
inky 0:4a75d653c18c 86 int iPressure;
inky 0:4a75d653c18c 87 int iCompass;
inky 0:4a75d653c18c 88 int iAccelX;
inky 0:4a75d653c18c 89 int iAccelY;
inky 0:4a75d653c18c 90 int iAccelZ;
inky 0:4a75d653c18c 91
inky 0:4a75d653c18c 92 }; // end class RovComms
inky 0:4a75d653c18c 93
inky 0:4a75d653c18c 94 #endif // ROVCOMMS_H