Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basestation configuration #5

Merged
merged 1 commit into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generator/latest_rem_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4
5
15 changes: 13 additions & 2 deletions generator/packets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
],
Expand All @@ -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"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remVersion should be 5 now right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 stands for 4 bits used, not for the version

["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"]
]
}
11 changes: 10 additions & 1 deletion include/BaseTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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*/
66 changes: 66 additions & 0 deletions include/BasestationConfiguration.h
Original file line number Diff line number Diff line change
@@ -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 <stdbool.h>
#include <stdint.h>
#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*/
42 changes: 42 additions & 0 deletions include/BasestationGetConfiguration.h
Original file line number Diff line number Diff line change
@@ -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 <stdbool.h>
#include <stdint.h>
#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*/
66 changes: 66 additions & 0 deletions include/BasestationSetConfiguration.h
Original file line number Diff line number Diff line change
@@ -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 <stdbool.h>
#include <stdint.h>
#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*/
17 changes: 17 additions & 0 deletions proto/BasestationConfiguration.proto
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 13 additions & 0 deletions proto/BasestationGetConfiguration.proto
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 17 additions & 0 deletions proto/BasestationSetConfiguration.proto
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 10 additions & 1 deletion python/BaseTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

67 changes: 67 additions & 0 deletions python/BasestationConfiguration.py
Original file line number Diff line number Diff line change
@@ -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()
Loading