generic/output:
- support optional <preamble> and <postamble> which are written right after opening and before closing respectively. This can be used for a header line or an XML header. - unescape <preamble>, <postamble>, <format>, <line_separator>, <var_separator> so that \t, \n, \r, \f, \v, \xnn, \nnn can be used directly (\a and \b are ignored; use \\ for the backslash) The long names ("carriagereturn") are still supported for <var_separator>, but one can just use \r, or \r\n too. - don't abort when a chunk doesn't have a <node>. This is useful for adding constant chunks which consist only of a <format>, such as XML tags.
This commit is contained in:
parent
991c2ff06a
commit
306b818490
2 changed files with 25 additions and 9 deletions
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
#include <Main/util.hxx>
|
||||||
|
|
||||||
#include "generic.hxx"
|
#include "generic.hxx"
|
||||||
|
|
||||||
|
@ -236,6 +237,13 @@ bool FGGeneric::open() {
|
||||||
|
|
||||||
set_enabled( true );
|
set_enabled( true );
|
||||||
|
|
||||||
|
if ( get_direction() == SG_IO_OUT && ! preamble.empty() ) {
|
||||||
|
if ( ! io->write( preamble.c_str(), preamble.size() ) ) {
|
||||||
|
SG_LOG( SG_IO, SG_WARN, "Error writing preamble." );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,6 +275,13 @@ bool FGGeneric::process() {
|
||||||
bool FGGeneric::close() {
|
bool FGGeneric::close() {
|
||||||
SGIOChannel *io = get_io_channel();
|
SGIOChannel *io = get_io_channel();
|
||||||
|
|
||||||
|
if ( get_direction() == SG_IO_OUT && ! postamble.empty() ) {
|
||||||
|
if ( ! io->write( postamble.c_str(), postamble.size() ) ) {
|
||||||
|
SG_LOG( SG_IO, SG_ALERT, "Error writing postamble." );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
set_enabled( false );
|
set_enabled( false );
|
||||||
|
|
||||||
if ( ! io->close() ) {
|
if ( ! io->close() ) {
|
||||||
|
@ -280,10 +295,7 @@ bool FGGeneric::close() {
|
||||||
void
|
void
|
||||||
FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
|
FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
|
||||||
{
|
{
|
||||||
if (root->hasValue("binary_mode"))
|
|
||||||
binary_mode = root->getBoolValue("binary_mode");
|
binary_mode = root->getBoolValue("binary_mode");
|
||||||
else
|
|
||||||
binary_mode = false;
|
|
||||||
|
|
||||||
if (!binary_mode) {
|
if (!binary_mode) {
|
||||||
/* These variables specified in the $FG_ROOT/data/Protocol/xxx.xml
|
/* These variables specified in the $FG_ROOT/data/Protocol/xxx.xml
|
||||||
|
@ -293,8 +305,10 @@ FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
|
||||||
* line_sep_string = the string/charachter to place at the end of each
|
* line_sep_string = the string/charachter to place at the end of each
|
||||||
* lot of variables
|
* lot of variables
|
||||||
*/
|
*/
|
||||||
var_sep_string = root->getStringValue("var_separator");
|
preamble = fgUnescape(root->getStringValue("preamble"));
|
||||||
line_sep_string = root->getStringValue("line_separator");
|
postamble = fgUnescape(root->getStringValue("postamble"));
|
||||||
|
var_sep_string = fgUnescape(root->getStringValue("var_separator"));
|
||||||
|
line_sep_string = fgUnescape(root->getStringValue("line_separator"));
|
||||||
|
|
||||||
if ( var_sep_string == "newline" )
|
if ( var_sep_string == "newline" )
|
||||||
var_separator = '\n';
|
var_separator = '\n';
|
||||||
|
@ -348,11 +362,11 @@ FGGeneric::read_config(SGPropertyNode *root, vector<_serial_prot> &msg)
|
||||||
_serial_prot chunk;
|
_serial_prot chunk;
|
||||||
|
|
||||||
// chunk.name = chunks[i]->getStringValue("name");
|
// chunk.name = chunks[i]->getStringValue("name");
|
||||||
chunk.format = chunks[i]->getStringValue("format", "%d");
|
chunk.format = fgUnescape(chunks[i]->getStringValue("format", "%d"));
|
||||||
chunk.offset = chunks[i]->getDoubleValue("offset");
|
chunk.offset = chunks[i]->getDoubleValue("offset");
|
||||||
chunk.factor = chunks[i]->getDoubleValue("factor", 1.0);
|
chunk.factor = chunks[i]->getDoubleValue("factor", 1.0);
|
||||||
|
|
||||||
string node = chunks[i]->getStringValue("node");
|
string node = chunks[i]->getStringValue("node", "/null");
|
||||||
chunk.prop = fgGetNode(node.c_str(), true);
|
chunk.prop = fgGetNode(node.c_str(), true);
|
||||||
|
|
||||||
string type = chunks[i]->getStringValue("type");
|
string type = chunks[i]->getStringValue("type");
|
||||||
|
|
|
@ -71,6 +71,8 @@ private:
|
||||||
int length;
|
int length;
|
||||||
char buf[ FG_MAX_MSG_SIZE ];
|
char buf[ FG_MAX_MSG_SIZE ];
|
||||||
|
|
||||||
|
string preamble;
|
||||||
|
string postamble;
|
||||||
string var_separator;
|
string var_separator;
|
||||||
string line_separator;
|
string line_separator;
|
||||||
string var_sep_string;
|
string var_sep_string;
|
||||||
|
|
Loading…
Add table
Reference in a new issue