Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102258440
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, Feb 18, 20:12
Size
1 KB
Mime Type
text/x-c
Expires
Thu, Feb 20, 20:12 (2 d)
Engine
blob
Format
Raw Data
Handle
24314598
Attached To
R6621 SBCP High-Level Driver
main.cpp
View Options
/**
* \file main.cpp
*
* \date Sep 25, 2012
* \author Alexandre Tuleu
*/
#include <libsbcp-tool/argstream.h>
#include <libsbcp-tool/Config.h>
const static unsigned int UnitializedByte = 0x0f00;
void FillDataIfNeeded(const std::string & name, bool nonInteractif, unsigned int & data){
std::ostringstream os;
if(data == UnitializedByte){
if(nonInteractif){
os << name << " should be provided.";
throw std::runtime_error(os.str());
}
std::cout << "Please enter a " << name << " : " << std::flush;
std::cin >> data;
}
if(data > 0xff){
os << name << "should be lower or equal to 0xff (here : 0x"
<< std::hex << data << ").";
throw std::runtime_error(os.str());
}
}
int main(int argc, char ** argv){
unsigned int klass = UnitializedByte;
unsigned int oldId = UnitializedByte;
unsigned int newId = UnitializedByte;
bool nonInteractive(false);
argstream as(argc,argv);
as >> parameter('c',"class",klass,"class to scan for",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();
std::tr1::shared_ptr<sbcp::Bus> bus = sbcp::Config::Instance().CreateBusFromStdFile();
FillDataIfNeeded("class",nonInteractive,klass);
FillDataIfNeeded("id of device",nonInteractive,oldId);
FillDataIfNeeded("new id",nonInteractive,newId);
sbcp::Device::Ptr dev = bus->OpenGenericDevice(klass,oldId);
if(! dev){
std::ostringstream os;
os << "Could not find device 0x" << std::hex << klass << ":0x" << oldId << std::endl;
throw std::runtime_error(os.str());
}
if(!nonInteractive){
std::cout << "Really change device 0x" << std::hex << klass
<< ":0x" << oldId << " to 0x" << klass << ":0x" << newId << " ?"
<< std::flush;
std::string foo;
std::cin >> foo;
}
dev->UnlockRegister(sbcp::Device::SBCP_ID);
dev->SetRegister(sbcp::Device::SBCP_ID,newId);
return 0;
}
Event Timeline
Log In to Comment