Subversion Repositories HomeAutomation

Rev

Rev 1596 | Rev 1599 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  *
  3.  *    Copyright (C) 2010  Mattias Runge
  4.  *
  5.  *    This program is free software; you can redistribute it and/or modify
  6.  *    it under the terms of the GNU General Public License as published by
  7.  *    the Free Software Foundation; either version 2 of the License, or
  8.  *    (at your option) any later version.
  9.  *
  10.  *    This program is distributed in the hope that it will be useful,
  11.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *    GNU General Public License for more details.
  14.  *
  15.  *    You should have received a copy of the GNU General Public License along
  16.  *    with this program; if not, write to the Free Software Foundation, Inc.,
  17.  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18.  *
  19.  */
  20.  
  21. #ifndef CAN_PROTOCOL_H
  22. #define CAN_PROTOCOL_H
  23.  
  24. #include <boost/shared_ptr.hpp>
  25.  
  26. #include <string>
  27.  
  28. #include "xml/Node.h"
  29. #include "logging/Logger.h"
  30. #include "type/Bitset.h"
  31.  
  32. namespace atom {
  33. namespace can {
  34.  
  35. class Protocol
  36. {
  37. public:
  38.     typedef boost::shared_ptr<Protocol> Pointer;
  39.    
  40.     virtual ~Protocol();
  41.    
  42.     static Pointer Instance();
  43.     static void Delete();
  44.    
  45.     bool Load(std::string filename);
  46.    
  47.    
  48.     std::string LookupClassName(unsigned int class_id);
  49.     unsigned int ResolveClassId(std::string className);
  50.    
  51.     std::string LookupDirectionFlag(unsigned int direction_flag);
  52.     unsigned int ResolveDirectionFlag(std::string direction_name);
  53.    
  54.     std::string LookupModuleName(unsigned int module_id);
  55.     unsigned int ResolveModuleId(std::string module_name);
  56.    
  57.     std::string LookupCommandName(unsigned int command_id, std::string module_name);
  58.     unsigned int ResolveCommandId(std::string command_name, std::string module_name);
  59.    
  60.     std::string GetDefineId(std::string name, std::string group);
  61.    
  62.     std::string LookupNMTCommandName(unsigned int command_id);
  63.     unsigned int ResolveNMTCommandId(std::string command_name);
  64.  
  65.     xml::Node::NodeList GetCommandVariables(std::string command_name, std::string module_name);
  66.     xml::Node::NodeList GetNMTCommandVariables(std::string command_name);
  67.    
  68.     std::string DecodeInt(type::Bitset& bitset, unsigned int start_bit, unsigned int bit_length);
  69.     void EncodeInt(type::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value);
  70.     std::string DecodeUint(type::Bitset& bitset, unsigned int start_bit, unsigned int bit_length);
  71.     void EncodeUint(type::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value);
  72.     std::string DecodeFloat(type::Bitset& bitset, unsigned int start_bit, unsigned int bit_length);
  73.     void EncodeFloat(type::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value);
  74.     std::string DecodeAscii(type::Bitset& bitset, unsigned int start_bit, unsigned int bit_length);
  75.     void EncodeAscii(type::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value);
  76.     std::string DecodeHexstring(type::Bitset& bitset, unsigned int start_bit, unsigned int bit_length);
  77.     void EncodeHexstring(type::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value);
  78.    
  79. private:
  80.     static Pointer instance_;
  81.    
  82.     xml::Node root_node_;
  83.    
  84.     Protocol();
  85.        
  86.     logging::Logger LOG;
  87. };
  88.  
  89. }; // namespace can
  90. }; // namespace atom
  91.  
  92. #endif // CAN_PROTOCOL_H
  93.