Skip to content

Commit

Permalink
Updated BURT_proto to handle larger packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Lesches committed May 22, 2024
1 parent 95a2a21 commit 75b9646
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion BURT_can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ template <class CanType>
bool BurtCan<CanType>::send(uint32_t id, const void* message, const pb_msgdesc_t* fields) {
// Encodes a Protobuf message and then sends it using #sendRaw.
uint8_t data[8];
int length = BurtProto::encode(data, fields, message);
int length = BurtProto::encode(data, fields, message, 8);
if (length == -1) {
Serial.println("[BurtCan] Error: Failed to encode message");
return false;
Expand Down
4 changes: 2 additions & 2 deletions BURT_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <Arduino.h>

int BurtProto::encode(uint8_t* buffer, const pb_msgdesc_t* fields, const void* message) {
pb_ostream_t stream = pb_ostream_from_buffer(buffer, 8);
int BurtProto::encode(uint8_t* buffer, const pb_msgdesc_t* fields, const void* message, int length) {
pb_ostream_t stream = pb_ostream_from_buffer(buffer, length);
// This *should* return false on failure, but it seems to return false positives
pb_encode(&stream, fields, message);
return stream.bytes_written;
Expand Down
2 changes: 1 addition & 1 deletion BURT_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class BurtProto {
public:
static int encode(uint8_t* buffer, const pb_msgdesc_t* fields, const void* message);
static int encode(uint8_t* buffer, const pb_msgdesc_t* fields, const void* message, int length);
static bool decodeRaw(const uint8_t* buffer, int length, const pb_msgdesc_t* fields, void* message);

template<typename T>
Expand Down
4 changes: 2 additions & 2 deletions BURT_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void BurtSerial::tryConnect(uint8_t* input, int length) {
response.receiver = connect.sender;
response.sender = device;
uint8_t buffer[8];
int newLength = BurtProto::encode(buffer, Connect_fields, &response);
int newLength = BurtProto::encode(buffer, Connect_fields, &response, Connect_size);
Serial.write(buffer, newLength);
isConnected = true;
}
Expand All @@ -66,7 +66,7 @@ bool BurtSerial::send(const void* message) {
if (!isConnected) return false;

uint8_t* buffer = new uint8_t[length];
int encodedLength = BurtProto::encode(buffer, descriptor, message);
int encodedLength = BurtProto::encode(buffer, descriptor, message, length);

int sentLength = Serial.write(buffer, encodedLength);
delete[] buffer;
Expand Down

0 comments on commit 75b9646

Please sign in to comment.