23 #ifndef DCCLTransitionalConstants20091211H 24 #define DCCLTransitionalConstants20091211H 36 #include "goby/acomms/acomms_constants.h" 37 #include "goby/acomms/dccl.h" 38 #include "goby/moos/protobuf/transitional.pb.h" 42 namespace transitional
68 POWER2_BITS_IN_BYTE = 3
70 inline unsigned bits2bytes(
unsigned bits) {
return bits >> POWER2_BITS_IN_BYTE; }
71 inline unsigned bytes2bits(
unsigned bytes) {
return bytes << POWER2_BITS_IN_BYTE; }
76 POWER2_NIBS_IN_BYTE = 1
78 inline unsigned bytes2nibs(
unsigned bytes) {
return bytes << POWER2_NIBS_IN_BYTE; }
79 inline unsigned nibs2bytes(
unsigned nibs) {
return nibs >> POWER2_NIBS_IN_BYTE; }
81 inline std::string type_to_string(
DCCLType type)
96 inline std::string type_to_protobuf_type(
DCCLType type)
107 throw(goby::acomms::DCCLException(
108 "cannot directly map DCCLv1 XML type to Protobuf Type"));
113 inline std::string type_to_string(
DCCLCppType type)
126 const unsigned DCCL_NUM_HEADER_BYTES = 6;
128 const unsigned DCCL_NUM_HEADER_PARTS = 8;
137 HEAD_MULTIMESSAGE_FLAG = 5,
138 HEAD_BROADCAST_FLAG = 6,
142 const std::string DCCL_HEADER_NAMES[] = {
143 "_ccl_id",
"_id",
"_time",
"_src_id",
"_dest_id",
"_multimessage_flag",
144 "_broadcast_flag",
"_unused",
146 inline std::string to_str(DCCLHeaderPart p) {
return DCCL_HEADER_NAMES[p]; }
150 HEAD_CCL_ID_SIZE = 8,
151 HEAD_DCCL_ID_SIZE = 9,
153 HEAD_SRC_ID_SIZE = 5,
154 HEAD_DEST_ID_SIZE = 5,
170 std::stringstream ss;
171 for (
unsigned int i = 0; i < n; i++)
172 ss << std::hex << std::setw(2) << std::setfill(
'0') <<
static_cast<unsigned int>(c[i]);
181 for (
unsigned int i = 0; i < n; i++)
183 std::stringstream ss;
185 ss << s.substr(2 * i, 2);
186 ss >> std::hex >> in;
187 c[i] =
static_cast<unsigned char>(in);
196 for (
unsigned int i = 0; i < bits; i++)
198 s[bits - i - 1] = (l & 1) ?
'1' :
'0';
202 return (std::string)s;
209 unsigned int bytes = (
unsigned int)(std::ceil(bs.length() / 8.0));
210 unsigned char c[bytes];
212 for (
size_t i = 0; i < bytes; ++i)
214 std::bitset<8> b(bs.substr(i * 8, 8));
215 c[i] = (char)b.to_ulong();
241 int bytes = bs.length() / 2;
242 unsigned char c[bytes];
248 for (
size_t i = 0; i < (size_t)bytes; i++) hs +=
long2binary_string((
unsigned long)c[i], 8);
270 std::stringstream ss;
282 template <
typename T>
bool number2hex_string(std::string& s,
const T& t,
unsigned int width = 2)
284 std::stringstream ss;
285 ss << std::hex << std::setw(width) << std::setfill('0') << static_cast<unsigned int>(t);
bool char_array2hex_string(const unsigned char *c, std::string &s, const unsigned int n)
converts a char (byte) array into a hex string
DCCLType
Enumeration of DCCL types used for sending messages. dccl_enum and dccl_string primarily map to cpp_s...
bool number2hex_string(std::string &s, const T &t, unsigned int width=2)
converts a decimal number of type T into a hex string
DCCLCppType
Enumeration of C++ types used in DCCL.
bool hex_string2char_array(unsigned char *c, const std::string &s, const unsigned int n)
turns a string of hex chars ABCDEF into a character array reading each byte 0xAB,0xCD, 0xEF, etc.
std::string binary_string2hex_string(const std::string &bs)
converts a binary string ("1000101010101010") into a hex string ("8AAA")
std::string hex_string2binary_string(const std::string &bs)
converts a boost::dynamic_bitset (similar to std::bitset but without compile time size requirements) ...
bool hex_string2number(const std::string &s, T &t)
converts a hex string ("8AAA") into a dynamic_bitset
The global namespace for the Goby project.
std::string long2binary_string(unsigned long l, unsigned short bits)
return a string represented the binary value of l for bits number of bits which reads MSB -> LSB ...