Skip to content

Commit

Permalink
Added CRC-Checking-call in Service-Interface
Browse files Browse the repository at this point in the history
  • Loading branch information
F-L-X-S committed Dec 18, 2024
1 parent 6d32141 commit 52d27f9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/ModbusRTU/ServiceInterface_modbusRTU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ void ServiceInterface_modbusRTU::getPDU_from_services()

};

/**
* @brief Check the CRC-validity of all Frames on the receive-stack and discard invalid Frames.
* Raise crcError if invalid frame was found.
*
*/
void ServiceInterface_modbusRTU::discardInvalidFrames()
{
// iterate through rec-stack
for (size_t i = 0; i < STACKSIZE; i++)
{
if (Frame_modbusRTU* frame = recStack.getElement(i)){
// check CRC for frame stored on index i
if (!frame->checkCRC16()){
recStack.deleteElement(i);
raiseError(crcError);
}
}else{
// leave loop if no frame is stored on index i
break;
};
}
}

// Execute all relevant tasks for transferring data between CommInterface and Services:
// - Get PDU from Services
Expand All @@ -74,6 +96,9 @@ void ServiceInterface_modbusRTU::communicate()
// get incoming frames from the Communication-Interface
processRecStack();

// Check received Frames for crc-validity
discardInvalidFrames();

// interact with Services
addPDU_to_services();
processServices();
Expand Down
7 changes: 7 additions & 0 deletions lib/ModbusRTU/ServiceInterface_modbusRTU.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ class ServiceInterface_modbusRTU: public ServiceInterface<CommInterface_modbusRT
*/
void getPDU_from_services() override;

/**
* @brief Check the CRC-validity of all Frames on the receive-stack and discard invalid Frames.
* Raise crcError if invalid frame was found.
*
*/
void discardInvalidFrames();

};

#endif // SERVICEINTERFACE_MODBUSRTU

0 comments on commit 52d27f9

Please sign in to comment.