Subversion Repositories HomeAutomation

Rev

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

Rev Author Line No. Line
981 runge 1
/***************************************************************************
2
 *   Copyright (C) December 27, 2008 by Mattias Runge                             *
3
 *   mattias@runge.se                                                      *
4
 *   candebug.cpp                                            *
5
 *                                                                         *
6
 *   This program is free software; you can redistribute it and/or modify  *
7
 *   it under the terms of the GNU General Public License as published by  *
8
 *   the Free Software Foundation; either version 2 of the License, or     *
9
 *   (at your option) any later version.                                   *
10
 *                                                                         *
11
 *   This program is distributed in the hope that it will be useful,       *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU General Public License for more details.                          *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU General Public License     *
17
 *   along with this program; if not, write to the                         *
18
 *   Free Software Foundation, Inc.,                                       *
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
20
 ***************************************************************************/
21
 
22
#include "candebug.h"
23
 
24
CanDebug* CanDebug::myInstance = NULL;
25
 
26
CanDebug& CanDebug::getInstance()
27
{
28
    if (myInstance == NULL)
29
    {
30
        myInstance = new CanDebug();
31
    }
32
 
33
    return *myInstance;
34
}
35
 
36
void CanDebug::deleteInstance()
37
{
38
    if (myInstance != NULL)
39
    {
40
        delete myInstance;
41
        myInstance = NULL;
42
    }
43
}
44
 
45
CanDebug::CanDebug()
46
{
47
}
48
 
49
CanDebug::~CanDebug()
50
{
51
}
52
 
999 runge 53
void CanDebug::sendCanMessageToAll(CanMessage canMessage)
981 runge 54
{
986 runge 55
    if (myClientSockets.size() > 0)
981 runge 56
    {
57
        string debugData = "";
58
 
986 runge 59
        if (canMessage.getClassName() == "nmt")
981 runge 60
        {
986 runge 61
            debugData += "NMT";
981 runge 62
        }
63
        else
64
        {
986 runge 65
            if (canMessage.getDirectionFlag() == "To_Owner")
66
            {
67
                debugData += "RX";
68
            }
69
            else if (canMessage.getDirectionFlag() == "From_Owner")
70
            {
71
                debugData += "TX";
72
            }
73
            else
74
            {
75
                debugData += "??";
76
            }
77
 
78
            debugData += " " + canMessage.getClassName();
79
            debugData += "_" + canMessage.getModuleName();
80
            debugData += ":" + itos(canMessage.getModuleId());
981 runge 81
        }
82
 
83
        debugData += " CMD=" + canMessage.getCommandName() + " ";
84
 
85
        map<string, CanVariable> vars = canMessage.getData();
991 runge 86
        map<int, string> sortMap;
981 runge 87
 
991 runge 88
        for (map<string, CanVariable>::iterator iter = vars.begin(); iter != vars.end(); iter++)
89
        {
90
            sortMap[iter->second.getStartBit()] = " " + iter->second.getName() + "=" + iter->second.getValue();
91
        }
981 runge 92
 
991 runge 93
        for (map<int, string>::iterator iter = sortMap.begin(); iter != sortMap.end(); iter++)
981 runge 94
        {
991 runge 95
            debugData += iter->second;
981 runge 96
        }
97
 
1122 linlun 98
        sendToAll("[" + niceTime() + "] " + debugData + "\r\n");
981 runge 99
    }
100
}
999 runge 101
 
102
void CanDebug::handleClientData(int id, string data)
103
{
104
 
105
}