1

I need to transfer files from the SPIFFS of the ESP8266 (Arduino/C++) to the PC over serial communication and using the YMODEM protocol.

As far as the YMODEM protocol is concerned, I have a complete implementation including auxiliary functions needed by the protocol and my project compiles successfully without any issue. However, the problem lies in the following function needed to transfer the file:

/**
  * @brief  Transmit a file using the YMODEM protocol
  * @param  buffer: Address of the first byte
  * @retval The size of the file
  */
uint8_t Ymodem_Trsfer(uint8_t *buffer, const uint8_t* sendFileName, uint32_t sizeFile)
{
   // code goes here
}

As you can see above, the function takes a pointer to a data buffer as a parameter. The file I want to transfer (almost 64 KB) is a binary file stored into the SPIFFS and downloaded earlier from web server over HTTP. I have no problem reading bytes from file and using most Stream methods on it, however, I'm not sure how to pass the address of the open file/stream to the function above so I can send its contents over YMODEM.

I have certain scenarios in mind, but I'd love to get some feedback first.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • 1
    It doesn't look like you can pass the file stream to it. It looks like you are expected to have already read the file stream into a `char` array and use the `char` array as the `buffer` argument. – user4581301 Aug 13 '19 at 21:00
  • 2
    This looks to be good reading for inspiration: [How to read a binary file into a vector of unsigned chars](https://stackoverflow.com/questions/15138353/how-to-read-a-binary-file-into-a-vector-of-unsigned-chars) – user4581301 Aug 13 '19 at 21:02
  • @user4581301: Yes, this is one of the scenarios I had in mind, but the main constraint here is the SRAM available for user on this tiny chip, which is below 40 KB. Perhaps splitting the file into multiple chunks could help do it? – Embedded Music Aug 13 '19 at 21:17
  • 1
    You may want to modify the `Ymodem_Trsfer` so that you can send in blocks, IOW, not all the file is stored in memory. This will allow you to fill up a buffer, call the function, fill up another buffer, call the function, etc. The Y-Modem protocol should be able to handle "chunks" of data. I don't remember if there is a total number of chunks in the protocol. Time for some protocol research. :-) – Thomas Matthews Aug 13 '19 at 21:22
  • If you can, try switching to USB. The block transfer protocol would be better suited for your application. – Thomas Matthews Aug 13 '19 at 21:23
  • @ThomasMatthews: I wish I could. The problem is I'm forced to use yModem on this particular one. As far as the protocol is concerned, yep, the protocol divides the data into multiple 128-byte and 1024-byte blocks. So the maximum size of data to send in one block is 1024 bytes. I guess the only way to work around this is to modify the ymodem_Trsfer() to alternate between several iterations, like you said earlier. – Embedded Music Aug 13 '19 at 21:56
  • Zoinks. Right. I wasn't paying enough attention to the embedded nature of what you were doing. The whole point of Y modem was small chunks over an unreliable network. Having to feed a massive byte array into it is kind-of stupid. you WANT to read the file chunk by chunk. If you have the source code, you can chop the head off of it, and feed it chunks straight from the file. If not, take comfort in Ymodem being a relatively simple protocol to write from scratch. – user4581301 Aug 13 '19 at 21:58
  • @user4581301: In fact, being forced to use this ancient protocol is kinda stupid in its essence, too. The problem is memory constraint for this SoC, otherwise, I could have easily read the whole file into a char array and called it a day! 'Embedded' flag has been added! – Embedded Music Aug 13 '19 at 22:08
  • Last time I had to write one of these was Zmodem back in 2006. But I'm semi-regularly writing stuff *like* this for people who want to misuse zigbee. – user4581301 Aug 13 '19 at 22:10
  • Nothing ever dies on the Internet so Chuck Forsberg's Y modem reference "book" is probably floating around somewhere. The hard part will probably be getting the CRC working correctly. – user4581301 Aug 13 '19 at 22:17
  • Like I said earlier, I've got the full source for the complete implementation for yModem and it works perfectly for another architecture. The problem is how to solve the parsing of the file on the ESP8266. – Embedded Music Aug 13 '19 at 22:20
  • You were correct. It's still of relevance for many projects around embedded world and probably beyond. I have the reference by Chuck Forsberg, and by the way, my source has all other functions needed as per the specs, including the CRC16 calculation algorithm. – Embedded Music Aug 13 '19 at 22:24

0 Answers0