Serial Lib for Process-Visualisation with SvVis3

Dependents:   ProcVisDemo1 bluetooth_0110 Ansteuerung_motor_2509 bluetooth_0110 ... more

Committer:
hollegha2
Date:
Fri Apr 25 18:23:25 2014 +0000
Revision:
0:b958bdf108cf
Child:
1:1a03b6d5226f
Serial_HL

Who changed what in which revision?

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