-
Notifications
You must be signed in to change notification settings - Fork 40
/
ptpdebug.cpp
133 lines (116 loc) · 3.05 KB
/
ptpdebug.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
/* Copyright (C) 2010-2011 Circuits At Home, LTD. All rights reserved.
This software may be distributed and modified under the terms of the GNU
General Public License version 2 (GPL2) as published by the Free Software
Foundation and appearing in the file GPL2.TXT included in the packaging of
this file. Please note that GPL2 Section 2[b] requires that all works based
on this software must also be made publicly available under the terms of
the GPL2 ("Copyleft").
Contact information
-------------------
Circuits At Home, LTD
Web : http://www.circuitsathome.com
e-mail : [email protected]
*/
#include "ptpdebug.h"
void HexDump::Parse(const uint16_t len, const uint8_t *pbuf, const uint32_t &offset)
{
for (uint16_t j=0; j<len; j++, byteCount++, byteTotal++)
{
if (!byteCount)
{
PrintHex<uint16_t>(byteTotal);
Serial.print(": ");
}
PrintHex<uint8_t>(pbuf[j]);
Serial.print(" ");
if (byteCount == 15)
{
Serial.println("");
byteCount = 0xFF;
}
}
}
void EOSEventDump::Parse(const uint16_t len, const uint8_t *pbuf, const uint32_t &offset)
{
uint8_t *p = (uint8_t*)pbuf;
uint16_t cntdn = (uint16_t)len;
switch (parseStage)
{
case 0:
// Get PTP data packet size
ptppktSize = *((uint32_t*)p);
// Return if the packet has only one empty record
if (ptppktSize == 0x14)
return;
Serial.println("\r\n");
for (uint8_t i=0; i<4; i++)
{
PrintHex<uint8_t>(((uint8_t*)&ptppktSize)[i]);
Serial.print(" ");
}
// Skip PTP packet header
p += 12;
cntdn -= 12;
parseStage ++;
case 1:
parseSubstage = 0;
parseStage ++;
case 2:
while (1)
{
switch (parseSubstage)
{
// CR after each event record
case 0:
Serial.println("");
valueParser.Initialize(&valueBuffer);
parseSubstage ++;
// Parse record size value
case 1:
//Serial.println("1");
if (!valueParser.Parse(&p, &cntdn))
return;
recordSize = (uint32_t)theBuffer;
for (uint8_t i=0; i<4; i++)
{
PrintHex<uint8_t>(((uint8_t*)&theBuffer)[i]);
Serial.print(" ");
}
recordSize -= 4;
valueParser.Initialize(&valueBuffer);
parseSubstage ++;
// Parse the first uint32_t value
case 2:
//Serial.println("2");
if (!valueParser.Parse(&p, &cntdn))
return;
for (uint8_t i=0; i<4; i++)
{
PrintHex<uint8_t>(((uint8_t*)&theBuffer)[i]);
Serial.print(" ");
}
recordSize -= 4;
// Return if empty(last) record
if (recordSize == 0x08 && (uint32_t)theBuffer == 0)
{
parseSubstage = 0;
parseStage = 0;
return;
}
parseSubstage ++;
// Print the rest of the record
case 3:
//Serial.println("3");
for (; recordSize && cntdn; recordSize--, cntdn--, p++)
{
PrintHex<uint8_t>(*p);
Serial.print(" ");
}
if (!recordSize)
parseSubstage = 0;
if (!cntdn)
return;
} // switch (parseSubstage)
} // while(1)
} // switch (parseStage)
}