SWUpdate library to be used with RPC.

Fork of SWUpdate by David Smart

Committer:
WiredHome
Date:
Sat Jun 14 18:18:28 2014 +0000
Revision:
3:c69fff55fc60
Parent:
2:ef2ac9627546
Child:
4:1a3656ae80dc
Updated documentation to support integrity checking.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 0:e221363f7942 1
WiredHome 0:e221363f7942 2 #include "mbed.h"
WiredHome 0:e221363f7942 3
WiredHome 0:e221363f7942 4 #ifndef SWUPDATE_H
WiredHome 0:e221363f7942 5 #define SWUPDATE_H
WiredHome 0:e221363f7942 6
WiredHome 1:208de08b1a19 7 /// After downloading, the user can choose what happens next.
WiredHome 0:e221363f7942 8 typedef enum {
WiredHome 0:e221363f7942 9 DEFER_REBOOT,
WiredHome 0:e221363f7942 10 AUTO_REBOOT
WiredHome 0:e221363f7942 11 } Reboot_T;
WiredHome 0:e221363f7942 12
WiredHome 1:208de08b1a19 13 /// This API performs some processing to see if a web server
WiredHome 1:208de08b1a19 14 /// has an updated version of software. If it does, then it
WiredHome 1:208de08b1a19 15 /// will try to download it. If that succeeds, then it can
WiredHome 1:208de08b1a19 16 /// optionally reboot to activate the new software.
WiredHome 1:208de08b1a19 17 ///
WiredHome 3:c69fff55fc60 18 /// The files on the web server are as follows:
WiredHome 3:c69fff55fc60 19 /// @li myprog.bin - The actual binary file. The name is unimportant, but
WiredHome 3:c69fff55fc60 20 /// this is the binary file that was generated from the sources.
WiredHome 3:c69fff55fc60 21 /// @li myprog.txt - A corresponding text file. The root name must match
WiredHome 3:c69fff55fc60 22 /// that of the binary file.
WiredHome 3:c69fff55fc60 23 ///
WiredHome 3:c69fff55fc60 24 /// The myprog.txt file shall have 3 comma-separated numbers in it.
WiredHome 3:c69fff55fc60 25 /// version,checksum,filesize (ex: "21,41384,107996")
WiredHome 3:c69fff55fc60 26 ///
WiredHome 3:c69fff55fc60 27 /// @li version is a simple number. If the number is different than
WiredHome 3:c69fff55fc60 28 /// what is stored on the local file system, then the program
WiredHome 3:c69fff55fc60 29 /// will be updated (even if the server number is lower).
WiredHome 3:c69fff55fc60 30 /// @li checksum is the decimal representation of a simple 16-bit checksum.
WiredHome 3:c69fff55fc60 31 /// @li filesize is the decimal representation of the size of the file.
WiredHome 3:c69fff55fc60 32 ///
WiredHome 3:c69fff55fc60 33 /// You can create the server "myprog.txt" file with this perl script (not
WiredHome 3:c69fff55fc60 34 /// every detail is shown, but it should be easy to figure out).
WiredHome 3:c69fff55fc60 35 ///
WiredHome 3:c69fff55fc60 36 /// # Read current .txt file
WiredHome 3:c69fff55fc60 37 /// <<code>>
WiredHome 3:c69fff55fc60 38 /// open (FT, "<$txt") || die("Can't read $txt.");
WiredHome 3:c69fff55fc60 39 /// $ver = <FT>; chomp $ver; close FT;
WiredHome 3:c69fff55fc60 40 /// $ver =~ s/(\d+),.*/$1/;
WiredHome 3:c69fff55fc60 41 /// print "Current Version is {$ver}\n";
WiredHome 3:c69fff55fc60 42 ///
WiredHome 3:c69fff55fc60 43 /// # Read new .bin file
WiredHome 3:c69fff55fc60 44 /// open (FB, "<$bin") || die("Can't read $bin.");
WiredHome 3:c69fff55fc60 45 /// binmode FB;
WiredHome 3:c69fff55fc60 46 /// while (sysread(FB, $c, 1))
WiredHome 3:c69fff55fc60 47 /// {
WiredHome 3:c69fff55fc60 48 /// $cksum = ($cksum + ord($c)) & 0xFFFF;
WiredHome 3:c69fff55fc60 49 /// $byteCount++;
WiredHome 3:c69fff55fc60 50 /// }
WiredHome 3:c69fff55fc60 51 /// close FB;
WiredHome 3:c69fff55fc60 52 /// # Advance version
WiredHome 3:c69fff55fc60 53 /// $ver++; print "$ver Checksum is $cksum over $byteCount bytes.\n";
WiredHome 3:c69fff55fc60 54 /// open (FT, ">$txt") || die("Can't write update to $txt.");
WiredHome 3:c69fff55fc60 55 /// printf(FT "%d,%d,%d\n", $ver, $cksum,$byteCount);
WiredHome 3:c69fff55fc60 56 /// close FT;
WiredHome 3:c69fff55fc60 57 /// <</code>>
WiredHome 1:208de08b1a19 58 ///
WiredHome 1:208de08b1a19 59 /// @param url is a pointer to a text string of the url from which to download.
WiredHome 1:208de08b1a19 60 /// @param name is the base filename of the binary file.
WiredHome 1:208de08b1a19 61 /// @param reboot determines whether to automatically reboot to activate the new bin.
WiredHome 2:ef2ac9627546 62 /// @return true if the update succeeded (and the reboot was set to DEFER_REBOOT).
WiredHome 1:208de08b1a19 63 ///
WiredHome 0:e221363f7942 64 bool SoftwareUpdate(const char *url, const char * name, Reboot_T reboot = DEFER_REBOOT);
WiredHome 0:e221363f7942 65
WiredHome 0:e221363f7942 66 #endif // SWUPDATE_H