Ultraschall Test Geschwindigkeitsregelung
Fork of BertlLib by
SvProtocol.h@5:a7849d022f69, 2015-02-25 (annotated)
- Committer:
- hollegha2
- Date:
- Wed Feb 25 08:17:43 2015 +0000
- Revision:
- 5:a7849d022f69
- Parent:
- 0:e0131e671ea0
Doku1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hollegha2 | 0:e0131e671ea0 | 1 | |
hollegha2 | 0:e0131e671ea0 | 2 | #ifndef SvProtocol_h |
hollegha2 | 0:e0131e671ea0 | 3 | #define SvProtocol_h |
hollegha2 | 0:e0131e671ea0 | 4 | |
hollegha2 | 0:e0131e671ea0 | 5 | #include "stdint.h" |
hollegha2 | 0:e0131e671ea0 | 6 | |
hollegha2 | 0:e0131e671ea0 | 7 | namespace mbed { |
hollegha2 | 0:e0131e671ea0 | 8 | |
hollegha2 | 0:e0131e671ea0 | 9 | class IStreamHL { |
hollegha2 | 0:e0131e671ea0 | 10 | public: |
hollegha2 | 0:e0131e671ea0 | 11 | virtual void PutChar(int aCh) = 0; |
hollegha2 | 0:e0131e671ea0 | 12 | virtual int GetChar() = 0; |
hollegha2 | 0:e0131e671ea0 | 13 | virtual void Write(void* aData, uint32_t aLenBytes) = 0; |
hollegha2 | 0:e0131e671ea0 | 14 | virtual void Read(void* aData, uint32_t aLenBytes) = 0; |
hollegha2 | 0:e0131e671ea0 | 15 | }; |
hollegha2 | 0:e0131e671ea0 | 16 | |
hollegha2 | 5:a7849d022f69 | 17 | /** SvProtocol for Bin-Communication with SvVis3 |
hollegha2 | 5:a7849d022f69 | 18 | @code |
hollegha2 | 5:a7849d022f69 | 19 | SerialBLK pc(USBTX, USBRX); |
hollegha2 | 5:a7849d022f69 | 20 | SvProtocol ua0(&pc); |
hollegha2 | 5:a7849d022f69 | 21 | |
hollegha2 | 5:a7849d022f69 | 22 | void main() |
hollegha2 | 5:a7849d022f69 | 23 | { |
hollegha2 | 5:a7849d022f69 | 24 | pc.format(8,SerialBLK::None,1); pc.baud(500000); |
hollegha2 | 5:a7849d022f69 | 25 | ua0.SvMessage("ProcVisDemo"); |
hollegha2 | 5:a7849d022f69 | 26 | Timer stw; stw.start(); |
hollegha2 | 5:a7849d022f69 | 27 | while(1) { |
hollegha2 | 5:a7849d022f69 | 28 | CommandHandler(); |
hollegha2 | 5:a7849d022f69 | 29 | if( (stw.read_ms()>100) ) { |
hollegha2 | 5:a7849d022f69 | 30 | stw.reset(); |
hollegha2 | 5:a7849d022f69 | 31 | sv1++; sv2++; |
hollegha2 | 5:a7849d022f69 | 32 | if( ua0.acqON ) { |
hollegha2 | 5:a7849d022f69 | 33 | ua0.WriteSvI16(1, sv1); |
hollegha2 | 5:a7849d022f69 | 34 | ua0.WriteSvI16(2, sv2); |
hollegha2 | 5:a7849d022f69 | 35 | } |
hollegha2 | 5:a7849d022f69 | 36 | } |
hollegha2 | 5:a7849d022f69 | 37 | } |
hollegha2 | 5:a7849d022f69 | 38 | } |
hollegha2 | 5:a7849d022f69 | 39 | |
hollegha2 | 5:a7849d022f69 | 40 | void CommandHandler() |
hollegha2 | 5:a7849d022f69 | 41 | { |
hollegha2 | 5:a7849d022f69 | 42 | uint8_t cmd; |
hollegha2 | 5:a7849d022f69 | 43 | int16_t idata1, idata2; |
hollegha2 | 5:a7849d022f69 | 44 | if( !pc.IsDataAvail() ) |
hollegha2 | 5:a7849d022f69 | 45 | return; |
hollegha2 | 5:a7849d022f69 | 46 | cmd = ua0.GetCommand(); |
hollegha2 | 5:a7849d022f69 | 47 | if( cmd==2 ) { |
hollegha2 | 5:a7849d022f69 | 48 | idata1 = ua0.ReadI16(); idata2 = ua0.ReadI16(); |
hollegha2 | 5:a7849d022f69 | 49 | ua0.SvPrintf("Command2 %d %d", idata1, idata2); |
hollegha2 | 5:a7849d022f69 | 50 | } |
hollegha2 | 5:a7849d022f69 | 51 | } |
hollegha2 | 5:a7849d022f69 | 52 | @endcode |
hollegha2 | 5:a7849d022f69 | 53 | */ |
hollegha2 | 0:e0131e671ea0 | 54 | class SvProtocol { |
hollegha2 | 0:e0131e671ea0 | 55 | public: |
hollegha2 | 0:e0131e671ea0 | 56 | IStreamHL* _st; |
hollegha2 | 0:e0131e671ea0 | 57 | uint8_t acqON; |
hollegha2 | 0:e0131e671ea0 | 58 | uint8_t svMessageON; |
hollegha2 | 0:e0131e671ea0 | 59 | public: |
hollegha2 | 5:a7849d022f69 | 60 | |
hollegha2 | 5:a7849d022f69 | 61 | //! Constructed with an IStreamHL as Parameter |
hollegha2 | 0:e0131e671ea0 | 62 | SvProtocol(IStreamHL* aStrm) { |
hollegha2 | 0:e0131e671ea0 | 63 | acqON=0; svMessageON=1; |
hollegha2 | 0:e0131e671ea0 | 64 | _st=aStrm; |
hollegha2 | 0:e0131e671ea0 | 65 | } |
hollegha2 | 0:e0131e671ea0 | 66 | |
hollegha2 | 5:a7849d022f69 | 67 | /** Check's first for acqOn/Off Command |
hollegha2 | 5:a7849d022f69 | 68 | ret 0 if acqOn/Off was handled in GetCommand */ |
hollegha2 | 0:e0131e671ea0 | 69 | int GetCommand(); |
hollegha2 | 0:e0131e671ea0 | 70 | |
hollegha2 | 0:e0131e671ea0 | 71 | void Puts(char* aCStr); // Terminate with 0 |
hollegha2 | 0:e0131e671ea0 | 72 | |
hollegha2 | 0:e0131e671ea0 | 73 | // \r\n is appended automatically |
hollegha2 | 0:e0131e671ea0 | 74 | void Printf(const char* format, ...); |
hollegha2 | 0:e0131e671ea0 | 75 | |
hollegha2 | 5:a7849d022f69 | 76 | //! use this printf when you communicate with the SV-Protocol (SvVis3) |
hollegha2 | 0:e0131e671ea0 | 77 | void SvPrintf(const char *format, ...); |
hollegha2 | 0:e0131e671ea0 | 78 | |
hollegha2 | 0:e0131e671ea0 | 79 | void WriteSV(int aId, char* aData) { |
hollegha2 | 0:e0131e671ea0 | 80 | if( !svMessageON ) return; |
hollegha2 | 0:e0131e671ea0 | 81 | _st->PutChar(aId); Puts(aData); |
hollegha2 | 0:e0131e671ea0 | 82 | } |
hollegha2 | 0:e0131e671ea0 | 83 | |
hollegha2 | 5:a7849d022f69 | 84 | //! If you only want to send Text ( no full printf ) |
hollegha2 | 0:e0131e671ea0 | 85 | void SvMessage(char* aTxt) { |
hollegha2 | 0:e0131e671ea0 | 86 | if( !svMessageON ) return; |
hollegha2 | 0:e0131e671ea0 | 87 | _st->PutChar(10); Puts(aTxt); |
hollegha2 | 0:e0131e671ea0 | 88 | } |
hollegha2 | 0:e0131e671ea0 | 89 | |
hollegha2 | 0:e0131e671ea0 | 90 | void VectHeader(int aId, int aNVals) |
hollegha2 | 0:e0131e671ea0 | 91 | { _st->PutChar(aId); _st->PutChar(aNVals); } |
hollegha2 | 0:e0131e671ea0 | 92 | |
hollegha2 | 5:a7849d022f69 | 93 | //! Write an int16_t Variable |
hollegha2 | 0:e0131e671ea0 | 94 | void WriteSvI16(int aId, int16_t aData) |
hollegha2 | 0:e0131e671ea0 | 95 | { _st->PutChar(aId+10); _st->Write(&aData,2); } |
hollegha2 | 0:e0131e671ea0 | 96 | |
hollegha2 | 0:e0131e671ea0 | 97 | void WriteSvI32(int aId, int32_t aData) |
hollegha2 | 0:e0131e671ea0 | 98 | { _st->PutChar(aId); _st->Write(&aData,4); } |
hollegha2 | 0:e0131e671ea0 | 99 | |
hollegha2 | 5:a7849d022f69 | 100 | //! Write a float Variable |
hollegha2 | 0:e0131e671ea0 | 101 | void WriteSV(int aId, float aData) |
hollegha2 | 0:e0131e671ea0 | 102 | { _st->PutChar(aId+20); _st->Write(&aData,4); } |
hollegha2 | 0:e0131e671ea0 | 103 | |
hollegha2 | 0:e0131e671ea0 | 104 | // float in 3.13 Format |
hollegha2 | 0:e0131e671ea0 | 105 | void WriteSV3p13(int aId, float aData); |
hollegha2 | 0:e0131e671ea0 | 106 | |
hollegha2 | 5:a7849d022f69 | 107 | //! read int16_t |
hollegha2 | 0:e0131e671ea0 | 108 | int16_t ReadI16() |
hollegha2 | 0:e0131e671ea0 | 109 | { int16_t ret; _st->Read(&ret,2); return ret; } |
hollegha2 | 0:e0131e671ea0 | 110 | |
hollegha2 | 0:e0131e671ea0 | 111 | int32_t ReadI32() |
hollegha2 | 0:e0131e671ea0 | 112 | { int32_t ret; _st->Read(&ret,4); return ret; } |
hollegha2 | 0:e0131e671ea0 | 113 | |
hollegha2 | 5:a7849d022f69 | 114 | //! read float |
hollegha2 | 0:e0131e671ea0 | 115 | float ReadF() |
hollegha2 | 0:e0131e671ea0 | 116 | { float ret; _st->Read(&ret,4); return ret; } |
hollegha2 | 0:e0131e671ea0 | 117 | }; |
hollegha2 | 0:e0131e671ea0 | 118 | |
hollegha2 | 0:e0131e671ea0 | 119 | } // namespace mbed |
hollegha2 | 0:e0131e671ea0 | 120 | |
hollegha2 | 0:e0131e671ea0 | 121 | // SV-Id Ranges and DataTypes for SvVis3 Visualisation-Tool |
hollegha2 | 0:e0131e671ea0 | 122 | //---------------------------------------------------------- |
hollegha2 | 0:e0131e671ea0 | 123 | // Id = 10 : string |
hollegha2 | 0:e0131e671ea0 | 124 | // Id = 1 .. 9 : format 3.13 2 Bytes |
hollegha2 | 0:e0131e671ea0 | 125 | // Id = 11 .. 20 : short 2 Bytes |
hollegha2 | 0:e0131e671ea0 | 126 | // Id = 21 .. 30 : float 4 Bytes |
hollegha2 | 0:e0131e671ea0 | 127 | |
hollegha2 | 0:e0131e671ea0 | 128 | #endif |