Critical Link MityCam SoC Firmware  1.0
Critical Link MityCam SoC Firmware
DspParserBase.h
Go to the documentation of this file.
1 #ifndef tcDspParserBase_H
2 #define tcDspParserBase_H
3 
4 // This allows the parser to be used on a Windows(tm) platform
5 #ifdef WIN32
6 #define WIN32_LEAN_AND_MEAN
7 #ifndef STRICT
8 #define STRICT 1
9 #endif
10 
11 #include <windows.h>
12 
13 #ifndef INIT_CRITICAL
14 #define INIT_CRITICAL(sema) InitializeCriticalSection(&(sema))
15 #endif
16 #ifndef DEL_CRITICAL
17 #define DEL_CRITICAL(sema) DeleteCriticalSection(&(sema))
18 #endif
19 #ifndef ENTER_CRITICAL
20 #define ENTER_CRITICAL(sema) EnterCriticalSection(&(sema))
21 #endif
22 #ifndef LEAVE_CRITICAL
23 #define LEAVE_CRITICAL(sema) LeaveCriticalSection(&(sema))
24 #endif
25 typedef CRITICAL_SECTION C_SECT;
26 
27 // Otherwise, assume this is the MityDSP itself
28 #elif defined(MITYDSP)
29 
30 #include <std.h>
31 #include <sem.h>
32 
33 #ifndef INIT_CRITICAL
34 #define INIT_CRITICAL(sema) ((sema) = SEM_create(1, NULL))
35 #endif
36 #ifndef DEL_CRITICAL
37 #define DEL_CRITICAL(sema) (SEM_delete(sema))
38 #endif
39 #ifndef ENTER_CRITICAL
40 #define ENTER_CRITICAL(sema) (SEM_pend((sema), SYS_FOREVER))
41 #endif
42 #ifndef LEAVE_CRITICAL
43 #define LEAVE_CRITICAL(sema) (SEM_post(sema))
44 #endif
45 typedef SEM_Handle C_SECT;
46 
47 #else
48 
49 #ifndef INIT_CRITICAL
50 #define INIT_CRITICAL(sema)
51 #endif
52 #ifndef DEL_CRITICAL
53 #define DEL_CRITICAL(sema)
54 #endif
55 #ifndef ENTER_CRITICAL
56 #define ENTER_CRITICAL(sema)
57 #endif
58 #ifndef LEAVE_CRITICAL
59 #define LEAVE_CRITICAL(sema)
60 #endif
61 typedef int C_SECT;
62 
63 #include <stdlib.h>
64 #include <stdio.h>
65 
66 #endif
67 
68 // Common code belongs in the MityDSP namespace
69 namespace SocCamera
70 {
71 
79 {
80 public:
81 
83  typedef enum
84  {
85  eeParseOK = 0,
90  eeBaseLast = -5
93 
104  typedef bool (*tfParserCallback)(int, void *, int, unsigned int,
105  void *);
106 
107  // constructors and destructors
108  tcDspParserBase(char *apOutBuf = NULL, int anOutBufLen = 4096);
109  virtual ~tcDspParserBase();
110 
111  // class-wide external methods
112 
113  // per-object external methods
114  virtual bool ResetParser(char *apOutBuf = NULL, int anOutBufLen = 0);
115  virtual int AddData(void *apData, int anLength);
116  virtual void RegisterCallback(tfParserCallback afCallback,
117  void *apUser = NULL);
118 
119  // class-wide externally visible attributes
120 
121  // per-object externally visible attributes
122  unsigned int mnBytesRead;
123  unsigned int mnBytesWritten;
124  unsigned int mnGoodMsgs;
125  unsigned int mnBadMsgs;
126  unsigned int mnSyncErrs;
127  unsigned int mnChecksumErrs;
128 
129 protected:
130 
131  // class-wide internal methods
132 
133  // per-object internal methods
134  int AssembleLine(void *apInput, int anLength, bool &arLineComplete);
135  char AsciiHexDigitVal(char anHexdigit);
136 
137  // class-wide internal attributes
138 
139  // per-object internal attributes
143  char *mpOutBuf;
145  unsigned int mnChecksum;
146  char *maLineBuffer;
147  int mnLineBufLen;
149  int mnLinePos;
151 };
152 
153 } // end of MityDSP namespace
154 
155 #endif
156 
SocCamera::tcDspParserBase::eeParseSyncErr
@ eeParseSyncErr
data sync error
Definition: DspParserBase.h:87
SocCamera::tcDspParserBase::mnBadMsgs
unsigned int mnBadMsgs
Count of bad messages.
Definition: DspParserBase.h:125
SocCamera::tcDspParserBase::mnOutBufLen
int mnOutBufLen
Current bytes written to output.
Definition: DspParserBase.h:144
SocCamera::tcDspParserBase::ResetParser
virtual bool ResetParser(char *apOutBuf=NULL, int anOutBufLen=0)
Definition: DspParserBase.cpp:94
SocCamera::tcDspParserBase::eeParseTooBigErr
@ eeParseTooBigErr
result too big for output buffer
Definition: DspParserBase.h:89
SocCamera::tcDspParserBase::eeParseChecksumErr
@ eeParseChecksumErr
checksum failure
Definition: DspParserBase.h:86
SocCamera::tcDspParserBase
Definition: DspParserBase.h:78
SocCamera::tcDspParserBase::eeParseBustedMsg
@ eeParseBustedMsg
broken message (missing data)
Definition: DspParserBase.h:88
SocCamera::tcDspParserBase::mnLineBufLen
int mnLineBufLen
Length of line buffer.
Definition: DspParserBase.h:148
SocCamera::tcDspParserBase::AddData
virtual int AddData(void *apData, int anLength)
Definition: DspParserBase.cpp:184
SocCamera::tcDspParserBase::eeParseOK
@ eeParseOK
success
Definition: DspParserBase.h:85
SocCamera::tcDspParserBase::tfParserCallback
bool(* tfParserCallback)(int, void *, int, unsigned int, void *)
Definition: DspParserBase.h:104
SocCamera::tcDspParserBase::mpOutBuf
char * mpOutBuf
Pointer to output storage.
Definition: DspParserBase.h:143
SocCamera::tcDspParserBase::mnLinePos
int mnLinePos
Working position in the line buffer.
Definition: DspParserBase.h:149
SocCamera::tcDspParserBase::mnBytesWritten
unsigned int mnBytesWritten
Bytes written to buffer.
Definition: DspParserBase.h:123
SocCamera::tcDspParserBase::mnBytesRead
unsigned int mnBytesRead
Bytes passed to parser.
Definition: DspParserBase.h:122
SocCamera::tcDspParserBase::mpUserParameter
void * mpUserParameter
User-provided parameter to callback.
Definition: DspParserBase.h:150
SocCamera::tcDspParserBase::eeBaseLast
@ eeBaseLast
base class
Definition: DspParserBase.h:90
SocCamera::tcDspParserBase::AsciiHexDigitVal
char AsciiHexDigitVal(char anHexdigit)
Definition: DspParserBase.cpp:334
SocCamera
Definition: CameraTypes.h:7
SocCamera::tcDspParserBase::RegisterCallback
virtual void RegisterCallback(tfParserCallback afCallback, void *apUser=NULL)
Definition: DspParserBase.cpp:242
SocCamera::tcDspParserBase::~tcDspParserBase
virtual ~tcDspParserBase()
Definition: DspParserBase.cpp:74
SocCamera::tcDspParserBase::tcDspParserBase
tcDspParserBase(char *apOutBuf=NULL, int anOutBufLen=4096)
Definition: DspParserBase.cpp:41
SocCamera::tcDspParserBase::mbStorageCreated
bool mbStorageCreated
Indicates whether out buf created.
Definition: DspParserBase.h:142
SocCamera::tcDspParserBase::mhMutex
C_SECT mhMutex
Semaphore to serialize access.
Definition: DspParserBase.h:141
SocCamera::tcDspParserBase::maLineBuffer
char * maLineBuffer
(or other entities) to parse.
Definition: DspParserBase.h:146
SocCamera::tcDspParserBase::mnChecksumErrs
unsigned int mnChecksumErrs
Number of checksum errors.
Definition: DspParserBase.h:127
SocCamera::tcDspParserBase::mnGoodMsgs
unsigned int mnGoodMsgs
Count of valid messages decoded.
Definition: DspParserBase.h:124
SocCamera::tcDspParserBase::mnChecksum
unsigned int mnChecksum
Storage to accumulate checksum.
Definition: DspParserBase.h:145
SocCamera::tcDspParserBase::teDspParseStatus
teDspParseStatus
possible return status'
Definition: DspParserBase.h:83
C_SECT
int C_SECT
Definition: DspParserBase.h:61
SocCamera::tcDspParserBase::mnSyncErrs
unsigned int mnSyncErrs
Number of synchronization errors.
Definition: DspParserBase.h:126
SocCamera::tcDspParserBase::AssembleLine
int AssembleLine(void *apInput, int anLength, bool &arLineComplete)
Definition: DspParserBase.cpp:264
SocCamera::tcDspParserBase::mfCallback
tfParserCallback mfCallback
Storage for parser callback.
Definition: DspParserBase.h:140