# uhi22/pyplc architecture

> Architecture diagram of the GitHub repository uhi22/pyplc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/uhi22/pyplc
- Repository: https://github.com/uhi22/pyplc

## Overview

##### Project Type and Purpose
This is a specialized communication software project that enables communication between electric vehicles and charging stations using the CCS protocol. The project supports three main modes:
- ListenMode: For sniffing traffic between CCS charger and car
- EvseMode: For implementing a charger with CCS support
- PevMode: For implementing charging unit communication

##### Main Components

A. Core Communication Components:
- PLC (Power Line Communication) Layer
- HomePlug Green PHY implementation
- SLAC (Signal Level Attenuation Characterization)
- Network management (NMK/NID handling)

B. Protocol Stack Layers:
- Physical Layer (PLC/HomePlug)
- Network Layer (IPv6)
- Transport Layer (TCP/UDP)
- Application Layer (ISO15118/DIN)
- V2GTP (Vehicle-to-Grid Transfer Protocol)
- EXI (Efficient XML Interchange)

C. State Machines:
- EVSE State Machine (fsmEvse.py)
- PEV State Machine (fsmPev.py)

D. Hardware Interface:
- Control Pilot Interface
- Power Supply Control
- GPIO Management

E. Support Systems:
- Configuration Management
- Logging System
- Debug/Analysis Tools

**[User Interface Layer]**
- ↕
**[Application Logic Layer (State Machines)]**
- ↕
**[Protocol Layer]**
- ↕
**[Network Layer]**
- ↕
**[Hardware Interface Layer]**

##### Key Relationships to Highlight

a) Communication Flow:
**[PLC Modem] ↔ [Network Stack] ↔ [Protocol Handler] ↔ [State Machine] ↔ [Application Logic]**

b) Hardware Control:
**[State Machine] → [Hardware Interface] → [Physical Hardware]**

c) Configuration and Monitoring:
**[Configuration] → [All Components]**
**[Logging] ← [All Components]**

##### Implementation Details

- How pyPlc.py acts as the main entry point
- How configmodule.py manages system configuration
- Relationship between hardwareInterface.py and the state machines
- EXI encoding/decoding process using OpenV2Gx

##### Testing and Simulation

A section showing:
- Test interfaces (mytestsuite.py)
- Simulation capabilities (simulateMqttBackend.py)
- Monitoring tools (scope.py, udplog.py)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "User Interface Layer"
        UI_EVSE["EVSE Mode UI"]:::ui
        UI_PEV["PEV Mode UI"]:::ui
        UI_Listen["Listen Mode UI"]:::ui
    end

    subgraph "Application Layer"
        MainApp["Main Application"]:::app
        click MainApp "https://github.com/uhi22/pyPLC/blob/master/pyPlc.py"
        
        EVSE_Mode["EVSE Mode"]:::mode
        click EVSE_Mode "https://github.com/uhi22/pyPLC/blob/master/evseNoGui.py"
        
        PEV_Mode["PEV Mode"]:::mode
        click PEV_Mode "https://github.com/uhi22/pyPLC/blob/master/pevNoGui.py"
        
        Listen_Mode["Listen Mode"]:::mode
        click Listen_Mode "https://github.com/uhi22/pyPLC/blob/master/listenerNoGui.py"
        
        ConnMgr["Connection Manager"]:::app
        click ConnMgr "https://github.com/uhi22/pyPLC/blob/master/connMgr.py"
        
        AddrMgr["Address Manager"]:::app
        click AddrMgr "https://github.com/uhi22/pyPLC/blob/master/addressManager.py"
    end

    subgraph "State Machines"
        FSM_EVSE["EVSE State Machine"]:::statemachine
        click FSM_EVSE "https://github.com/uhi22/pyPLC/blob/master/fsmEvse.py"
        
        FSM_PEV["PEV State Machine"]:::statemachine
        click FSM_PEV "https://github.com/uhi22/pyPLC/blob/master/fsmPev.py"
    end

    subgraph "Protocol Stack"
        EXI["EXI Handler"]:::protocol
        click EXI "https://github.com/uhi22/pyPLC/blob/master/exiConnector.py"
        
        TCP["TCP Layer"]:::protocol
        click TCP "https://github.com/uhi22/pyPLC/blob/master/pyPlcTcpSocket.py"
        
        IPv6["IPv6 Layer"]:::protocol
        click IPv6 "https://github.com/uhi22/pyPLC/blob/master/pyPlcIpv6.py"
        
        PLC["PLC Communication"]:::protocol
        click PLC "https://github.com/uhi22/pyPLC/blob/master/pyPlcHomeplug.py"
    end

    subgraph "Hardware Interface"
        HWInterface["Hardware Interface"]:::hardware
        click HWInterface "https://github.com/uhi22/pyPLC/blob/master/hardwareInterface.py"
        
        HWDesign["Hardware Design"]:::hardware
        click HWDesign "https://github.com/uhi22/pyPLC/tree/master/hardware/plc_evse/"
    end

    subgraph "Support Systems"
        Config["Configuration Manager"]:::support
        click Config "https://github.com/uhi22/pyPLC/blob/master/configmodule.py"
        
        Logger["Logging System"]:::support
        click Logger "https://github.com/uhi22/pyPLC/blob/master/udplog.py"
        
        Debug["Debug Tools"]:::support
        click Debug "https://github.com/uhi22/pyPLC/blob/master/scope.py"
        
        TestSuite["Test Suite"]:::support
        click TestSuite "https://github.com/uhi22/pyPLC/blob/master/mytestsuite.py"
        
        Simulator["MQTT Simulator"]:::support
        click Simulator "https://github.com/uhi22/pyPLC/blob/master/simulateMqttBackend.py"
        
        TestFramework["Testing Framework"]:::support
        click TestFramework "https://github.com/uhi22/pyPLC/blob/master/tests/tester.py"
    end

    %% Connections
    UI_EVSE --> EVSE_Mode
    UI_PEV --> PEV_Mode
    UI_Listen --> Listen_Mode
    
    MainApp --> |Manages| ConnMgr
    MainApp --> |Manages| AddrMgr
    
    EVSE_Mode --> FSM_EVSE
    PEV_Mode --> FSM_PEV
    
    FSM_EVSE & FSM_PEV --> EXI
    EXI --> TCP
    TCP --> IPv6
    IPv6 --> PLC
    
    FSM_EVSE & FSM_PEV --> HWInterface
    HWInterface --> HWDesign
    
    Config --> MainApp
    Logger --> MainApp
    Debug & TestSuite & Simulator & TestFramework --> MainApp

    %% Styles
    classDef ui fill:#f9f,stroke:#333,stroke-width:2px
    classDef app fill:#9cf,stroke:#333,stroke-width:2px
    classDef mode fill:#fc9,stroke:#333,stroke-width:2px
    classDef statemachine fill:#f96,stroke:#333,stroke-width:2px
    classDef protocol fill:#9fc,stroke:#333,stroke-width:2px
    classDef hardware fill:#ccc,stroke:#333,stroke-width:2px
    classDef support fill:#ff9,stroke:#333,stroke-width:2px
```
