SWUpdate library to be used with RPC.

Fork of SWUpdate by David Smart

SWUpdate.h

Committer:
WiredHome
Date:
2014-06-14
Revision:
4:1a3656ae80dc
Parent:
3:c69fff55fc60
Child:
5:e10f18e9b93a

File content as of revision 4:1a3656ae80dc:

/// Firmware Over The Air (FOTA) Update.
///
#include "mbed.h"

#ifndef SWUPDATE_H
#define SWUPDATE_H

/// After downloading, the user can choose what happens next.
typedef enum {
    DEFER_REBOOT,
    AUTO_REBOOT
} Reboot_T;

/// This API performs some processing to see if a web server
/// has an updated version of software. If it does, then it
/// will try to download it. If that succeeds, then it can
/// optionally reboot to activate the new software.
///
/// The files on the web server are as follows:
///   @li myprog.bin - The actual binary file. The name is unimportant, but
///             this is the binary file that was generated from the sources.
///   @li myprog.txt - A corresponding text file. The root name must match
///             that of the binary file.
///
/// The myprog.txt file shall have 3 comma-separated numbers in it.
///   version,checksum,filesize (ex: "21,41384,107996")
///
///   @li version is a simple number. If the number is different than
///             what is stored on the local file system, then the program
///             will be updated (even if the server number is lower).
///   @li checksum is the decimal representation of a simple 16-bit checksum.
///   @li filesize is the decimal representation of the size of the file.
///
/// You can create the server "myprog.txt" file with this perl script (not
/// every detail is shown, but it should be easy to figure out).
/// <<code>>
/// # Read current .txt file
/// open (FT, "<$txt") || die("Can't read $txt.");
/// $ver = <FT>; chomp $ver; close FT;
/// $ver =~ s/(\d+),.*/$1/;
/// print "Current Version is {$ver}\n";
/// 
/// # Read new .bin file
/// open (FB, "<$bin") || die("Can't read $bin.");
/// binmode FB;
/// while (sysread(FB, $c, 1))
///     {
///     $cksum = ($cksum + ord($c)) & 0xFFFF;
///     $byteCount++;
///     }
/// close FB;
/// # Advance version number and write the new .txt file
/// $ver++; print "$ver Checksum is $cksum over $byteCount bytes.\n";
/// open (FT, ">$txt") || die("Can't write update to $txt.");
/// printf(FT "%d,%d,%d\n", $ver, $cksum,$byteCount);
/// close FT;
/// <</code>>
///
/// @param url is a pointer to a text string of the url from which to download.
/// @param name is the base filename of the binary file.
/// @param reboot determines whether to automatically reboot to activate the new bin.
/// @return true if the update succeeded (and the reboot was set to DEFER_REBOOT).
///
bool SoftwareUpdate(const char *url, const char * name, Reboot_T reboot = DEFER_REBOOT);

#endif // SWUPDATE_H