Openvario / variod

Daemon for autonomous e-vario
4 stars 8 forks source link

Fix XCSoar connection dropping #6

Closed iglesiasmarianod closed 4 years ago

iglesiasmarianod commented 4 years ago

Found out that Variod creates and detroys the socket in each turn of the while loop. Just as a quick test, moved out of the While loop the XCSoar socket creation and commented out the closing of that socket. Just create a socket once and send/receive any amount of messages, Whith this mod XCSoar responded quickly to vario changes and accepts STF and Vario mode commands instantly. Debug button stopped flickering too. Did not see the xcsoar log but seems the problem with these delays lays there. This still needs work, how to deal with disconnects etc.. Please, test it if you have spare time and comment.

kedder commented 4 years ago

That's great! Will it still work if xcsoar is restarted while variod is running though?

iglesiasmarianod commented 4 years ago

That's part of what's missing. Let me think how to handle reconnects and test some more. Right now it does not connect again if you restart xcsoar. If the send fails Variod waits for a reconnection. In case the socket is destroyed I would clean everything up, try to re create socket and reconnect there.

iglesiasmarianod commented 4 years ago

Ready, closed old socket and recreated one on send failure. Now Variod reconnects to xcsoar.

bomilkar commented 4 years ago

This part is broken:

      if ((read_size = recv(xcsoar_sock, client_message, 2000, 0 )) > 0 ) {
        // we got some message
        // terminate received buffer
        client_message[read_size] = '\0';

        ddebug_print("Message from XCSoar: %s\n",client_message);

        // parse message from XCSoar
        parse_NMEA_command(client_message);

      }

Compare what is reported form the ""Message from XCSoar: " and compare this with the reports from parse_NMEA_command(). If XCSoar throws several commands in a short time variod runs into Segmentation Fault (maybe the reason the socket closes?).

Same issue around parse_NMEA_sensor(client_message, &sensors);

I've addressed the above in https://github.com/Openvario/variod/pull/4

iglesiasmarianod commented 4 years ago

I did not look into the parsers yet, I just looked into the connection problem. The socket was closed and opened by design. This is the way it was written. If you look at the code you'll see two nested whiles, the outermost, the infinite loop, creates and closes the xcsoar socket all the time. Create a socket, transmit a message, check incoming messages, close socket and then repeat. I'll have a look at the parsers to see if I can help.

iglesiasmarianod commented 4 years ago

Comments reviewed in the code.