dockemu

Digital Twin Emulator - C20 Simulator

Kompletny emulator systemu C20 z wieloma mikroserwisami w Docker. System oferuje dwa tryby pracy:

Architektura Systemu

System składa się z następujących mikroserwisów:

🚀 Quick Start

Get everything running in 3 commands:

git clone <repository-url>
cd dockemu
make quick-start

Then open http://localhost:8088 for the unified dashboard! 🎉

📖 Project Overview

This project provides a complete Docker-based simulation environment for C20 hardware components, including:

Serwisy Główne

Interfejsy Użytkownika

Systemy I/O

Dostępne Porty

Serwis Port Opis URL
WebGUI 8088 Główny interfejs http://localhost:8088
LCD Display 8089 Symulator LCD http://localhost:8089
HUI Keyboard 8087 Panel klawiatury http://localhost:8087
Modbus Visualizer 8084 Wizualizacja Modbus http://localhost:8084
Modbus IO API 8085 API Modbus RTU http://localhost:8085
RPi3PC API 4000 API emulatora http://localhost:4000
MQTT Broker 1883 MQTT protokół mqtt://localhost:1883
MQTT WebSocket 9001 WebSocket MQTT ws://localhost:9001

🛠️ Installation

Prerequisites

Step-by-Step Setup

  1. Clone the repository:
    git clone <repository-url>
    cd dockemu
    
  2. Build all containers:
    make build
    
  3. Start all services:
    make up
    
  4. Verify everything is running:
    make status
    

🎮 Using the Simulations

Access: http://localhost:8088

The unified dashboard provides complete control over all simulators:

🖥️ Layout Modes

🎛️ Control Panel Features

⌨️ Keyboard Shortcuts

Individual Service Access

🖥️ LCD Display Simulator

Access: http://localhost:8091

Simulates the 7.9” HDMI display showing:

⌨️ HUI Keyboard Panel

Access: http://localhost:8092

Interactive keyboard interface for:

Usage:

📊 Modbus I/O Visualizer

Access: http://localhost:8084

Real-time visualization of 8-channel Modbus RTU:

How to use:

  1. Click output channel buttons to toggle states
  2. Monitor input changes in real-time
  3. Adjust register values using sliders
  4. Export/import configurations

🔬 Test Procedures

BLS Mask Testing:

# Run BLS 5000 test
make shell SERVICE=rpi
python3 /shared/test_procedures.py --test BLS_5000

# Run BLS 8000 test  
python3 /shared/test_procedures.py --test BLS_8000

API Testing:

# Start a test procedure via API
curl -X POST http://localhost:8088/api/procedures/start \
  -H "Content-Type: application/json" \
  -d '{"procedure": "BLS_5000_TEST", "serial": "SN123456"}'

🌡️ Pressure Sensors

I2C Communication Test:

make shell SERVICE=rpi
python3 -c "
from hardware.i2c_bus import I2CBusSimulator
import asyncio

async def test_sensors():
    bus = I2CBusSimulator()
    # Read LP sensor (0x48)
    lp_data = await bus.read(0x48, 2)
    print(f'LP Pressure: {int.from_bytes(lp_data, \"big\")} mbar')
    
    # Read MP sensor (0x49)  
    mp_data = await bus.read(0x49, 2)
    print(f'MP Pressure: {int.from_bytes(mp_data, \"big\")} mbar')
    
    # Read HP sensor (0x4A)
    hp_data = await bus.read(0x4A, 2)  
    print(f'HP Pressure: {int.from_bytes(hp_data, \"big\")} mbar')

asyncio.run(test_sensors())
"

⚡ Valve Controller

Control 12-channel outputs:

make shell SERVICE=rpi
python3 -c "
from hardware.gpio_controller import GPIOController
import time

gpio = GPIOController()
# Turn on valve 1
gpio.set_pin(1, True)
time.sleep(2)
# Turn off valve 1  
gpio.set_pin(1, False)
"

🌐 Available Services

Service Port Description Health Check
Unified Dashboard 8088 Main control interface http://localhost:8088/health
LCD Display 8091 System display simulation http://localhost:8091
HUI Keyboard 8092 Interactive keyboard http://localhost:8092
Modbus Visual 8084 I/O visualization http://localhost:8084
MQTT Broker 1883 Message communication -
WebSocket 9001 Real-time communication -

🔧 Makefile Commands

Basic Operations

make help           # Show all available commands
make build          # Build all Docker images
make up             # Start all services  
make down           # Stop all services
make restart        # Restart all services
make clean          # Complete cleanup (containers, images, volumes)

Development & Debugging

make logs                           # Show logs from all services
make logs-service SERVICE=rpi       # Show logs from specific service
make shell SERVICE=rpi              # Open shell in container
make status                         # Show container status
make monitoring                     # Real-time resource monitoring

Testing

make test-all       # Run all test procedures
make test-bls       # Run BLS mask tests  
make test-modbus    # Test Modbus communication

Utilities

make install        # Setup project dependencies
make backup         # Create project backup
make dev            # Start in development mode

🏗️ Architecture

Component Overview

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│  Unified        │    │  LCD Display    │    │  HUI Keyboard   │
│  Dashboard      │    │  (nginx)        │    │  (Flask)        │
│  :8088          │    │  :8091          │    │  :8092          │
└─────────────────┘    └─────────────────┘    └─────────────────┘
         │                       │                       │
         └───────────────────────┼───────────────────────┘
                                 │
         ┌───────────────────────┼───────────────────────┐
         │                       │                       │
┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│  RPI Controller │    │  Modbus I/O     │    │  MQTT Broker    │
│  (Python)       │    │  Visualizer     │    │  (Mosquitto)    │
│  I2C/GPIO       │    │  :8084          │    │  :1883/:9001    │
└─────────────────┘    └─────────────────┘    └─────────────────┘
         │                       │                       │
         └───────────────────────┼───────────────────────┘
                                 │
┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│  Pressure       │    │  Valve          │    │  Test           │
│  Sensors        │    │  Controller     │    │  Procedures     │
│  (I2C)          │    │  (I2C)          │    │  (Python)       │
└─────────────────┘    └─────────────────┘    └─────────────────┘

Communication Protocols

🐛 Troubleshooting

Common Issues

🔴 Build Failures

# Clean everything and rebuild
make clean
make build

# Check specific service logs
make logs-service SERVICE=<service-name>

🔴 Port Conflicts

# Check what's using ports
sudo netstat -tulpn | grep :808

# Stop conflicting services
sudo systemctl stop <service-name>

🔴 Permission Issues

# Fix Docker permissions
sudo usermod -aG docker $USER
newgrp docker

🔴 Container Won’t Start

# Check container status
make status

# Restart specific service
make restart-service SERVICE=<service-name>

# Emergency stop and restart
make down
make up

Service-Specific Issues

LCD Display Not Loading

Keyboard Not Responding

Modbus Communication Issues

👨‍💻 Development

Adding New Services

  1. Create service directory:
    mkdir new-service
    cd new-service
    
  2. Add Dockerfile and code

  3. Update docker-compose.yml:
    new-service:
      build: ./new-service
      container_name: c20-new-service
      ports:
        - "8086:80"
      networks:
        - c20-network
    
  4. Update unified dashboard to include new service iframe

Protocol Extension

The C20 protocol (shared/protocols/c20_protocol.py) can be extended with:

Testing

# Run unit tests
make shell SERVICE=rpi
python3 -m pytest /app/tests/ -v

# Integration tests
make test-all

# Load testing
make monitoring  # Monitor during tests

📞 Support

For issues and questions:

Happy simulating! 🎉