Markus Paar
/
firmware
firmware update from USB stick, does not work properly. If someone can get it work, please inform me.
Embed:
(wiki syntax)
Show/hide line numbers
FirmwareUpdater.h
00001 /** 00002 * ============================================================================= 00003 * Firmware updater (Version 0.0.1) 00004 * ============================================================================= 00005 * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems) 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a copy 00008 * of this software and associated documentation files (the "Software"), to deal 00009 * in the Software without restriction, including without limitation the rights 00010 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00011 * copies of the Software, and to permit persons to whom the Software is 00012 * furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included in 00015 * all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00018 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00020 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00021 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00022 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00023 * THE SOFTWARE. 00024 * ============================================================================= 00025 */ 00026 00027 #ifndef FIRMWARE_UPDATER_H 00028 #define FIRMWARE_UPDATER_H 00029 00030 #include "mbed.h" 00031 #include "LocalFileSystem.h" 00032 #include "MSCFileSystem.h" 00033 #include <string> 00034 00035 /** 00036 * @code 00037 * #include "mbed.h" 00038 * #include "FirmwareUpdater.h" 00039 * #include "EthernetNetIf.h" 00040 * 00041 * EthernetNetIf eth; 00042 * FirmwareUpdater fwup("http://mbed.org/media/uploads/shintamainjp/", "firmware", true); 00043 * 00044 * // There are 2 files for the firmware. 00045 * // 1. firmware.txt : firmware version file. 00046 * // 2. firmware.bin : firmware binary file. 00047 * 00048 * int main() { 00049 * eth.setup(); 00050 * if (fwup.exist() == 0) { 00051 * printf("Found a new firmware.\n"); 00052 * if (fwup.execute() == 0) { 00053 * printf("Update succeed.\n"); 00054 * printf("Resetting this system...\n\n\n\n\n"); 00055 * fwup.reset(); 00056 * } else { 00057 * printf("Update failed!\n"); 00058 * } 00059 * } 00060 * } 00061 * @endcode 00062 */ 00063 class FirmwareUpdater { 00064 public: 00065 /** 00066 * Create. 00067 * 00068 * @param url URL for firmware. Do not include a target file name. 00069 * @param name An application name. Do not include a extention. 00070 * @param log True if logging. 00071 */ 00072 FirmwareUpdater(std::string src_name, std::string dest_name, bool log = false); 00073 00074 /** 00075 * Dispose. 00076 */ 00077 ~FirmwareUpdater(); 00078 00079 /** 00080 * Get a URL. 00081 * 00082 * @return URL. 00083 */ 00084 const std::string get_src_name() const; 00085 00086 /** 00087 * Get a name. 00088 * 00089 * @return name. 00090 */ 00091 const std::string get_dest_name() const; 00092 00093 /** 00094 * Checking a new firmware. 00095 * Compare versions of the software between local storage on mbed and on webserver. 00096 * 00097 * @return Return 0 if a new firmware exists. 00098 */ 00099 int exist(); 00100 00101 /** 00102 * Execute update. 00103 * 00104 * @return Return 0 if it succeed. 00105 */ 00106 int execute(); 00107 00108 /** 00109 * Reset system. 00110 */ 00111 void reset(); 00112 00113 private: 00114 static const std::string EXT_BIN; 00115 static const std::string EXT_BINTMP; 00116 static const std::string EXT_TXT; 00117 static const std::string EXT_TXTTMP; 00118 const std::string src_name; 00119 const std::string dest_name; 00120 const bool log; 00121 LocalFileSystem local; 00122 00123 00124 /** 00125 * Fetch a file. 00126 * 00127 * @param src_url URL of a source file. 00128 * @param local_file Local file name. 00129 * 00130 * @return Return 0 if it succeed. 00131 */ 00132 int fetch(std::string src_url, std::string local_file); 00133 00134 /** 00135 * Copy a file. 00136 * 00137 * @param local_file1 Source file. 00138 * @param local_file2 Destination file. 00139 * 00140 * @return Return 0 if it succeed. 00141 */ 00142 int copy(std::string local_file1, std::string local_file2); 00143 00144 /** 00145 * Output a message to a log file. 00146 * 00147 * @param format ... 00148 */ 00149 void LOG(const char* format, ...); 00150 00151 }; 00152 00153 #endif
Generated on Wed Jul 13 2022 17:07:14 by 1.7.2