iCub-main
Loading...
Searching...
No Matches
yafu.h
Go to the documentation of this file.
1/*
2 * Copyright (C)2025 iCub Facility - Istituto Italiano di Tecnologia
3 * Author: SATHISH KUMAR S
4 * email: sathish.subramani@iit.it
5 * github: https://github.com/sksubiit
6 * website: www.robotcub.org
7 * Permission is granted to copy, distribute, and/or modify this program
8 * under the terms of the GNU General Public License, version 2 or any
9 * later version published by the Free Software Foundation.
10 *
11 * A copy of the license can be found at
12 * http://www.robotcub.org/icub/license/gpl.txt
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
17 * License for more details
18*/
19#ifndef __TEST_H__
20#define __TEST_H__
21
22#include <iostream>
23#include <string>
24#include <vector>
25#include <cstring>
26#include <cerrno>
27#include <sys/socket.h>
28#include <netinet/in.h>
29#include <arpa/inet.h>
30#include <unistd.h>
31#include <algorithm>
32#include <fstream>
33#include <sstream>
34#include <cctype>
35#include <limits>
36#include <sys/stat.h>
37#include <thread>
38#include <mutex>
39#include <set>
40#include <regex>
41#include <chrono>
42#include <iomanip>
43#include <limits.h>
44#include <unistd.h>
45#include <sys/wait.h>
46#include <sys/types.h>
47#include <fcntl.h>
48#include <cstdlib>
49
50#include "EoBoards.h"
51#include "EoUpdaterProtocol.h"
52
53
55{
56public:
57
58 simpleEthClient(): sock_(-1) {}
60
61 //bool open(const char *ip, uint16_t port = 7777, double rx_timeout_sec = 1.0);
62 bool open(const char *ip, double rx_timeout_sec = 5.0);
63 void closeSocket();
64 bool sendRaw(const void *buf, size_t len);
65
66 // Board operations
67 bool discover();
68 bool jump2updater();
70 bool restart();
71 bool blink();
72
73 // normal programming mode
74 bool program();
75
76 // Ensure the target at `ip` is in maintenance (eUpdater). Logs progress to `log`.
77 // Returns: 0 => entered maintenance and needs programming,
78 // 2 => already up-to-date (skip programming),
79 // 1 => failure.
80 int ensureMaintenance(const char *ip, int max_retries, int retry_delay_sec, std::ostream &log);
81
82 // find firmware entry and optional version in firmware.info.xml
83 bool findFirmwareForBoardWithVersion(const std::string &boardname, std::string &out_hexpath, int &out_major, int &out_minor);
84
85 // Orchestrator entry: parse network file, prepare all boards in parallel, then program prepared ones.
86 // Returns 0 on full success, non-zero otherwise.
87 static int orchestrateParallelProgram();
88
89private:
90 int sock_;
91 struct sockaddr_in dest_;
92 struct sockaddr_in src_;
93
94 // helpers for programming
95 static std::string resolveFirmwareInfoXml();
96 bool recvReplyForIP(uint8_t expected_opc, int timeout_ms, eOuprot_result_t &out_res);
97 bool findFirmwareForBoard(const std::string &boardname, std::string &out_hexpath);
98 bool sendPROG_START(eOuprot_partition2prog_t partition, eOuprot_result_t &out_res);
99 bool sendPROG_DATA_chunk(uint32_t address, const uint8_t *data, size_t len, eOuprot_result_t &out_res);
100 bool sendPROG_END(uint16_t numberofpkts, eOuprot_result_t &out_res);
101
102 //discover reply printers
103 static void print_discover_reply(const eOuprot_cmd_DISCOVER_REPLY_t *reply, const char *srcip);
104 static void print_legacy_scan_reply(const eOuprot_cmd_LEGACY_SCAN_REPLY_t *scan, const char *srcip);
105
106
107
108 // Orchestrator helpers (tagged to the class)
109 static std::vector<std::string> parseIPsFromNetworkFile(const char *xmlpath);
110 static std::string logname(const std::string &ip);
111 static pid_t spawn_and_log(const std::string &exe_path, const std::vector<std::string> &args, const std::string &logpath, bool append);
112};
113#endif // __TEST_H__
@ data
static int orchestrateParallelProgram()
Definition yafu.cpp:1173
~simpleEthClient()
Definition yafu.h:59
void closeSocket()
Definition yafu.cpp:670
bool jump2updater()
Definition yafu.cpp:750
bool sendRaw(const void *buf, size_t len)
Definition yafu.cpp:675
bool discover()
Definition yafu.cpp:682
bool blink()
Definition yafu.cpp:784
int ensureMaintenance(const char *ip, int max_retries, int retry_delay_sec, std::ostream &log)
Definition yafu.cpp:901
bool program()
Definition yafu.cpp:309
bool restart()
Definition yafu.cpp:774
simpleEthClient()
Definition yafu.h:58
bool findFirmwareForBoardWithVersion(const std::string &boardname, std::string &out_hexpath, int &out_major, int &out_minor)
Definition yafu.cpp:192
bool open(const char *ip, double rx_timeout_sec=5.0)
Definition yafu.cpp:588
bool def2run_application()
Definition yafu.cpp:763