Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_Frsky_Telem/AP_Frsky_MAVlite_Message.cpp
Views: 1798
#include "AP_Frsky_MAVlite_Message.h"12#include <AP_Math/AP_Math.h>34#if HAL_WITH_FRSKY_TELEM_BIDIRECTIONAL5bool AP_Frsky_MAVlite_Message::get_bytes(uint8_t *bytes, const uint8_t offset, const uint8_t count) const6{7if (offset + count > MAVLITE_MAX_PAYLOAD_LEN) {8return false;9}10memcpy(bytes, &payload[offset], count);11return true;12}1314bool AP_Frsky_MAVlite_Message::set_bytes(const uint8_t *bytes, const uint8_t offset, const uint8_t count)15{16if (offset + count > MAVLITE_MAX_PAYLOAD_LEN) {17return false;18}19memcpy(&payload[offset], bytes, count);20len += count;21return true;22}2324bool AP_Frsky_MAVlite_Message::get_string(char* value, const uint8_t offset) const25{26if (get_bytes((uint8_t*)value, offset, MIN((uint8_t)16, len - offset))) {27value[MIN((uint8_t)16, len - offset)] = 0x00; // terminator28return true;29}30return false;31}3233bool AP_Frsky_MAVlite_Message::set_string(const char* value, const uint8_t offset)34{35return set_bytes((uint8_t*)value, offset, MIN((uint8_t)16, strlen(value)));36}373839uint8_t AP_Frsky_MAVlite_Message::bit8_unpack(const uint8_t value, const uint8_t bit_count, const uint8_t bit_offset)40{41uint8_t mask = 0;42for (uint8_t i=bit_offset; i<=bit_count; i++) {43mask |= 1 << i;44}45return (value & mask) >> bit_offset;46}4748void AP_Frsky_MAVlite_Message::bit8_pack(uint8_t &value, const uint8_t bit_value, const uint8_t bit_count, const uint8_t bit_offset)49{50uint8_t mask = 0;51for (uint8_t i=bit_offset; i<=bit_count; i++) {52mask |= 1 << i;53}54value |= (bit_value<<bit_offset) & mask;55}56#endif5758