Move packet building and sending logic out of main.cpp

This commit is contained in:
2025-05-24 14:36:32 +10:00
parent b50edfa4aa
commit 32e0462a69
5 changed files with 160 additions and 107 deletions

View File

@@ -0,0 +1,27 @@
#include "PacketSender.h"
PacketSender::PacketSender(RFPowerView& powerView) : powerView(powerView)
{
}
bool PacketSender::send(Packet packet)
{
Serial.println("Attempting to send a packet");
packet.rollingCode1 = lastRollingCode1 + 1;
packet.rollingCode2 = lastRollingCode2 + 1;
bool didSend = powerView.sendPacket(&packet);
if (!didSend) {
Serial.println("Failed to send");
return false;
} else {
lastRollingCode1++;
lastRollingCode2++;
return true;
}
}
void PacketSender::setLastRollingCodes(uint8_t code1, uint8_t code2) {
lastRollingCode1 = code1;
lastRollingCode2 = code2;
}

View File

@@ -0,0 +1,20 @@
#ifndef PACKET_SENDER_H
#define PACKET_SENDER_H
#include <RFPowerView.h>
#include <PacketTypes.h>
class PacketSender {
public:
PacketSender(RFPowerView& powerView);
bool send(Packet packet);
void setLastRollingCodes(uint8_t code1, uint8_t code2);
private:
RFPowerView& powerView;
uint8_t lastRollingCode1 = 0x3D;
uint8_t lastRollingCode2 = 0x96;
};
#endif // PACKET_SENDER_H