Skip to content

Feat/client server#3

Merged
KevinRomanello merged 10 commits intomasterfrom
feat/client-server
Feb 23, 2026
Merged

Feat/client server#3
KevinRomanello merged 10 commits intomasterfrom
feat/client-server

Conversation

@YugenUniverse
Copy link
Copy Markdown

Purpose

The goal of this pull request is to enable concurrent access to GPS data by implementing a TCP Server/Client architecture within gpslib, resolving #2.
This PR decouples the hardware connection from the data processing, allowing a single Server instance to broadcast raw GPS data to multiple Clients simultaneously.

Overview

This pull request introduces significant changes to gps_interface to support connection management and ensure data integrity for both NMEA and UBX protocols.

  • Added TCP Server/Client Modes: Implemented the two new modes and their respective interface openers. Extended gps_serial_port with a server context that wraps the underlying physical GPS port, managing the server socket in the top layer and the serial connection in the bottom layer.
  • Packet Reconstruction: Modified gps_interface_get_line to reconstruct the full raw packet (re-attaching stripped Start Sequences/Sync Bytes and Newlines) before broadcasting. This ensures clients receive valid, checksum-verifiable data.
  • Error Handling: Implemented a fail-count mechanism in broadcast_to_clients. It uses MSG_NOSIGNAL to detect broken pipes (EPIPE/ECONNRESET) and disconnects dead clients immediately, while tolerating temporary failures (up to MAX_FAILS) for congested connections.
  • Thread Safety: Added pthread support to manage the acceptance of new connections and mutexes to protect the client socket and failure lists during broadcast operations.

Guidance

I recommend reviewing the files in the following order:

  1. gps_interface.h: Start here to review the changes to the gps_serial_port struct and the new server context definitions.
  2. gps_interface.c:
    • SERVER Logic:
      1. Review gps_interface_open_server to see how the context is initialized.
      2. Review gps_interface_read and gps_interface_get_line to see how the code detects the protocol type and reconstructs the full message buffer before calling broadcast.
      3. Review broadcast_to_clients to examine the MSG_NOSIGNAL implementation and the strike-count logic for handling client disconnects.
      4. Review acceptThreadFunc, the detached thread that continuously listens for and accepts new client connections.
    • CLIENT Logic:
      1. Review gps_interface_open_client to see how the connection is established.
      2. Review gps_interface_read for the client-side socket handling.

@YugenUniverse YugenUniverse self-assigned this Jan 28, 2026
@YugenUniverse YugenUniverse linked an issue Jan 28, 2026 that may be closed by this pull request
Comment thread gps_interface.c Outdated
Comment thread gps_interface.c Outdated
Comment thread gps_interface.c
Comment thread gps_interface.c
Comment thread gps_interface.c Outdated
Copy link
Copy Markdown
Contributor

@KevinRomanello KevinRomanello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job 👍🏿😎🎾

@KevinRomanello KevinRomanello merged commit 25fc4d3 into master Feb 23, 2026
@KevinRomanello KevinRomanello deleted the feat/client-server branch February 23, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add server/client mode

3 participants