forked from triffid/FiveD_on_Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsermsg.c
103 lines (86 loc) · 1.8 KB
/
sermsg.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "sermsg.h"
#include "serial.h"
void serwrite_hex4(uint8_t v) {
v &= 0xF;
if (v < 10)
serial_writechar('0' + v);
else
serial_writechar('A' - 10 + v);
}
void serwrite_hex8(uint8_t v) {
serwrite_hex4(v >> 4);
serwrite_hex4(v & 0x0F);
}
void serwrite_hex16(uint16_t v) {
serwrite_hex8(v >> 8);
serwrite_hex8(v & 0xFF);
}
void serwrite_hex32(uint32_t v) {
serwrite_hex8(v >> 16);
serwrite_hex8(v & 0xFFFF);
}
void serwrite_uint32(uint32_t v) {
uint8_t t = 0;
if (v >= 1000000000) {
for (t = 0; v >= 1000000000; v -= 1000000000, t++);
serial_writechar(t + '0');
}
if (v >= 100000000) {
for (t = 0; v >= 100000000; v -= 100000000, t++);
serial_writechar(t + '0');
}
else if (t != 0)
serial_writechar('0');
if (v >= 10000000) {
for (t = 0; v >= 10000000; v -= 10000000, t++);
serial_writechar(t + '0');
}
else if (t != 0)
serial_writechar('0');
if (v >= 1000000) {
for (t = 0; v >= 1000000; v -= 1000000, t++);
serial_writechar(t + '0');
}
else if (t != 0)
serial_writechar('0');
if (v >= 100000) {
for (t = 0; v >= 100000; v -= 100000, t++);
serial_writechar(t + '0');
}
else if (t != 0)
serial_writechar('0');
if (v >= 10000) {
for (t = 0; v >= 10000; v -= 10000, t++);
serial_writechar(t + '0');
}
else if (t != 0)
serial_writechar('0');
if (v >= 1000) {
for (t = 0; v >= 1000; v -= 1000, t++);
serial_writechar(t + '0');
}
else if (t != 0)
serial_writechar('0');
if (v >= 100) {
t = v / 100;
serial_writechar(t + '0');
v -= (t * 100);
}
else if (t != 0)
serial_writechar('0');
if (v >= 10) {
t = v / 10;
serial_writechar(t + '0');
v -= (t * 10);
}
else if (t != 0)
serial_writechar('0');
serial_writechar(v + '0');
}
void serwrite_int32(int32_t v) {
if (v < 0) {
serial_writechar('-');
v = -v;
}
serwrite_uint32(v);
}