Subversion Repositories HomeAutomation

Rev

Rev 1989 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1596 runge 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"
1642 runge 30
#include "common/Bitset.h"
1596 runge 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();
1599 runge 43
    static void Create();
1596 runge 44
    static void Delete();
45
 
1989 runge 46
    bool Load(std::string file_path);
1596 runge 47
 
48
 
49
    std::string LookupClassName(unsigned int class_id);
50
    unsigned int ResolveClassId(std::string className);
51
 
52
    std::string LookupDirectionFlag(unsigned int direction_flag);
53
    unsigned int ResolveDirectionFlag(std::string direction_name);
54
 
55
    std::string LookupModuleName(unsigned int module_id);
56
    unsigned int ResolveModuleId(std::string module_name);
57
 
58
    std::string LookupCommandName(unsigned int command_id, std::string module_name);
59
    unsigned int ResolveCommandId(std::string command_name, std::string module_name);
60
 
61
    std::string GetDefineId(std::string name, std::string group);
62
 
63
    std::string LookupNMTCommandName(unsigned int command_id);
64
    unsigned int ResolveNMTCommandId(std::string command_name);
65
 
66
    xml::Node::NodeList GetCommandVariables(std::string command_name, std::string module_name);
67
    xml::Node::NodeList GetNMTCommandVariables(std::string command_name);
68
 
1642 runge 69
    std::string DecodeInt(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length);
70
    void EncodeInt(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value);
71
    std::string DecodeUint(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length);
72
    void EncodeUint(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value);
73
    std::string DecodeFloat(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length);
74
    void EncodeFloat(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value);
2266 linlun 75
    std::string DecodeIEEE32(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length);
76
    void EncodeIEEE32(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value);
1642 runge 77
    std::string DecodeAscii(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length);
78
    void EncodeAscii(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value);
79
    std::string DecodeHexstring(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length);
80
    void EncodeHexstring(common::Bitset& bitset, unsigned int start_bit, unsigned int bit_length, std::string value);
1596 runge 81
 
82
private:
83
    static Pointer instance_;
84
 
85
    xml::Node root_node_;
86
 
87
    Protocol();
88
 
89
    logging::Logger LOG;
90
};
91
 
92
}; // namespace can
93
}; // namespace atom
94
 
95
#endif // CAN_PROTOCOL_H