20 #include <arpa/inet.h> 89 unsigned distance : 13;
91 unsigned protective : 1;
92 unsigned warn_field : 1;
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])) ) {
204 size_field_start_byte_(0),
205 crc_bytes_in_size_(0),
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;
214 if(!
check(tc1_, DEVICE_ADDR)) {
220 if(debug)
print(tc1_);
227 int full_data_size = 0;
240 size_field_start_byte_ = 4;
241 crc_bytes_in_size_ = 2;
260 size_field_start_byte_ = 8;
261 crc_bytes_in_size_ = 2;
276 size_field_start_byte_ = 12;
277 crc_bytes_in_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);
static bool check(const TELEGRAM_COMMON1 &tc, const uint8_t DEVICE_ADDR)
static void ntoh(TELEGRAM_COMMON2 &tc)
static void ntoh(TELEGRAM_COMMON1 &tc)
static void print(const TELEGRAM_COMMON3 &tc)
static void print(const TELEGRAM_DISTANCE &tc)
static void print(const TELEGRAM_TAIL &tc)
static unsigned int createCRC(uint8_t *ptrData, int Size)
uint8_t coordination_flag
static void ntoh(TELEGRAM_DISTANCE &tc)
uint16_t protocol_version
static void ntoh(TELEGRAM_COMMON3 &tc)
static void ntoh(TELEGRAM_TAIL &tc)
void readDistRaw(const unsigned char *buffer, std::vector< int > &res, bool debug) const
static void print(const TELEGRAM_COMMON1 &tc)
bool parseHeader(const unsigned char *buffer, const size_t max_size, const uint8_t DEVICE_ADDR, const bool debug)
int size_field_start_byte_
static void print(const TELEGRAM_COMMON2 &tc)
int getCompletePacketSize() const