# tremaru/iarduino_gsm architecture

> Architecture diagram of the GitHub repository tremaru/iarduino_gsm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tremaru/iarduino_gsm
- Repository: https://github.com/tremaru/iarduino_gsm

## Overview

1. **Repository type and boundary**
   - This is an **Arduino library**, not a standalone application.
   - The core deliverable is a reusable C++ library in `src/` that abstracts an **iArduino GSM/GPRS Shield** for microcontroller sketches.
   - The repo boundary is: user sketch → `iarduino_GSM` library → serial link → GSM modem/shield → cellular network.

2. **Core runtime subsystem**
   - The main implementation lives in `src/iarduino_GSM.cpp` and `src/iarduino_GSM.h`.
   - This layer is the only place that should contain protocol handling, AT command formatting/parsing, and device state management.
   - The README shows the public API surface; the library is a thin hardware-facing abstraction rather than a large framework.

3. **Communication model**
   - The library talks to the GSM module through an Arduino UART abstraction supplied to `begin(UART)`.
   - The repo supports both **HardwareSerial** and **SoftwareSerial** in examples, meaning the library is designed to operate over either physical or bit-banged serial ports.
   - This is the main architectural boundary: the library does not own the serial transport, it consumes an Arduino serial object.

4. **Primary functional domains**
   - The API groups into a few clear subsystems:
     - module lifecycle and status: `begin`, `status`, `pwr`, `reset`, `pin`, `puk`
     - command execution: `runAT`, `runUSSD`
     - SMS: `SMSavailable`, `SMSmax`, `SMSread`, `SMSsend`, encoding/class controls
     - voice calls: `CALLavailable`, `CALLup`, `CALLend`, `CALLdial`, `CALLstatus`
     - audio controls: `SOUNDdevice`, `SOUNDvolume`, `SOUNDmute`
   - These are all application-facing wrappers around modem capabilities.

5. **Data flow for control operations**
   - A sketch calls a library method.
   - The library converts that request into AT commands and sends them over serial.
   - The modem responds with modem text/URC responses.
   - The library interprets the response and returns status/data to the sketch.
   - For most features, the library is acting as a request/response adapter over AT command text.

6. **SMS subsystem**
   - SMS support is one of the larger functional areas and likely includes text encoding/decoding, storage queries, and message transfer.
   - `extras/PDU.txt` indicates the library also documents or supports **PDU format** handling, which matters for SMS transport and encoding.
   - The encoding controls in the README (`TXTreadCoding`, `TXTsendCoding`, `TXTsendCodingDetect`) suggest the SMS path is responsible for charset conversion as well as message exchange.

7. **Voice call subsystem**
   - The call-related APIs form a separate modem feature group for incoming/outgoing voice sessions.
   - The library exposes call detection, dialing, answer, hangup, and status, plus audio routing and volume controls.
   - Architecturally, this is still the same serial/AT channel, but it represents a distinct state machine in the modem domain.

8. **Module lifecycle and recovery**
   - `begin`, `pwr`, `reset`, `pin`, and `puk` indicate the library manages module readiness and SIM security state, not just data services.
   - This means the library likely has startup sequencing and recovery behavior before higher-level features can work.
   - In diagram terms, these are initialization and fault-recovery paths around the main serial control path.

9. **Example application layer**
   - The `examples/` tree is extensive and organized by:
     - board/shield variant: `Shield_A6`, `Shield_A9`
     - transport type: `HardwareSerial`, `SoftwareSerial`
     - feature demo: `begin`, `balance`, `sms_send`, `sms_read`, `call_outgoing`, `call_incoming`, `AT_commands`, `reset_GSM`, `all`, and “mini” variants
   - These sketches are the consumer layer that demonstrate how the library is used in real Arduino programs.
   - They also show the intended deployment matrix: different shield revisions and serial transport choices.

10. **Packaging and Arduino IDE integration**
   - `library.properties` makes this a proper Arduino library package.
   - `keywords.txt` supports Arduino IDE syntax highlighting and API discovery.
   - `License.txt` and the README/wiki links indicate the repo is distributed as a documented hardware support library, not as a service or backend system.

11. **Technologies and environment**
   - Runtime: **Arduino C++** on embedded microcontrollers.
   - External dependency: a **GSM/GPRS modem/shield** from iArduino.ru.
   - No web stack, server, or database is present; the architectural center is embedded serial device control.

12. **What an architecture diagram should emphasize**
   - Show the sketch/application as the caller.
   - Show `iarduino_GSM` as the hardware abstraction layer.
   - Show serial transport as the interface to the GSM shield.
   - Show the shield/modem as the stateful external device that implements SMS, calls, USSD, and AT command behavior.
   - Treat the examples and `extras/` as supporting material around the core library, not as runtime components.

Main entry points: [`src/iarduino_GSM.cpp`](https://github.com/tremaru/iarduino_gsm/blob/master/src/iarduino_GSM.cpp) (Core logic), [`src/iarduino_GSM.h`](https://github.com/tremaru/iarduino_gsm/blob/master/src/iarduino_GSM.h) (iarduino_GSM), [`examples/Shield_A6/HardwareSerial`](https://github.com/tremaru/iarduino_gsm/tree/master/examples/Shield_A6/HardwareSerial) (A6 HW), [`examples/Shield_A6/SoftwareSerial`](https://github.com/tremaru/iarduino_gsm/tree/master/examples/Shield_A6/SoftwareSerial) (A6 SW)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_core["Core library"]
  node_iarduino_gsm["iarduino_GSM<br/>[iarduino_GSM.h]"]
  node_gsm_core["Core logic<br/>C++ impl<br/>[iarduino_GSM.cpp]"]
  node_serial_port(("Serial port<br/>Arduino UART"))
  node_at_protocol["AT protocol<br/>command layer"]
  node_modem_shield["GSM shield<br/>device"]
  node_cell_network(("Cell network<br/>external network"))
  node_lifecycle{{"Lifecycle<br/>module control"}}
  node_sms_api{{"SMS<br/>feature area"}}
  node_call_api{{"Calls<br/>feature area"}}
  node_ussd_api{{"USSD<br/>feature area"}}
end

subgraph group_group_examples["Examples"]
  node_sketch_api["Sketch API<br/>Arduino sketch"]
  node_examples_a6_hw["A6 HW<br/>example set"]
  node_examples_a6_sw["A6 SW<br/>example set"]
  node_examples_a9_hw["A9 HW<br/>example set"]
  node_examples_a9_sw["A9 SW<br/>example set"]
  node_examples_gallery["Demo sketches<br/>example topics"]
end

subgraph group_group_support["Support files"]
  node_pdu_docs["PDU notes<br/>docs<br/>[PDU.txt]"]
  node_packaging["Arduino package<br/>metadata"]
end

node_sketch_api -->|"uses"| node_iarduino_gsm
node_iarduino_gsm -->|"implements"| node_gsm_core
node_gsm_core -->|"reads/writes"| node_serial_port
node_gsm_core -->|"formats"| node_at_protocol
node_at_protocol -->|"controls"| node_modem_shield
node_modem_shield -->|"connects"| node_cell_network
node_gsm_core -->|"manages"| node_lifecycle
node_gsm_core -->|"manages"| node_sms_api
node_gsm_core -->|"manages"| node_call_api
node_gsm_core -->|"manages"| node_ussd_api
node_examples_a6_hw -->|"contains"| node_examples_gallery
node_examples_a6_sw -->|"contains"| node_examples_gallery
node_examples_a9_hw -->|"contains"| node_examples_gallery
node_examples_a9_sw -->|"contains"| node_examples_gallery
node_examples_gallery -->|"demonstrates"| node_sketch_api
node_pdu_docs -.->|"documents"| node_sms_api
node_packaging -.->|"packages"| node_iarduino_gsm

click node_iarduino_gsm "https://github.com/tremaru/iarduino_gsm/blob/master/src/iarduino_GSM.h"
click node_gsm_core "https://github.com/tremaru/iarduino_gsm/blob/master/src/iarduino_GSM.cpp"
click node_examples_a6_hw "https://github.com/tremaru/iarduino_gsm/tree/master/examples/Shield_A6/HardwareSerial"
click node_examples_a6_sw "https://github.com/tremaru/iarduino_gsm/tree/master/examples/Shield_A6/SoftwareSerial"
click node_examples_a9_hw "https://github.com/tremaru/iarduino_gsm/tree/master/examples/Shield_A9/HardwareSerial"
click node_examples_a9_sw "https://github.com/tremaru/iarduino_gsm/tree/master/examples/Shield_A9/SoftwareSerial"
click node_pdu_docs "https://github.com/tremaru/iarduino_gsm/blob/master/extras/PDU.txt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_iarduino_gsm,node_gsm_core,node_serial_port,node_at_protocol,node_modem_shield,node_cell_network,node_lifecycle,node_sms_api,node_call_api,node_ussd_api toneBlue
class node_sketch_api,node_examples_a6_hw,node_examples_a6_sw,node_examples_a9_hw,node_examples_a9_sw,node_examples_gallery toneAmber
class node_pdu_docs,node_packaging toneMint
```

## Components

### Core library

Reusable Arduino C++ layer that abstracts GSM modem control.

- [iarduino_GSM](https://github.com/tremaru/iarduino_gsm/blob/master/src/iarduino_GSM.h): library · Main Arduino GSM/GPRS shield abstraction and public API. · `src/iarduino_GSM.h`
- [Core logic](https://github.com/tremaru/iarduino_gsm/blob/master/src/iarduino_GSM.cpp): C++ impl · Implements AT command formatting, parsing, and modem state management. · `src/iarduino_GSM.cpp`
- **Serial port**: Arduino UART · HardwareSerial or SoftwareSerial transport passed into the library.
- **AT protocol**: command layer · Text command/response interface used to control the modem.
- **GSM shield**: device · External iArduino GSM/GPRS modem that executes SMS, call, USSD, and audio features.
- **Cell network**: external network · Carrier network reached by the shield for messaging and calls.
- **Lifecycle**: module control · Startup, power, reset, PIN, and PUK handling.
- **SMS**: feature area · Send/read messages, storage queries, and text coding controls.
- **Calls**: feature area · Incoming/outgoing call handling and audio state control.
- **USSD**: feature area · Balance and other short code request/response operations.

### Examples

Sketches that demonstrate library usage across shield variants and serial transports.

- **Sketch API**: Arduino sketch · User code that calls the library from a microcontroller program.
- [A6 HW](https://github.com/tremaru/iarduino_gsm/tree/master/examples/Shield_A6/HardwareSerial): example set · HardwareSerial examples for the A6 shield variant. · `examples/Shield_A6/HardwareSerial`
- [A6 SW](https://github.com/tremaru/iarduino_gsm/tree/master/examples/Shield_A6/SoftwareSerial): example set · SoftwareSerial examples for the A6 shield variant. · `examples/Shield_A6/SoftwareSerial`
- [A9 HW](https://github.com/tremaru/iarduino_gsm/tree/master/examples/Shield_A9/HardwareSerial): example set · HardwareSerial examples for the A9 shield variant. · `examples/Shield_A9/HardwareSerial`
- [A9 SW](https://github.com/tremaru/iarduino_gsm/tree/master/examples/Shield_A9/SoftwareSerial): example set · SoftwareSerial examples for the A9 shield variant. · `examples/Shield_A9/SoftwareSerial`
- **Demo sketches**: example topics · Begin, SMS, call, AT command, reset, balance, and all-in-one demonstrations.

### Support files

Documentation and Arduino packaging metadata.

- [PDU notes](https://github.com/tremaru/iarduino_gsm/blob/master/extras/PDU.txt): docs · SMS PDU format notes and encoding reference. · `extras/PDU.txt`
- **Arduino package**: metadata · library.properties and keywords.txt for IDE integration.

## Connections

- Sketch API → iarduino_GSM: uses · Sketches call the public API methods exposed by the library.
- iarduino_GSM → Core logic: implements · Header defines the interface; source file implements the behavior.
- Core logic → Serial port: reads/writes · Library sends commands and receives modem responses over UART.
- Core logic → AT protocol: formats · Core code builds and parses AT command text.
- AT protocol → GSM shield: controls · AT commands drive modem lifecycle and feature operations.
- GSM shield → Cell network: connects · The shield uses the cellular network for SMS and voice service.
- Core logic → Lifecycle: manages · Begin, power, reset, PIN, and PUK handling.
- Core logic → SMS: manages · SMS send/read and encoding support are handled in the modem layer.
- Core logic → Calls: manages · Call detection, dialing, answer, hangup, and audio controls.
- Core logic → USSD: manages · USSD requests are issued as a modem command path.
- A6 HW → Demo sketches: contains · HardwareSerial demos for the A6 shield variant.
- A6 SW → Demo sketches: contains · SoftwareSerial demos for the A6 shield variant.
- A9 HW → Demo sketches: contains · HardwareSerial demos for the A9 shield variant.
- A9 SW → Demo sketches: contains · SoftwareSerial demos for the A9 shield variant.
- Demo sketches → Sketch API: demonstrates · Example sketches show how to call the library from Arduino programs.
- PDU notes → SMS: documents · PDU notes support SMS transport and encoding behavior.
- Arduino package → iarduino_GSM: packages · Arduino library metadata and IDE keyword support wrap the core library.
