Skip to content

Commit ef8f283

Browse files
DONE
1 parent cde9bc9 commit ef8f283

File tree

4 files changed

+446
-14
lines changed

4 files changed

+446
-14
lines changed

FprimeZephyrReference/Components/CameraHandler/CameraHandler.cpp

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ void CameraHandler ::TAKE_IMAGE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
157157
}
158158

159159
void CameraHandler ::PING_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
160+
if (this->m_receiving) {
161+
this->log_WARNING_LO_FailedCommandCurrentlyReceiving();
162+
return;
163+
}
164+
this->m_waiting_for_pong = true;
160165
const char* pingCmd = "ping";
161166
SEND_COMMAND_cmdHandler(opCode, cmdSeq, Fw::CmdStringArg(pingCmd));
162167
}
163168

164-
void CameraHandler ::SET_IMAGE_QUALITY_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
165-
const char* takeImageCmd = "snap";
166-
SEND_COMMAND_cmdHandler(opCode, cmdSeq, Fw::CmdStringArg(takeImageCmd));
167-
}
168-
169169
void CameraHandler ::SEND_COMMAND_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdStringArg& cmd) {
170170
// Append newline to command to send to PayloadCom
171171
Fw::CmdStringArg tempCmd = cmd;
@@ -184,7 +184,6 @@ void CameraHandler ::SEND_COMMAND_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, co
184184
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
185185
}
186186

187-
188187
// ----------------------------------------------------------------------
189188
// Helper method implementations
190189
// ----------------------------------------------------------------------
@@ -219,6 +218,22 @@ void CameraHandler ::processProtocolBuffer() {
219218
}
220219

221220
if (headerStart == -1) {
221+
222+
// Check for PONG response (only if buffer has enough bytes)
223+
if (m_protocolBufferSize >= PONG_LEN) {
224+
for (U32 i = 0; i <= m_protocolBufferSize - PONG_LEN; ++i) {
225+
if (isPong(&m_protocolBuffer[i], m_protocolBufferSize - i)) {
226+
if (this->m_waiting_for_pong){
227+
this->log_ACTIVITY_HI_PongReceived();
228+
this->m_waiting_for_pong = false;
229+
} else {
230+
this->log_WARNING_HI_BadPongReceived();
231+
}
232+
return;
233+
}
234+
}
235+
}
236+
222237
// No header found - if buffer is nearly full, discard old data
223238
// Be aggressive: if buffer is > 50% full and no header, it's probably text responses
224239
if (m_protocolBufferSize > (PROTOCOL_BUFFER_SIZE / 2)) {
@@ -496,4 +511,21 @@ bool CameraHandler ::isImageStartCommand(const U8* line, U32 length) {
496511

497512
return true;
498513
}
514+
515+
bool CameraHandler ::isPong(const U8* line, U32 length) {
516+
const char* command = "PONG";
517+
518+
if (length < PONG_LEN) {
519+
return false;
520+
}
521+
522+
for (U32 i = 0; i < PONG_LEN; ++i) {
523+
if (line[i] != static_cast<U8>(command[i])) {
524+
return false;
525+
}
526+
}
527+
528+
return true;
529+
}
530+
499531
} // namespace Components

FprimeZephyrReference/Components/CameraHandler/CameraHandler.fpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ module Components {
1010
@ Camera Ping
1111
sync command PING()
1212

13-
@ Set Camera Format
14-
sync command SET_IMAGE_QUALITY()
15-
1613
@ Send command to camera via PayloadCom
1714
sync command SEND_COMMAND(cmd: string)
1815

@@ -31,6 +28,12 @@ module Components {
3128
@ Emitted when image transfer completes successfully
3229
event ImageTransferComplete(path: string, $size: U32) severity activity high format "Image saved: {} ({} bytes)"
3330

31+
event FailedCommandCurrentlyReceiving() severity warning low format "Cannot send command while image is receiving!"
32+
33+
event PongReceived() severity activity high format "Ping Received"
34+
35+
event BadPongReceived() severity warning high format "Ping Received when we did not expect it!"
36+
3437
# Telemetry for debugging image transfer state
3538
@ Number of bytes received so far in current image transfer
3639
telemetry BytesReceived: U32

FprimeZephyrReference/Components/CameraHandler/CameraHandler.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ class CameraHandler final : public CameraHandlerComponentBase {
5858
void PING_cmdHandler(FwOpcodeType opCode, //!< The opcode
5959
U32 cmdSeq //!< The command sequence number
6060
) override;
61-
62-
void SET_IMAGE_QUALITY_cmdHandler(FwOpcodeType opCode, //!< The opcode
63-
U32 cmdSeq //!< The command sequence number
64-
) override;
6561

6662
// ----------------------------------------------------------------------
6763
// Helper methods for protocol processing
@@ -95,12 +91,16 @@ class CameraHandler final : public CameraHandlerComponentBase {
9591
//! Returns true if line is "<IMG_START>"
9692
bool isImageStartCommand(const U8* line, U32 length);
9793

94+
bool isPong(const U8* line, U32 length);
95+
9896
// ----------------------------------------------------------------------
9997
// Member variables
10098
// ----------------------------------------------------------------------
10199

102100
U8 m_data_file_count = 0;
103101
bool m_receiving = false;
102+
bool m_waiting_for_pong = false;
103+
104104
U32 m_bytes_received = 0;
105105
U32 m_file_error_count = 0; // Track total file errors
106106
U32 m_images_saved = 0; // Track total images successfully saved
@@ -123,12 +123,17 @@ class CameraHandler final : public CameraHandlerComponentBase {
123123
static constexpr U32 SIZE_VALUE_LEN = 4; // 4-byte little-endian uint32
124124
static constexpr U32 SIZE_CLOSE_TAG_LEN = 7; // strlen("</SIZE>")
125125
static constexpr U32 IMG_END_LEN = 9; // strlen("<IMG_END>")
126-
126+
static constexpr U32 PONG_LEN = 4; // strlen("PONG")
127+
static constexpr U32 QUAL_SET_HD = 22; // strlen("<FRAME_CHANGE_SUCCESS>")
128+
129+
127130
// Derived constants
128131
static constexpr U32 HEADER_SIZE = IMG_START_LEN + SIZE_TAG_LEN + SIZE_VALUE_LEN + SIZE_CLOSE_TAG_LEN; // 28 bytes
129132
static constexpr U32 SIZE_TAG_OFFSET = IMG_START_LEN; // 11
130133
static constexpr U32 SIZE_VALUE_OFFSET = IMG_START_LEN + SIZE_TAG_LEN; // 17
131134
static constexpr U32 SIZE_CLOSE_TAG_OFFSET = SIZE_VALUE_OFFSET + SIZE_VALUE_LEN; // 21
135+
136+
132137

133138
U32 m_expected_size = 0; // Expected image size from header
134139
U8 m_lastMilestone = 0; // Last progress milestone emitted (0, 25, 50, 75)

0 commit comments

Comments
 (0)