Func-Gen - basic setup

Dependencies:   mbed

Committer:
stkiegerl
Date:
Tue Mar 23 17:13:12 2021 +0000
Revision:
3:9fd12684fa88
Parent:
0:e1bc83101929
-

Who changed what in which revision?

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