• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

utilities/UploadApp.cxx (r4864/r3229)

Go to the documentation of this file.
00001 //============================================================================
00002 // Name        : UploadApp.cpp
00003 // Author      : Stefan Mueller-Klieser / S.Linev
00004 // Version     :
00005 // Copyright   : Kirchhoff-Institut fuer Physik / GSI
00006 // Description : Upload firmware/software/configuration files onto roc
00007 //============================================================================
00008 
00009 #include <string.h>
00010 #include <time.h>
00011 #include <sys/time.h>
00012 #include <iostream>
00013 #include <unistd.h>
00014 
00015 #include "roc/Board.h"
00016 #include "roc/UdpBoard.h"
00017 
00018 int main(int argc, char* argv[])
00019 {
00020    std::cout << "Data uploader for roc::Board" << std::endl;
00021    std::cout << "Can be used for firmware, software or configuration upload" << std::endl;
00022 
00023    std::cout << "Usage: rocupload boardIp -fw0|-fw1|-sw|-cfg fileName [rocFileName]" << std::endl;
00024 
00025    if (argc<4) {
00026       std::cout << "Not all parameters are specified!!!" << std::endl;
00027        return -1;
00028    }
00029 
00030    const char* boardIp = argv[1];
00031    int typ = -1;
00032    if (!strcmp(argv[2], "-fw0")) typ = 1; else
00033    if (!strcmp(argv[2], "-fw") || !strcmp(argv[2], "-fw1")) typ = 2; else
00034    if (!strcmp(argv[2], "-sw")) typ = 3; else
00035    if (!strcmp(argv[2], "-cfg")) typ = 4; else {
00036       std::cout << "Invalid type of upload " << argv[2] << std::endl;
00037       return -1;
00038    }
00039    const char* fileName = argv[3];
00040    const char* tgtFileName = 0;
00041    if ((argc>4) && (typ==4)) tgtFileName = argv[4];
00042 
00043    roc::Board* brd = roc::Board::Connect(boardIp);
00044 
00045    if(brd == 0) {
00046       std::cout << "-----   Setup could not connect to board. Exit!   -----" << std::endl;
00047       return -1;
00048    }
00049 
00050    roc::UdpBoard* udp = dynamic_cast<roc::UdpBoard*> (brd);
00051    if (udp==0) {
00052       std::cout << "Cannot use for non-udp connected board. Exit! ------" << std::endl;
00053       roc::Board::Close(brd);
00054       return -1;
00055    }
00056 
00057    udp->setConsoleOutput(true, true);
00058 
00059    int upload_tm = false;
00060 
00061    switch(typ) {
00062       case 1:
00063          std::cout << "-----   Uploading firmware on position 0: " << fileName << " -------- " << std::endl;
00064          upload_tm = udp->uploadBitfile(fileName, 0);
00065          break;
00066       case 2:
00067          std::cout << "-----   Uploading firmware on position 1: " << fileName << " -------- " << std::endl;
00068          upload_tm = udp->uploadBitfile(fileName, 1);
00069          break;
00070       case 3:
00071          std::cout << "-----   Uploading software: " << fileName << " -------- " << std::endl;
00072          upload_tm = udp->uploadSDfile(fileName, "image.bin");
00073          break;
00074       case 4:
00075          if (tgtFileName==0) tgtFileName = "roc1.cfg";
00076          std::cout << "-----   Uploading configuration: " << fileName << " to " << tgtFileName << std::endl;
00077          upload_tm = udp->uploadSDfile(fileName, tgtFileName);
00078          break;
00079       default:
00080          std::cout << "Error type !" << std::endl;
00081          break;
00082     }
00083 
00084    if (upload_tm<=0) {
00085       std::cout << "Error detected !" << std::endl;
00086       return 1;
00087    }
00088 
00089    bool upload_res = false;
00090 
00091    while (upload_tm>0) {
00092       sleep(1);
00093       upload_tm--;
00094       std::cout << ".";
00095       std::cout.flush();
00096       int res = udp->checkUpload();
00097       if (res==2) { upload_res = true; break; }
00098       if (res!=1) break;
00099    }
00100    std::cout << std::endl;
00101 
00102    udp->setConsoleOutput();
00103 
00104    if ((typ==3) && upload_res) {
00105       std::cout << "-----   Restart ROC -------- " << std::endl;
00106       udp->restartRoc();
00107    }
00108 
00109    roc::Board::Close(brd);
00110 
00111    return 0;
00112 }

Generated on Tue Dec 10 2013 04:52:24 for ROCsoft by  doxygen 1.7.1