.. _program_listing_file__tmp_ws_src_sicks300_2_include_common_TelegramS300.h: Program Listing for File TelegramS300.h ======================================= |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/sicks300_2/include/common/TelegramS300.h``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include /* * S300 header format in continuous mode: * * | 00 00 00 00 | 4 byte reply header * | 00 00 | data block number (fixed for continuous output) * | xx xx | size of data telegram in 16-bit data words * | FF xx | coordination flag and device address (07 in most cases, but 08 for slave configured scanners) * | xx xx | protocol version (02 01 for old protocol,.otherwise 03 01) * | 0x 00 | status: 00 00 = normal, 01 00 = lockout * | xx xx xx xx | scan number (time stamp) * | xx xx | telegram number * | BB BB | ID of output (AAAA=I/O, BBBB=range measruements, CCCC=reflector measurements) * | 11 11 | number of configures measurement field (1111, 2222, 3333, 4444 or 5555) * ... data * | xx xx | CRC * * in this parser, user_data_ denotes all but the first 20 bytes (up to and including telegram number above) * and the last two bytes (CRC) * */ class TelegramParser { #pragma pack(push,1) union TELEGRAM_COMMON1 { struct { uint32_t reply_telegram; uint16_t trigger_result; uint16_t size; // in 16bit=2byte words uint8_t coordination_flag; uint8_t device_addresss; }; uint8_t bytes[10]; }; union TELEGRAM_COMMON2 { struct { uint16_t protocol_version; uint16_t status; uint32_t scan_number; uint16_t telegram_number; }; uint8_t bytes[10]; }; union TELEGRAM_COMMON3 { struct { uint16_t type; }; uint8_t bytes[2]; }; union TELEGRAM_DISTANCE { struct { uint16_t type; }; uint8_t bytes[2]; }; union TELEGRAM_TAIL { struct { uint16_t crc; }; uint8_t bytes[2]; }; union TELEGRAM_S300_DIST_2B { struct { unsigned distance : 13; //cm unsigned bit13 : 1; //reflector or scanner distorted unsigned protective : 1; unsigned warn_field : 1; }; uint16_t val16; uint8_t bytes[2]; }; #pragma pack(pop) enum TELEGRAM_COMMON_HS {JUNK_SIZE=4}; enum TELEGRAM_COMMON_TYPES {IO=0xAAAA, DISTANCE=0xBBBB, REFLEXION=0xCCCC}; enum TELEGRAM_DIST_SECTOR {_1=0x1111, _2=0x2222, _3=0x3333, _4=0x4444, _5=0x5555}; static void ntoh(TELEGRAM_COMMON1 &tc) { tc.reply_telegram = ntohl(tc.reply_telegram); tc.trigger_result = ntohs(tc.trigger_result); tc.size = ntohs(tc.size); } static void ntoh(TELEGRAM_COMMON2 &tc) { tc.protocol_version = ntohs(tc.protocol_version); tc.status = ntohs(tc.status); tc.scan_number = ntohl(tc.scan_number); tc.telegram_number = ntohs(tc.telegram_number); } static void ntoh(TELEGRAM_COMMON3 &tc) { tc.type = ntohs(tc.type); } static void ntoh(TELEGRAM_DISTANCE &tc) { tc.type = ntohs(tc.type); } static void ntoh(TELEGRAM_TAIL &tc) { //crc calc. is also in network order //tc.crc = ntohs(tc.crc); } static void print(const TELEGRAM_COMMON1 &tc) { std::cout<<"HEADER"<max_size) return false; tc1_ = *((TELEGRAM_COMMON1*)buffer); if(!check(tc1_, DEVICE_ADDR)) { //if(debug) std::cout<<"basic check failed"< (int)max_size) { if(debug) std::cout<<"invalid header size"< &res, bool debug) const { res.clear(); if(!isDist()) return; size_t num_points = (user_data_size_ - sizeof(TELEGRAM_COMMON3) - sizeof(TELEGRAM_DISTANCE)) / sizeof(TELEGRAM_S300_DIST_2B); if (debug) std::cout << "Number of points: " << std::dec << num_points << std::endl; for(size_t i=0; i