mirror of
https://github.com/BotChain-Robots/control.git
synced 2026-07-08 21:57:20 +02:00
Bulk OTa
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
[requires]
|
[requires]
|
||||||
libcontrol/1.0.0
|
libcontrol/1.0.3
|
||||||
flatbuffers/24.12.23
|
flatbuffers/24.12.23
|
||||||
spdlog/1.16.0
|
spdlog/1.16.0
|
||||||
librpc/1.1.7
|
librpc/1.1.8
|
||||||
|
|
||||||
[generators]
|
[generators]
|
||||||
CMakeDeps
|
CMakeDeps
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <random>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -10,19 +11,27 @@
|
|||||||
#include "rpc/RemoteManagement.h"
|
#include "rpc/RemoteManagement.h"
|
||||||
|
|
||||||
void progress_monitor_task(std::shared_ptr<RemoteManagement> rm, uint8_t module_id) {
|
void progress_monitor_task(std::shared_ptr<RemoteManagement> rm, uint8_t module_id) {
|
||||||
|
std::random_device dev;
|
||||||
|
std::mt19937 rng(dev());
|
||||||
|
std::uniform_int_distribution<std::mt19937::result_type> dist6(10, 100);
|
||||||
|
|
||||||
|
std::cout << dist6(rng) << std::endl;
|
||||||
while (true) {
|
while (true) {
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::milliseconds(5000 + dist6(rng)));
|
||||||
std::cout << "Module " << (int)module_id << ": " << rm->ota_progress() * 100 << "% complete\n";
|
std::cout << "Module " << (int)module_id << ": " << rm->ota_progress() * 100 << "% complete"
|
||||||
if (rm->ota_progress() >= 1.0) return;
|
<< std::endl;
|
||||||
|
if (rm->ota_progress() >= 1.0)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void task(std::shared_ptr<RobotController> controller, uint8_t module_id, const std::string& filepath) {
|
void task(std::shared_ptr<RobotController> controller, uint8_t module_id,
|
||||||
|
const std::string &filepath) {
|
||||||
auto rm = std::make_shared<RemoteManagement>(module_id, filepath, controller);
|
auto rm = std::make_shared<RemoteManagement>(module_id, filepath, controller);
|
||||||
std::thread t(progress_monitor_task, rm, module_id);
|
std::thread t(progress_monitor_task, rm, module_id);
|
||||||
rm->perform_ota();
|
rm->perform_ota();
|
||||||
t.join();
|
t.join();
|
||||||
std::cout << "Done updating " << (int)module_id << "\n";
|
std::cout << "Done updating " << (int)module_id << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@@ -33,8 +42,10 @@ int main() {
|
|||||||
std::vector<uint8_t> to_update{};
|
std::vector<uint8_t> to_update{};
|
||||||
for (const auto &maybe_module : robot_controller->getModules()) {
|
for (const auto &maybe_module : robot_controller->getModules()) {
|
||||||
if (const auto &module = maybe_module.lock()) {
|
if (const auto &module = maybe_module.lock()) {
|
||||||
if (module->get_leader() != module->get_device_id()) { continue; }
|
if (module->get_leader() != module->get_device_id()) {
|
||||||
std::cout << "Updating module " << (int)module->get_device_id();
|
continue;
|
||||||
|
}
|
||||||
|
std::cout << "Updating module " << (int)module->get_device_id() << std::endl;
|
||||||
to_update.emplace_back(module->get_device_id());
|
to_update.emplace_back(module->get_device_id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,8 +55,7 @@ int main() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string filename =
|
std::string filename = "/home/jslightham/Documents/capstone/firmware/build/firmware.bin";
|
||||||
"/Users/jslightham/Documents/Classes/capstone/firmware/build/firmware.bin";
|
|
||||||
std::vector<std::thread> threads;
|
std::vector<std::thread> threads;
|
||||||
for (int i = 0; i < to_update.size(); i++) {
|
for (int i = 0; i < to_update.size(); i++) {
|
||||||
threads.emplace_back(task, robot_controller, to_update[i], filename);
|
threads.emplace_back(task, robot_controller, to_update[i], filename);
|
||||||
|
|||||||
@@ -62,12 +62,16 @@ void RemoteManagement::restart() {
|
|||||||
|
|
||||||
bool RemoteManagement::start_ota() {
|
bool RemoteManagement::start_ota() {
|
||||||
// std::cout << "Starting OTA" << std::endl;
|
// std::cout << "Starting OTA" << std::endl;
|
||||||
|
int attempts = 0;
|
||||||
|
while (attempts < MAX_PACKET_TX_ATTEMPTS) {
|
||||||
const auto maybe = m_robot_controller->remote_call(4, m_module_id, {});
|
const auto maybe = m_robot_controller->remote_call(4, m_module_id, {});
|
||||||
if (maybe) {
|
if (maybe) {
|
||||||
// std::cout << "Got valid response" << std::endl;
|
// std::cout << "Got valid response" << std::endl;
|
||||||
m_sequence_num = 1;
|
m_sequence_num = 1;
|
||||||
return (*maybe)->at(0) > 0;
|
return (*maybe)->at(0) > 0;
|
||||||
}
|
}
|
||||||
|
attempts++;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
[requires]
|
[requires]
|
||||||
libcontrol/1.0.0
|
libcontrol/1.0.3
|
||||||
flatbuffers/24.12.23
|
flatbuffers/24.12.23
|
||||||
spdlog/1.16.0
|
spdlog/1.16.0
|
||||||
librpc/1.1.7
|
librpc/1.1.8
|
||||||
|
|
||||||
[generators]
|
[generators]
|
||||||
CMakeDeps
|
CMakeDeps
|
||||||
|
|||||||
@@ -24,18 +24,21 @@ int main() {
|
|||||||
std::cout << "Found " << controller->getModules().size() << " modules" << std::endl;
|
std::cout << "Found " << controller->getModules().size() << " modules" << std::endl;
|
||||||
for (const auto &maybe_module : controller->getModules()) {
|
for (const auto &maybe_module : controller->getModules()) {
|
||||||
if (const auto &module = maybe_module.lock()) {
|
if (const auto &module = maybe_module.lock()) {
|
||||||
if (module->get_type() == ModuleType_DC_MOTOR) {
|
if (module->get_type() == ModuleType_SERVO_2 ||
|
||||||
|
module->get_type() == ModuleType_SERVO_1) {
|
||||||
|
std::cout << "Actuating " << (int)module->get_device_id() << " leader "
|
||||||
|
<< (int)module->get_leader() << std::endl;
|
||||||
int randomNumber = dist(gen);
|
int randomNumber = dist(gen);
|
||||||
if (module->get_position() > 90) {
|
if (module->get_position() > 90) {
|
||||||
module->actuate(70 - randomNumber);
|
module->actuate(50 - randomNumber);
|
||||||
} else {
|
} else {
|
||||||
module->actuate(110 + randomNumber);
|
module->actuate(150 + randomNumber);
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user