-
Notifications
You must be signed in to change notification settings - Fork 0
/
SerLog.cpp
327 lines (233 loc) · 5.94 KB
/
SerLog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#include "predef.h"
#include <ctype.h>
#include <basictypes.h>
#include <system.h>
#include <constants.h>
#include <ucos.h>
#include <ucosmcfc.h>
#include <serialirq.h>
#include <stdio.h>
#include <smarttrap.h>
#include <serialupdate.h>
#include <string.h>
#include <Pins.h>
#include <sim.h>
#include <cfinter.h>
#include <iointernals.h>
#include "car.h"
#include "gps.h"
#include "imu.h"
#include "dsm2_sub.h"
#include "log.h"
#include "sensor_config.h"
#include "filereporter.h"
#include "nav.h"
#include "mytrap.h"
void IRQ_WriteCharNoBlock( int portnum, char c );
volatile DWORD LogPagesWritten;
typedef enum tNames
{
tu8=1,
ti8=2,
tu16=3,
ti16=4,
tu32=5,
ti32=6,
tpu8=7,
tpi8=8,
tf32=9,
td64=10
};
//Log Descriptor Type...
#define LOG_TYPE_STRUCT (1)
#define LOG_TYPE_ITEM (2)
#define MSG_TYPE (0x11)
OS_CRIT LogShiftCrit;
#define LOG_REC_START (0xEB)
#define LOG_REC_END (0xEE)
#define LOG_REC_ESC (0xEC)
#define LOG_REC_TICK (0xED)
static BOOL bBlock;
volatile DWORD LogCount;
char hexnib(BYTE b)
{
b=b&0x0F;
if (b<10) return b+'0';
return b+'A'-10;
}
void PutRawByte(BYTE b)
{
//IRQ_writechar(LOG_UART,hexnib(b>>4));
//IRQ_writechar(LOG_UART,hexnib(b &0x0f));
// iprintf("%c",b);
// iprintf("%02X",b);
//if(bBlock)
IRQ_writechar(LOG_UART,b);
//else
//IRQ_WriteCharNoBlock(LOG_UART,b);
LogCount++;
}
void PutEscapedByte(BYTE b)
{
if(b==LOG_REC_START) {PutRawByte(LOG_REC_ESC); PutRawByte(0); }
else
if(b==LOG_REC_ESC) {PutRawByte(LOG_REC_ESC); PutRawByte(1); }
else
if(b==LOG_REC_END) {PutRawByte(LOG_REC_ESC); PutRawByte(2); }
else
if(b==LOG_REC_TICK) {PutRawByte(LOG_REC_ESC); PutRawByte(3); }
else
if(b==0x11) {PutRawByte(LOG_REC_ESC); PutRawByte(4); }
else
if(b==0x13) {PutRawByte(LOG_REC_ESC); PutRawByte(5); }
else
PutRawByte(b);
}
inline void StartLogRecord() { PutRawByte(LOG_REC_START); }
inline void EndLogRecord() { PutRawByte(LOG_REC_END); }
void LogRawRecord(BYTE msg, const unsigned char * data, int len)
{
BYTE bs=(msg);
StartLogRecord();
PutRawByte(msg);
for(int i=0; i<len; i++)
{
bs+=data[i];
PutEscapedByte(((PBYTE)data)[i]);
}
EndLogRecord();
PutEscapedByte(bs);
}
void StartItemIntro(BYTE id, int siz, const char * name)
{
PutRawByte(LOG_REC_START);
PutRawByte(LOG_TYPE_STRUCT);
BYTE bs=LOG_TYPE_STRUCT;
PutRawByte(id);
bs+=id;
PutEscapedByte((BYTE)(siz>>8)&0xFF);
bs+=(BYTE)(siz>>8)&0xFF;
PutEscapedByte((BYTE)(siz&0xFF));
bs+=(BYTE)(siz&0xFF);
while(*name)
{bs+=*name;
PutEscapedByte(*name++);
}
PutRawByte(LOG_REC_END);
PutEscapedByte(bs);
}
//Log the base element of a structure */
void ShowBaseElement(BYTE id,PBYTE p1, PBYTE p2,int siz, enum tNames tn, const char * el_name)
{
//iprintf("Offset : %d size :%d type %d name %s\r\n",(p2-p1),siz,tn ,el_name);
int offset=(p2-p1);
PutRawByte(LOG_REC_START);
PutRawByte(LOG_TYPE_ITEM );
BYTE bs=LOG_TYPE_ITEM;
PutEscapedByte((BYTE)id);
bs+=id;
PutEscapedByte((BYTE)tn);
bs+=tn;
PutEscapedByte((BYTE)(siz>>8)&0xFF);
bs+=(BYTE)(siz>>8)&0xFF;
PutEscapedByte((BYTE)(siz&0xFF));
bs+=(BYTE)(siz&0xFF);
PutEscapedByte((BYTE)(offset>>8)&0xFF);
bs+=(BYTE)(offset>>8)&0xFF;
PutEscapedByte((BYTE)(offset&0xFF));
bs+=(BYTE)(offset&0xFF);
while(*el_name)
{
bs+=*el_name;
PutEscapedByte(*el_name++);
}
PutRawByte(LOG_REC_END);
PutEscapedByte(bs);
}
//Generic message class...
void LogMessage(const char * msg)
{
LogRawRecord(MSG_TYPE,( const unsigned char * )msg,strlen(msg));
}
inline static void ShowElement(BYTE id,void * vp,void * vp2, short el,const char * name)
{
ShowBaseElement(id,(PBYTE)vp,(PBYTE)vp2,sizeof(el),ti16,name);
}
inline static void ShowElement(BYTE id,void * vp,void * vp2, int el,const char * name)
{
ShowBaseElement(id,(PBYTE)vp,(PBYTE)vp2,sizeof(el),ti32,name);
}
inline static void ShowElement(BYTE id,void * vp,void * vp2, long el,const char * name)
{
ShowBaseElement(id,(PBYTE)vp,(PBYTE)vp2,sizeof(el),ti32,name);
}
inline static void ShowElement(BYTE id,void * vp,void * vp2, unsigned short el,const char * name)
{
ShowBaseElement(id,(PBYTE)vp,(PBYTE)vp2,sizeof(el),tu16,name);
}
inline static void ShowElement(BYTE id,void * vp,void * vp2, unsigned long el,const char * name)
{
ShowBaseElement(id,(PBYTE)vp,(PBYTE)vp2,sizeof(el),tu32,name);
}
inline static void ShowElement(BYTE id,void * vp,void * vp2, char el,const char * name)
{
ShowBaseElement(id,(PBYTE)vp,(PBYTE)vp2,sizeof(el),ti8,name);
}
inline static void ShowElement(BYTE id,void * vp,void * vp2, unsigned char el,const char * name)
{
ShowBaseElement(id,(PBYTE)vp,(PBYTE)vp2,sizeof(el),tu8,name);
}
inline static void ShowElement(BYTE id,void * vp,void * vp2, float el,const char * name)
{
ShowBaseElement(id,(PBYTE)vp,(PBYTE)vp2,sizeof(el),tf32,name);
}
inline static void ShowElement(BYTE id,void * vp,void * vp2, double el,const char * name)
{
ShowBaseElement(id,(PBYTE)vp,(PBYTE)vp2,sizeof(el),td64,name);
}
/*
inline static void ShowElement(BYTE id,void * vp,void * vp2, char * el,const char * name)
{
ShowBaseElement(id,(PBYTE)vp,(PBYTE)vp2,sizeof(el),tpi8,name);
}
inline static void ShowElement(BYTE id,void * vp,void * vp2, unsigned char * el,const char * name)
{
ShowBaseElement(id,(PBYTE)vp,(PBYTE)vp2,sizeof(el),tpu8,name);
}
*/
int null_stdio_close(int fd)
{
IoExpands[fd].read = NULL;
IoExpands[fd].write = NULL;
IoExpands[fd].close = NULL;
return 0;
}
int null_stdio_read(int fd, char *buf, int nbytes)
{
return 0;
}
int null_stdio_write(int fd, const char *buf, int nbytes)
{
return nbytes;
}
void DumpRecords();
void InitLog()
{
IoExpands[0].extra = 0;
IoExpands[0].read = null_stdio_read;
IoExpands[0].write = null_stdio_write;
IoExpands[0].close = null_stdio_close;
IoExpands[1].extra = 0;
IoExpands[1].read = null_stdio_read;
IoExpands[1].write = null_stdio_write;
IoExpands[1].close = null_stdio_close;
SimpleUart(LOG_UART,115200);
writestring(LOG_UART,"Starting log\r\n");
bBlock=true;
DumpRecords();
bBlock=false;
}
void LogServiceTask()
{
};
#include "logcore.cpp"