Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120095202
main.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jul 1, 22:06
Size
2 KB
Mime Type
text/x-c
Expires
Thu, Jul 3, 22:06 (2 d)
Engine
blob
Format
Raw Data
Handle
27137785
Attached To
R6621 SBCP High-Level Driver
main.cpp
View Options
/**
* \file main.cpp
*
* \date Sep 25, 2012
* \author Alexandre Tuleu
*/
#include <iostream>
#include <libsbcp/utils/HexaByte.h>
#include <libsbcp-tool/argstream.h>
#include <libsbcp/utils/Config.h>
#include <libsbcp-tool/UIElements.h>
#include <biorob-cpp/log/Logger.h>
int main(int argc, char ** argv){
sbcp::HexaByte klass,oldId ,newId;
bool nonInteractive(false);
argstream as(argc,argv);
std::string busName(sbcp::BusesConfigSection::DEFAULT_BUS_NAME);
as >> parameter('c',"class",klass,"class to scan for",false)
>> parameter('b',"bus",busName,"name of the bus to use",false)
>> parameter('o',"old_id",oldId,"id to modify",false)
>> parameter('n',"new_id",newId,"new id",false)
>> option('s',"non-interactive",nonInteractive,"run in non interactif mode")
>> help();
as.defaultErrorHandling();
sbcp::Config config;
config.LoadAllFiles();
std::tr1::shared_ptr<sbcp::Bus> bus = config.OpenBusWithFrame(busName,1,16);
FillHexaByteIfNeeded("class",nonInteractive,klass);
FillHexaByteIfNeeded("id of device",nonInteractive,oldId);
FillHexaByteIfNeeded("new id",nonInteractive,newId);
sbcp::Device::Ptr dev = bus->OpenGenericDevice(klass,oldId);
if(! dev){
std::ostringstream os;
os << "Could not find device " << klass << ":" << oldId << std::endl;
throw std::runtime_error(os.str());
}
if(!nonInteractive){
std::ostringstream os;
os << "Really change device " << klass << ":" << oldId << " to "
<< klass;
if(!AskYesNoQuestion(os.str())){
return 0;
}
}
loggers::debug.SetCerr();
log(debug,"Unlocking device ", klass, ":", oldId , " register " , sbcp::Device::SBCP_ID);
dev->UnlockRegister(sbcp::Device::SBCP_ID);
log(debug,"Unlocking device ", klass, ":", oldId , " register " , sbcp::Device::SBCP_ID , " to " , newId);
try {
dev->SetRegister(sbcp::Device::SBCP_ID,newId);
} catch (const sbcp::TransferError & e) {
// a transfer error will be issued, since the ID changed !!!!
//check if it does have changed !!!
if(e.EmettorID() != newId.AsByte() || e.EmettorClass() != klass.AsByte()){
throw;
}
}
return 0;
}
Event Timeline
Log In to Comment