iCub-main
Loading...
Searching...
No Matches
EthUpdater.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012 RobotCub Consortium
3 * Author: Alessandro Scalzo alessandro.scalzo@iit.it
4 * CopyPolicy: Released under the terms of the GNU GPL v2.0.
5 *
6 */
7
8#ifndef __ETHUPDATER_H__
9#define __ETHUPDATER_H__
10
11
12#include "EoUpdaterProtocol.h"
13
14
15#include "DSocket.h"
16#include "BoardList.h"
17
18#include <vector>
19using namespace std;
20
22{
23protected:
25
29
31
32 unsigned char mRxBuffer[uprot_UDPmaxsize];
33 unsigned char mTxBuffer[uprot_UDPmaxsize];
34
35 ACE_UINT16 mPort;
36 ACE_UINT32 mBroadcast;
37 ACE_UINT32 mMyAddress;
38
40
41public:
42 static const int partition_APPLICATION;
43 static const int partition_LOADER;
44 static const int partition_UPDATER;
45
47 {
48 }
49
51 {
52 mSocket.Close();
54 }
55
56 bool create(ACE_UINT16 port,ACE_UINT32 address)
57 {
58 mPort=port;
59 mMyAddress=address;
60 mBroadcast=mMyAddress|0x0000FFFF;
61
63 }
64
65 bool create(ACE_UINT16 port,std::string& address)
66 {
67 mPort=port;
68 ACE_UINT32 ip1,ip2,ip3,ip4;
69 sscanf(address.c_str(),"%d.%d.%d.%d",&ip1,&ip2,&ip3,&ip4);
70 mMyAddress=(ip1<<24)|(ip2<<16)|(ip3<<8)|ip4;
71 mBroadcast=mMyAddress|0x0000FFFF;
72
74 }
75
77
78 // - part related to messages sent to the board(s)
79
80
81 // used to see if a capability is supported by the process running on a board (or by all the selected boards if address is 0)
82 // we can use this method to check if a command button can be enabled.
83 bool isCmdSupported(eOuprot_proc_capabilities_t capability, ACE_UINT32 address = 0);
84
85
86 // used to discover all the available boards.
87 // we send the command in broadcast.
88 // capabilities to be verified are one or both of teh following:
89 // - uprot_canDO_reply2discover: the board sends back full information
90 // - uprot_canDO_LEGACY_scan: the board sends back a limited subset of information
91 // every board replies to this method.
92 // returns the number of discovered boards.
93
94 int cmdDiscover();
95
96
97 // in all following methods: we send the commands in unicast but:
98 // if address = 0 we send the command to every selected board, otherwise only to the specifeid address.
99
100
101 // used to refresh the info about a board (or about all the selected boards if address is 0)
102 // refreshInfo = true allows to update the boardinfo inside mBoardList
103 // capabilities to be verified are one or both of the following:
104 // - uprot_canDO_reply2moreinfo: the board sends back full information (as with cmdDiscover()).
105 // if plusString = true this methods also requests a string with info about the partition table as old boards do.
106 // if refreshInfo = true this methods also updates the boardinfo inside mBoardList
107 // - uprot_canDO_LEGACY_procs: the board sends back only a string with info about the partition table.
108 std::string cmdGetMoreInfo(bool refreshInfo = false, ACE_UINT32 address = 0);
109
110
111 // used to clear the 32-bytes field which is stored in EEPROM of each board.
112 // capability to be checked is:
113 // - uprot_canDO_PAGE_clr
114 bool cmdInfo32Clear(ACE_UINT32 address = 0);
115
116 // used to set the 32-bytes field which is stored in EEPROM of each board.
117 // capability to be checked is:
118 // - uprot_canDO_PAGE_set
119 bool cmdInfo32Set(const string &info32, ACE_UINT32 address = 0);
120
121 // used to get the 32-bytes field which is stored in EEPROM of each board.
122 // capability to be checked is:
123 // - uprot_canDO_PAGE_get
124 vector<string> cmdInfo32Get(ACE_UINT32 address = 0);
125
126 // used to force a restart
127 // capability to be checked is:
128 // - uprot_canDO_restart
129 bool cmdRestart(ACE_UINT32 address = 0);
130
131 // used to impose the default to run process (the one after the 5 seconds)
132 // capability to be checked is:
133 // - uprot_canDO_DEF2RUN_set
134 bool cmdSetDEF2RUN(eOuprot_process_t process, ACE_UINT32 address = 0);
135
136 // used to force a jump to the eUpdater (only if the eApplication called eMaintainer is running)
137 // capability to be checked is:
138 // - uprot_canDO_JUMP2UPDATER
139 bool cmdJumpUpd(ACE_UINT32 address = 0);
140
141 // used to force a jump to a given ROM address
142 // capability to be checked is:
143 // - uprot_canDO_JUMP2ADDRESS
144 bool cmdJump2ROMaddress(uint32_t romaddress, ACE_UINT32 address = 0);
145
146 // forces a series of blinks in the LEDs of selected boards
147 // capability to be checked is:
148 // - uprot_canDO_blink
149 bool cmdBlink(ACE_UINT32 address = 0);
150
151 // forces a full erase of the EEPROM. VERY DANGEROUS to do it in multicast because it sets IP addresses to 10.0.1.99
152 // capability to be checked is one or both of the following:
153 // - uprot_canDO_LEGACY_EEPROM_erase: it erase the whole eeprom
154 // - uprot_canDO_EEPROM_erase: it can erase the whole eeprom but also a subset.
155 bool cmdEraseEEPROM(ACE_UINT32 address = 0);
156
157
158 // reads the EEPROM of a board. it must be used with care and towards one board at a time. the return value *eeprom is just
159 // a pointer to the data stored in the internal reply packet, hence it must be copied elsewhere at reception.
160 // capability to be checked is:
161 // - uprot_canDO_EEPROM_read: it reads a portion of eeprom contained in [from, from+size) with size <= uprot_EEPROMmaxsize (1024) bytes.
162 bool cmdReadEEPROM(uint16_t from, uint16_t size, ACE_UINT32 address, uint8_t **value);
163
164 // changes the IP address of a given board. despite default address 0, it does not support it
165 // capability to be checked is one or both of the following:
166 // - uprot_canDO_LEGACY_IPaddr_set: it just changes address.
167 // - uprot_canDO_IPaddr_set: it changes address and it also may force a restart (not requested for now)
168 bool cmdChangeAddress(ACE_UINT32 newaddress, ACE_UINT32 address = 0);
169
170
171 // used to program a given partition of a given board
172 // capability to be checked is:
173 // - uprot_canDO_PROG_loader: for programming into the loader partition (the first)
174 // - uprot_canDO_PROG_updater: for programming into the updater partition (the second)
175 // - uprot_canDO_PROG_application: for programming into the application partition (the third)
176 std::string cmdProgram(FILE *programFile, int partition, void (*updateProgressBar)(float), ACE_UINT32 address = 0);
177
178protected:
179
180 void sendCommandSelected(void * cmd, uint16_t len);
181 int sendPROG(const uint8_t opc, void * data, int size, int answers, int retry);
182
183private:
184
185 // in here are methods which we prefer not to be used, but which may be useful in special cases
186
187 // changes the IP mask of a given board, despite default address 0, it does not support it
188 // capability to be checked is:
189 // - uprot_canDO_LEGACY_IPmask_set
190 // NOTE: it is very dangerous to change the IP mask. it is also very improbable that we want to do it. we keep the method however.
191 bool cmdChangeMask(ACE_UINT32 newMask, ACE_UINT32 address = 0);
192
193 // changes the MAC of a given board
194 // capability to be checked is:
195 // - uprot_canDO_LEGACY_MAC_set
196 // NOTE: we may change the MAC only if ... there are two equal mac addresses on two boards ...
197 bool cmdChangeMAC(uint64_t newMAC48, ACE_UINT32 address);
198
199 bool cmdPageClr(eOuprot_pagesize_t pagesize, ACE_UINT32 address = 0);
200 bool cmdPageSet(eOuprot_pagesize_t pagesize, uint8_t *data, ACE_UINT32 address = 0);
201 bool cmdPageGet(eOuprot_pagesize_t pagesize, uint8_t **data, ACE_UINT32 address);
202
203};
204
205#endif
206
207// eof
208
@ data
void empty()
Definition BoardList.h:50
bool Create(ACE_UINT16 port, std::string &address)
Definition DSocket.cpp:25
void Close()
Definition DSocket.cpp:137
void sendCommandSelected(void *cmd, uint16_t len)
bool cmdRestart(ACE_UINT32 address=0)
int cmdDiscover()
bool cmdReadEEPROM(uint16_t from, uint16_t size, ACE_UINT32 address, uint8_t **value)
static const int partition_LOADER
Definition EthUpdater.h:43
BoardList & getBoardList()
Definition EthUpdater.h:76
std::string cmdProgram(FILE *programFile, int partition, void(*updateProgressBar)(float), ACE_UINT32 address=0)
int sendPROG(const uint8_t opc, void *data, int size, int answers, int retry)
unsigned char mRxBuffer[uprot_UDPmaxsize]
Definition EthUpdater.h:32
bool create(ACE_UINT16 port, ACE_UINT32 address)
Definition EthUpdater.h:56
bool cmdSetDEF2RUN(eOuprot_process_t process, ACE_UINT32 address=0)
bool cmdBlink(ACE_UINT32 address=0)
DSocket mSocket
Definition EthUpdater.h:39
ACE_UINT32 mBroadcast
Definition EthUpdater.h:36
bool isCmdSupported(eOuprot_proc_capabilities_t capability, ACE_UINT32 address=0)
vector< string > cmdInfo32Get(ACE_UINT32 address=0)
bool cmdJumpUpd(ACE_UINT32 address=0)
bool cmdJump2ROMaddress(uint32_t romaddress, ACE_UINT32 address=0)
unsigned char mTxBuffer[uprot_UDPmaxsize]
Definition EthUpdater.h:33
static const int partition_APPLICATION
Definition EthUpdater.h:42
ACE_UINT16 mPort
Definition EthUpdater.h:35
BoardInfo * mBoard2Prog[256]
Definition EthUpdater.h:30
bool create(ACE_UINT16 port, std::string &address)
Definition EthUpdater.h:65
bool cmdChangeAddress(ACE_UINT32 newaddress, ACE_UINT32 address=0)
int mNProgSteps
Definition EthUpdater.h:27
BoardList mBoardList
Definition EthUpdater.h:24
static const int partition_UPDATER
Definition EthUpdater.h:44
ACE_UINT32 mMyAddress
Definition EthUpdater.h:37
bool cmdInfo32Set(const string &info32, ACE_UINT32 address=0)
std::string cmdGetMoreInfo(bool refreshInfo=false, ACE_UINT32 address=0)
bool cmdEraseEEPROM(ACE_UINT32 address=0)
bool cmdInfo32Clear(ACE_UINT32 address=0)
cmd
Definition dataTypes.h:30