BayEOS-Arduino  1.8.0_0.0.4
BayDebug.cpp
1 #include "BayDebug.h"
2 
3 void BayEOSDebugInterface::parseDataFrame(uint8_t offset){
4  if(getPayload(offset)!=BayEOS_DataFrame){
5  println("No DF:");
6  return;
7  }
8  offset++;
9  uint8_t data_type=(getPayload(offset) & BayEOS_DATATYP_MASK);
10  uint8_t channel_type=(getPayload(offset) & BayEOS_OFFSETTYP_MASK);
11  uint8_t channel=0;
12 
13  println("Data:");
14  if(channel_type==0x0){
15  offset++;
16  channel=getPayload(offset);
17  }
18  offset++;
19 
20 
21  while(offset<getPacketLength()-_checksum){
22  if (channel_type == BayEOS_ChannelLabel) {
23  channel=getPayload(offset)+offset+1;//this is actually the end of the channel label
24  offset++;
25  while(offset<(getPacketLength()-_checksum) && offset<channel){
26  print((char) getPayload(offset));
27  offset++;
28  }
29  } else {
30  if (channel_type == BayEOS_ChannelNumber) {
31 
32  channel = getPayload(offset);
33  offset++;
34  } else
35  channel++;
36  print("CH");
37  print(channel);
38  }
39  print(":");
40  switch(data_type){
41  case 0x1:
42  print(*(float*) (getPayload()+offset));
43  offset+=4;
44  break;
45  case 0x2:
46  print(*(long*) (getPayload()+offset));
47  offset+=4;
48  break;
49  case 0x3:
50  print(*(int*) (getPayload()+offset));
51  offset+=2;
52  break;
53  case 0x4:
54  print(*(uint8_t*) (getPayload()+offset));
55  offset++;
56  break;
57  }
58  println();
59  }
60  return;
61 }
62 
63 void BayEOSDebugInterface::parse(uint8_t offset){
64  uint16_t checksum;
65  uint8_t current_offset;
66 
67 // print(" ");
68  switch(getPayload(offset)){
69  case BayEOS_DataFrame:
70  parseDataFrame(offset);
71  break;
72  case BayEOS_RoutedFrame:
73  print("RF: MY:");
74  print(*(uint16_t*) (getPayload()+offset+1));
75  print(" PAN:");
76  println(*(uint16_t*) (getPayload()+offset+3));
77  parse(offset+5);
78  break;
79  case BayEOS_RoutedFrameRSSI:
80  print("RF: MY:");
81  print(*(uint16_t*) (getPayload()+offset+1));
82  print(" PAN:");
83  print(*(uint16_t*) (getPayload()+offset+3));
84  print(" RSSI:");
85  println(*(uint8_t*) (getPayload()+offset+5));
86  parse(offset+6);
87  break;
88  case BayEOS_OriginFrame:
89  case BayEOS_RoutedOriginFrame:
90  if(getPayload(offset)==BayEOS_RoutedOriginFrame) print('R');
91  print("OF:");
92  offset++;
93  current_offset=getPayload(offset);
94  offset++;
95  while(current_offset>0){
96  print((char) getPayload(offset));
97  offset++;
98  current_offset--;
99  }
100  println();
101  parse(offset);
102  break;
103  case BayEOS_DelayedFrame:
104  print("DF: Delay:");
105  println(*(unsigned long*) (getPayload()+offset+1));
106  parse(offset+5);
107  break;
108  case BayEOS_TimestampFrame:
109  print("TF: TS:");
110  println(*(unsigned long*) (getPayload()+offset+1));
111  parse(offset+5);
112  break;
113  case BayEOS_ErrorMessage:
114  print("EM: ");
115  offset++;
116  while(offset<getPacketLength()-_checksum){
117  print((char) getPayload(offset));
118  offset++;
119  }
120  println();
121  break;
122  case BayEOS_Message:
123  print("M: ");
124  offset++;
125  while(offset<getPacketLength()-_checksum){
126  print((char) getPayload(offset));
127  offset++;
128  }
129  println();
130  break;
131  case BayEOS_ChecksumFrame:
132  checksum=0;
133  current_offset=offset;
134  while(current_offset<getPacketLength()-2){
135  checksum+=getPayload(current_offset);
136  current_offset++;
137  }
138  checksum+=*(uint16_t*)(getPayload()+current_offset);
139  print("C:");
140  if(checksum==0xffff) print( "OK");
141  else print( "ERR");
142  println();
143  offset++;
144  _checksum=2;
145  parse(offset);
146  break;
147  default:
148  print("U: ");
149  print(getPayload(offset),HEX);
150  print(" ");
151  offset++;
152  while(offset<getPacketLength()-_checksum){
153  print(getPayload(offset),HEX);
154  print(":");
155  offset++;
156  }
157  println();
158 
159  }
160 
161 }
162 
164  _checksum=0;
165  if(_modus & 0x1 ==0){
166  print("Payload: ");
167  for(uint8_t i=0;i<getPacketLength();i++){
168  print(getPayload(i),HEX);
169  }
170  } else {
171  parse();
172 
173  }
174  println();
175  if(_modus & 0x2) _error_next=!_error_next;
176  return(_error_next);
177 }
178 
179 
180 void BayDebug::begin(long baud, uint8_t modus){
181  _serial->begin(baud);
182  _modus=modus;
183 }
184 
185 BayDebug::BayDebug(HardwareSerial &serial){
186  _serial = &serial;
187 }
188 int BayDebug::available(void){
189  return _serial->available();
190 }
191 int BayDebug::read(void){
192  return _serial->read();
193 }
194 size_t BayDebug::write(uint8_t b){
195  return _serial->write(b);
196 }
197 int BayDebug::peek(void){
198  return _serial->peek();
199 };
200 void BayDebug::flush(void){
201  _serial->flush();
202 };
203 
204 
const uint8_t * getPayload(void) const
Definition: BayEOS.cpp:399
uint8_t getPacketLength(void) const
Definition: BayEOS.cpp:395
void begin(long baud, uint8_t modus=3)
Definition: BayDebug.cpp:180
uint8_t sendPayload(void)
Definition: BayDebug.cpp:163
BayDebug(HardwareSerial &serial)
Definition: BayDebug.cpp:185