Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93920469
Config.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
Mon, Dec 2, 12:50
Size
2 KB
Mime Type
text/x-c
Expires
Wed, Dec 4, 12:50 (1 d, 20 h)
Engine
blob
Format
Raw Data
Handle
22722416
Attached To
R6621 SBCP High-Level Driver
Config.cpp
View Options
/**
* \file Config.cpp
*
* \date Sep 25, 2012
* \author Alexandre Tuleu
*/
#include "Config.h"
#include <libatuleu/options/Parsers.h>
#include <sbcpd/bus.h>
#include <sbcpd/si/ft2232h.h>
#include <sbcpd/si/linux_serial.h>
namespace sbcp {
Config::Config()
: d_root(new options::Section("",""))
, d_config(d_root->AddSubSection("SBCP","sbcp general settings")){
}
Config::~Config(){}
void Config::LoadFromStdFiles(){
options::ConfigFileParser parser;
std::vector<std::string> prefixes;
prefixes.push_back("/etc/defaults/");
prefixes.push_back(std::string(getenv("HOME")) + "/." );
prefixes.push_back("");
for(std::vector<std::string>::const_iterator p = prefixes.begin();
p != prefixes.end();
++p){
parser.Parse(*p + BaseFileName,d_root);
}
}
std::tr1::shared_ptr<Bus> Config::CreateBusFromStdFile(){
LoadFromStdFiles();
sbcpd_bus_settings * s = sbcpd_bus_settings_create();
sbcpd_bus_settings_set_master_id(s,0);
sbcpd_bus_settings_set_required_frame_definition(s,1,16);
sbcpd_serial_interface * si(NULL);
int err = 0;
if(Sbcp().SerialType() == "ftdi"){
throw std::runtime_error("Unimplemented yet, first need implementation in SBCPD.");
} else if( Sbcp().SerialType() == "ft2232h") {
si = sbcpd_ft2232h_create_interface();
err = sbcpd_ft2232h_open(si,
Sbcp().Baudrate(),
Sbcp().Latency(),
Sbcp().Interface());
} else if ( Sbcp().SerialType() == "linux") {
si = sbcpd_linux_serial_create_interface();
err = sbcpd_linux_serial_open(si,
Sbcp().DevName().c_str(),
Sbcp().Baudrate());
} else {
throw std::runtime_error("unknown serial type '" + Sbcp().SerialType() + "'.");
}
if(err != 0){
throw std::runtime_error(std::string("Error while opening interface : ") + si->error.msg);
}
return std::tr1::shared_ptr<Bus> (new Bus(s,si));
}
const SbcpConfig & Config::Sbcp() const {
return d_config;
}
SbcpConfig::SbcpConfig(options::Section::Ptr base)
: d_oBaudrate(base->AddOption<unsigned int>("baudrate",3310000,"baudrate to use"))
, d_oInterface(base->AddOption<unsigned int>("interface",2,"interface to use for ftdi chips"))
, d_oLatency(base->AddOption<unsigned int>("latency",0,"latency to use for ftdi chips"))
, d_oSerialType(base->AddOption<std::string>("Serial_type","ft2232h","serial type to use, either 'ft2232h', 'linux', 'ftdi' "))
, d_oDevName(base->AddOption<std::string>("devname","/dev/tty1","linux devname to use if type is 'linux'")){
}
const char * Config::BaseFileName("sbcp.config");
} /* namespace sbcp */
Event Timeline
Log In to Comment