Subversion Repositories HomeAutomation

Rev

Rev 999 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 999 Rev 1024
Line 57... Line 57...
57
    delete myChannel;
57
    delete myChannel;
58
}
58
}
59
 
59
 
60
void CanNetManager::run()
60
void CanNetManager::run()
61
{
61
{
62
    SyslogStream &slog = SyslogStream::getInstance();
62
    Logger &log = Logger::getInstance();
63
    VirtualMachine &vm = VirtualMachine::getInstance();
63
    VirtualMachine &vm = VirtualMachine::getInstance();
64
    CanDebug &canDebug = CanDebug::getInstance();
64
    CanDebug &canDebug = CanDebug::getInstance();
65
 
65
 
66
    string address = Settings::get("CanNetAddress");
66
    string address = Settings::get("CanNetAddress");
67
    if (address == "")
67
    if (address == "")
Line 98... Line 98...
98
            SocketEvent socketEvent = myChannel->eventFetch();
98
            SocketEvent socketEvent = myChannel->eventFetch();
99
 
99
 
100
            switch (socketEvent.getType())
100
            switch (socketEvent.getType())
101
            {
101
            {
102
                case SocketEvent::TYPE_CONNECTED:
102
                case SocketEvent::TYPE_CONNECTED:
103
                slog << "Connected to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + ".\n";
103
                log.add("Connected to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + ".\n");
104
                break;
104
                break;
105
 
105
 
106
                case SocketEvent::TYPE_CONNECTING:
106
                case SocketEvent::TYPE_CONNECTING:
107
                slog << "Connecting to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + ".\n";
107
                log.add("Connecting to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + ".\n");
108
                break;
108
                break;
109
 
109
 
110
                case SocketEvent::TYPE_CONNECTION_CLOSED:
110
                case SocketEvent::TYPE_CONNECTION_CLOSED:
111
                slog << "Connection to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + " closed.\n";
111
                log.add("Connection to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + " closed.\n");
112
                vm.queueExpression("setAllOffline();");
112
                vm.queueExpression("setAllOffline();");
113
                break;
113
                break;
114
 
114
 
115
                case SocketEvent::TYPE_CONNECTION_DIED:
115
                case SocketEvent::TYPE_CONNECTION_DIED:
116
                slog << "Connection to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + " died :: " + socketEvent.getData() + "\n";
116
                log.add("Connection to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + " died :: " + socketEvent.getData() + "\n");
117
                vm.queueExpression("setAllOffline();");
117
                vm.queueExpression("setAllOffline();");
118
                break;
118
                break;
119
 
119
 
120
                case SocketEvent::TYPE_CONNECTION_RESET:
120
                case SocketEvent::TYPE_CONNECTION_RESET:
121
                slog << "Connection to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + " was reset :: " + socketEvent.getData() + "\n";
121
                log.add("Connection to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + " was reset :: " + socketEvent.getData() + "\n");
122
                vm.queueExpression("setAllOffline();");
122
                vm.queueExpression("setAllOffline();");
123
                break;
123
                break;
124
 
124
 
125
                case SocketEvent::TYPE_CONNECTION_FAILED:
125
                case SocketEvent::TYPE_CONNECTION_FAILED:
126
                slog << "Connection to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + " failed :: " + socketEvent.getData() + "\n";
126
                log.add("Connection to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + " failed :: " + socketEvent.getData() + "\n");
127
                vm.queueExpression("setAllOffline();");
127
                vm.queueExpression("setAllOffline();");
128
                break;
128
                break;
129
 
129
 
130
                case SocketEvent::TYPE_DATA:
130
                case SocketEvent::TYPE_DATA:
131
                waitingForPong = false;
131
                waitingForPong = false;
Line 137... Line 137...
137
                    {
137
                    {
138
                        data = trim(dataLines[n], '\n');
138
                        data = trim(dataLines[n], '\n');
139
 
139
 
140
                        if (data == "PONG")
140
                        if (data == "PONG")
141
                        {
141
                        {
142
                            slog << "Received pong.\n";
142
                            log.add("Received pong.\n");
143
                            continue;
143
                            continue;
144
                        }
144
                        }
145
 
145
 
146
                        canMessage = new CanMessage(data);
146
                        canMessage = new CanMessage(data);
147
 
147
 
Line 184... Line 184...
184
                    if (canMessage != NULL)
184
                    if (canMessage != NULL)
185
                    {
185
                    {
186
                        delete canMessage;
186
                        delete canMessage;
187
                    }
187
                    }
188
 
188
 
189
                    slog << "CanMessageException was caught:\n";
189
                    log.add("CanMessageException was caught:\n");
190
                    slog << e->getDescription() + "\n";
190
                    log.add(e->getDescription() + "\n");
191
                }
191
                }
192
                break;
192
                break;
193
 
193
 
194
                case SocketEvent::TYPE_INACTIVITY:
194
                case SocketEvent::TYPE_INACTIVITY:
195
                if (waitingForPong)
195
                if (waitingForPong)
196
                {
196
                {
197
                    slog << "We have not received a pong for our ping.\n";
197
                    log.add("We have not received a pong for our ping.\n");
198
                    waitingForPong = false;
198
                    waitingForPong = false;
199
                    vm.queueExpression("setAllOffline();");
199
                    vm.queueExpression("setAllOffline();");
200
                    myChannel->forceReconnect();
200
                    myChannel->forceReconnect();
201
                }
201
                }
202
                else
202
                else
203
                {
203
                {
204
                    //slog << "We have not received anything from the canDaemon in some time.\n";
204
                    //log.add("We have not received anything from the canDaemon in some time.\n";
205
                    waitingForPong = true;
205
                    waitingForPong = true;
206
                    slog << "Sending ping.\n";
206
                    log.add("Sending ping.\n");
207
                    myChannel->sendData("PING");
207
                    myChannel->sendData("PING");
208
                }
208
                }
209
                break;
209
                break;
210
 
210
 
211
                case SocketEvent::TYPE_WAITING_RECONNECT:
211
                case SocketEvent::TYPE_WAITING_RECONNECT:
212
                slog << "Will try to reconnect to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + " in " + itos(myChannel->getReconnectTimeout()) + " seconds.\n";
212
                log.add("Will try to reconnect to " + myChannel->getAddress() + ":" + itos(myChannel->getPort()) + " in " + itos(myChannel->getReconnectTimeout()) + " seconds.\n");
213
                break;
213
                break;
214
            }
214
            }
215
        }
215
        }
216
    }
216
    }
217
 
217