Interface to a component via serial line. More...
#include <Y2SerialComponent.h>
Public Member Functions | |
Y2SerialComponent (string device_name, long baud_rate) | |
~Y2SerialComponent () | |
string | name () const |
YCPValue | evaluate (const YCPValue &command) |
void | result (const YCPValue &result) |
void | setServerOptions (int argc, char **argv) |
YCPValue | doActualWork (const YCPList &arglist, Y2Component *user_interface) |
Private Member Functions | |
int | open_tty () |
void | close_tty () |
int | setup_serial_device () |
int | make_raw () |
int | set_fixed_line_speed (long speed) |
bool | await_readable (long timeout) |
bool | initializeConnection () |
void | sendToSerial (const YCPValue &v) |
YCPValue | receiveFromSerial () |
Private Attributes | |
string | device_name |
long | baud_rate |
int | fd_serial |
string | full_name |
Parser | parser |
int | timeout_seconds |
Interface to a component via serial line.
Y2SerialComponent::Y2SerialComponent | ( | string | device_name, | |
long | baud_rate | |||
) |
Creates a new serial component.
References full_name.
Y2SerialComponent::~Y2SerialComponent | ( | ) |
Cleans up
bool Y2SerialComponent::await_readable | ( | long | timeout | ) | [private] |
wait with timeout (microseconds) for readability
References fd_serial.
Referenced by initializeConnection().
void Y2SerialComponent::close_tty | ( | ) | [private] |
close serial line if necessary and reset flag
References fd_serial.
Referenced by doActualWork(), initializeConnection(), and result().
YCPValue Y2SerialComponent::doActualWork | ( | const YCPList & | arglist, | |
Y2Component * | user_interface | |||
) | [virtual] |
Here the client does its actual work.
arglist | YCPList of client arguments. | |
user_interface | Option display server (user interface) |
This method is only defined, if the component is a client.
Reimplemented from Y2Component.
References close_tty(), Y2Component::evaluate(), initializeConnection(), receiveFromSerial(), sendToSerial(), YCPList::size(), and y2warning.
Defined only in the server role
Reimplemented from Y2Component.
References device_name, fd_serial, initializeConnection(), YCPElement::isNull(), receiveFromSerial(), sendToSerial(), and y2error.
bool Y2SerialComponent::initializeConnection | ( | ) | [private] |
initializes the serial connection
References await_readable(), baud_rate, close_tty(), device_name, fd_serial, make_raw(), NUMSPACES, open_tty(), parser, set_fixed_line_speed(), Parser::setInput(), setup_serial_device(), TIMEOUT, timeout_seconds, and y2error.
Referenced by doActualWork(), and evaluate().
int Y2SerialComponent::make_raw | ( | ) | [private] |
Set raw mode 8,N,1, no parity for serial line
References device_name, fd_serial, and y2error.
Referenced by initializeConnection().
string Y2SerialComponent::name | ( | ) | const [virtual] |
int Y2SerialComponent::open_tty | ( | ) | [private] |
Open the given tty and return the corresponding file descriptor on success.
References device_name, fd_serial, and y2error.
Referenced by initializeConnection().
YCPValue Y2SerialComponent::receiveFromSerial | ( | ) | [private] |
Reads one YCP value from the serial line. Return 0 if none could be read.
References Parser::parse(), and parser.
Referenced by doActualWork(), and evaluate().
void Y2SerialComponent::result | ( | const YCPValue & | result | ) | [virtual] |
Defined only in the server role
Reimplemented from Y2Component.
References YCPTerm::add(), close_tty(), and sendToSerial().
void Y2SerialComponent::sendToSerial | ( | const YCPValue & | v | ) | [private] |
Send a YCPValue over the serial line
References fd_serial.
Referenced by doActualWork(), evaluate(), and result().
int Y2SerialComponent::set_fixed_line_speed | ( | long | speed | ) | [private] |
Set line speed for serial line
References device_name, fd_serial, and y2error.
Referenced by initializeConnection().
void Y2SerialComponent::setServerOptions | ( | int | argc, | |
char ** | argv | |||
) | [virtual] |
Sets the commandline options of the server. Server options for the cat server are simply ignored.
This method is only defined, if the component is a server.
Reimplemented from Y2Component.
References timeout_seconds, y2milestone, and y2warning.
int Y2SerialComponent::setup_serial_device | ( | ) | [private] |
Setup serial device
References device_name, fd_serial, and y2error.
Referenced by initializeConnection().
long Y2SerialComponent::baud_rate [private] |
The baud rate to use
Referenced by initializeConnection().
string Y2SerialComponent::device_name [private] |
The name of the device to use
Referenced by evaluate(), initializeConnection(), make_raw(), open_tty(), set_fixed_line_speed(), and setup_serial_device().
int Y2SerialComponent::fd_serial [private] |
file descriptor for serial connection
Referenced by await_readable(), close_tty(), evaluate(), initializeConnection(), make_raw(), open_tty(), sendToSerial(), set_fixed_line_speed(), and setup_serial_device().
string Y2SerialComponent::full_name [private] |
Full name of component
Referenced by name(), and Y2SerialComponent().
Parser Y2SerialComponent::parser [private] |
Parser used to parse input
Referenced by initializeConnection(), and receiveFromSerial().
int Y2SerialComponent::timeout_seconds [private] |
After so many seconds cancel to try establishing the connection and to an exit(10);
Referenced by initializeConnection(), and setServerOptions().