Skip to content

Commit

Permalink
Made BurtSerial.send easier
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Lesches committed May 21, 2024
1 parent dab44d6 commit 4fc82b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions BURT_serial.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "BURT_serial.h"
#include "BURT_proto.h"

BurtSerial::BurtSerial(Device device, ProtoHandler onMessage) :
BurtSerial::BurtSerial(Device device, ProtoHandler onMessage, const pb_msgdesc_t* descriptor, int length) :
device(device),
onMessage(onMessage)
onMessage(onMessage),
descriptor(descriptor),
length(length)
{ }

bool isResetCode(uint8_t* buffer, int length) {
Expand Down Expand Up @@ -60,11 +62,11 @@ void BurtSerial::tryConnect(uint8_t* input, int length) {
* @param length The maximum length of the encoded message. Use the generated MessageName_size.
* @return Returns `true` if the entire message is sent successfully, `false` otherwise.
*/
bool BurtSerial::send(const pb_msgdesc_t* fields, const void* message, int length) {
bool BurtSerial::send(const void* message) {
if (!isConnected) return false;

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

int sentLength = Serial.write(buffer, encodedLength);
delete[] buffer;
Expand Down
6 changes: 4 additions & 2 deletions BURT_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ class BurtSerial {
public:
bool isConnected = false;

BurtSerial(Device device, ProtoHandler onMessage);
BurtSerial(Device device, ProtoHandler onMessage, const pb_msgdesc_t* descriptor, int length);
void setup() { /* No setup needed */ }
void update();
bool send(const pb_msgdesc_t* fields, const void* message, int length);
bool send(const void* message);

private:
void tryConnect(uint8_t* input, int length);
Device device;
ProtoHandler onMessage;
const pb_msgdesc_t* descriptor;
int length;
};

0 comments on commit 4fc82b0

Please sign in to comment.