Stefan Kiegerl
/
FuncGen
Function Generator for TINF 2021
include/SvProtocol.h@0:464b401734fd, 2021-03-09 (annotated)
- Committer:
- stkiegerl
- Date:
- Tue Mar 09 20:46:10 2021 +0000
- Revision:
- 0:464b401734fd
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stkiegerl | 0:464b401734fd | 1 | #ifndef SvProtocol_h |
stkiegerl | 0:464b401734fd | 2 | #define SvProtocol_h |
stkiegerl | 0:464b401734fd | 3 | |
stkiegerl | 0:464b401734fd | 4 | #include "stdint.h" |
stkiegerl | 0:464b401734fd | 5 | |
stkiegerl | 0:464b401734fd | 6 | namespace mbed { |
stkiegerl | 0:464b401734fd | 7 | |
stkiegerl | 0:464b401734fd | 8 | class IStreamHL { |
stkiegerl | 0:464b401734fd | 9 | public: |
stkiegerl | 0:464b401734fd | 10 | virtual void PutChar(int aCh) = 0; |
stkiegerl | 0:464b401734fd | 11 | virtual int GetChar() = 0; |
stkiegerl | 0:464b401734fd | 12 | virtual void Write(void* aData, uint32_t aLenBytes) = 0; |
stkiegerl | 0:464b401734fd | 13 | virtual void Read(void* aData, uint32_t aLenBytes) = 0; |
stkiegerl | 0:464b401734fd | 14 | |
stkiegerl | 0:464b401734fd | 15 | virtual void Flush() { } |
stkiegerl | 0:464b401734fd | 16 | }; |
stkiegerl | 0:464b401734fd | 17 | |
stkiegerl | 0:464b401734fd | 18 | class SvProtocol { |
stkiegerl | 0:464b401734fd | 19 | public: |
stkiegerl | 0:464b401734fd | 20 | IStreamHL* _st; |
stkiegerl | 0:464b401734fd | 21 | uint8_t acqON; |
stkiegerl | 0:464b401734fd | 22 | uint8_t svMessageON; |
stkiegerl | 0:464b401734fd | 23 | public: |
stkiegerl | 0:464b401734fd | 24 | SvProtocol(IStreamHL* aStrm) { |
stkiegerl | 0:464b401734fd | 25 | acqON=0; svMessageON=1; |
stkiegerl | 0:464b401734fd | 26 | _st=aStrm; |
stkiegerl | 0:464b401734fd | 27 | } |
stkiegerl | 0:464b401734fd | 28 | |
stkiegerl | 0:464b401734fd | 29 | // Check's first for acqOn/Off Command |
stkiegerl | 0:464b401734fd | 30 | // ret 0 if acqOn/Off was handled in GetCommand |
stkiegerl | 0:464b401734fd | 31 | int GetCommand(); |
stkiegerl | 0:464b401734fd | 32 | |
stkiegerl | 0:464b401734fd | 33 | void Puts(char* aCStr); // Terminate with 0 |
stkiegerl | 0:464b401734fd | 34 | |
stkiegerl | 0:464b401734fd | 35 | // \r\n is appended automatically |
stkiegerl | 0:464b401734fd | 36 | void Printf(const char* format, ...); |
stkiegerl | 0:464b401734fd | 37 | |
stkiegerl | 0:464b401734fd | 38 | void SvPrintf(const char *format, ...); |
stkiegerl | 0:464b401734fd | 39 | |
stkiegerl | 0:464b401734fd | 40 | void WriteSV(int aId, char* aData) { |
stkiegerl | 0:464b401734fd | 41 | if( !svMessageON ) return; |
stkiegerl | 0:464b401734fd | 42 | _st->PutChar(aId); Puts(aData); |
stkiegerl | 0:464b401734fd | 43 | } |
stkiegerl | 0:464b401734fd | 44 | |
stkiegerl | 0:464b401734fd | 45 | void SvMessage(char* aTxt) { |
stkiegerl | 0:464b401734fd | 46 | if( !svMessageON ) return; |
stkiegerl | 0:464b401734fd | 47 | _st->PutChar(10); Puts(aTxt); |
stkiegerl | 0:464b401734fd | 48 | } |
stkiegerl | 0:464b401734fd | 49 | |
stkiegerl | 0:464b401734fd | 50 | void VectHeader(int aId, int aNVals) |
stkiegerl | 0:464b401734fd | 51 | { _st->PutChar(aId); _st->PutChar(aNVals); } |
stkiegerl | 0:464b401734fd | 52 | |
stkiegerl | 0:464b401734fd | 53 | void WriteSvI16(int aId, int16_t aData) |
stkiegerl | 0:464b401734fd | 54 | { _st->PutChar(aId+10); _st->Write(&aData,2); } |
stkiegerl | 0:464b401734fd | 55 | |
stkiegerl | 0:464b401734fd | 56 | void WriteSvI32(int aId, int32_t aData) |
stkiegerl | 0:464b401734fd | 57 | { _st->PutChar(aId); _st->Write(&aData,4); } |
stkiegerl | 0:464b401734fd | 58 | |
stkiegerl | 0:464b401734fd | 59 | void WriteSV(int aId, float aData) |
stkiegerl | 0:464b401734fd | 60 | { _st->PutChar(aId+20); _st->Write(&aData,4); } |
stkiegerl | 0:464b401734fd | 61 | |
stkiegerl | 0:464b401734fd | 62 | // aLen = Anzahl g�ltiger Werte in aAry |
stkiegerl | 0:464b401734fd | 63 | void WriteArray(int16_t aAry[], int aLen) |
stkiegerl | 0:464b401734fd | 64 | { |
stkiegerl | 0:464b401734fd | 65 | _st->PutChar(100); // Id f�r array |
stkiegerl | 0:464b401734fd | 66 | _st->PutChar(aLen); // L�nge als Byte geschrieben |
stkiegerl | 0:464b401734fd | 67 | for(int i=0; i<aLen; i++) |
stkiegerl | 0:464b401734fd | 68 | { |
stkiegerl | 0:464b401734fd | 69 | _st->Write(&(aAry[i]),2); // jeder Arrayeintrag als int16 |
stkiegerl | 0:464b401734fd | 70 | } |
stkiegerl | 0:464b401734fd | 71 | } |
stkiegerl | 0:464b401734fd | 72 | |
stkiegerl | 0:464b401734fd | 73 | // float in 3.13 Format |
stkiegerl | 0:464b401734fd | 74 | void WriteSV3p13(int aId, float aData); |
stkiegerl | 0:464b401734fd | 75 | |
stkiegerl | 0:464b401734fd | 76 | int16_t ReadI16() |
stkiegerl | 0:464b401734fd | 77 | { int16_t ret; _st->Read(&ret,2); return ret; } |
stkiegerl | 0:464b401734fd | 78 | |
stkiegerl | 0:464b401734fd | 79 | int32_t ReadI32() |
stkiegerl | 0:464b401734fd | 80 | { int32_t ret; _st->Read(&ret,4); return ret; } |
stkiegerl | 0:464b401734fd | 81 | |
stkiegerl | 0:464b401734fd | 82 | float ReadF() |
stkiegerl | 0:464b401734fd | 83 | { float ret; _st->Read(&ret,4); return ret; } |
stkiegerl | 0:464b401734fd | 84 | }; |
stkiegerl | 0:464b401734fd | 85 | |
stkiegerl | 0:464b401734fd | 86 | } // namespace mbed |
stkiegerl | 0:464b401734fd | 87 | |
stkiegerl | 0:464b401734fd | 88 | // SV-Id Ranges and DataTypes for SvVis3 Visualisation-Tool |
stkiegerl | 0:464b401734fd | 89 | //---------------------------------------------------------- |
stkiegerl | 0:464b401734fd | 90 | // Id = 10 : string |
stkiegerl | 0:464b401734fd | 91 | // Id = 1 .. 9 : format 3.13 2 Bytes |
stkiegerl | 0:464b401734fd | 92 | // Id = 11 .. 20 : short 2 Bytes |
stkiegerl | 0:464b401734fd | 93 | // Id = 21 .. 30 : float 4 Bytes |
stkiegerl | 0:464b401734fd | 94 | // Id = 100 : int16-Array |
stkiegerl | 0:464b401734fd | 95 | |
stkiegerl | 0:464b401734fd | 96 | #endif |
stkiegerl | 0:464b401734fd | 97 | |
stkiegerl | 0:464b401734fd | 98 |