-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug.c
88 lines (68 loc) · 1.83 KB
/
debug.c
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
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "debug.h"
#include "error.h"
#include "chatpad.h"
#include "global.h"
//----------------------------------------------------------------------------
void spin (void)
{
#if RUN_DEBUG == 1
static int i = 0;
printf("%c\b", "|/-\\"[++i&3]);
fflush(stdout);
#endif
return;
}
//----------------------------------------------------------------------------
void dumpBuf (uint8_t* buf)
{
int i;
INFOF("{");
if (*buf) {
for (i = 1; i < *buf; i++) INFOF("%02X,", buf[i]) ;
INFOF("%02X}[%d]", buf[i], i);
} else {
INFOF("}[]");
}
return;
}
//----------------------------------------------------------------------------
// code is non-reentrant
//
char* timestamp (void)
{
static char buf[32];
int len;
int mSec;
struct tm* tm;
struct timeval tv;
gettimeofday(&tv, NULL);
mSec = (tv.tv_usec +500) /1000; // Round to nearest millisec
if (mSec >= 1000) { // In case we round up to a second
mSec -= 1000;
tv.tv_sec++;
}
tm = localtime(&tv.tv_sec);
len = strftime(buf, sizeof(buf), /*"%Y:%m:%d "*/"%H:%M:%S", tm);
if ( ((sizeof(buf) - len) - 1) >= (1 + 3))
sprintf(buf + len, ".%03d\n", mSec);
return buf;
}
//----------------------------------------------------------------------------
void showStatus (void)
{
int i = 0;
INFOF("# Status {");
for (i = 0; i < STATUSLEN -1; i++) INFOF("%02X,", g.st.status[i]) ;
INFOF("%02X}[%d]\n", g.st.status[i], i);
INFOF(" LEDs : Main : %s\n", g.st.ledMain ? "on" : "off");
INFOF(" : Shift : %s\n", g.st.ledShf ? "on" : "off");
INFOF(" : Green : %s\n", g.st.ledGrn ? "on" : "off");
INFOF(" : People : %s\n", g.st.ledPpl ? "on" : "off");
INFOF(" : Orange : %s\n", g.st.ledOrn ? "on" : "off");
return;
}