Motion Master
Loading...
Searching...
No Matches
flash.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <functional>
5#include <map>
6#include <vector>
7
9#include "motion-master.pb.h"
10
11class EthercatSlave;
14
15class Flash {
16 public:
28 Flash(VirtualDeviceManager& vdm, uint32_t device_address, const char* data,
29 size_t size, bool skip_sii_installation,
30 std::vector<std::string> skip_files);
31
42
44 motionmaster::MotionMasterMessage::Status*>&
46
47 private:
49 EthercatSlave* slave_;
50
51 uint32_t device_address_;
52 std::vector<uint8_t> zip_data_;
53 std::map<std::string, std::vector<uint8_t>> unzipped_files_;
54 std::string sii_file_name_;
55 std::string app_file_name_;
56 std::string com_file_name_;
57
58 bool skip_sii_installation_ = false;
59
60 std::vector<std::string> skip_files_;
61
67 const std::unordered_set<std::string> filename_whitelist_ = {
68 "stack_image.svg.zip", "SOMANET_CiA_402.xml.zip"};
69
71 static constexpr uint8_t kWriteStartPercentage = 10;
72 static constexpr uint8_t kWriteEndPercentage = 95;
73
75 static constexpr uint32_t kPreOpTimeoutMs = 30000;
76
78 size_t total_bytes_ = 0;
79 size_t written_bytes_ = 0;
80
81 std::pair<uint8_t, uint8_t> progress_range_;
82 uint8_t progress_percentage_ = 0;
83 std::string progress_message_;
84
86 motionmaster::MotionMasterMessage::Status*>
87 outgoing_status_message_queue_;
88
89 std::function<void(uint8_t)> progress_callback_;
90
100 MotionMasterError flash_bin_file(const std::string& file_name,
101 const std::vector<uint8_t>& content,
102 const std::string& description);
103
114 MotionMasterError confirm_firmware_removed();
115
117 uint8_t write_percentage(size_t bytes) const;
118
120 void begin_file(size_t size);
121
123 void end_file(size_t size);
124
131 void send_progress(uint8_t percentage, const std::string& message = "");
132
139 void send_warning(motionmaster::MotionMasterMessage::Status::
140 DeviceFirmwareInstallation::Warning::Code warning_code,
141 const std::string& message);
142};
Definition ethercat_slave.h:10
mm::core::containers::ThreadSafeQueue< motionmaster::MotionMasterMessage::Status * > & get_status_message_queue()
Definition flash.cc:523
MotionMasterError start()
Start the installation of the package files.
Definition flash.cc:147
Flash(VirtualDeviceManager &vdm, uint32_t device_address, const char *data, size_t size, bool skip_sii_installation, std::vector< std::string > skip_files)
Unpack the ZIP file and validate the files inside.
Definition flash.cc:23
Definition motion_master_error.h:6
Definition virtual_device_manager.h:16
Thread-safe FIFO queue with optional capacity limit.
Definition thread_safe_queue.h:23