You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
278 lines
16 KiB
278 lines
16 KiB
// scaledencode.h was generated by ProtoGen version 3.2.a |
|
|
|
/* |
|
* This file is free software: you can redistribute it and/or modify it |
|
* under the terms of the GNU General Public License as published by the |
|
* Free Software Foundation, either version 3 of the License, or |
|
* (at your option) any later version. |
|
* |
|
* This file is distributed in the hope that it will be useful, but |
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
* See the GNU General Public License for more details. |
|
* |
|
* You should have received a copy of the GNU General Public License along |
|
* with this program. If not, see <http://www.gnu.org/licenses/>. |
|
* |
|
* Author: Oliver Walters |
|
*/ |
|
|
|
#ifndef _SCALEDENCODE_H |
|
#define _SCALEDENCODE_H |
|
|
|
// Language target is C, C++ compilers: don't mangle us |
|
#ifdef __cplusplus |
|
extern "C" { |
|
#endif |
|
|
|
/*! |
|
* \file |
|
*/ |
|
|
|
/*! |
|
* \file |
|
* scaledencode routines place scaled numbers into a byte stream. |
|
* |
|
* scaledencode routines place scaled values into a big or little endian byte |
|
* stream. The values can be any legitimate type (double, float, uint32_t, |
|
* uint16_t, uint8_t, int32_t, int16_t, int8_t), and are encoded as either a |
|
* unsigned or signed integer from 1 to 8 bytes in length. Unsigned encodings |
|
* allow the caller to specify a minimum and a maximum value, with the only |
|
* limitation that the maximum value must be more than the minimum. Signed |
|
* encodings only allow the caller to specify a maximum value which gives |
|
* maximum absolute value that can be encoded. |
|
* |
|
* An example encoding would be: take a float that represents speed in meters |
|
* per second and encode it in two bytes from -200 to 200 meters per second. |
|
* In that example the encoding function would be: |
|
* |
|
* float32ScaledTo2SignedBeBytes(speed, bytestream, &index, 200); |
|
* |
|
* This would scale the speed according to (32767/200), and copy the resulting |
|
* two bytes to bytestream[index] as a signed 16 bit number in big endian |
|
* order. This would result in a velocity resolution of 0.006 m/s. |
|
* |
|
* Another example encoding is: take a double that represents altitude in |
|
* meters and encode it in three bytes from -1000 to 49000 meters: |
|
* |
|
* float64ScaledTo3UnsignedLeBytes(alt, bytestream, &index, -1000, 49000); |
|
* |
|
* This would transform the altitude according to (alt *(16777215/50000) + 1000) |
|
* and copy the resulting three bytes to bytestream[index] as an unsigned 24 |
|
* bit number in little endian order. This would result in an altitude |
|
* resolution of 0.003 meters. |
|
* |
|
* scaledencode does not include routines that increase the resolution of the |
|
* inmemory value. For example the function floatScaledTo5UnsignedBeBytes() does |
|
* not exist, because expanding a float to 5 bytes does not make any resolution |
|
* improvement over encoding it in 4 bytes. In general the encoded format |
|
* must be equal to or less than the number of bytes of the raw data. |
|
* |
|
* Code generation for this module was affected by these global flags: |
|
* 64-bit integers are not supported. |
|
* Normal bitfields are supported, long bitfields are not. |
|
* Double precision floating points are not supported. |
|
*/ |
|
|
|
#define __STDC_CONSTANT_MACROS |
|
#include <stdint.h> |
|
|
|
//! Scale a float using floating point scaling to the base integer type used for bitfields. |
|
unsigned int float32ScaledToBitfield(float value, float min, float scaler, int bits); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 4 unsigned bytes in big endian order. |
|
void float32ScaledTo4UnsignedBeBytes(float value, uint8_t* bytes, int* index, float min, float scaler); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 4 unsigned bytes in little endian order. |
|
void float32ScaledTo4UnsignedLeBytes(float value, uint8_t* bytes, int* index, float min, float scaler); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 4 signed bytes in big endian order. |
|
void float32ScaledTo4SignedBeBytes(float value, uint8_t* bytes, int* index, float scaler); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 4 signed bytes in little endian order. |
|
void float32ScaledTo4SignedLeBytes(float value, uint8_t* bytes, int* index, float scaler); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 3 unsigned bytes in big endian order. |
|
void float32ScaledTo3UnsignedBeBytes(float value, uint8_t* bytes, int* index, float min, float scaler); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 3 unsigned bytes in little endian order. |
|
void float32ScaledTo3UnsignedLeBytes(float value, uint8_t* bytes, int* index, float min, float scaler); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 3 signed bytes in big endian order. |
|
void float32ScaledTo3SignedBeBytes(float value, uint8_t* bytes, int* index, float scaler); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 3 signed bytes in little endian order. |
|
void float32ScaledTo3SignedLeBytes(float value, uint8_t* bytes, int* index, float scaler); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 2 unsigned bytes in big endian order. |
|
void float32ScaledTo2UnsignedBeBytes(float value, uint8_t* bytes, int* index, float min, float scaler); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 2 unsigned bytes in little endian order. |
|
void float32ScaledTo2UnsignedLeBytes(float value, uint8_t* bytes, int* index, float min, float scaler); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 2 signed bytes in big endian order. |
|
void float32ScaledTo2SignedBeBytes(float value, uint8_t* bytes, int* index, float scaler); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 2 signed bytes in little endian order. |
|
void float32ScaledTo2SignedLeBytes(float value, uint8_t* bytes, int* index, float scaler); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 1 unsigned byte. |
|
void float32ScaledTo1UnsignedBytes(float value, uint8_t* bytes, int* index, float min, float scaler); |
|
|
|
//! Encode a float on a byte stream by floating point scaling to fit in 1 signed byte. |
|
void float32ScaledTo1SignedBytes(float value, uint8_t* bytes, int* index, float scaler); |
|
|
|
//! Scale a uint32_t using integer scaling to the base integer type used for bitfields. |
|
unsigned int uint32ScaledToBitfield(uint32_t value, int32_t min, uint32_t scaler, int bits); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 4 unsigned bytes in big endian order. |
|
void uint32ScaledTo4UnsignedBeBytes(uint32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 4 unsigned bytes in little endian order. |
|
void uint32ScaledTo4UnsignedLeBytes(uint32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 4 signed bytes in big endian order. |
|
void uint32ScaledTo4SignedBeBytes(uint32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 4 signed bytes in little endian order. |
|
void uint32ScaledTo4SignedLeBytes(uint32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 3 unsigned bytes in big endian order. |
|
void uint32ScaledTo3UnsignedBeBytes(uint32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 3 unsigned bytes in little endian order. |
|
void uint32ScaledTo3UnsignedLeBytes(uint32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 3 signed bytes in big endian order. |
|
void uint32ScaledTo3SignedBeBytes(uint32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 3 signed bytes in little endian order. |
|
void uint32ScaledTo3SignedLeBytes(uint32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 2 unsigned bytes in big endian order. |
|
void uint32ScaledTo2UnsignedBeBytes(uint32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 2 unsigned bytes in little endian order. |
|
void uint32ScaledTo2UnsignedLeBytes(uint32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 2 signed bytes in big endian order. |
|
void uint32ScaledTo2SignedBeBytes(uint32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 2 signed bytes in little endian order. |
|
void uint32ScaledTo2SignedLeBytes(uint32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 1 unsigned byte. |
|
void uint32ScaledTo1UnsignedBytes(uint32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a uint32_t on a byte stream by integer scaling to fit in 1 signed byte. |
|
void uint32ScaledTo1SignedBytes(uint32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Scale a int32_t using integer scaling to the base integer type used for bitfields. |
|
unsigned int int32ScaledToBitfield(int32_t value, int32_t min, uint32_t scaler, int bits); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 4 unsigned bytes in big endian order. |
|
void int32ScaledTo4UnsignedBeBytes(int32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 4 unsigned bytes in little endian order. |
|
void int32ScaledTo4UnsignedLeBytes(int32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 4 signed bytes in big endian order. |
|
void int32ScaledTo4SignedBeBytes(int32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 4 signed bytes in little endian order. |
|
void int32ScaledTo4SignedLeBytes(int32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 3 unsigned bytes in big endian order. |
|
void int32ScaledTo3UnsignedBeBytes(int32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 3 unsigned bytes in little endian order. |
|
void int32ScaledTo3UnsignedLeBytes(int32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 3 signed bytes in big endian order. |
|
void int32ScaledTo3SignedBeBytes(int32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 3 signed bytes in little endian order. |
|
void int32ScaledTo3SignedLeBytes(int32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 2 unsigned bytes in big endian order. |
|
void int32ScaledTo2UnsignedBeBytes(int32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 2 unsigned bytes in little endian order. |
|
void int32ScaledTo2UnsignedLeBytes(int32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 2 signed bytes in big endian order. |
|
void int32ScaledTo2SignedBeBytes(int32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 2 signed bytes in little endian order. |
|
void int32ScaledTo2SignedLeBytes(int32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 1 unsigned byte. |
|
void int32ScaledTo1UnsignedBytes(int32_t value, uint8_t* bytes, int* index, int32_t min, uint32_t scaler); |
|
|
|
//! Encode a int32_t on a byte stream by integer scaling to fit in 1 signed byte. |
|
void int32ScaledTo1SignedBytes(int32_t value, uint8_t* bytes, int* index, uint32_t scaler); |
|
|
|
//! Scale a uint16_t using integer scaling to the base integer type used for bitfields. |
|
unsigned int uint16ScaledToBitfield(uint16_t value, int16_t min, uint16_t scaler, int bits); |
|
|
|
//! Encode a uint16_t on a byte stream by integer scaling to fit in 2 unsigned bytes in big endian order. |
|
void uint16ScaledTo2UnsignedBeBytes(uint16_t value, uint8_t* bytes, int* index, int16_t min, uint16_t scaler); |
|
|
|
//! Encode a uint16_t on a byte stream by integer scaling to fit in 2 unsigned bytes in little endian order. |
|
void uint16ScaledTo2UnsignedLeBytes(uint16_t value, uint8_t* bytes, int* index, int16_t min, uint16_t scaler); |
|
|
|
//! Encode a uint16_t on a byte stream by integer scaling to fit in 2 signed bytes in big endian order. |
|
void uint16ScaledTo2SignedBeBytes(uint16_t value, uint8_t* bytes, int* index, uint16_t scaler); |
|
|
|
//! Encode a uint16_t on a byte stream by integer scaling to fit in 2 signed bytes in little endian order. |
|
void uint16ScaledTo2SignedLeBytes(uint16_t value, uint8_t* bytes, int* index, uint16_t scaler); |
|
|
|
//! Encode a uint16_t on a byte stream by integer scaling to fit in 1 unsigned byte. |
|
void uint16ScaledTo1UnsignedBytes(uint16_t value, uint8_t* bytes, int* index, int16_t min, uint16_t scaler); |
|
|
|
//! Encode a uint16_t on a byte stream by integer scaling to fit in 1 signed byte. |
|
void uint16ScaledTo1SignedBytes(uint16_t value, uint8_t* bytes, int* index, uint16_t scaler); |
|
|
|
//! Scale a int16_t using integer scaling to the base integer type used for bitfields. |
|
unsigned int int16ScaledToBitfield(int16_t value, int16_t min, uint16_t scaler, int bits); |
|
|
|
//! Encode a int16_t on a byte stream by integer scaling to fit in 2 unsigned bytes in big endian order. |
|
void int16ScaledTo2UnsignedBeBytes(int16_t value, uint8_t* bytes, int* index, int16_t min, uint16_t scaler); |
|
|
|
//! Encode a int16_t on a byte stream by integer scaling to fit in 2 unsigned bytes in little endian order. |
|
void int16ScaledTo2UnsignedLeBytes(int16_t value, uint8_t* bytes, int* index, int16_t min, uint16_t scaler); |
|
|
|
//! Encode a int16_t on a byte stream by integer scaling to fit in 2 signed bytes in big endian order. |
|
void int16ScaledTo2SignedBeBytes(int16_t value, uint8_t* bytes, int* index, uint16_t scaler); |
|
|
|
//! Encode a int16_t on a byte stream by integer scaling to fit in 2 signed bytes in little endian order. |
|
void int16ScaledTo2SignedLeBytes(int16_t value, uint8_t* bytes, int* index, uint16_t scaler); |
|
|
|
//! Encode a int16_t on a byte stream by integer scaling to fit in 1 unsigned byte. |
|
void int16ScaledTo1UnsignedBytes(int16_t value, uint8_t* bytes, int* index, int16_t min, uint16_t scaler); |
|
|
|
//! Encode a int16_t on a byte stream by integer scaling to fit in 1 signed byte. |
|
void int16ScaledTo1SignedBytes(int16_t value, uint8_t* bytes, int* index, uint16_t scaler); |
|
|
|
//! Scale a uint8_t using integer scaling to the base integer type used for bitfields. |
|
unsigned int uint8ScaledToBitfield(uint8_t value, int8_t min, uint8_t scaler, int bits); |
|
|
|
//! Encode a uint8_t on a byte stream by integer scaling to fit in 1 unsigned byte. |
|
void uint8ScaledTo1UnsignedBytes(uint8_t value, uint8_t* bytes, int* index, int8_t min, uint8_t scaler); |
|
|
|
//! Encode a uint8_t on a byte stream by integer scaling to fit in 1 signed byte. |
|
void uint8ScaledTo1SignedBytes(uint8_t value, uint8_t* bytes, int* index, uint8_t scaler); |
|
|
|
//! Scale a int8_t using integer scaling to the base integer type used for bitfields. |
|
unsigned int int8ScaledToBitfield(int8_t value, int8_t min, uint8_t scaler, int bits); |
|
|
|
//! Encode a int8_t on a byte stream by integer scaling to fit in 1 unsigned byte. |
|
void int8ScaledTo1UnsignedBytes(int8_t value, uint8_t* bytes, int* index, int8_t min, uint8_t scaler); |
|
|
|
//! Encode a int8_t on a byte stream by integer scaling to fit in 1 signed byte. |
|
void int8ScaledTo1SignedBytes(int8_t value, uint8_t* bytes, int* index, uint8_t scaler); |
|
|
|
#ifdef __cplusplus |
|
} |
|
#endif |
|
#endif // _SCALEDENCODE_H
|
|
|