From d492aeecd8165260579947e2e38b5f35c4d48769 Mon Sep 17 00:00:00 2001 From: Floris Heinen Date: Wed, 22 Dec 2021 16:38:21 +0100 Subject: [PATCH] Add basestation configuration --- generator/latest_rem_version.txt | 2 +- generator/packets.py | 15 +++++- include/BaseTypes.h | 11 +++- include/BasestationConfiguration.h | 66 ++++++++++++++++++++++++ include/BasestationGetConfiguration.h | 42 ++++++++++++++++ include/BasestationSetConfiguration.h | 66 ++++++++++++++++++++++++ proto/BasestationConfiguration.proto | 17 +++++++ proto/BasestationGetConfiguration.proto | 13 +++++ proto/BasestationSetConfiguration.proto | 17 +++++++ python/BaseTypes.py | 11 +++- python/BasestationConfiguration.py | 67 +++++++++++++++++++++++++ python/BasestationGetConfiguration.py | 43 ++++++++++++++++ python/BasestationSetConfiguration.py | 67 +++++++++++++++++++++++++ 13 files changed, 432 insertions(+), 5 deletions(-) create mode 100644 include/BasestationConfiguration.h create mode 100644 include/BasestationGetConfiguration.h create mode 100644 include/BasestationSetConfiguration.h create mode 100644 proto/BasestationConfiguration.proto create mode 100644 proto/BasestationGetConfiguration.proto create mode 100644 proto/BasestationSetConfiguration.proto create mode 100644 python/BasestationConfiguration.py create mode 100644 python/BasestationGetConfiguration.py create mode 100644 python/BasestationSetConfiguration.py diff --git a/generator/latest_rem_version.txt b/generator/latest_rem_version.txt index bf0d87a..7813681 100644 --- a/generator/latest_rem_version.txt +++ b/generator/latest_rem_version.txt @@ -1 +1 @@ -4 \ No newline at end of file +5 \ No newline at end of file diff --git a/generator/packets.py b/generator/packets.py index 05bfe0b..51f06ba 100644 --- a/generator/packets.py +++ b/generator/packets.py @@ -96,8 +96,6 @@ ["bot15_sent", 8, None, "Packets sent to robot with ID 15"], ["bot15_rcvd", 8, None, "Packets received from robot with ID 15"], ], - - "BasestationGetStatistics" : [ ["header", 8, None, "Header byte indicating the type of packet"] ], @@ -109,5 +107,18 @@ ["remVersion", 4, None, "Version of roboteam_embedded_messages"], ["id", 4, None, "Id of the robot"], ["message_length", 8, None, "Length of the following message"] + ], + "BasestationGetConfiguration" : [ + ["header", 8, None, "Header byte indicating the type of packet"] + ], + "BasestationConfiguration" : [ + ["header", 8, None, "Header byte indicating the type of packet"], + ["remVersion", 4, None, "Version of roboteam_embedded_messages"], + ["channel", 1, None, "Channel on which the basestation and robots communicate"] + ], + "BasestationSetConfiguration" : [ + ["header", 8, None, "Header byte indicating the type of packet"], + ["remVersion", 4, None, "Version of roboteam_embedded_messages"], + ["channel", 1, None, "Channel on which the basestation and robots communicate"] ] } \ No newline at end of file diff --git a/include/BaseTypes.h b/include/BaseTypes.h index 8560106..5e6c37b 100644 --- a/include/BaseTypes.h +++ b/include/BaseTypes.h @@ -7,7 +7,7 @@ #ifndef __BASETYPES_H #define __BASETYPES_H -#define LOCAL_REM_VERSION 4 +#define LOCAL_REM_VERSION 5 #define PACKET_TYPE_ROBOT_COMMAND 0b00001111 // 15 #define PACKET_SIZE_ROBOT_COMMAND 12 @@ -90,4 +90,13 @@ #define PACKET_TYPE_ROBOT_LOG 0b10010110 // 150 #define PACKET_SIZE_ROBOT_LOG 3 +#define PACKET_TYPE_BASESTATION_GET_CONFIGURATION 0b10011001 // 153 +#define PACKET_SIZE_BASESTATION_GET_CONFIGURATION 1 + +#define PACKET_TYPE_BASESTATION_CONFIGURATION 0b10100101 // 165 +#define PACKET_SIZE_BASESTATION_CONFIGURATION 2 + +#define PACKET_TYPE_BASESTATION_SET_CONFIGURATION 0b10101010 // 170 +#define PACKET_SIZE_BASESTATION_SET_CONFIGURATION 2 + #endif /*__BASETYPES_H*/ \ No newline at end of file diff --git a/include/BasestationConfiguration.h b/include/BasestationConfiguration.h new file mode 100644 index 0000000..865856e --- /dev/null +++ b/include/BasestationConfiguration.h @@ -0,0 +1,66 @@ +// AUTOGENERATED. Run generator/main.py to regenerate +/* +[ 0 ] [ 1 ] +11111111 -------- header +-------- 1111---- remVersion +-------- ----1--- channel +*/ + +#ifndef __BASESTATION_CONFIGURATION_H +#define __BASESTATION_CONFIGURATION_H + +#include +#include +#include "BaseTypes.h" + +typedef struct _BasestationConfigurationPayload { + uint8_t payload[PACKET_SIZE_BASESTATION_CONFIGURATION]; +} BasestationConfigurationPayload; + +typedef struct _BasestationConfiguration { + uint32_t header ; // integer [0, 255] Header byte indicating the type of packet + uint32_t remVersion ; // integer [0, 15] Version of roboteam_embedded_messages + bool channel ; // integer [0, 1] Channel on which the basestation and robots communicate +} BasestationConfiguration; + +// ================================ GETTERS ================================ +static inline uint32_t BasestationConfiguration_get_header(BasestationConfigurationPayload *bcp){ + return ((bcp->payload[0])); +} + +static inline uint32_t BasestationConfiguration_get_remVersion(BasestationConfigurationPayload *bcp){ + return ((bcp->payload[1] & 0b11110000) >> 4); +} + +static inline bool BasestationConfiguration_get_channel(BasestationConfigurationPayload *bcp){ + return (bcp->payload[1] & 0b00001000) > 0; +} + +// ================================ SETTERS ================================ +static inline void BasestationConfiguration_set_header(BasestationConfigurationPayload *bcp, uint32_t header){ + bcp->payload[0] = header; +} + +static inline void BasestationConfiguration_set_remVersion(BasestationConfigurationPayload *bcp, uint32_t remVersion){ + bcp->payload[1] = ((remVersion << 4) & 0b11110000) | (bcp->payload[1] & 0b00001111); +} + +static inline void BasestationConfiguration_set_channel(BasestationConfigurationPayload *bcp, bool channel){ + bcp->payload[1] = ((channel << 3) & 0b00001000) | (bcp->payload[1] & 0b11110111); +} + +// ================================ ENCODE ================================ +static inline void encodeBasestationConfiguration(BasestationConfigurationPayload *bcp, BasestationConfiguration *bc){ + BasestationConfiguration_set_header (bcp, bc->header); + BasestationConfiguration_set_remVersion (bcp, bc->remVersion); + BasestationConfiguration_set_channel (bcp, bc->channel); +} + +// ================================ DECODE ================================ +static inline void decodeBasestationConfiguration(BasestationConfiguration *bc, BasestationConfigurationPayload *bcp){ + bc->header = BasestationConfiguration_get_header(bcp); + bc->remVersion = BasestationConfiguration_get_remVersion(bcp); + bc->channel = BasestationConfiguration_get_channel(bcp); +} + +#endif /*__BASESTATION_CONFIGURATION_H*/ diff --git a/include/BasestationGetConfiguration.h b/include/BasestationGetConfiguration.h new file mode 100644 index 0000000..b3d184d --- /dev/null +++ b/include/BasestationGetConfiguration.h @@ -0,0 +1,42 @@ +// AUTOGENERATED. Run generator/main.py to regenerate +/* +[ 0 ] +11111111 header +*/ + +#ifndef __BASESTATION_GET_CONFIGURATION_H +#define __BASESTATION_GET_CONFIGURATION_H + +#include +#include +#include "BaseTypes.h" + +typedef struct _BasestationGetConfigurationPayload { + uint8_t payload[PACKET_SIZE_BASESTATION_GET_CONFIGURATION]; +} BasestationGetConfigurationPayload; + +typedef struct _BasestationGetConfiguration { + uint32_t header ; // integer [0, 255] Header byte indicating the type of packet +} BasestationGetConfiguration; + +// ================================ GETTERS ================================ +static inline uint32_t BasestationGetConfiguration_get_header(BasestationGetConfigurationPayload *bgcp){ + return ((bgcp->payload[0])); +} + +// ================================ SETTERS ================================ +static inline void BasestationGetConfiguration_set_header(BasestationGetConfigurationPayload *bgcp, uint32_t header){ + bgcp->payload[0] = header; +} + +// ================================ ENCODE ================================ +static inline void encodeBasestationGetConfiguration(BasestationGetConfigurationPayload *bgcp, BasestationGetConfiguration *bgc){ + BasestationGetConfiguration_set_header (bgcp, bgc->header); +} + +// ================================ DECODE ================================ +static inline void decodeBasestationGetConfiguration(BasestationGetConfiguration *bgc, BasestationGetConfigurationPayload *bgcp){ + bgc->header = BasestationGetConfiguration_get_header(bgcp); +} + +#endif /*__BASESTATION_GET_CONFIGURATION_H*/ diff --git a/include/BasestationSetConfiguration.h b/include/BasestationSetConfiguration.h new file mode 100644 index 0000000..81e3207 --- /dev/null +++ b/include/BasestationSetConfiguration.h @@ -0,0 +1,66 @@ +// AUTOGENERATED. Run generator/main.py to regenerate +/* +[ 0 ] [ 1 ] +11111111 -------- header +-------- 1111---- remVersion +-------- ----1--- channel +*/ + +#ifndef __BASESTATION_SET_CONFIGURATION_H +#define __BASESTATION_SET_CONFIGURATION_H + +#include +#include +#include "BaseTypes.h" + +typedef struct _BasestationSetConfigurationPayload { + uint8_t payload[PACKET_SIZE_BASESTATION_SET_CONFIGURATION]; +} BasestationSetConfigurationPayload; + +typedef struct _BasestationSetConfiguration { + uint32_t header ; // integer [0, 255] Header byte indicating the type of packet + uint32_t remVersion ; // integer [0, 15] Version of roboteam_embedded_messages + bool channel ; // integer [0, 1] Channel on which the basestation and robots communicate +} BasestationSetConfiguration; + +// ================================ GETTERS ================================ +static inline uint32_t BasestationSetConfiguration_get_header(BasestationSetConfigurationPayload *bscp){ + return ((bscp->payload[0])); +} + +static inline uint32_t BasestationSetConfiguration_get_remVersion(BasestationSetConfigurationPayload *bscp){ + return ((bscp->payload[1] & 0b11110000) >> 4); +} + +static inline bool BasestationSetConfiguration_get_channel(BasestationSetConfigurationPayload *bscp){ + return (bscp->payload[1] & 0b00001000) > 0; +} + +// ================================ SETTERS ================================ +static inline void BasestationSetConfiguration_set_header(BasestationSetConfigurationPayload *bscp, uint32_t header){ + bscp->payload[0] = header; +} + +static inline void BasestationSetConfiguration_set_remVersion(BasestationSetConfigurationPayload *bscp, uint32_t remVersion){ + bscp->payload[1] = ((remVersion << 4) & 0b11110000) | (bscp->payload[1] & 0b00001111); +} + +static inline void BasestationSetConfiguration_set_channel(BasestationSetConfigurationPayload *bscp, bool channel){ + bscp->payload[1] = ((channel << 3) & 0b00001000) | (bscp->payload[1] & 0b11110111); +} + +// ================================ ENCODE ================================ +static inline void encodeBasestationSetConfiguration(BasestationSetConfigurationPayload *bscp, BasestationSetConfiguration *bsc){ + BasestationSetConfiguration_set_header (bscp, bsc->header); + BasestationSetConfiguration_set_remVersion (bscp, bsc->remVersion); + BasestationSetConfiguration_set_channel (bscp, bsc->channel); +} + +// ================================ DECODE ================================ +static inline void decodeBasestationSetConfiguration(BasestationSetConfiguration *bsc, BasestationSetConfigurationPayload *bscp){ + bsc->header = BasestationSetConfiguration_get_header(bscp); + bsc->remVersion = BasestationSetConfiguration_get_remVersion(bscp); + bsc->channel = BasestationSetConfiguration_get_channel(bscp); +} + +#endif /*__BASESTATION_SET_CONFIGURATION_H*/ diff --git a/proto/BasestationConfiguration.proto b/proto/BasestationConfiguration.proto new file mode 100644 index 0000000..80979c0 --- /dev/null +++ b/proto/BasestationConfiguration.proto @@ -0,0 +1,17 @@ +// AUTOGENERATED. Run generator/main.py to regenerate +/* +[ 0 ] [ 1 ] +11111111 -------- header +-------- 1111---- remVersion +-------- ----1--- channel +*/ + +syntax="proto3"; + +package proto; + +message BasestationConfiguration { + uint32 header = 1; // integer [0, 255] Header byte indicating the type of packet + uint32 remVersion = 2; // integer [0, 15] Version of roboteam_embedded_messages + bool channel = 3; // integer [0, 1] Channel on which the basestation and robots communicate +} diff --git a/proto/BasestationGetConfiguration.proto b/proto/BasestationGetConfiguration.proto new file mode 100644 index 0000000..dd6c00c --- /dev/null +++ b/proto/BasestationGetConfiguration.proto @@ -0,0 +1,13 @@ +// AUTOGENERATED. Run generator/main.py to regenerate +/* +[ 0 ] +11111111 header +*/ + +syntax="proto3"; + +package proto; + +message BasestationGetConfiguration { + uint32 header = 1; // integer [0, 255] Header byte indicating the type of packet +} diff --git a/proto/BasestationSetConfiguration.proto b/proto/BasestationSetConfiguration.proto new file mode 100644 index 0000000..2d970ce --- /dev/null +++ b/proto/BasestationSetConfiguration.proto @@ -0,0 +1,17 @@ +// AUTOGENERATED. Run generator/main.py to regenerate +/* +[ 0 ] [ 1 ] +11111111 -------- header +-------- 1111---- remVersion +-------- ----1--- channel +*/ + +syntax="proto3"; + +package proto; + +message BasestationSetConfiguration { + uint32 header = 1; // integer [0, 255] Header byte indicating the type of packet + uint32 remVersion = 2; // integer [0, 15] Version of roboteam_embedded_messages + bool channel = 3; // integer [0, 1] Channel on which the basestation and robots communicate +} diff --git a/python/BaseTypes.py b/python/BaseTypes.py index babca27..1b1fe6f 100644 --- a/python/BaseTypes.py +++ b/python/BaseTypes.py @@ -4,7 +4,7 @@ # 0b00000000 : The null-terminator, used to signal the end of strings / arrays / etc. # 0b00001010 : The byte for newline, used for line termination. -LOCAL_REM_VERSION = 4 +LOCAL_REM_VERSION = 5 PACKET_TYPE_ROBOT_COMMAND = 0b00001111 # 15 PACKET_SIZE_ROBOT_COMMAND = 12 @@ -87,3 +87,12 @@ PACKET_TYPE_ROBOT_LOG = 0b10010110 # 150 PACKET_SIZE_ROBOT_LOG = 3 +PACKET_TYPE_BASESTATION_GET_CONFIGURATION = 0b10011001 # 153 +PACKET_SIZE_BASESTATION_GET_CONFIGURATION = 1 + +PACKET_TYPE_BASESTATION_CONFIGURATION = 0b10100101 # 165 +PACKET_SIZE_BASESTATION_CONFIGURATION = 2 + +PACKET_TYPE_BASESTATION_SET_CONFIGURATION = 0b10101010 # 170 +PACKET_SIZE_BASESTATION_SET_CONFIGURATION = 2 + diff --git a/python/BasestationConfiguration.py b/python/BasestationConfiguration.py new file mode 100644 index 0000000..417e8db --- /dev/null +++ b/python/BasestationConfiguration.py @@ -0,0 +1,67 @@ +# AUTOGENERATED. Run generator/main.py to regenerate +""" +[ 0 ] [ 1 ] +11111111 -------- header +-------- 1111---- remVersion +-------- ----1--- channel +""" + +import numpy as np +from . import BaseTypes + + + +class BasestationConfiguration: + header = 0 # integer [0, 255] Header byte indicating the type of packet + remVersion = 0 # integer [0, 15] Version of roboteam_embedded_messages + channel = 0 # integer [0, 1] Channel on which the basestation and robots communicate + + + +# ================================ GETTERS ================================ + @staticmethod + def get_header(payload): + return ((payload[0])); + + @staticmethod + def get_remVersion(payload): + return ((payload[1] & 0b11110000) >> 4); + + @staticmethod + def get_channel(payload): + return (payload[1] & 0b00001000) > 0; + +# ================================ SETTERS ================================ + @staticmethod + def set_header(payload, header): + payload[0] = header; + + @staticmethod + def set_remVersion(payload, remVersion): + payload[1] = ((remVersion << 4) & 0b11110000) | (payload[1] & 0b00001111); + + @staticmethod + def set_channel(payload, channel): + payload[1] = ((channel << 3) & 0b00001000) | (payload[1] & 0b11110111); + +# ================================ ENCODE ================================ + def encode(self): + payload = np.zeros(BaseTypes.PACKET_SIZE_BASESTATION_CONFIGURATION, dtype=np.uint8) + BasestationConfiguration.set_header (payload, self.header) + BasestationConfiguration.set_remVersion (payload, self.remVersion) + BasestationConfiguration.set_channel (payload, self.channel) + return payload + + +# ================================ DECODE ================================ + def decode(self, payload): + self.header = BasestationConfiguration.get_header(payload) + self.remVersion = BasestationConfiguration.get_remVersion(payload) + self.channel = BasestationConfiguration.get_channel(payload) + + + def print_bit_string(self): + payload = self.encode() + for i in range(len(payload)): + print(format(payload[i], '08b'), end=" ") + print() diff --git a/python/BasestationGetConfiguration.py b/python/BasestationGetConfiguration.py new file mode 100644 index 0000000..634485e --- /dev/null +++ b/python/BasestationGetConfiguration.py @@ -0,0 +1,43 @@ +# AUTOGENERATED. Run generator/main.py to regenerate +""" +[ 0 ] +11111111 header +""" + +import numpy as np +from . import BaseTypes + + + +class BasestationGetConfiguration: + header = 0 # integer [0, 255] Header byte indicating the type of packet + + + +# ================================ GETTERS ================================ + @staticmethod + def get_header(payload): + return ((payload[0])); + +# ================================ SETTERS ================================ + @staticmethod + def set_header(payload, header): + payload[0] = header; + +# ================================ ENCODE ================================ + def encode(self): + payload = np.zeros(BaseTypes.PACKET_SIZE_BASESTATION_GET_CONFIGURATION, dtype=np.uint8) + BasestationGetConfiguration.set_header (payload, self.header) + return payload + + +# ================================ DECODE ================================ + def decode(self, payload): + self.header = BasestationGetConfiguration.get_header(payload) + + + def print_bit_string(self): + payload = self.encode() + for i in range(len(payload)): + print(format(payload[i], '08b'), end=" ") + print() diff --git a/python/BasestationSetConfiguration.py b/python/BasestationSetConfiguration.py new file mode 100644 index 0000000..22830fc --- /dev/null +++ b/python/BasestationSetConfiguration.py @@ -0,0 +1,67 @@ +# AUTOGENERATED. Run generator/main.py to regenerate +""" +[ 0 ] [ 1 ] +11111111 -------- header +-------- 1111---- remVersion +-------- ----1--- channel +""" + +import numpy as np +from . import BaseTypes + + + +class BasestationSetConfiguration: + header = 0 # integer [0, 255] Header byte indicating the type of packet + remVersion = 0 # integer [0, 15] Version of roboteam_embedded_messages + channel = 0 # integer [0, 1] Channel on which the basestation and robots communicate + + + +# ================================ GETTERS ================================ + @staticmethod + def get_header(payload): + return ((payload[0])); + + @staticmethod + def get_remVersion(payload): + return ((payload[1] & 0b11110000) >> 4); + + @staticmethod + def get_channel(payload): + return (payload[1] & 0b00001000) > 0; + +# ================================ SETTERS ================================ + @staticmethod + def set_header(payload, header): + payload[0] = header; + + @staticmethod + def set_remVersion(payload, remVersion): + payload[1] = ((remVersion << 4) & 0b11110000) | (payload[1] & 0b00001111); + + @staticmethod + def set_channel(payload, channel): + payload[1] = ((channel << 3) & 0b00001000) | (payload[1] & 0b11110111); + +# ================================ ENCODE ================================ + def encode(self): + payload = np.zeros(BaseTypes.PACKET_SIZE_BASESTATION_SET_CONFIGURATION, dtype=np.uint8) + BasestationSetConfiguration.set_header (payload, self.header) + BasestationSetConfiguration.set_remVersion (payload, self.remVersion) + BasestationSetConfiguration.set_channel (payload, self.channel) + return payload + + +# ================================ DECODE ================================ + def decode(self, payload): + self.header = BasestationSetConfiguration.get_header(payload) + self.remVersion = BasestationSetConfiguration.get_remVersion(payload) + self.channel = BasestationSetConfiguration.get_channel(payload) + + + def print_bit_string(self): + payload = self.encode() + for i in range(len(payload)): + print(format(payload[i], '08b'), end=" ") + print()