Serial Lib for Process-Visualisation with SvVis3
Dependents: ProcVisDemo1 bluetooth_0110 Ansteuerung_motor_2509 bluetooth_0110 ... more
Revision 1:1a03b6d5226f, committed 2016-04-07
- Comitter:
- hollegha2
- Date:
- Thu Apr 07 09:50:12 2016 +0000
- Parent:
- 0:b958bdf108cf
- Commit message:
- V 1.2
Changed in this revision
Serial_HL.cpp | Show annotated file Show diff for this revision Revisions of this file |
SvProtocol.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r b958bdf108cf -r 1a03b6d5226f Serial_HL.cpp --- a/Serial_HL.cpp Fri Apr 25 18:23:25 2014 +0000 +++ b/Serial_HL.cpp Thu Apr 07 09:50:12 2016 +0000 @@ -3,6 +3,8 @@ #include <stdarg.h> #include <stdio.h> +// V1.2 + namespace mbed { SerialBLK::SerialBLK(PinName tx, PinName rx) { @@ -123,6 +125,20 @@ return cmd; } + +void SvProtocol::ReadCString(char* aBuff, char aTermChar) +{ + int ch = _st->GetChar(); + char* ptr = aBuff; + while( ch!=aTermChar ) + { + *ptr=ch; ptr++; + ch=_st->GetChar(); + } + *ptr=ch; ptr++; + *ptr=0; +} + } // namespace mbed
diff -r b958bdf108cf -r 1a03b6d5226f SvProtocol.h --- a/SvProtocol.h Fri Apr 25 18:23:25 2014 +0000 +++ b/SvProtocol.h Thu Apr 07 09:50:12 2016 +0000 @@ -4,71 +4,99 @@ #include "stdint.h" -namespace mbed { +// V1.2 + +namespace mbed +{ -class IStreamHL { - public: - virtual void PutChar(int aCh) = 0; - virtual int GetChar() = 0; - virtual void Write(void* aData, uint32_t aLenBytes) = 0; - virtual void Read(void* aData, uint32_t aLenBytes) = 0; +class IStreamHL +{ +public: + virtual void PutChar(int aCh) = 0; + virtual int GetChar() = 0; + virtual void Write(void* aData, uint32_t aLenBytes) = 0; + virtual void Read(void* aData, uint32_t aLenBytes) = 0; }; -class SvProtocol { - public: - IStreamHL* _st; - uint8_t acqON; +class SvProtocol +{ +public: + IStreamHL* _st; + uint8_t acqON; uint8_t svMessageON; - public: - SvProtocol(IStreamHL* aStrm) { - acqON=0; svMessageON=1; - _st=aStrm; - } - - // Check's first for acqOn/Off Command +public: + SvProtocol(IStreamHL* aStrm) { + acqON=0; + svMessageON=1; + _st=aStrm; + } + + // Check's first for acqOn/Off Command // ret 0 if acqOn/Off was handled in GetCommand int GetCommand(); - - void Puts(char* aCStr); // Terminate with 0 + + void Puts(char* aCStr); // Terminate with 0 // \r\n is appended automatically void Printf(const char* format, ...); void SvPrintf(const char *format, ...); - + void WriteSV(int aId, char* aData) { - if( !svMessageON ) return; - _st->PutChar(aId); Puts(aData); + if( !svMessageON ) return; + _st->PutChar(aId); + Puts(aData); } - + void SvMessage(char* aTxt) { - if( !svMessageON ) return; - _st->PutChar(10); Puts(aTxt); + if( !svMessageON ) return; + _st->PutChar(10); + Puts(aTxt); + } + + void VectHeader(int aId, int aNVals) { + _st->PutChar(aId); + _st->PutChar(aNVals); } - - void VectHeader(int aId, int aNVals) - { _st->PutChar(aId); _st->PutChar(aNVals); } - - void WriteSvI16(int aId, int16_t aData) - { _st->PutChar(aId+10); _st->Write(&aData,2); } - - void WriteSvI32(int aId, int32_t aData) - { _st->PutChar(aId); _st->Write(&aData,4); } - - void WriteSV(int aId, float aData) - { _st->PutChar(aId+20); _st->Write(&aData,4); } - + + void WriteSvI16(int aId, int16_t aData) { + _st->PutChar(aId+10); + _st->Write(&aData,2); + } + + void WriteSvI32(int aId, int32_t aData) { + _st->PutChar(aId); + _st->Write(&aData,4); + } + + void WriteSV(int aId, float aData) { + _st->PutChar(aId+20); + _st->Write(&aData,4); + } + // float in 3.13 Format void WriteSV3p13(int aId, float aData); - int16_t ReadI16() - { int16_t ret; _st->Read(&ret,2); return ret; } + int16_t ReadI16() { + int16_t ret; + _st->Read(&ret,2); + return ret; + } - int32_t ReadI32() - { int32_t ret; _st->Read(&ret,4); return ret; } - - float ReadF() - { float ret; _st->Read(&ret,4); return ret; } + int32_t ReadI32() { + int32_t ret; + _st->Read(&ret,4); + return ret; + } + + float ReadF() { + float ret; + _st->Read(&ret,4); + return ret; + } + + // reads until aTermChar is found + void ReadCString(char* aBuff, char aTermChar); }; } // namespace mbed