software and system v1

This commit is contained in:
2026-02-02 00:49:50 +01:00
parent 9c5082cd9e
commit a23dbf0828
21 changed files with 4400 additions and 137 deletions

View File

@@ -0,0 +1,119 @@
# Message Formatter Component (CBOR)
## ASF Sensor Hub (Sub-Hub) Embedded System
**Component ID:** C-MSG-FMT-001
**Version:** 1.0
**Date:** 2025-02-01
**Location:** `application_layer/utils/message_formatter/`
**Encoding:** CBOR (RFC 8949)
---
## 1. Component Overview
The Message Formatter provides CBOR (Concise Binary Object Representation) encoding and decoding for MQTT message payloads. This component ensures efficient, compact message encoding for network communication.
**Primary Purpose:** Encode/decode MQTT messages using CBOR format.
---
## 2. Responsibilities
### 2.1 In-Scope
- CBOR encoding of sensor data
- CBOR encoding of diagnostic events
- CBOR encoding of system status
- CBOR encoding of commands
- CBOR decoding of received messages
- Message format validation
- Version compatibility checking
### 2.2 Out-of-Scope
- MQTT protocol handling (handled by Network Stack)
- Message routing (handled by Communication Manager)
---
## 3. Provided Interfaces
### 3.1 Encoding Interface
```c
/**
* @brief Encode sensor data to CBOR
* @param sensor_data Sensor data structure
* @param buffer Output buffer
* @param buffer_size Buffer size
* @param encoded_len Output encoded length
* @return true on success
*/
bool msg_fmt_encode_sensor_data(const sensor_data_t* sensor_data,
uint8_t* buffer, size_t buffer_size,
size_t* encoded_len);
/**
* @brief Encode diagnostic event to CBOR
* @param diag_event Diagnostic event structure
* @param buffer Output buffer
* @param buffer_size Buffer size
* @param encoded_len Output encoded length
* @return true on success
*/
bool msg_fmt_encode_diagnostic(const diagnostic_event_t* diag_event,
uint8_t* buffer, size_t buffer_size,
size_t* encoded_len);
```
### 3.2 Decoding Interface
```c
/**
* @brief Decode CBOR message
* @param buffer Input CBOR buffer
* @param buffer_len Buffer length
* @param message_type Output message type
* @param message_data Output message data
* @return true on success
*/
bool msg_fmt_decode_message(const uint8_t* buffer, size_t buffer_len,
message_type_t* message_type, void* message_data);
```
---
## 4. CBOR Message Format
### 4.1 Message Structure
```c
{
"version": 1,
"type": "sensor_data" | "diagnostic" | "status" | "command",
"timestamp": <uint64>,
"device_id": <string>,
"data": <message-specific data>
}
```
### 4.2 Message Types
- **sensor_data:** Sensor readings
- **diagnostic:** Diagnostic events
- **status:** System status
- **command:** Commands from Main Hub
---
## 5. Traceability
### 5.1 Software Requirements
- **SWR-COM-012:** CBOR encoding for MQTT payloads
- **SWR-COM-002:** CBOR-encoded sensor data transmission
---
**Document Status:** Complete
**Next Review:** Before implementation