Function Generator for TINF 2021

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SvProtocol.h Source File

SvProtocol.h

00001 #ifndef SvProtocol_h
00002 #define SvProtocol_h
00003 
00004 #include "stdint.h"
00005 
00006 namespace mbed {
00007 
00008 class IStreamHL {
00009     public:
00010         virtual void PutChar(int aCh) = 0;
00011         virtual int GetChar() = 0;
00012         virtual void Write(void* aData, uint32_t aLenBytes) = 0;
00013         virtual void Read(void* aData, uint32_t aLenBytes) = 0;
00014         
00015         virtual void Flush() { }
00016 };
00017 
00018 class SvProtocol {
00019     public:
00020         IStreamHL* _st;
00021         uint8_t acqON;
00022     uint8_t svMessageON;
00023     public:
00024         SvProtocol(IStreamHL* aStrm) {
00025             acqON=0; svMessageON=1;
00026             _st=aStrm; 
00027         }
00028     
00029         // Check's first for acqOn/Off Command
00030     // ret 0 if acqOn/Off was handled in GetCommand
00031     int GetCommand();
00032         
00033         void Puts(char* aCStr); // Terminate with 0
00034 
00035     // \r\n is appended automatically
00036     void Printf(const char* format, ...);
00037 
00038     void SvPrintf(const char *format, ...);
00039     
00040     void WriteSV(int aId, char* aData) {
00041       if( !svMessageON ) return;
00042       _st->PutChar(aId); Puts(aData); 
00043     }
00044     
00045     void SvMessage(char* aTxt) {
00046       if( !svMessageON ) return;
00047       _st->PutChar(10); Puts(aTxt);
00048     }
00049     
00050     void VectHeader(int aId, int aNVals)
00051       { _st->PutChar(aId); _st->PutChar(aNVals); }
00052     
00053     void WriteSvI16(int aId, int16_t aData)
00054       { _st->PutChar(aId+10); _st->Write(&aData,2); }
00055     
00056     void WriteSvI32(int aId, int32_t aData)
00057       { _st->PutChar(aId); _st->Write(&aData,4); }
00058     
00059     void WriteSV(int aId, float aData)
00060       { _st->PutChar(aId+20); _st->Write(&aData,4); }
00061             
00062         // aLen = Anzahl g�ltiger Werte in aAry   
00063         void WriteArray(int16_t aAry[], int aLen)
00064         {
00065             _st->PutChar(100); // Id f�r array
00066             _st->PutChar(aLen); // L�nge als Byte geschrieben
00067             for(int i=0; i<aLen; i++)
00068             {
00069                 _st->Write(&(aAry[i]),2); // jeder Arrayeintrag als int16
00070             }
00071         }
00072     
00073     // float in 3.13 Format
00074     void WriteSV3p13(int aId, float aData);
00075 
00076     int16_t ReadI16()
00077       { int16_t ret; _st->Read(&ret,2); return ret; }
00078 
00079     int32_t ReadI32()
00080       { int32_t ret; _st->Read(&ret,4); return ret; }
00081     
00082     float ReadF()
00083       { float ret; _st->Read(&ret,4); return ret; }
00084 };
00085 
00086 } // namespace mbed
00087 
00088 // SV-Id Ranges and DataTypes for SvVis3 Visualisation-Tool
00089 //----------------------------------------------------------
00090 // Id = 10       : string
00091 // Id = 1 .. 9   : format 3.13  2 Bytes
00092 // Id = 11 .. 20 : short        2 Bytes
00093 // Id = 21 .. 30 : float        4 Bytes
00094 // Id = 100      : int16-Array
00095 
00096 #endif
00097 
00098