Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
/**
* The MIT License (MIT)
*
* Copyright (c) 2018-2019 Erik Moqvist
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* This file was generated by cantools version 37.2.0 Sun Dec 18 09:02:57 2022.
*/
#include <string.h>
#include "candata.h"
static inline uint8_t pack_left_shift_u8(
uint8_t value,
uint8_t shift,
uint8_t mask)
{
return (uint8_t)((uint8_t)(value << shift) & mask);
}
static inline uint8_t pack_left_shift_u16(
uint16_t value,
uint8_t shift,
uint8_t mask)
{
return (uint8_t)((uint8_t)(value << shift) & mask);
}
static inline uint8_t pack_right_shift_u16(
uint16_t value,
uint8_t shift,
uint8_t mask)
{
return (uint8_t)((uint8_t)(value >> shift) & mask);
}
static inline uint16_t unpack_left_shift_u16(
uint8_t value,
uint8_t shift,
uint8_t mask)
{
return (uint16_t)((uint16_t)(value & mask) << shift);
}
static inline uint8_t unpack_right_shift_u8(
uint8_t value,
uint8_t shift,
uint8_t mask)
{
return (uint8_t)((uint8_t)(value & mask) >> shift);
}
static inline uint16_t unpack_right_shift_u16(
uint8_t value,
uint8_t shift,
uint8_t mask)
{
return (uint16_t)((uint16_t)(value & mask) >> shift);
}
int candata_indicator_control_pack(
uint8_t *dst_p,
const struct candata_indicator_control_t *src_p,
size_t size)
{
if (size < 4u) {
return (-EINVAL);
}
memset(&dst_p[0], 0, 4);
dst_p[0] |= pack_left_shift_u8(src_p->left_indicator, 0u, 0x01u);
dst_p[0] |= pack_left_shift_u8(src_p->right_indicator, 1u, 0x02u);
return (4);
}
int candata_indicator_control_unpack(
struct candata_indicator_control_t *dst_p,
const uint8_t *src_p,
size_t size)
{
if (size < 4u) {
return (-EINVAL);
}
dst_p->left_indicator = unpack_right_shift_u8(src_p[0], 0u, 0x01u);
dst_p->right_indicator = unpack_right_shift_u8(src_p[0], 1u, 0x02u);
return (0);
}
uint8_t candata_indicator_control_left_indicator_encode(double value)
{
return (uint8_t)(value);
}
double candata_indicator_control_left_indicator_decode(uint8_t value)
{
return ((double)value);
}
bool candata_indicator_control_left_indicator_is_in_range(uint8_t value)
{
return (value <= 1u);
}
uint8_t candata_indicator_control_right_indicator_encode(double value)
{
return (uint8_t)(value);
}
double candata_indicator_control_right_indicator_decode(uint8_t value)
{
return ((double)value);
}
bool candata_indicator_control_right_indicator_is_in_range(uint8_t value)
{
return (value <= 1u);
}
int candata_speed_pack(
uint8_t *dst_p,
const struct candata_speed_t *src_p,
size_t size)
{
if (size < 5u) {
return (-EINVAL);
}
memset(&dst_p[0], 0, 5);
dst_p[3] |= pack_right_shift_u16(src_p->speed, 8u, 0xffu);
dst_p[4] |= pack_left_shift_u16(src_p->speed, 0u, 0xffu);
return (5);
}
int candata_speed_unpack(
struct candata_speed_t *dst_p,
const uint8_t *src_p,
size_t size)
{
if (size < 5u) {
return (-EINVAL);
}
dst_p->speed = unpack_left_shift_u16(src_p[3], 8u, 0xffu);
dst_p->speed |= unpack_right_shift_u16(src_p[4], 0u, 0xffu);
return (0);
}
uint16_t candata_speed_speed_encode(double value)
{
return (uint16_t)(value);
}
double candata_speed_speed_decode(uint16_t value)
{
return ((double)value);
}
bool candata_speed_speed_is_in_range(uint16_t value)
{
return (value <= 48280u);
}