class SerialPort: public AbstractIo
{
+private:
+ speed_t speed;
+
public:
SerialPort(std::string _tty)
:tty(_tty)
{
-
+ speed = B9600;
}
~SerialPort()
close();
}
+ int setSpeed(int newspeed)
+ {
+ int ret = 0;
+ switch(newspeed)
+ {
+ case 2400:
+ speed = B2400;
+ break;
+ case 4800:
+ speed = B4800;
+ break;
+ case 9600:
+ speed = B9600;
+ break;
+ case 19200:
+ speed = B19200;
+ break;
+ case 38400:
+ speed = B38400;
+ break;
+ default:
+ ret = -EINVAL;
+ }
+ return ret;
+ }
+
bool open()
{
fd = ::open(tty.c_str(), O_RDWR, O_NOCTTY);
//oldtio.c_cc[VEOL] = '\r';
- cfsetispeed(&oldtio, B9600);
- cfsetospeed(&oldtio, B9600);
+ cfsetispeed(&oldtio, speed);
+ cfsetospeed(&oldtio, speed);
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &oldtio);
"name" : "gpsnmea",
"path" : "/usr/lib/automotive-message-broker/gpsnmea.so",
"device" : "/dev/ttyUSB0",
+ "baudrate" : "4800",
"bluetoothAdapter" : "00:00:00:00:00:00"
}
"device"
gps device. This must be a serial device. It can also be a bluetooth address.
+"baudrate"
+Baudrate for serial devices : 2400,4800,9600,19200 or 38400. Default is 9600.
+
Default: none
"bluetoothAdapter"
GpsNmeaSource::GpsNmeaSource(AbstractRoutingEngine *re, map<string, string> config)
:AbstractSource(re,config), mUuid("33d86462-1708-4f78-a001-99ea8d55422b")
{
+ int baudrate = 0;
location =new Location(re, mUuid);
VehicleProperty::registerProperty(GPSTIME,[](){ return new BasicPropertyType<double>(GPSTIME,0); });
std::string btaddapter = config["bluetoothAdapter"];
+ if(config.find("baudrate")!= config.end())
+ {
+ baudrate = boost::lexical_cast<int>( config["baudrate"] );
+ }
+
if(config.find("device")!= config.end())
{
std::string dev = config["device"];
device = new SerialPort(dev);
+ if(baudrate!=0)
+ {
+ if((static_cast<SerialPort*>(device))->setSpeed(baudrate))
+ DebugOut(DebugOut::Error)<<"Unsupported baudrate " << config["baudrate"] << endl;
+ }
+
if(!device->open())
{
DebugOut(DebugOut::Error)<<"Failed to open gps tty: "<<config["device"]<<endl;