Program the control the fischertechnik robo interface or intelligent interface via tcp socket or via a java gui.
msgSerial.h@1:2c9d412ad471, 2011-05-04 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
networker | 0:7f26f0680202 | 1 | #ifndef MSGSERIAL_H |
networker | 0:7f26f0680202 | 2 | #define MSGSERIAL_H |
networker | 0:7f26f0680202 | 3 | #include "mbed.h" |
networker | 0:7f26f0680202 | 4 | #define SZ 7 |
networker | 0:7f26f0680202 | 5 | class msgSerial: public Serial { |
networker | 0:7f26f0680202 | 6 | public: |
networker | 0:7f26f0680202 | 7 | private: |
networker | 0:7f26f0680202 | 8 | void (*onMsgReceived)(char*); |
networker | 0:7f26f0680202 | 9 | char in[SZ], out[SZ]; |
networker | 0:7f26f0680202 | 10 | int ii, io; |
networker | 0:7f26f0680202 | 11 | void readByte() { |
networker | 0:7f26f0680202 | 12 | if (ii<SZ) { |
networker | 0:7f26f0680202 | 13 | in[ii++] = getc(); |
networker | 0:7f26f0680202 | 14 | if (in[0] != 0x90) {//not a valid message |
networker | 0:7f26f0680202 | 15 | ii = 0; |
networker | 0:7f26f0680202 | 16 | return; |
networker | 0:7f26f0680202 | 17 | } |
networker | 0:7f26f0680202 | 18 | if (ii==SZ) { |
networker | 0:7f26f0680202 | 19 | if (onMsgReceived) |
networker | 0:7f26f0680202 | 20 | onMsgReceived(in); |
networker | 0:7f26f0680202 | 21 | ii = 0; |
networker | 0:7f26f0680202 | 22 | } |
networker | 0:7f26f0680202 | 23 | } |
networker | 0:7f26f0680202 | 24 | } |
networker | 0:7f26f0680202 | 25 | void writeByte() { |
networker | 0:7f26f0680202 | 26 | if (io<SZ) |
networker | 0:7f26f0680202 | 27 | putc(out[io++]); |
networker | 0:7f26f0680202 | 28 | } |
networker | 0:7f26f0680202 | 29 | public: |
networker | 0:7f26f0680202 | 30 | msgSerial(PinName out, PinName in, void (*cb)(char*)): Serial(out, in) { |
networker | 0:7f26f0680202 | 31 | onMsgReceived = cb; |
networker | 0:7f26f0680202 | 32 | attach(this, &msgSerial::readByte, RxIrq); |
networker | 0:7f26f0680202 | 33 | attach(this, &msgSerial::writeByte, TxIrq); |
networker | 0:7f26f0680202 | 34 | ii = io = 0; |
networker | 0:7f26f0680202 | 35 | } |
networker | 0:7f26f0680202 | 36 | virtual ~msgSerial(){ |
networker | 0:7f26f0680202 | 37 | onMsgReceived = 0; |
networker | 0:7f26f0680202 | 38 | attach(0, RxIrq); |
networker | 0:7f26f0680202 | 39 | attach(0, TxIrq); |
networker | 0:7f26f0680202 | 40 | } |
networker | 0:7f26f0680202 | 41 | void write(char *m) { |
networker | 0:7f26f0680202 | 42 | memcpy(out, m, SZ); |
networker | 0:7f26f0680202 | 43 | io = 0; |
networker | 0:7f26f0680202 | 44 | writeByte(); |
networker | 0:7f26f0680202 | 45 | } |
networker | 0:7f26f0680202 | 46 | }; |
networker | 0:7f26f0680202 | 47 | #endif |