Subversion Repositories HomeAutomation

Rev

Rev 1026 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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