Author Topic: writing data to flash  (Read 12910 times)

Offline alager

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
writing data to flash
« on: December 01, 2009, 01:41:57 AM »
Mark,

We are using the telnet interface to communicate to our servers and would like to be able to pass base64 data from the server to uTasker and then save it to flash.  This is actually for a firmware upgrade function.  I thought I could base it on some of the code from the ftp.c, but in the case for STOR, after the ptrFile and ucMimeType are set, I don't see where data is actually being written to flash, it looks like the function returns shortly after that.

If you could point me in the right direction that would be great.

Thanks,
Aaron

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3240
    • View Profile
    • uTasker
Re: writing data to flash
« Reply #1 on: December 01, 2009, 12:23:05 PM »
Hi Aaron

Although FTP doesn't convert base64 data it may well be suitable as a reference for saving the data.
However FTP uses 2 TCP connections - the STOR command is received on the command connection and the data is later received on the data connection (which is opened as a consequence of the successful STOR command).

You will see that the STOR command is used to open the file and it also sets a state called ucFTP_action = DO_SAVE. This is later used by the data connection to know what it should do. On an open of the data connection the state is changed to ucFTP_action = DOING_SAVE and following data packets are saved to the uFileSystem:
eg:

    case TCP_EVENT_DATA:                                                 // we have new receive data
        if (DOING_SAVE == ucFTP_action) {
           uFileWrite(ptrFile, ucIp_Data, usPortLen SUBFILE_WRITE);      // save the received data to file. Existing files will automatically be deleted
        }
        break;


and on connection close (which always occurs after the data has been completely received) the close also closes the file

    case TCP_EVENT_CLOSED:
        if (DOING_SAVE == ucFTP_action) {
            uFileCloseMime(ptrFile, &ucMimeType);                        // this will cause the file length and type to be written in the file
            ucFTP_action = DATA_INACTIVE;
        }
...
        break;


In your case you may need to first send a command informing of the file length (and possibly its name) otherwise you will not be sure when the file has been fully received. FTP is special since it always closes the data connection to inform of the complete transmission.

Regards

Mark