134#include <yarp/os/Time.h>
135#include <yarp/os/Log.h>
136#include <yarp/dev/Drivers.h>
145#include <iCubCanProtocol.h>
146#include <iCubCanProto_types.h>
176#define INVALID_CMD_STRING -1
177#define INVALID_PARAM_CANTYPE -2
178#define INVALID_PARAM_CANNUM -3
179#define INVALID_PARAM_BOARDID -4
180#define INVALID_PARAM_FILE -5
181#define ERR_NO_BOARDS_FOUND -10
182#define ERR_BOARD_ID_NOT_FOUND -11
183#define ERR_UNKNOWN -12
184#define ERR_NO_NETWORK_INTERFACE -13
185#define DOWNLOADERR_NOT_CONNECTED -20
186#define DOWNLOADERR_BOARD_NOT_SEL -21
187#define DOWNLOADERR_FILE_NOT_SEL -22
188#define DOWNLOADERR_FILE_NOT_OPEN -23
189#define DOWNLOADERR_BOARD_NOT_START -24
190#define DOWNLOADERR_TRANSFER_ERROR -25
200 ACE_UINT32 ip1,ip2,ip3,ip4;
201 sscanf(addr,
"%d.%d.%d.%d",&ip1,&ip2,&ip3,&ip4);
205 ACE_INET_Addr* addr_array=NULL;
206 int ret=ACE::get_ip_interfaces(count,addr_array);
213 localAddr=addr_array[0].get_ip_address();
215 for (
unsigned int a=1; a<count; ++a)
217 if ((
remoteAddr & 0xFFFF0000)==(addr_array[a].get_ip_address() & 0xFFFF0000))
219 localAddr=addr_array[a].get_ip_address();
234 yarp::os::Property params;
239 yError() <<
"ETH not supported yet" ;
244 params.put(
"canTxQueue", 64);
245 params.put(
"canRxQueue", 64);
246 params.put(
"canTxTimeout", 2000);
247 params.put(
"canRxTimeout", 2000);
255 yError() <<
"Init driver failed" <<
"Hardware busy or not connected?!";
265 yError() <<
"Communication error" <<
"No answers received (no boards found).";
271 yInfo() <<
"Driver Connected";
276 yInfo() <<
"Driver Stopped";
283 double timer_start =0;
288 yError() <<
"Driver not running " <<
" Use 'Connect' button to start the driver";
293 bool at_least_one_board_selected =
false;
300 at_least_one_board_selected =
true;
303 if (!at_least_one_board_selected)
305 yError() <<
"No Boards selected! " <<
"Select one or more boards to download the firmware";
314 yError() <<
"No files selected! " <<
"Select the file You want to download, first";
319 std::string*
p = (std::string*)user_data;
320 buffer =
new char[255];
321 strcpy(buffer,(
p->c_str()));
325 yError() <<
"Error opening the selected file!";
330 int firmware_board_type=0;
331 int firmware_version=0;
332 int firmware_revision=0;
335 int download_type = icubCanProto_boardType__unknown;
336 bool download_eeprom =
false;
355 yError() <<
"Unable to start the board" <<
"Unable to send message 'start' or no answer received";
368 timer_start= yarp::os::Time::now();
370 bool print00 =
false, print25 =
false, print50 =
false, print75 =
false, print99 =
false;
398 timer_end= yarp::os::Time::now();
408 double download_time = (timer_end-timer_start) ;
409 sprintf (time_text,
"All Board OK\nDownload Time (s): %.2f", download_time);
422 int first_type = icubCanProto_boardType__unknown;
423 bool something_selected=
false;
429 something_selected=
true;
434 if (something_selected ==
false)
443 if (wanted_type != first_type)
490 yError(
"Unable to parse the command line. The correct format is:\n");
491 yError(
"canLoader --canDeviceType t --canDeviceNum x --boardId y --firmware myFirmware.out.S\n");
492 yError(
"canLoader --canDeviceType ETH --canDeviceNum 1|2 --boardId y --firmware myFirmware.out.S --boardIPAddr aaa.aaa.aaa.aaa\n");
496 yError(
"invalid --canDeviceType parameter \n");
497 yError(
"must be 'ecan' or 'pcan' or 'cfw2' or 'socketcan'\n");
501 yError(
"invalid --canDeviceNum parameter \n");
502 yError(
"must be between 0 and 3\n");
506 yError(
"invalid --boardId parameter \n");
507 yError(
"must be between 0 and 15\n");
511 yError(
"invalid --firmware parameter \n");
512 yError(
"file not found\n");
516 yError(
"no boards found \n");
517 yError(
"check canbus cable, power supply connection etc.\n");
521 yError(
"the specified board is not available \n");
525 yError(
"could not find network interface\n");
529 yError(
"Unknown error\n");
544 yarp::dev::DriverCollection dev;
547 if (argc==2 && strcmp(argv[1],
"--calib")==0)
555 yInfo(
"Initializing prompt version of canLoader...\n");
556 if (argc==2 && strcmp(argv[1],
"--help")==0)
558 yInfo(
"CANLOADER APPLICATION V2.9\n");
560 yInfo(
"to execute the command line version of the canLoader:\n");
561 yInfo(
"./canLoader --canDeviceType <t> --canDeviceNum <x> --discover\n");
562 yInfo(
"./canLoader --canDeviceType <t> --canDeviceNum <x> --boardId <y> --firmware myFirmware.out.S\n");
563 yInfo(
"./canLoader --canDeviceType ETH --canDeviceNum 1|2 --boardId <y> --firmware myFirmware.out.S --boardIPAddr <aaa.aaa.aaa.aaa>\n");
564 yInfo(
"parameter <t> is the name of the CAN bus driver. It can be 'ecan' or 'pcan' or 'cfw2can' or 'socketcan'\n");
565 yInfo(
"parameter <x> is the number of the CAN bus (0-9)\n");
566 yInfo(
"parameter <y> is the CAN address of the board (0-14)\n");
567 yInfo(
"parameter <aaa.aaa.aaa.aaa> IP address of the board (ETH boards only)\n");
575 if (strcmp(argv[2],
"ecan") != 0 &&
576 strcmp(argv[2],
"pcan") != 0 &&
577 strcmp(argv[2],
"cfw2can") != 0 &&
578 strcmp(argv[2],
"socketcan") != 0 &&
579 strcmp(argv[2],
"ETH") != 0)
593 if (strcmp(argv[5],
"--discover") == 0)
599 if (argc==9 || argc==11)
603 if (strcmp(argv[5],
"--boardId")!=0 &&
606 if (strcmp(argv[7],
"--firmware")!=0 &&
607 strcmp(argv[7],
"--calibration")!=0 &&
610 int param_board_id=0;
611 std::string param_filename =
"empty";
624 temp_val=atoi(argv[4]);
625 if (temp_val<0 || temp_val>9)
634 temp_val=atoi(argv[6]);
635 if (temp_val<0 || temp_val>15)
641 param_board_id=temp_val;
644 param_filename=argv[8];
645 std::fstream filestr;
646 filestr.open ( param_filename.c_str(), std::fstream::in);
647 if (!filestr.is_open())
656 yInfo(
"Selecting canDeviceType %s canDeviceNum %d, boardId %d, firmware %s\n",
networkType.c_str(),
networkId, param_board_id, param_filename.c_str());
659 bool use_eeprom=
false;
660 if (strcmp(argv[7],
"--firmwareANDeeprom")==0)
662 yInfo(
"EEprom flag is active");
673 bool one_selected=
false;
683 if (one_selected==
false)
690 yInfo(
"Program terminated successfully!");
692 yError(
"Program terminated, DOWNLOAD FAILED!");
702 yInfo(
"CANLOADER APPLICATION V2.9\n");
704 yInfo(
"to execute the command line version of the canLoader:\n");
705 yInfo(
"./canLoader --canDeviceType <t> --canDeviceNum <x> --discover\n");
706 yInfo(
"./canLoader --canDeviceType <t> --canDeviceNum <x> --boardId <y> --firmware myFirmware.out.S\n");
707 yInfo(
"./canLoader --canDeviceType ETH --canDeviceNum 1|2 --boardId <y> --firmware myFirmware.out.S --boardIPAddr <aaa.aaa.aaa.aaa>\n");
708 yInfo(
"parameter <t> is the name of the CAN bus driver. It can be 'ecan' or 'pcan' or 'cfw2can' or 'socketcan'\n");
709 yInfo(
"parameter <x> is the number of the CAN bus (0-9)\n");
710 yInfo(
"parameter <y> is the CAN address of the board (0-14)\n");
711 yInfo(
"parameter <aaa.aaa.aaa.aaa> IP address of the board (ETH ethernet boards only)\n");
718int main(
int argc,
char* argv[])
720 return myMain(argc, argv);
int open_file(std::string file)
int startscheda(int bus, int board_pid, bool board_eeprom, int download_type)
int stopscheda(int bus, int board_pid)
int initdriver(yarp::os::Searchable &config, bool verbose=true)
int download_file(int bus, int board_pid, int download_type, bool eeprom)
#define INVALID_PARAM_FILE
static int download_click(std::string *user_data)
#define ERR_BOARD_ID_NOT_FOUND
#define INVALID_CMD_STRING
#define ERR_NO_BOARDS_FOUND
#define DOWNLOADERR_NOT_CONNECTED
#define INVALID_PARAM_CANNUM
int myMain(int argc, char *argv[])
#define DOWNLOADERR_BOARD_NOT_START
#define DOWNLOADERR_FILE_NOT_OPEN
#define INVALID_PARAM_BOARDID
#define INVALID_PARAM_CANTYPE
static void start_end_click()
#define ERR_NO_NETWORK_INTERFACE
#define DOWNLOADERR_TRANSFER_ERROR
#define DOWNLOADERR_BOARD_NOT_SEL
bool validate_selection(int wanted_type)
#define DOWNLOADERR_FILE_NOT_SEL
static bool compile_ip_addresses(const char *addr)