Skip to content

Commit 83131e2

Browse files
committed
Hive parity
1 parent dd37843 commit 83131e2

22 files changed

+408
-336
lines changed

src/comms/comms_layer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int CommsLayer::init() {
3333

3434
int CommsLayer::run() {
3535
// read packets from the physical layers
36-
recv_packets();
36+
receive_packets();
3737

3838
// write packets to the physical layers
3939
send_packets();
@@ -72,16 +72,16 @@ void CommsLayer::queue_data(CommsData* data) {
7272
void CommsLayer::send_packets() {
7373
// prepare and send a HID packet
7474
m_hid_payload.construct_data();
75-
memcpy(m_hid_outgoing.payload(), m_hid_payload.data(), HID_PACKET_PAYLOAD_SIZE);
75+
memcpy(m_hid_outgoing.payload(), m_hid_payload.data(), m_hid_payload.get_max_size());
7676
m_hid.send_packet(m_hid_outgoing);
7777

7878
// prepare and send an ethernet packet
7979
m_ethernet_payload.construct_data();
80-
memcpy(m_ethernet_outgoing.payload(), m_ethernet_payload.data(), ETHERNET_PACKET_PAYLOAD_SIZE);
80+
memcpy(m_ethernet_outgoing.payload(), m_ethernet_payload.data(), m_ethernet_payload.get_max_size());
8181
m_ethernet.send_packet(m_ethernet_outgoing);
8282
};
8383

84-
void CommsLayer::recv_packets() {
84+
void CommsLayer::receive_packets() {
8585
// defaulted to true so tests can run without physical layers
8686
bool hid_recv = true;
8787
bool ethernet_recv = true;
@@ -96,10 +96,10 @@ void CommsLayer::recv_packets() {
9696

9797
// process packets
9898
if (hid_recv) {
99-
m_hid_payload.deconstruct_data(m_hid_incoming.payload(), HID_PACKET_PAYLOAD_SIZE);
99+
m_hid_payload.deconstruct_data(m_hid_incoming.payload(), m_hid_payload.get_max_size());
100100
}
101101
if (ethernet_recv) {
102-
m_ethernet_payload.deconstruct_data(m_ethernet_incoming.payload(), ETHERNET_PACKET_PAYLOAD_SIZE);
102+
m_ethernet_payload.deconstruct_data(m_ethernet_incoming.payload(), m_ethernet_payload.get_max_size());
103103
}
104104
};
105105

src/comms/comms_layer.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CommsLayer {
3939

4040
/// @brief Receive and process packets from the appropriate physical layer
4141
/// @note This function should only be ran internally
42-
void recv_packets();
42+
void receive_packets();
4343

4444
/// @brief Check if Ethernet is connected
4545
/// @return True if connected, false if not
@@ -66,14 +66,16 @@ class CommsLayer {
6666
/// @param packet The incoming HID packet
6767
void set_hid_incoming(HIDPacket&& packet);
6868

69-
/// @brief Get the firmware data
69+
/// @brief Get the data from Firmware
70+
/// @note Populated on outgoing packets
7071
/// @return The firmware data
7172
FirmwareData& get_firmware_data();
7273
/// @brief Set the firmware data
7374
/// @param data The firmware data to set
7475
void set_firmware_data(FirmwareData& data);
7576

76-
/// @brief Get the hive data
77+
/// @brief Get the data from Hive
78+
/// @note Populated on incoming packets
7779
/// @return The hive data
7880
HiveData& get_hive_data();
7981
/// @brief Set the hive data

src/comms/config_layer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ const Config* const ConfigLayer::configure(Comms::CommsLayer* comms, bool config
7474
// memset(outgoing.raw, 0, sizeof(outgoing.raw));
7575
// comms->set_hid_outgoing(outgoing);
7676

77-
// Hive marks the config process as done once teensy sends a packet with info_bit == 0
78-
// Hive then sends a packet back with info_bit == 0 as well, so ping until we get a non-config back
77+
// Hive marks the config process as done once teensy sends a packet with request_bit == 0
78+
// Hive then sends a packet back with request_bit == 0 as well, so ping until we get a non-config back
7979
// TODO: this timeout is a hack, but it seems to work very well. Hive ends up seeing the 0 info bit before firmware does, causing this loop to never end
8080
uint32_t start = micros();
81-
while (comms_layer.get_hive_data().config_section.info_bit == 1 || micros() - start < 500000) {
81+
while (comms_layer.get_hive_data().config_section.request_bit == 1 || micros() - start < 500000) {
8282
Comms::Sendable<ConfigSection> sendable;
83-
sendable.data.info_bit = 0;
83+
sendable.data.request_bit = 0;
8484
sendable.send_to_comms();
8585
comms->run();
8686
}
@@ -145,13 +145,13 @@ void ConfigLayer::process() {
145145
in.payload()[0] = 0xff; // filler byte (needed for some reason)
146146
in.payload()[1] = in_section.section_id;
147147
in.payload()[2] = in_section.subsection_id;
148-
in.payload()[3] = in_section.info_bit;
148+
in.payload()[3] = in_section.request_bit;
149149
*reinterpret_cast<uint16_t*>(in.payload() + 4) = in_section.section_size;
150150
*reinterpret_cast<uint16_t*>(in.payload() + 6) = in_section.subsection_size;
151151
memcpy(in.payload() + 8, in_section.raw, 1000);
152152

153153
// if this is the packet we want
154-
if (in_section.section_id == seek_sec && in_section.subsection_id == seek_subsec && in_section.info_bit == 1) {
154+
if (in_section.section_id == seek_sec && in_section.subsection_id == seek_subsec && in_section.request_bit == 1) {
155155
// received the initial config packet
156156
if (in_section.section_id == -1) {
157157
/*
@@ -205,7 +205,7 @@ void ConfigLayer::process() {
205205

206206
out_section.section_id = seek_sec;
207207
out_section.subsection_id = seek_subsec;
208-
out_section.info_bit = 1;
208+
out_section.request_bit = 1;
209209

210210
// if configuration isn't complete, request the next packet
211211
if (!configured) {

src/comms/data/buff_encoder_data.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#if defined(FIRMWARE)
4+
#include "comms/data/comms_data.hpp" // for CommsData
5+
#elif defined(HIVE)
6+
#include "modules/comms/data/comms_data.hpp" // for CommsData
7+
#endif
8+
9+
#include <stdint.h> // uintN_t
10+
11+
/// @brief Structure for the buff encoder sensor.
12+
struct BuffEncoderData : Comms::CommsData {
13+
BuffEncoderData() : CommsData(Comms::TypeLabel::BuffEncoderData, Comms::PhysicalMedium::Ethernet, Comms::Priority::Medium, sizeof(BuffEncoderData)) { }
14+
/// Sensor ID.
15+
uint8_t id;
16+
/// Measured angle.
17+
float m_angle;
18+
};

src/comms/data/comms_data.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "comms_data.hpp"
22

33
#if defined(HIVE)
4-
#include "doctest/doctest.h" // for doctest
4+
#include <doctest/doctest.h> // for doctest
55

66
TEST_CASE("To string does stuff") {
77
CHECK(Comms::to_string(Comms::TypeLabel::NONE) == "NONE");

src/comms/data/comms_ref_data.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#if defined(FIRMWARE)
4+
#include "comms/data/comms_data.hpp" // for CommsData
5+
#elif defined(HIVE)
6+
#include "modules/comms/data/comms_data.hpp" // for CommsData
7+
#endif
8+
9+
#include <stdint.h> // uintN_t
10+
11+
// TODO: make this nice
12+
/// @brief Ref data
13+
struct CommsRefData : Comms::CommsData {
14+
CommsRefData() : CommsData(Comms::TypeLabel::CommsRefData, Comms::PhysicalMedium::Ethernet, Comms::Priority::High, sizeof(CommsRefData)) { }
15+
16+
/// @brief Raw data
17+
uint8_t raw[180] = { 0 };
18+
};

src/comms/data/config_data.hpp

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/comms/data/config_section.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#if defined(FIRMWARE)
4+
#include "comms/data/comms_data.hpp" // for CommsData
5+
#elif defined(HIVE)
6+
#include "modules/comms/data/comms_data.hpp" // for CommsData
7+
#endif
8+
9+
#include <stdint.h> // uintN_t
10+
11+
// TODO: make this ethernet capable
12+
/// @brief Section of a config packet
13+
struct ConfigSection : Comms::CommsData {
14+
ConfigSection() : CommsData(Comms::TypeLabel::ConfigSection, Comms::PhysicalMedium::HID, Comms::Priority::High, sizeof(ConfigSection)) { }
15+
16+
/// @brief filler byte
17+
uint8_t filler = 0xff;
18+
/// @brief Section ID
19+
int8_t section_id = 0;
20+
/// @brief Subsection ID
21+
int8_t subsection_id = 0;
22+
/// @brief Info bit, stores the config request bit
23+
bool request_bit = 0;
24+
25+
/// @brief Size of the whole section
26+
uint16_t section_size = 0;
27+
/// @brief Size of the subsection
28+
uint16_t subsection_size = 0;
29+
30+
/// @brief Raw config data
31+
uint8_t raw[1000] = { 0 };
32+
};

0 commit comments

Comments
 (0)