NetBurner 3.5.6
PDF Version
Serial To Ethernet

Serial to Ethernet Bridge Application

Overview

This NetBurner NNDK application creates a bidirectional bridge between an RS-232 serial device and an Ethernet network. The program enables real-time data transmission between serial and network clients, effectively allowing serial devices to communicate over TCP/IP networks.

Note
Excellent example of creating a user web page configuration, using the Configuration System (config_object), Configuration Tags, and configuration objects in an application.

Features

  • Bidirectional Data Flow: Forwards data seamlessly between serial port and TCP connections
  • Web-based Configuration: HTML interface for configuring settings without recompilation
  • Connection Management: Handles multiple connection attempts with configurable timeout and override policies
  • Real-time Data Pumping: Efficient select() based I/O multiplexing for simultaneous data transfer
  • Debug Support: Configurable debug output to separate or shared serial ports
  • Persistent Settings: Configuration stored in flash memory

Architecture

Core Components

  • main.cpp: Application entry point, network setup, and connection handling
  • datapump.cpp: Core data transfer engine using select() for I/O multiplexing
  • nvsettings.h: Configuration class definitions and default values
  • datapump.h: Data pump interface and message definitions
  • index.html: Web-based configuration interface

Data Flow

[Serial Device] <---> [Serial Port] <---> [DataPump] <---> [TCP Socket] <---> [Network Client]

Configuration Options

Network Settings

  • Listen Port: TCP port for incoming connections (default: 23 - Telnet)
  • Client Timeout: Inactivity timeout in seconds (default: 60)
  • Client Override Timeout: Time before allowing new connections to override existing ones (default: 20)

Serial Settings

  • Baud Rate: Configurable via web interface (9600, 19200, 38400, 57600, 115200, 230400)
  • Data Format: 8 data bits, 1 stop bit, no parity (fixed)
  • Flow Control: None (configurable in code)

Connection Override Policies

  • Ignore New Connections: Set override timeout to 0xFFFFFFFF
  • Replace After Timeout: Set override timeout to desired seconds
  • Always Replace: Set override timeout to 0

Build Configuration

Preprocessor Definitions

  • SETTINGS_KEY: Flash memory configuration key (0x48666050)
  • DATA_SERIAL_PORT: Serial port number for data (1)
  • DEBUG_SERIAL_PORT: Serial port for debug output (0)
  • DEBUG: Enable/disable debug output (1)

Buffer Sizes

  • BUFFER_SIZE: Data transfer buffer size (1500 bytes)
  • CLIENT_WRITE_BUF_SIZE: Client write buffer (256 bytes)

Usage

Initial Setup

  1. Connect serial device to the configured data serial port
  2. Connect NetBurner device to Ethernet network
  3. Power on and wait for network initialization

Web Configuration

  1. Navigate to the device's IP address in a web browser
  2. Configure TCP and serial port settings as needed
  3. Save settings (optionally reboot on save)

Client Connection

  1. Connect TCP client to device IP on configured port
  2. Data will flow bidirectionally between serial device and TCP client
  3. Connection status messages are sent to both serial and network endpoints

Connection Management

Message Types

  • MTS (Message To Serial): Status messages sent to serial port
  • MTN (Message To Network): Status messages sent to network client

Status Messages

  • Connection opened/closed notifications
  • Timeout warnings
  • Connection override notifications

Data Pump Algorithm

The DataPump function implements efficient I/O multiplexing:

  1. Setup: Initialize file descriptor sets for read, write, and error monitoring
  2. Select: Wait for I/O activity with configurable timeout
  3. Process: Handle data transfer in both directions simultaneously
  4. Buffer Management: Manage separate buffers for each direction
  5. Error Handling: Detect and handle connection errors gracefully

Error Handling

  • Connection Errors: Automatic cleanup and restart
  • Timeout Management: Configurable inactivity timeouts
  • Buffer Overflow: Fixed-size buffers with proper bounds checking
  • Network Errors: Graceful socket closure and restart

Performance Characteristics

  • Throughput: Limited by slowest link (typically serial port)
  • Latency: Low latency due to select() based I/O
  • Memory Usage: Fixed buffer allocation for predictable memory footprint
  • CPU Usage: Event-driven architecture minimizes CPU overhead

Development Notes

Adding Features

  • Modify classSerialSettings in nvsettings.h for new configuration options
  • Update index.html for web interface changes
  • Extend DataPump function for additional protocols

Debug Configuration

  • Set DEBUG_SERIAL_PORT to -1 to share debug and data ports
  • Set DEBUG to 0 to disable debug output entirely
  • Use separate debug port for isolation during development

Hardware Requirements

  • NetBurner embedded module with NNDK support
  • RS-232 serial interface
  • Ethernet connection

Software Dependencies

  • NetBurner NNDK (NetBurner Network Development Kit)
  • Config server system for web-based configuration
  • Standard POSIX socket and file descriptor APIs