Ymodem ESP32 1.0.0
Loading...
Searching...
No Matches
YmodemUtils.h File Reference

Ymodem utility functions. More...

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "driver/gpio.h"
#include "rom/crc.h"
#include <FS.h>
#include <driver/uart.h>
#include "YmodemDef.h"
+ Include dependency graph for YmodemUtils.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void IRAM_ATTR LED_toggle ()
 Toggles the state of an LED.
 
unsigned short crc16 (const unsigned char *buf, unsigned long count)
 Computes the CRC-16 checksum for a given buffer.
 
int32_t Receive_Byte (unsigned char *c, uint32_t timeout)
 Receives a byte from a communication interface.
 
void uart_consume ()
 Consumes data from the UART buffer.
 
uint32_t Send_Byte (char c)
 Sends a single byte of data.
 
void send_CA ()
 Sends the CA (Cancel) signal.
 
void send_ACK ()
 Sends an acknowledgment (ACK) signal.
 
void send_ACKCRC16 ()
 Sends an acknowledgment with CRC16.
 
void send_NAK ()
 Sends a Negative Acknowledgement (NAK) signal.
 
void send_CRC16 ()
 Sends the CRC16 checksum.
 
int32_t Receive_Packet (uint8_t *data, int *length, uint32_t timeout)
 Receives a packet of data.
 

Detailed Description

Ymodem utility functions.

Author
Miguel Ferrer (mferr.nosp@m.er@i.nosp@m.nbiot.nosp@m..es)
Version
0.1
Date
2025-01-24

This file contains utility functions used in the Ymodem protocol implementation. These functions provide low-level functionality for sending and receiving data over a serial connection using the Ymodem protocol.

Definition in file YmodemUtils.h.

Function Documentation

◆ crc16()

unsigned short crc16 ( const unsigned char * buf,
unsigned long count )

Computes the CRC-16 checksum for a given buffer.

This function calculates the CRC-16 checksum for the provided buffer using a standard polynomial. The CRC-16 checksum is commonly used for error-checking in data transmission and storage.

Parameters
bufPointer to the buffer containing the data to be checksummed.
countThe number of bytes in the buffer.
Returns
The computed CRC-16 checksum as an unsigned short.

Definition at line 29 of file YmodemUtils.cpp.

◆ LED_toggle()

void IRAM_ATTR LED_toggle ( )

Toggles the state of an LED.

This function is marked with the IRAM_ATTR attribute, indicating that it should be placed in the IRAM (Instruction RAM) for faster execution. This is typically used for functions that need to be executed quickly, such as interrupt service routines.

Note: Ensure that the LED is properly initialized before calling this function.

Definition at line 17 of file YmodemUtils.cpp.

◆ Receive_Byte()

int32_t Receive_Byte ( unsigned char * c,
uint32_t timeout )

Receives a byte from a communication interface.

This function attempts to receive a single byte from a communication interface within a specified timeout period.

Parameters
[out]cPointer to an unsigned char where the received byte will be stored.
[in]timeoutThe maximum time to wait for a byte to be received, in milliseconds.
Returns
int32_t Returns 0 on success, or a negative error code on failure.

Definition at line 47 of file YmodemUtils.cpp.

◆ Receive_Packet()

int32_t Receive_Packet ( uint8_t * data,
int * length,
uint32_t timeout )

Receives a packet of data.

This function attempts to receive a packet of data within a specified timeout period.

Parameters
dataPointer to the buffer where the received data will be stored.
lengthPointer to an integer where the length of the received data will be stored.
timeoutThe maximum time to wait for a packet, in milliseconds.
Returns
int32_t Returns the status of the packet reception. A non-negative value indicates success, while a negative value indicates an error.

Definition at line 101 of file YmodemUtils.cpp.

◆ send_ACK()

void send_ACK ( )

Sends an acknowledgment (ACK) signal.

This function is used to send an ACK signal to indicate successful receipt of data or successful completion of a process.

Definition at line 80 of file YmodemUtils.cpp.

◆ send_ACKCRC16()

void send_ACKCRC16 ( )

Sends an acknowledgment with CRC16.

This function sends an acknowledgment (ACK) signal with a CRC16 checksum. It is typically used in communication protocols to confirm the successful receipt of data.

Definition at line 85 of file YmodemUtils.cpp.

◆ Send_Byte()

uint32_t Send_Byte ( char c)

Sends a single byte of data.

This function transmits a single character (byte) over a communication interface.

Parameters
cThe character to be sent.
Returns
uint32_t Returns a status code indicating the result of the operation.

Definition at line 65 of file YmodemUtils.cpp.

◆ send_CA()

void send_CA ( )

Sends the CA (Cancel) signal.

This function is used to send the CA (Cancel) signal, which is typically used to abort an ongoing operation or communication.

Definition at line 74 of file YmodemUtils.cpp.

◆ send_CRC16()

void send_CRC16 ( )

Sends the CRC16 checksum.

This function calculates and sends the CRC16 checksum for data integrity verification. It is typically used in communication protocols to ensure that the transmitted data has not been corrupted.

Definition at line 96 of file YmodemUtils.cpp.

◆ send_NAK()

void send_NAK ( )

Sends a Negative Acknowledgement (NAK) signal.

This function is used to send a NAK signal, typically in communication protocols, to indicate that the received data is not valid or an error has occurred.

Definition at line 91 of file YmodemUtils.cpp.

◆ uart_consume()

void uart_consume ( )

Consumes data from the UART buffer.

This function reads and discards data from the UART buffer. It is typically used to clear the buffer of any unwanted or residual data before starting a new communication session or operation.

Definition at line 58 of file YmodemUtils.cpp.