mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-23 03:00:56 +00:00
add more documentaiton
This commit is contained in:
committed by
Thomas Göttgens
parent
641d117106
commit
e9cbe54eca
@@ -1,3 +1,18 @@
|
||||
/**
|
||||
* @file xmodem.cpp
|
||||
* @brief Implementation of XMODEM protocol for Meshtastic devices.
|
||||
*
|
||||
* This file contains the implementation of the XMODEM protocol for Meshtastic devices. It is based on the XMODEM implementation by Georges Menie (www.menie.org) and has been adapted for protobuf encapsulation.
|
||||
*
|
||||
* The XMODEM protocol is used for reliable transmission of binary data over a serial connection. This implementation supports both sending and receiving of data.
|
||||
*
|
||||
* The XModemAdapter class provides the main functionality for the protocol, including CRC calculation, packet handling, and control signal sending.
|
||||
*
|
||||
* @copyright Copyright (c) 2001-2019 Georges Menie
|
||||
* @author
|
||||
* @author
|
||||
* @date
|
||||
*/
|
||||
/***********************************************************************************************************************
|
||||
* based on XMODEM implementation by Georges Menie (www.menie.org)
|
||||
***********************************************************************************************************************
|
||||
@@ -36,6 +51,13 @@ XModemAdapter xModem;
|
||||
|
||||
XModemAdapter::XModemAdapter() {}
|
||||
|
||||
/**
|
||||
* Calculates the CRC-16 CCITT checksum of the given buffer.
|
||||
*
|
||||
* @param buffer The buffer to calculate the checksum for.
|
||||
* @param length The length of the buffer.
|
||||
* @return The calculated checksum.
|
||||
*/
|
||||
unsigned short XModemAdapter::crc16_ccitt(const pb_byte_t *buffer, int length)
|
||||
{
|
||||
unsigned short crc16 = 0;
|
||||
@@ -52,6 +74,15 @@ unsigned short XModemAdapter::crc16_ccitt(const pb_byte_t *buffer, int length)
|
||||
return crc16;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the checksum of the given buffer and compares it to the given
|
||||
* expected checksum. Returns 1 if the checksums match, 0 otherwise.
|
||||
*
|
||||
* @param buf The buffer to calculate the checksum of.
|
||||
* @param sz The size of the buffer.
|
||||
* @param tcrc The expected checksum.
|
||||
* @return 1 if the checksums match, 0 otherwise.
|
||||
*/
|
||||
int XModemAdapter::check(const pb_byte_t *buf, int sz, unsigned short tcrc)
|
||||
{
|
||||
return crc16_ccitt(buf, sz) == tcrc;
|
||||
|
||||
Reference in New Issue
Block a user