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

Don't leak msppacket every Get on HDZero/Skyzone #100

Merged
merged 1 commit into from
Jul 21, 2023
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
30 changes: 15 additions & 15 deletions src/hdzero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ uint8_t
HDZero::GetChannelIndex()
{
MSP msp;
mspPacket_t* packet = new mspPacket_t;
packet->reset();
packet->makeCommand();
packet->function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX;
mspPacket_t packet;
packet.reset();
packet.makeCommand();
packet.function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX;

// Send request, then wait for a response back from the VRX
bool receivedResponse = msp.awaitPacket(packet, m_port, VRX_RESPONSE_TIMEOUT);
bool receivedResponse = msp.awaitPacket(&packet, m_port, VRX_RESPONSE_TIMEOUT);

if (receivedResponse)
{
packet = msp.getReceivedPacket();
mspPacket_t *packetResponse = msp.getReceivedPacket();
msp.markPacketReceived();
return packet->readByte();
return packetResponse->readByte();
}

DBGLN("HDZero module: Exceeded timeout while waiting for channel index response");
Expand All @@ -61,19 +61,19 @@ uint8_t
HDZero::GetRecordingState()
{
MSP msp;
mspPacket_t* packet = new mspPacket_t;
packet->reset();
packet->makeCommand();
packet->function = MSP_ELRS_BACKPACK_GET_RECORDING_STATE;
mspPacket_t packet;
packet.reset();
packet.makeCommand();
packet.function = MSP_ELRS_BACKPACK_GET_RECORDING_STATE;

// Send request, then wait for a response back from the VRX
bool receivedResponse = msp.awaitPacket(packet, m_port, VRX_RESPONSE_TIMEOUT);
bool receivedResponse = msp.awaitPacket(&packet, m_port, VRX_RESPONSE_TIMEOUT);

if (receivedResponse)
{
packet = msp.getReceivedPacket();
mspPacket_t *packetResponse = msp.getReceivedPacket();
msp.markPacketReceived();
return packet->readByte() ? VRX_DVR_RECORDING_ACTIVE : VRX_DVR_RECORDING_INACTIVE;
return packetResponse->readByte() ? VRX_DVR_RECORDING_ACTIVE : VRX_DVR_RECORDING_INACTIVE;
}

DBGLN("HDZero module: Exceeded timeout while waiting for recording state response");
Expand Down Expand Up @@ -136,6 +136,6 @@ HDZero::SetRTC()
packet.addByte(timeData.tm_hour);
packet.addByte(timeData.tm_min);
packet.addByte(timeData.tm_sec);

msp.sendPacket(&packet, m_port);
}
28 changes: 14 additions & 14 deletions src/skyzone_msp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ uint8_t
SkyzoneMSP::GetChannelIndex()
{
MSP msp;
mspPacket_t* packet = new mspPacket_t;
packet->reset();
packet->makeCommand();
packet->function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX;
mspPacket_t packet;
packet.reset();
packet.makeCommand();
packet.function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX;

// Send request, then wait for a response back from the VRX
bool receivedResponse = msp.awaitPacket(packet, m_port, VRX_RESPONSE_TIMEOUT);
bool receivedResponse = msp.awaitPacket(&packet, m_port, VRX_RESPONSE_TIMEOUT);

if (receivedResponse)
{
packet = msp.getReceivedPacket();
mspPacket_t* packetResponse = msp.getReceivedPacket();
msp.markPacketReceived();
return packet->readByte();
return packetResponse->readByte();
}

DBGLN("Skyzone module: Exceeded timeout while waiting for channel index response");
Expand All @@ -60,19 +60,19 @@ uint8_t
SkyzoneMSP::GetRecordingState()
{
MSP msp;
mspPacket_t* packet = new mspPacket_t;
packet->reset();
packet->makeCommand();
packet->function = MSP_ELRS_BACKPACK_GET_RECORDING_STATE;
mspPacket_t packet;
packet.reset();
packet.makeCommand();
packet.function = MSP_ELRS_BACKPACK_GET_RECORDING_STATE;

// Send request, then wait for a response back from the VRX
bool receivedResponse = msp.awaitPacket(packet, m_port, VRX_RESPONSE_TIMEOUT);
bool receivedResponse = msp.awaitPacket(&packet, m_port, VRX_RESPONSE_TIMEOUT);

if (receivedResponse)
{
packet = msp.getReceivedPacket();
mspPacket_t *packetResponse = msp.getReceivedPacket();
msp.markPacketReceived();
return packet->readByte() ? VRX_DVR_RECORDING_ACTIVE : VRX_DVR_RECORDING_INACTIVE;
return packetResponse->readByte() ? VRX_DVR_RECORDING_ACTIVE : VRX_DVR_RECORDING_INACTIVE;
}

DBGLN("Skyzone module: Exceeded timeout while waiting for recording state response");
Expand Down