UDP comms to ROV

Committer:
inky
Date:
Fri Jan 13 20:24:19 2012 +0000
Revision:
0:4a75d653c18c
Child:
1:f51739cada16
First stab, some comms

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