aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorToni Uhlig <Toni.Uhlig@tq-group.com>2017-11-30 16:55:09 +0100
committerToni Uhlig <Toni.Uhlig@tq-group.com>2017-11-30 16:55:09 +0100
commitf33b50ead78caf56e38a82bd8748c6b811b36dc0 (patch)
tree25bc7769f89ea84da7b9166468c39612460383f9 /src
parent6f0e2dda985d42d4e8837482c82b13f927bb8154 (diff)
EMC version check support (remote/local-image)
Diffstat (limited to 'src')
-rw-r--r--src/JobQueue.cpp12
-rw-r--r--src/UpdateFactory.cpp51
-rw-r--r--src/UpdateFactory.hpp10
-rw-r--r--src/UpdateGUI.cpp1
-rw-r--r--src/UpdateTool.cpp24
5 files changed, 73 insertions, 25 deletions
diff --git a/src/JobQueue.cpp b/src/JobQueue.cpp
index 33b7dce..7615879 100644
--- a/src/JobQueue.cpp
+++ b/src/JobQueue.cpp
@@ -57,10 +57,10 @@ void WorkerThread::doJob()
uf.setPass(job.m_Arg.password);
rv = uf.doAuth();
- if (uf.getVersion() != EMC_UNKNOWN) {
+ if (uf.getEmcVersion() != EMC_UNKNOWN) {
m_pQueue->Report(Job::eID_THREAD_MSG,
wxString::Format(wxT("Job #%d: Current EnergyManager version: %s"),
- job.m_Arg.jobid, mapEmcVersion(uf.getVersion())), m_ID);
+ job.m_Arg.jobid, mapEmcVersion(uf.getEmcVersion())), m_ID);
}
if (rv != UPDATE_OK) {
@@ -72,10 +72,13 @@ void WorkerThread::doJob()
}
m_pQueue->Report(Job::eID_THREAD_MSG,
- wxString::Format(wxT("Job #%d: Uploading file \"%s\""),
+ wxString::Format(wxT("Job #%d: Loading file \"%s\""),
job.m_Arg.jobid, job.m_Arg.update_file), m_ID);
uf.setUpdateFile(job.m_Arg.update_file.c_str());
rv = uf.loadUpdateFile();
+ m_pQueue->Report(Job::eID_THREAD_MSG,
+ wxString::Format(wxT("Job #%d: Firmware image version: %s"),
+ job.m_Arg.jobid, mapEmcVersion(uf.getFwVersion())), m_ID);
if (rv != UPDATE_OK) {
mapEmcError(rv, err);
m_pQueue->Report(Job::eID_THREAD_MSGERR,
@@ -84,6 +87,9 @@ void WorkerThread::doJob()
break;
}
+ m_pQueue->Report(Job::eID_THREAD_MSG,
+ wxString::Format(wxT("Job #%d: Uploading file \"%s\""),
+ job.m_Arg.jobid, job.m_Arg.update_file), m_ID);
rv = uf.doUpdate();
mapEmcError(rv, err);
if (rv != UPDATE_OK) {
diff --git a/src/UpdateFactory.cpp b/src/UpdateFactory.cpp
index a614d79..d3c8921 100644
--- a/src/UpdateFactory.cpp
+++ b/src/UpdateFactory.cpp
@@ -1,4 +1,5 @@
#include <iostream>
+#include <fstream>
#include <string>
#include <sstream>
#include <unordered_map>
@@ -7,6 +8,9 @@
#include "UpdateFactory.hpp"
#include "Csv.hpp"
+/* update image trailer data structure */
+#include "trailer.h"
+
/* debug only */
#if 0
@@ -53,7 +57,24 @@ std::string mapEmcVersion(EMCVersion ver)
for (auto& v : version_map)
if (v.second == ver)
return v.first;
- return "";
+ return "Unknown";
+}
+
+bool isEmcVersionLowerThen(enum EMCVersion ver, enum EMCVersion check_ver)
+{
+ size_t i = 0, j = 0;
+
+ for (auto& v : version_map) {
+ i++;
+ if (v.second == ver)
+ break;
+ }
+ for (auto& v : version_map) {
+ j++;
+ if (v.second == check_ver)
+ break;
+ }
+ return (i > j);
}
static const std::map<const int, const std::string> error_map = {
@@ -64,6 +85,7 @@ static const std::map<const int, const std::string> error_map = {
{ UPDATE_JSON_ERROR, "Invalid JSON HTTP response (not an EnergyManager)" },
{ UPDATE_AUTH_ERROR, "Authentication failed" },
{ UPDATE_VERSION, "Invalid EnergyManager version" },
+ { UPDATE_UPDATED, "EnergyManager already updated to an equal or higher firmware version" },
{ UPDATE_FILE, "Could not open update file" }
};
@@ -100,8 +122,8 @@ inline void dump_class(UpdateFactory *uf)
std::cerr << "Host...: " << uf->hostname << ":" << uf->port << std::endl;
if (!uf->emc_serial.empty())
std::cerr << "Serial.: " << uf->emc_serial << std::endl;
- if (!uf->emc_version.empty())
- std::cerr << "Version: " << uf->emc_version << std::endl;
+ if (uf->mapped_emc_version != EMC_UNKNOWN)
+ std::cerr << "Version: " << mapEmcVersion(uf->mapped_emc_version) << std::endl;
}
void UpdateFactory::setDest(const char *hostname, int port)
@@ -112,9 +134,9 @@ void UpdateFactory::setDest(const char *hostname, int port)
http_client = new httplib::Client(hostname, port);
phpsessid = "";
emc_serial = "";
- emc_version = "";
authenticated = false;
mapped_emc_version = EMC_UNKNOWN;
+ mapped_firmware_version = EMC_UNKNOWN;
}
void UpdateFactory::setDest(std::string& hostname, int port)
@@ -166,7 +188,7 @@ int UpdateFactory::doAuth()
httplib::Request req;
httplib::Response res1, res2;
json11::Json json;
- std::string errmsg;
+ std::string errmsg, fw_ver;
if (!http_client)
return UPDATE_HTTP_ERROR;
@@ -184,8 +206,8 @@ int UpdateFactory::doAuth()
dump_json(json);
emc_serial = json["serial"].string_value();
- emc_version = json["app_version"].string_value();
- mapped_emc_version = mapEmcVersion(emc_version);
+ fw_ver = json["app_version"].string_value();
+ mapped_emc_version = mapEmcVersion(fw_ver);
if (mapped_emc_version == EMC_UNKNOWN)
return UPDATE_VERSION;
authenticated = json["authentication"].bool_value();
@@ -214,14 +236,24 @@ int UpdateFactory::doAuth()
int UpdateFactory::loadUpdateFile()
{
- std::ifstream input(update_file, std::ios::binary);
+ struct update_trailer trl;
+ std::ifstream input(update_file, std::ifstream::in | std::ios::binary);
+ std::string fw_ver;
+
if (!input)
return UPDATE_FILE;
+
std::vector<unsigned char> buffer(
(std::istreambuf_iterator<char>(input)),
(std::istreambuf_iterator<char>())
);
+ if (buffer.size() < sizeof(trl))
+ return UPDATE_VERSION;
+
update_buffer = buffer;
+ fw_ver = std::string(buffer.end() - sizeof(trl), buffer.end() - sizeof(trl) + sizeof(trl.version));
+ fw_ver = std::string(fw_ver.c_str()); /* discard trailed NUL bytes */
+ mapped_firmware_version = mapEmcVersion(fw_ver);
return UPDATE_OK;
}
@@ -235,7 +267,7 @@ int UpdateFactory::doUpdate()
if (!http_client)
return UPDATE_HTTP_ERROR;
- if (mapped_emc_version == EMC_UNKNOWN)
+ if (mapped_emc_version == EMC_UNKNOWN || mapped_firmware_version == EMC_UNKNOWN)
return UPDATE_VERSION;
if (!authenticated)
return UPDATE_AUTH_ERROR;
@@ -289,7 +321,6 @@ void UpdateFactory::cleanup()
}
authenticated = false;
emc_serial = "";
- emc_version = "";
}
void UpdateFactory::genRequest(httplib::Request& req, const char *path,
diff --git a/src/UpdateFactory.hpp b/src/UpdateFactory.hpp
index 096b94c..7932f5a 100644
--- a/src/UpdateFactory.hpp
+++ b/src/UpdateFactory.hpp
@@ -14,7 +14,8 @@
#define UPDATE_JSON_ERROR 4
#define UPDATE_AUTH_ERROR 5
#define UPDATE_VERSION 6
-#define UPDATE_FILE 7
+#define UPDATE_UPDATED 7
+#define UPDATE_FILE 8
enum EMCVersion {
@@ -30,6 +31,7 @@ enum EMCVersion {
enum EMCVersion mapEmcVersion(std::string& emc_version);
std::string mapEmcVersion(enum EMCVersion ver);
+bool isEmcVersionLowerThen(enum EMCVersion ver, enum EMCVersion check_ver);
void mapEmcError(int error, std::string& out);
@@ -49,7 +51,8 @@ public:
const char *getUpdateFile() const { return this->update_file.c_str(); }
const char *getHostname() const { return this->hostname.c_str(); }
const char *getPassword() const { return this->passwd.c_str(); }
- enum EMCVersion getVersion() const { return this->mapped_emc_version; }
+ enum EMCVersion getEmcVersion() const { return this->mapped_emc_version; }
+ enum EMCVersion getFwVersion() const { return this->mapped_firmware_version; }
int getPort() const { return this->port; }
int doAuth();
int loadUpdateFile();
@@ -58,9 +61,8 @@ public:
protected:
std::string phpsessid;
std::string emc_serial;
- std::string emc_version;
bool authenticated;
- enum EMCVersion mapped_emc_version;
+ enum EMCVersion mapped_emc_version, mapped_firmware_version;
std::string update_file;
std::string passwd;
std::vector<unsigned char> update_buffer;
diff --git a/src/UpdateGUI.cpp b/src/UpdateGUI.cpp
index 0830cd0..e2c0c0f 100644
--- a/src/UpdateGUI.cpp
+++ b/src/UpdateGUI.cpp
@@ -185,6 +185,7 @@ void UpdateGUIFrame::OnAbout(wxCommandEvent& event)
aboutInfo.SetWebSite(PACKAGE_URL);
aboutInfo.AddDeveloper("Toni Uhlig");
aboutInfo.AddDeveloper("Valeri Budjko");
+ aboutInfo.AddDeveloper("Theres Teichmann");
wxAboutBox(aboutInfo, this);
}
diff --git a/src/UpdateTool.cpp b/src/UpdateTool.cpp
index 8206131..58c8277 100644
--- a/src/UpdateTool.cpp
+++ b/src/UpdateTool.cpp
@@ -55,16 +55,24 @@ int main(int argc, char *argv[])
for (auto *u : uf) {
rv = u->doAuth();
mapEmcError(rv, errstr);
- std::cerr << "doAuth returned " << rv << ": " << errstr << std::endl;
if (rv == UPDATE_OK) {
- std::cerr << "uploading file " << u->getUpdateFile() << std::endl;
+ std::cerr << "loading file " << u->getUpdateFile() << std::endl;
rv = u->loadUpdateFile();
- mapEmcError(rv, errstr);
- std::cerr << "load file returned " << rv << ": " << errstr << std::endl;
- rv = u->doUpdate();
- mapEmcError(rv, errstr);
- std::cerr << "doUpdate returned " << rv << ": " << errstr << std::endl;
- }
+ std::cerr << "firmware version: " << mapEmcVersion(u->getFwVersion()) << std::endl;
+ if (rv == UPDATE_OK) {
+ std::cerr << "uploading file " << u->getUpdateFile() << std::endl;
+ rv = u->doUpdate();
+ if (rv == UPDATE_OK) {
+ std::cerr << "Update succeeded!" << std::endl;
+ } else {
+ mapEmcError(rv, errstr);
+ std::cerr << "doUpdate returned " << rv << ": " << errstr << std::endl;
+ }
+ } else {
+ mapEmcError(rv, errstr);
+ std::cerr << "load file returned " << rv << ": " << errstr << std::endl;
+ }
+ } else std::cerr << "doAuth returned " << rv << ": " << errstr << std::endl;
}
for (auto *u : uf) {