Commit 3c978465 authored by Andrea Zoli's avatar Andrea Zoli
Browse files

Add support for xml config files (converter).

parent aeb469d7
Loading
Loading
Loading
Loading

conf/telemetry.xsd

0 → 100644
+88 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://iasfbo.inaf.it/telemetry" targetNamespace="http://iasfbo.inaf.it/telemetry">
  <xs:element name="stream">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="1" ref="header" />
        <xs:element minOccurs="1" maxOccurs="unbounded" ref="packet" />
      </xs:sequence>
      <xs:attribute name="name" type="xs:Name" />
      <xs:attribute name="bigendian" type="xs:boolean" default="false" />
      <xs:attribute name="prefix" type="xs:boolean" />
      <xs:attribute name="prefixsize" type="xs:integer" />
    </xs:complexType>
  </xs:element>

  <xs:element name="header">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="unbounded" ref="field" />
      </xs:sequence>
      <xs:attribute name="name" type="xs:Name" />
      <xs:attribute name="description" />
      <xs:attribute name="idref" type="xs:IDREF" />
    </xs:complexType>
  </xs:element>

  <xs:element name="packet">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="1" ref="datafieldheader" />
        <xs:element minOccurs="0" maxOccurs="1" ref="sourcedatafield" />
        <xs:element minOccurs="0" maxOccurs="1" ref="tail" />
      </xs:sequence>
      <xs:attribute name="name" use="required" type="xs:Name" />
      <xs:attribute name="description" />
    </xs:complexType>
  </xs:element>

  <xs:element name="datafieldheader">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="unbounded" ref="field" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="sourcedatafield">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="field" />
        <xs:element minOccurs="1" maxOccurs="unbounded" ref="rblock" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="rblock">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="field" />
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="rblock" />
      </xs:sequence>
      <xs:attribute name="name" use="required" type="xs:Name" />
      <xs:attribute name="maxnumberofblocks" use="required" type="xs:integer" /> <!-- max number of blocks for each rblock -->
      <xs:attribute name="idref" type="xs:IDREF" />
    </xs:complexType>
  </xs:element>

  <xs:element name="tail">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" ref="field" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="field">
    <xs:complexType>
      <xs:attribute name="name" use="required" />
      <xs:attribute name="type" use="required" />
      <xs:attribute name="id" type="xs:ID" />
      <xs:attribute name="numberofblocksoffset" type="xs:integer" default="0" />
      <xs:attribute name="packetid" />
      <xs:attribute name="default" />
      <xs:attribute name="description" />
    </xs:complexType>
  </xs:element>

</xs:schema>

include/XmlConfig.h

0 → 100644
+47 −0
Original line number Diff line number Diff line
/***************************************************************************
    begin                : Tue May 20 2014
    copyright            : (C) 2014 Andrea Zoli
    email                : zoli@iasfbo.inaf.it
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef PACKETLIB_XMLCONFIG_H
#define PACKETLIB_XMLCONFIG_H

#include <string>
#include <fstream>
#include <map>
#include "pugixml.h"

namespace PacketLib
{

class XmlConfig
{

	const static std::string _fixed32[];
	const static std::string _fixed64[];

	std::map<pugi::xml_node, int> _physicalIndex;

	void _cachePhysicalIndexes(pugi::xml_node node);
	void _writeFields(pugi::xml_node parent, std::fstream& fs);

	void _writeRBlock(pugi::xml_node rblock, std::fstream& fs, pugi::xml_document& doc);

public:

	std::string convert(const std::string& filename);
};

}

#endif

include/pugiconfig.h

0 → 100644
+72 −0
Original line number Diff line number Diff line
/**
 * pugixml parser - version 1.4
 * --------------------------------------------------------
 * Copyright (C) 2006-2014, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
 * Report bugs and download new versions at http://pugixml.org/
 *
 * This library is distributed under the MIT License. See notice at the end
 * of this file.
 *
 * This work is based on the pugxml parser, which is:
 * Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)
 */

#ifndef HEADER_PUGICONFIG_HPP
#define HEADER_PUGICONFIG_HPP

// Uncomment this to enable wchar_t mode
// #define PUGIXML_WCHAR_MODE

// Uncomment this to disable XPath
// #define PUGIXML_NO_XPATH

// Uncomment this to disable STL
// #define PUGIXML_NO_STL

// Uncomment this to disable exceptions
// #define PUGIXML_NO_EXCEPTIONS

// Set this to control attributes for public classes/functions, i.e.:
// #define PUGIXML_API __declspec(dllexport) // to export all public symbols from DLL
// #define PUGIXML_CLASS __declspec(dllimport) // to import all classes from DLL
// #define PUGIXML_FUNCTION __fastcall // to set calling conventions to all public functions to fastcall
// In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead

// Tune these constants to adjust memory-related behavior
// #define PUGIXML_MEMORY_PAGE_SIZE 32768
// #define PUGIXML_MEMORY_OUTPUT_STACK 10240
// #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096

// Uncomment this to switch to header-only version
// #define PUGIXML_HEADER_ONLY
// #include "pugixml.cpp"

// Uncomment this to enable long long support
// #define PUGIXML_HAS_LONG_LONG

#endif

/**
 * Copyright (c) 2006-2014 Arseny Kapoulkine
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

include/pugixml.h

0 → 100644
+1332 −0

File added.

Preview size limit exceeded, changes collapsed.

+18 −4
Original line number Diff line number Diff line
/***************************************************************************
                          ConfigurationFile.cpp  -  description
                          ConfigurationFile.cpp
                          -------------------
    begin                : Thu Nov 29 2001
    copyright            : (C) 2001, 2013 by Andrea Bulgarelli
    email                : bulgarelli@iasfbo.inaf.it
                           (C) 2014 by Andrea Zoli
    email                : bulgarelli@iasfbo.inaf.it, zoli@iasfbo.inaf.it
 ***************************************************************************/

/***************************************************************************
@@ -17,7 +18,9 @@

#include "ConfigurationFile.h"
#include "InputTextFile.h"
#include "XmlConfig.h"
#include <unistd.h>
#include <string>

using namespace PacketLib;

@@ -39,6 +42,17 @@ bool ConfigurationFile::open(char** parameters) throw(PacketExceptionIO*)

    bool ret;
    currentpwd = getcwd(NULL, 512L);

	if(std::string(parameters[0]).find(".xml") != std::string::npos)
	{
		XmlConfig config;
		std::string streamfile = config.convert(parameters[0]);
		int size = streamfile.size();
		parameters[0] = new char[size];
		memcpy(parameters[0], streamfile.c_str(), size);
		parameters[0][size] = 0;
	}
	
	ret = InputTextFile::open(parameters);
    if(!closed)
        fchdir();
Loading