M Seiser / Serial_HL

Fork of Serial_HL by michael hollegha

Committer:
hollegha2
Date:
Thu Apr 07 09:50:12 2016 +0000
Revision:
1:1a03b6d5226f
Parent:
0:b958bdf108cf
V 1.2

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 1:1a03b6d5226f 7 // V1.2
hollegha2 1:1a03b6d5226f 8
hollegha2 1:1a03b6d5226f 9 namespace mbed
hollegha2 1:1a03b6d5226f 10 {
hollegha2 0:b958bdf108cf 11
hollegha2 1:1a03b6d5226f 12 class IStreamHL
hollegha2 1:1a03b6d5226f 13 {
hollegha2 1:1a03b6d5226f 14 public:
hollegha2 1:1a03b6d5226f 15 virtual void PutChar(int aCh) = 0;
hollegha2 1:1a03b6d5226f 16 virtual int GetChar() = 0;
hollegha2 1:1a03b6d5226f 17 virtual void Write(void* aData, uint32_t aLenBytes) = 0;
hollegha2 1:1a03b6d5226f 18 virtual void Read(void* aData, uint32_t aLenBytes) = 0;
hollegha2 0:b958bdf108cf 19 };
hollegha2 0:b958bdf108cf 20
hollegha2 1:1a03b6d5226f 21 class SvProtocol
hollegha2 1:1a03b6d5226f 22 {
hollegha2 1:1a03b6d5226f 23 public:
hollegha2 1:1a03b6d5226f 24 IStreamHL* _st;
hollegha2 1:1a03b6d5226f 25 uint8_t acqON;
hollegha2 0:b958bdf108cf 26 uint8_t svMessageON;
hollegha2 1:1a03b6d5226f 27 public:
hollegha2 1:1a03b6d5226f 28 SvProtocol(IStreamHL* aStrm) {
hollegha2 1:1a03b6d5226f 29 acqON=0;
hollegha2 1:1a03b6d5226f 30 svMessageON=1;
hollegha2 1:1a03b6d5226f 31 _st=aStrm;
hollegha2 1:1a03b6d5226f 32 }
hollegha2 1:1a03b6d5226f 33
hollegha2 1:1a03b6d5226f 34 // Check's first for acqOn/Off Command
hollegha2 0:b958bdf108cf 35 // ret 0 if acqOn/Off was handled in GetCommand
hollegha2 0:b958bdf108cf 36 int GetCommand();
hollegha2 1:1a03b6d5226f 37
hollegha2 1:1a03b6d5226f 38 void Puts(char* aCStr); // Terminate with 0
hollegha2 0:b958bdf108cf 39
hollegha2 0:b958bdf108cf 40 // \r\n is appended automatically
hollegha2 0:b958bdf108cf 41 void Printf(const char* format, ...);
hollegha2 0:b958bdf108cf 42
hollegha2 0:b958bdf108cf 43 void SvPrintf(const char *format, ...);
hollegha2 1:1a03b6d5226f 44
hollegha2 0:b958bdf108cf 45 void WriteSV(int aId, char* aData) {
hollegha2 1:1a03b6d5226f 46 if( !svMessageON ) return;
hollegha2 1:1a03b6d5226f 47 _st->PutChar(aId);
hollegha2 1:1a03b6d5226f 48 Puts(aData);
hollegha2 0:b958bdf108cf 49 }
hollegha2 1:1a03b6d5226f 50
hollegha2 0:b958bdf108cf 51 void SvMessage(char* aTxt) {
hollegha2 1:1a03b6d5226f 52 if( !svMessageON ) return;
hollegha2 1:1a03b6d5226f 53 _st->PutChar(10);
hollegha2 1:1a03b6d5226f 54 Puts(aTxt);
hollegha2 1:1a03b6d5226f 55 }
hollegha2 1:1a03b6d5226f 56
hollegha2 1:1a03b6d5226f 57 void VectHeader(int aId, int aNVals) {
hollegha2 1:1a03b6d5226f 58 _st->PutChar(aId);
hollegha2 1:1a03b6d5226f 59 _st->PutChar(aNVals);
hollegha2 0:b958bdf108cf 60 }
hollegha2 1:1a03b6d5226f 61
hollegha2 1:1a03b6d5226f 62 void WriteSvI16(int aId, int16_t aData) {
hollegha2 1:1a03b6d5226f 63 _st->PutChar(aId+10);
hollegha2 1:1a03b6d5226f 64 _st->Write(&aData,2);
hollegha2 1:1a03b6d5226f 65 }
hollegha2 1:1a03b6d5226f 66
hollegha2 1:1a03b6d5226f 67 void WriteSvI32(int aId, int32_t aData) {
hollegha2 1:1a03b6d5226f 68 _st->PutChar(aId);
hollegha2 1:1a03b6d5226f 69 _st->Write(&aData,4);
hollegha2 1:1a03b6d5226f 70 }
hollegha2 1:1a03b6d5226f 71
hollegha2 1:1a03b6d5226f 72 void WriteSV(int aId, float aData) {
hollegha2 1:1a03b6d5226f 73 _st->PutChar(aId+20);
hollegha2 1:1a03b6d5226f 74 _st->Write(&aData,4);
hollegha2 1:1a03b6d5226f 75 }
hollegha2 1:1a03b6d5226f 76
hollegha2 0:b958bdf108cf 77 // float in 3.13 Format
hollegha2 0:b958bdf108cf 78 void WriteSV3p13(int aId, float aData);
hollegha2 0:b958bdf108cf 79
hollegha2 1:1a03b6d5226f 80 int16_t ReadI16() {
hollegha2 1:1a03b6d5226f 81 int16_t ret;
hollegha2 1:1a03b6d5226f 82 _st->Read(&ret,2);
hollegha2 1:1a03b6d5226f 83 return ret;
hollegha2 1:1a03b6d5226f 84 }
hollegha2 0:b958bdf108cf 85
hollegha2 1:1a03b6d5226f 86 int32_t ReadI32() {
hollegha2 1:1a03b6d5226f 87 int32_t ret;
hollegha2 1:1a03b6d5226f 88 _st->Read(&ret,4);
hollegha2 1:1a03b6d5226f 89 return ret;
hollegha2 1:1a03b6d5226f 90 }
hollegha2 1:1a03b6d5226f 91
hollegha2 1:1a03b6d5226f 92 float ReadF() {
hollegha2 1:1a03b6d5226f 93 float ret;
hollegha2 1:1a03b6d5226f 94 _st->Read(&ret,4);
hollegha2 1:1a03b6d5226f 95 return ret;
hollegha2 1:1a03b6d5226f 96 }
hollegha2 1:1a03b6d5226f 97
hollegha2 1:1a03b6d5226f 98 // reads until aTermChar is found
hollegha2 1:1a03b6d5226f 99 void ReadCString(char* aBuff, char aTermChar);
hollegha2 0:b958bdf108cf 100 };
hollegha2 0:b958bdf108cf 101
hollegha2 0:b958bdf108cf 102 } // namespace mbed
hollegha2 0:b958bdf108cf 103
hollegha2 0:b958bdf108cf 104 // SV-Id Ranges and DataTypes for SvVis3 Visualisation-Tool
hollegha2 0:b958bdf108cf 105 //----------------------------------------------------------
hollegha2 0:b958bdf108cf 106 // Id = 10 : string
hollegha2 0:b958bdf108cf 107 // Id = 1 .. 9 : format 3.13 2 Bytes
hollegha2 0:b958bdf108cf 108 // Id = 11 .. 20 : short 2 Bytes
hollegha2 0:b958bdf108cf 109 // Id = 21 .. 30 : float 4 Bytes
hollegha2 0:b958bdf108cf 110
hollegha2 0:b958bdf108cf 111 #endif