firmware.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <boost/system/error_code.hpp>
9 #include <rapidjson/document.h>
10 #include <string>
11 #include "files.h"
12 #include "systemConfiguration.h"
13 
14 #ifdef TESTING
15 #include "gtest/gtest.h"
16 #include "command.h"
17 #endif
18 
19 namespace dpyFirmware {
20 
23  std::string full_path;
24  std::string version;
25 };
26 
27 
30 {
31  std::string version;
32  std::string product;
33  std::string vendor;
34  std::string protocol;
35  std::string bootloader;
36 };
37 
39 enum Device
40 {
41  MCU = 0,
42  UX410 = 1,
43  EM7455 = 2,
44  RC7620 = 3,
45  EC25 = 4,
46  PN7412 = 5,
47  WP7607 = 6,
48  RC7611 = 7,
49  BK3_2 = 8
50 };
52 
54 enum Rfs
55 {
56  CURRENT = 0,
58 };
59 
60 }
61 
67 class Firmware {
68 
69 static const std::string version_file;
70 
71 public:
72  static boost::system::error_code requestFirmware(dpyFirmware::FirmwareVersionPath& image, enum dpyFirmware::Device device, enum dpyFirmware::Rfs rfs);
73  static boost::system::error_code parseVersionFile(std::string path, dpyFirmware::FirmwareVersionPath& image);
74 private:
75  static std::string deviceToString(enum dpyFirmware::Device device);
76  static std::string rfsToString(enum dpyFirmware::Rfs rfs);
77 
78 #ifdef TESTING
79 public:
80  FRIEND_TEST(Firmware_test, directoryError);
81  FRIEND_TEST(Firmware_test, fileError);
82  FRIEND_TEST(Firmware_test, fileError2);
83  FRIEND_TEST(Firmware_test, nameError);
84  FRIEND_TEST(Firmware_test, nameContentError);
85  FRIEND_TEST(Firmware_test, versionError);
86  FRIEND_TEST(Firmware_test, versionContentError);
87 
88  //Methods used in tests
89  static bool write_release_txt(const enum dpyFirmware::Device device, const std::string version_to_write){
90  std::string path = SystemConfiguration::getInstance()->getConfigurationValue("DEVICE_UPDATES_PATH") + deviceToString(device) + "/";
91  std::string command = "mkdir -p " + path;
92  Command::executeCommand(command);
93  std::string str_json = "{\"name\":\"firmware_name\",\"version\": \"" +version_to_write+"\" }";
94  Files file;
95  boost::system::error_code ec;
96  std::cout << "[write_release_txt_to_tmp] creating dir at " << path << std::endl;
97  bool result = file.createAndWrite(ec, path + "release.txt",str_json);
98  return result;
99  }
100 
101 
102  static void remove_release_txt(const enum dpyFirmware::Device device){
103  std::string path = SystemConfiguration::getInstance()->getConfigurationValue("DEVICE_UPDATES_PATH") + deviceToString(device) + "/";
104  std::string command = "rm -rf " + path;
105  Command::executeCommand(command);
106  }
107 
108 
109 #endif
110 };
std::string full_path
Path and name of the firmware.
Definition: firmware.h:23
This class implementes the read/write operations to work with text files stored in the file sytem...
Definition: files.h:43
A structure use to store firmware info.
Definition: firmware.h:29
Defines a class for executing commands and getting output.
static SystemConfiguration * getInstance()
Definition: firmware.h:19
std::string product
product
Definition: firmware.h:32
RC7620.
Definition: firmware.h:44
std::string version
Firmware version.
Definition: firmware.h:24
MCU.
Definition: firmware.h:41
std::string vendor
vendor
Definition: firmware.h:33
ALTERNATIVE.
Definition: firmware.h:57
std::string version
firmware version
Definition: firmware.h:31
std::string bootloader
bootloader
Definition: firmware.h:35
CURRENT.
Definition: firmware.h:56
Struct which contains all fields needed to can upgrade devices firmware.
Definition: firmware.h:22
Rfs
Defines the possible root file systems where binaries are located.
Definition: firmware.h:54
Definition: firmware.h:49
UX410.
Definition: firmware.h:42
RC7611.
Definition: firmware.h:48
PN7412.
Definition: firmware.h:46
WP7607.
Definition: firmware.h:47
Class to request upgrading firmware by device in case any is availability.
Definition: firmware.h:67
A common files library.
std::string protocol
protocol
Definition: firmware.h:34
std::string getConfigurationValue(const std::string &parameter)
EC25.
Definition: firmware.h:45
EM7455.
Definition: firmware.h:43
Device
Defines the possible devices whose firmware can be upgraded.
Definition: firmware.h:39