Rev 997 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 997 | Rev 999 | ||
|---|---|---|---|
| Line 46... | Line 46... | ||
| 46 | { |
46 | { |
| 47 | } |
47 | } |
| 48 | 48 | ||
| 49 | CanDebug::~CanDebug() |
49 | CanDebug::~CanDebug() |
| 50 | { |
50 | { |
| 51 | stop(); |
- | |
| 52 | - | ||
| 53 | for (map<int, AsyncSocket*>::iterator iter = myClientSockets.begin(); iter != myClientSockets.end(); iter++) |
- | |
| 54 | { |
- | |
| 55 | if (iter->second->isConnected()) |
- | |
| 56 | { |
- | |
| 57 | iter->second->stop(); |
- | |
| 58 | } |
- | |
| 59 | - | ||
| 60 | delete iter->second; |
- | |
| 61 | } |
- | |
| 62 | } |
- | |
| 63 | - | ||
| 64 | void CanDebug::run() |
- | |
| 65 | { |
- | |
| 66 | SyslogStream &slog = SyslogStream::getInstance(); |
- | |
| 67 | - | ||
| 68 | string port = Settings::get("CanDebugPort"); |
- | |
| 69 | - | ||
| 70 | if (port == "") |
- | |
| 71 | { |
- | |
| 72 | slog << "CanDebugPort is not defined in the config file, will not start debug interface\n"; |
- | |
| 73 | return; |
- | |
| 74 | } |
- | |
| 75 | - | ||
| 76 | try |
- | |
| 77 | { |
- | |
| 78 | mySocket.setPort(stoi(port)); |
- | |
| 79 | - | ||
| 80 | mySocket.startListen(); |
- | |
| 81 | - | ||
| 82 | slog << "CanDebug is listening for connections on port " + port + ".\n"; |
- | |
| 83 | - | ||
| 84 | while (true) |
- | |
| 85 | { |
- | |
| 86 | AsyncSocket *newSocket = new AsyncSocket(); |
- | |
| 87 | - | ||
| 88 | if (mySocket.accept(newSocket)) |
- | |
| 89 | { |
- | |
| 90 | newSocket->sendData("Welcome to Atom " + ftos(VERSION) + " - CanDebug output\n"); |
- | |
| 91 | - | ||
| 92 | slog << "CanDebug accepted new client on socket " + itos(newSocket->getSocket()) + ".\n"; |
- | |
| 93 | myClientSockets[newSocket->getSocket()] = newSocket; |
- | |
| 94 | myClientSockets[newSocket->getSocket()]->start(); |
- | |
| 95 | } |
- | |
| 96 | } |
- | |
| 97 | } |
- | |
| 98 | catch (SocketException* e) |
- | |
| 99 | { |
- | |
| 100 | slog << "Exception was caught:" + e->getDescription() + ".\n"; |
- | |
| 101 | } |
- | |
| 102 | } |
- | |
| 103 | - | ||
| 104 | void CanDebug::sendData(string data) |
- | |
| 105 | { |
- | |
| 106 | SyslogStream &slog = SyslogStream::getInstance(); |
- | |
| 107 | - | ||
| 108 | for (map<int, AsyncSocket*>::iterator iter = myClientSockets.begin(); iter != myClientSockets.end(); iter++) |
- | |
| 109 | { |
- | |
| 110 | if (iter->second->isConnected()) |
- | |
| 111 | { |
- | |
| 112 | //slog << "CanDebug: sent data to client " + itos(iter->second->getSocket()) + ".\n"; |
- | |
| 113 | - | ||
| 114 | try |
- | |
| 115 | { |
- | |
| 116 | iter->second->sendData(data); |
- | |
| 117 | } |
- | |
| 118 | catch (SocketException* e) |
- | |
| 119 | { |
- | |
| 120 | slog << "CanDebug caught an exception:" + e->getDescription() + ".\n"; |
- | |
| 121 | } |
- | |
| 122 | } |
- | |
| 123 | else |
- | |
| 124 | { |
- | |
| 125 | slog << "CanDebug had a client disconnect.\n"; |
- | |
| 126 | delete iter->second; |
- | |
| 127 | myClientSockets.erase(iter); |
- | |
| 128 | } |
- | |
| 129 | } |
- | |
| 130 | } |
51 | } |
| 131 | 52 | ||
| 132 | void CanDebug:: |
53 | void CanDebug::sendCanMessageToAll(CanMessage canMessage) |
| 133 | { |
54 | { |
| 134 | if (myClientSockets.size() > 0) |
55 | if (myClientSockets.size() > 0) |
| 135 | { |
56 | { |
| 136 | string debugData = ""; |
57 | string debugData = ""; |
| 137 | 58 | ||
| 138 | if (canMessage.getClassName() == "nmt") |
59 | if (canMessage.getClassName() == "nmt") |
| 139 | { |
60 | { |
| 140 | debugData += "NMT"; |
61 | debugData += "NMT"; |
| 141 | } |
62 | } |
| 142 | else |
63 | else |
| 143 | { |
64 | { |
| 144 | if (canMessage.getDirectionFlag() == "To_Owner") |
65 | if (canMessage.getDirectionFlag() == "To_Owner") |
| 145 | { |
66 | { |
| 146 | debugData += "RX"; |
67 | debugData += "RX"; |
| 147 | } |
68 | } |
| 148 | else if (canMessage.getDirectionFlag() == "From_Owner") |
69 | else if (canMessage.getDirectionFlag() == "From_Owner") |
| Line 150... | Line 71... | ||
| 150 | debugData += "TX"; |
71 | debugData += "TX"; |
| 151 | } |
72 | } |
| 152 | else |
73 | else |
| 153 | { |
74 | { |
| 154 | debugData += "??"; |
75 | debugData += "??"; |
| 155 | } |
76 | } |
| 156 | 77 | ||
| 157 | debugData += " " + canMessage.getClassName(); |
78 | debugData += " " + canMessage.getClassName(); |
| 158 | debugData += "_" + canMessage.getModuleName(); |
79 | debugData += "_" + canMessage.getModuleName(); |
| 159 | debugData += ":" + itos(canMessage.getModuleId()); |
80 | debugData += ":" + itos(canMessage.getModuleId()); |
| 160 | } |
81 | } |
| 161 | 82 | ||
| Line 172... | Line 93... | ||
| 172 | 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++) |
| 173 | { |
94 | { |
| 174 | debugData += iter->second; |
95 | debugData += iter->second; |
| 175 | } |
96 | } |
| 176 | 97 | ||
| 177 |
|
98 | sendToAll("[" + niceTime() + "] " + debugData + "\n"); |
| 178 | } |
99 | } |
| - | 100 | } |
|
| - | 101 | ||
| - | 102 | void CanDebug::handleClientData(int id, string data) |
|
| - | 103 | { |
|
| - | 104 | ||
| 179 | } |
105 | } |