Skip to content

Commit

Permalink
Added some doc files. MUST review navigation links and file formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkBrines committed Oct 16, 2024
1 parent 95468c2 commit da5fa06
Show file tree
Hide file tree
Showing 6 changed files with 1,156 additions and 0 deletions.
117 changes: 117 additions & 0 deletions docs/modules/gsm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# GSM module

This document details the implementation of the GSM module within the PaxOS operating system. The module handles communication with a GSM/GPRS modem, enabling functionalities like sending/receiving SMS messages, making/receiving calls, and managing MMS.

## 1. `contacts.cpp` / `contacts.hpp`

This module manages contact information. Contacts are stored in a JSON file (`/apps/contacts/list.json`) and loaded into memory for quick access.

### Data Structures

* **`Contacts::contact`:** Represents a single contact with `name` (std::string) and `phone` (std::string) fields.

### Functions

* **`Contacts::load()`:** Loads contacts from the `list.json` file into the `contactList` vector. Handles JSON parsing errors.
* **`Contacts::save()`:** Saves the `contactList` to the `list.json` file in JSON format.
* **`Contacts::listContacts()`:** Returns a copy of the `contactList`.
* **`Contacts::addContact(contact c)`:** Adds a new contact to the `contactList`.
* **`Contacts::deleteContact(std::string name)`:** Deletes a contact with the given name from the `contactList`.
* **`Contacts::editContact(std::string name, contact c)`:** Edits the contact with the given name, updating its information with the provided `contact` object.
* **`Contacts::getContact(std::string name)`:** Returns the `contact` object associated with the given name. Returns an empty contact if not found.
* **`Contacts::getByNumber(std::string number)`:** Returns the `contact` object associated with the given phone number. Returns an empty contact if not found.


## 2. `conversation.cpp` / `conversation.hpp`

This module handles conversation data, including loading and saving messages for each conversation.

### Data Structures

* **`Conversations::Message`:** Represents a single message with `message` (std::string), `who` (bool indicating sender - false for self, true for other), and `date` (std::string) fields.
* **`Conversations::Conversation`:** Represents a conversation with a specific `number` (std::string) and a vector of `messages` (std::vector<Message>).

### Functions

* **`Conversations::loadConversation(const storage::Path &filePath, Conversation &conv)`:** Loads a conversation from the specified JSON file. Handles file errors and JSON parsing exceptions.
* **`Conversations::saveConversation(const storage::Path &filePath, const Conversation &conv)`:** Saves a conversation to the specified JSON file. Limits the number of saved messages to `MAX_MESSAGES` (40), keeping the most recent ones. Creates the necessary directories if they don't exist.


## 3. `gsm.cpp` / `gsm.hpp`

This module provides the core GSM functionality, interacting directly with the GSM modem. It manages calls, SMS, MMS, network status, and battery level.

### Constants

* `BAUDRATE`: Default baud rate for serial communication (921600).
* `MESSAGES_LOCATION`: Directory for storing message data (`apps/messages/data`).
* `MESSAGES_IMAGES_LOCATION`: Directory for storing MMS images (`apps/messages/images`).
* `MESSAGES_NOTIF_LOCATION`: File storing unread message notifications (`apps/messages/unread.txt`).
* `MAX_MESSAGES`: Maximum number of messages stored per conversation (40).

### Data Structures

* **`GSM::Request`:** Represents a request to be executed by the GSM module, with a `function` (std::function<void(void)>) and a `priority` (enum).
* **`GSM::Key`:** Represents a key string to watch for in the GSM modem's responses, with a `key` (std::string) and a `function` (std::function<void()>) to execute when the key is found.
* **`GSM::State`:** Represents the current state of the GSM module (call state, call failure, calling number).
* **`GSM::Message`:** Represents an SMS message, with `number`, `message`, and `date`.
* **`GSM::ExternalEvents`:** Namespace containing callback functions for incoming calls, new messages, and message errors.
* **`GSM::Stream::Chunk`:** Used for streaming MMS data; contains a data pointer and size. (ESP_PLATFORM only)

### Functions

* **`GSM::init()`:** Initializes the GSM modem, including setting baud rate and handling modem power-on (ESP_PLATFORM specific).
* **`GSM::reInit()`:** Re-initializes the serial communication after clock speed changes.
* **`GSM::download(uint64_t timeout = 50)`:** Reads data from the GSM modem's serial port with a timeout.
* **`GSM::send(const std::string &message, const std::string &answerKey, uint64_t timeout = 200)`:** Sends a command to the GSM modem and waits for a specific response key. Returns the modem's full response.
* **`GSM::appendRequest(Request request)`:** Adds a request to the queue of requests to be processed by the GSM module.
* **`GSM::process()`:** Processes received data, checking for key strings and executing associated functions.
* **`GSM::checkRequest()`:** Executes pending requests in the queue, prioritizing high-priority requests.
* **`GSM::onRinging()`:** Handles incoming call events, updating the module's state.
* **`GSM::onHangOff()`:** Handles call hang-up events.
* **`GSM::onMessage()`:** Handles incoming SMS/MMS messages. Decodes PDUs, saves messages to conversations, and triggers the `onNewMessage` callback.
* **`GSM::sendMessage(const std::string &number, const std::string &message)`:** Sends an SMS message. Saves the sent message to the conversation history.
* **`GSM::newMessage(std::string number, std::string message)`:** Queues a message to be sent.
* **`GSM::sendCall(const std::string &number)`:** Initiates a call to the specified number.
* **`GSM::newCall(std::string number)`:** Queues a call to be made.
* **`GSM::endCall()`:** Ends the current call.
* **`GSM::acceptCall()`:** Accepts an incoming call.
* **`GSM::rejectCall()`:** Rejects an incoming call.
* **`GSM::getVoltage()`:** Retrieves the battery voltage.
* **`GSM::getBatteryLevel()`:** Calculates and returns the battery level (0.0 - 1.0) based on voltage.
* **`GSM::updateHour()`:** Updates the current time from the GSM modem.
* **`GSM::getHour()`:** Queues a request to update the time.
* **`GSM::getNetworkStatus()`:** Returns the network signal quality.
* **`GSM::updateNetworkQuality()`:** Updates the network signal quality.
* **`GSM::getNetworkQuality()`:** Queues a request to update the network quality.
* **`GSM::isFlightMode()`:** Checks if flight mode is enabled.
* **`GSM::setFlightMode(bool mode)`:** Sets the flight mode.
* **`GSM::run()`:** Main loop of the GSM module. Handles initialization, request processing, and event handling.
* **`GSM::getHttpMMS(std::string number, std::string url)`:** Downloads and processes MMS messages (ESP_PLATFORM only).


## 4. `message.cpp` / `message.hpp`

Provides functions for loading and saving messages from/to JSON files. This module seems redundant given the similar functionality in `conversation.cpp/hpp`, and its usage isn't clear within the provided code.

### Data Structures

* **`Message::Message`:** Same structure as `Conversations::Message`.

### Functions

* **`Message::loadMessages(const std::string& filePath, std::vector<Message>& messages)`:** Loads messages from a JSON file.
* **`Message::saveMessages(const std::string& filePath, const std::vector<Message>& messages)`:** Saves messages to a JSON file.


## 5. `pdu.cpp` / `pdu.hpp`

This module handles the decoding of PDU-formatted messages received from the GSM modem.

### Data Structures

* **`PDU`:** Contains the decoded information from a PDU string: `sender` (std::string), `message` (std::string), `url` (std::string for MMS URLs), and `type` (enum PDU_type: SMS, MMS, UNKNOWN).

### Functions

* **`decodePDU(std::string pdu)`:** Decodes a PDU string and returns a `PDU` object containing the extracted information (sender, message, URL, type).
10 changes: 10 additions & 0 deletions docs/modules/gui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Module graphique

S'occupe de la gestion de l'affichage

Le module est séparé en deux parties:
- une partie pour la gestion des buffers, gestion de l'écran
- une partie pour la gestion de la hirarchie des widgets, leur rendu, l'algorithme de rendu...


La classe Widget représente la base de construction d'un widget
95 changes: 95 additions & 0 deletions docs/modules/storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Storage module

This document details the `storage` and `appFile` modules used within the Paxos project for file system interaction. The modules provide a platform-agnostic interface for file and directory manipulation, reading, and writing.

## 1. `storage` Module

This module provides the core file system functionalities.

### 1.1 `storage::Path` Class

Represents a file or directory path.

#### 1.1.1 Constructors

* `Path()`: Creates an empty path.
* `Path(const std::string& raw)`: Creates a path from a string, parsing and simplifying it.
* `Path(const Path& other)`: Copy constructor.

#### 1.1.2 Methods

* `join(const Path& other)`: Appends another path to this path.
* `join(const std::string& other)`: Appends a string representation of a path to this path.
* `operator/(const Path& other) const`: Returns a new path by joining this path with another.
* `operator/(const std::string& other) const`: Returns a new path by joining this path with a string representation of a path.
* `operator/=(const Path& other)`: Appends another path to this path (in-place).
* `operator/=(const std::string& other)`: Appends a string representation of a path to this path (in-place).
* `operator=(const Path& other)`: Assignment operator.
* `operator=(const std::string& other)`: Assigns a string representation of a path to this path.
* `operator==(const Path& other) const`: Equality operator.
* `assign(const Path& other)`: Assigns another path to this path.
* `assign(const std::string& other)`: Assigns a string representation of a path to this path.
* `clear()`: Clears the path.
* `str() const`: Returns the string representation of the path.
* `listdir(bool onlyDirs = false) const`: Returns a vector of filenames within the directory represented by this path. If `onlyDirs` is true, only directory names are returned.
* `exists() const`: Checks if the path exists.
* `isfile() const`: Checks if the path represents a file.
* `isdir() const`: Checks if the path represents a directory.
* `newfile() const`: Creates a new empty file at the specified path.
* `newdir() const`: Creates a new directory at the specified path.
* `remove() const`: Removes the file or directory at the specified path.
* `rename(const Path& to)`: Renames the file or directory at the specified path.

### 1.2 `storage::FileStream` Class

Provides an interface for reading and writing files.

#### 1.2.1 Constructors

* `FileStream()`: Creates an empty filestream.
* `FileStream(const std::string& path, Mode mode)`: Creates a filestream and opens the specified file with the given mode.

#### 1.2.2 Methods

* `open(const std::string& path, Mode mode)`: Opens the specified file with the given mode.
* `close()`: Closes the file.
* `read()`: Reads the entire file content into a string.
* `readline()`: Reads a single line from the file.
* `readword()`: Reads a single word from the file.
* `readchar()`: Reads a single character from the file.
* `write(const std::string& str)`: Writes a string to the file.
* `write(const char* str, std::size_t len)`: Writes a character array to the file.
* `write(const char c)`: Writes a single character to the file.
* `isopen() const`: Checks if the file is open.
* `size()`: Returns the size of the file.

#### 1.2.3 Operators

* `operator<<(FileStream& stream, const std::string& text)`: Writes a string to the filestream.
* `operator>>(FileStream& stream, std::string& buff)`: Reads a word from the filestream.

### 1.3 `storage::init()` function

Initializes the storage module (specifically for ESP32 platform). Returns `true` on success, `false` otherwise.

## 2. `appFile` Module

Provides higher-level file operations, including JSON parsing and saving.

### 2.1 Functions

* `load(std::string filename)`: Loads the content of a file into a string, handling path restrictions.
* `parse(std::string str)`: Parses a JSON string into a `nlohmann::json` object. Returns `NULL` on failure.
* `save(std::string filename, json jsonObj)`: Saves a `nlohmann::json` object to a file.


## 3. Notes

* The codebase is designed to be platform-agnostic, supporting both desktop (Linux, Windows, macOS) and embedded (ESP32) systems.
* The `PATH_LOCATION` macro defines the base directory for file operations.
* The `storage::init()` function should be called before any other `storage` functions on ESP32.
* Error handling is implemented for JSON parsing and SD card initialization. File operations generally rely on the underlying system's error handling.
* The `appFile` module provides a convenient way to work with JSON files, built upon the `storage` module's functionalities.


This documentation provides a comprehensive overview of the `storage` and `appFile` modules, enabling developers to understand and utilize their functionalities effectively within the Paxos project.
Loading

0 comments on commit da5fa06

Please sign in to comment.