20 #include <arpa/inet.h>
132 std::cout<<
"HEADER"<<std::dec<<std::endl;
135 std::cout<<
"size"<<
":"<<2*tc.
size<<std::endl;
137 std::cout<<
"device_addresss"<<
":"<< std::hex<<(int)tc.
device_addresss<<std::endl;
141 std::cout<<
"protocol_version"<<
":"<< std::hex<<tc.
protocol_version<<std::endl;
142 std::cout<<
"status"<<
":"<<tc.
status<<std::endl;
143 std::cout<<
"scan_number"<<
":"<< std::hex<<tc.
scan_number<<std::endl;
144 std::cout<<
"telegram_number"<<
":"<< std::hex<<tc.
telegram_number<<std::endl;
148 std::cout<<
"type"<<
":"<< std::hex<<tc.
type<<std::endl;
150 case IO: std::cout<<
"type"<<
": "<<
"IO"<<std::endl;
break;
151 case DISTANCE: std::cout<<
"type"<<
": "<<
"DISTANCE"<<std::endl;
break;
152 case REFLEXION: std::cout<<
"type"<<
": "<<
"REFLEXION"<<std::endl;
break;
153 default: std::cout<<
"type"<<
": "<<
"unknown "<<tc.
type<<std::endl;
break;
155 std::cout<<std::dec<<std::endl;
159 std::cout<<
"DISTANCE"<<std::endl;
160 std::cout<<
"type"<<
":"<< std::hex<<tc.
type<<std::endl;
162 case _1: std::cout<<
"field 1"<<std::endl;
break;
163 case _2: std::cout<<
"field 2"<<std::endl;
break;
164 case _3: std::cout<<
"field 3"<<std::endl;
break;
165 case _4: std::cout<<
"field 4"<<std::endl;
break;
166 case _5: std::cout<<
"field 5"<<std::endl;
break;
167 default: std::cout<<
"unknown "<<tc.
type<<std::endl;
break;
169 std::cout<<std::dec<<std::endl;
173 std::cout<<
"TAIL"<<std::endl;
174 std::cout<<
"crc"<<
":"<< std::hex<<tc.
crc<<std::endl;
175 std::cout<<std::dec<<std::endl;
179 static unsigned int createCRC(uint8_t *ptrData,
int Size);
183 uint8_t TELEGRAM_COMMON_PATTERN_EQ[] = {0,0,0,0, 0,0, 0,0, 0xFF, 0&DEVICE_ADDR};
184 uint8_t TELEGRAM_COMMON_PATTERN_OR[] = {0,0,0,0, 0,0, 0xff,0xff, 0,0xff};
186 for(
size_t i=0; i<
sizeof(TELEGRAM_COMMON_PATTERN_EQ); i++) {
187 if(TELEGRAM_COMMON_PATTERN_EQ[i] != (tc.
bytes[i]&(~TELEGRAM_COMMON_PATTERN_OR[i])) ) {
209 bool parseHeader(
const unsigned char *buffer,
const size_t max_size,
const uint8_t DEVICE_ADDR,
const bool debug)
211 if(
sizeof(
tc1_)>max_size)
return false;
227 int full_data_size = 0;
292 if(debug) std::cout<<
"invalid header size"<<std::endl;
303 std::cout<<
"invalid CRC: "<<crc<<
" ("<<tt.
crc<<
")"<<std::endl;
308 memset(&
td_, 0,
sizeof(
td_));
313 if(debug) std::cout<<
"got distance"<<std::endl;
321 default:
return false;
343 void readDistRaw(
const unsigned char *buffer, std::vector<int> &res,
bool debug)
const
350 if (debug) std::cout <<
"Number of points: " << std::dec << num_points << std::endl;
351 for(
size_t i=0; i<num_points; ++i) {
357 res.push_back((
int)dist.
val16);