ReduxLib C++ 2024.3.2
Loading...
Searching...
No Matches
CanandFirmwareVersion.h
1// Copyright (c) Redux Robotics and other contributors.
2// This is open source and can be modified and shared under the 3-clause BSD license.
3
4#pragma once
5#include <cstdint>
6
7namespace redux::canand {
8
9/**
10 * Represents a firmware version associated with a Redux product.
11 *
12 * @param year the year associated with the firmware version.
13 * Within a year/season, the message API is expected to remain the same until the postseason.
14 * @param minor the minor number associated with the firmware version
15 * @param patch the patch number associated with the firmware version
16 */
18 public:
19 /**
20 * Constructor.
21 *
22 * @param year the year associated with the firmware version.
23 * Within a year/season, the message API is expected to remain the same until the postseason.
24 * @param minor the minor number associated with the firmware version
25 * @param patch the patch number associated with the firmware version
26 */
27 constexpr CanandFirmwareVersion(uint16_t year, uint8_t minor, uint8_t patch): year{year}, minor{minor}, patch{patch} {};
28 /** Firmware year. */
29 uint16_t year;
30 /** Firmware minor version. */
31 uint8_t minor;
32 /** Firmware patch version. */
33 uint8_t patch;
34
35 /**
36 * Serializes the firmware version record into a wire-formattable Long.
37 *
38 * @return long representing the setting data.
39 */
40 constexpr uint64_t ToSettingData() {
41 return (year << 16) | (minor << 8) | (patch);
42 }
43
44 /**
45 * Returns a new CanandFirmwareVersion generated from setting data.
46 *
47 * @param value setting data, as a 48-bit long
48 * @return CanandFirmwareVersion data
49 */
50 static constexpr CanandFirmwareVersion FromSettingData(uint64_t value) {
51 return CanandFirmwareVersion{(uint16_t) (value >> 16), (uint8_t) ((value >> 8) & 0xff), (uint8_t) ((value & 0xff))};
52 }
53
54};
55
56}
Definition: CanandMessage.h:10
Definition: CanandFirmwareVersion.h:17
uint16_t year
Definition: CanandFirmwareVersion.h:29
constexpr CanandFirmwareVersion(uint16_t year, uint8_t minor, uint8_t patch)
Definition: CanandFirmwareVersion.h:27
constexpr uint64_t ToSettingData()
Definition: CanandFirmwareVersion.h:40
uint8_t minor
Definition: CanandFirmwareVersion.h:31
uint8_t patch
Definition: CanandFirmwareVersion.h:33
static constexpr CanandFirmwareVersion FromSettingData(uint64_t value)
Definition: CanandFirmwareVersion.h:50