ProcVisDemo_Accel

Dependencies:   MMA7660 mbed

Committer:
Wizo
Date:
Thu Nov 15 18:04:08 2018 +0000
Revision:
0:fca9076d3362
ProcVisDemo_Accel

Who changed what in which revision?

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