Ymodem ESP32 1.0.0
Loading...
Searching...
No Matches
YmodemCore.cpp
Go to the documentation of this file.
1
15#include "YmodemCore.h"
16
18{
19 pinMode(ledPin, OUTPUT);
20}
21
22void Ymodem::setLedPin(int pin)
23{
24 ledPin = pin;
25 // Set the LED pin as an output
26 pinMode(ledPin, OUTPUT);
27 log_i("LED pin set to %d", ledPin);
28}
29
31{
32 return ledPin;
33}
34
44void Ymodem::finalizeSession()
45{
46#if YMODEM_LED_ACT
47 digitalWrite(ledPin, YMODEM_LED_ACT_ON ^ 1);
48#endif
49}
50
51int Ymodem::receive(fs::File& ffd, unsigned int maxsize, char* getname)
52{
53 int size = 0;
54 unsigned int session_done = 0, errors = 0;
55
56 while (!session_done) {
57 int result = handleFileSession(ffd, maxsize, getname, &session_done, &errors);
58 if (result < 0) {
59 size = result; // Código de error
60 break;
61 }
62 size = result; // Tamaño del archivo recibido
63 }
64
65 finalizeSession();
66 return size;
67}
68
69int Ymodem::transmit(char* sendFileName, unsigned int sizeFile, fs::File& ffd)
70{
71 int err;
72
73 // Wait for response from receiver
75 if (err != 0) {
76 return err;
77 }
78
79 // Send initial packet
80 err = sendInitialPacket(sendFileName, sizeFile);
81 if (err != 0) {
82 return err;
83 }
84
85 // Send file blocks
86 err = sendFileBlocks(sizeFile, ffd);
87 if (err != 0) {
88 return err;
89 }
90
91 // Send EOT
92 err = sendEOT();
93 if (err != 0) {
94 return err;
95 }
96
97 // Send last packet
98 err = sendLastPacket();
99 if (err != 0) {
100 return err;
101 }
102
103 return 0; // file transmitted successfully
104}
Ymodem core functions.
#define YMODEM_LED_ACT_ON
Definition YmodemDef.h:24
int handleFileSession(fs::File &ffd, unsigned int maxsize, char *getname, unsigned int *session_done, unsigned int *errors)
Handles a file session for receiving data.
int sendInitialPacket(char *sendFileName, unsigned int sizeFile)
Sends the initial packet for a file transfer using the Ymodem protocol.
int sendFileBlocks(unsigned int sizeFile, fs::File &ffd)
Sends file blocks over a communication channel.
int waitForReceiverResponse()
Waits for a response from the receiver.
int sendEOT()
Sends the End Of Transmission (EOT) signal.
int sendLastPacket()
Sends the last packet in the Ymodem transmission.
int getLedPin()
Retrieves the pin number associated with the LED.
Ymodem()
Constructor for the Ymodem class.
int receive(fs::File &ffd, unsigned int maxsize, char *getname)
Receives data and writes it to the provided file.
void setLedPin(int pin)
Sets the pin number for the LED.
int transmit(char *sendFileName, unsigned int sizeFile, fs::File &ffd)
Transmits a file using the Ymodem protocol.