Skip to content

Commit

Permalink
Merge pull request #4 from robsonos/dev
Browse files Browse the repository at this point in the history
Merge main into dev
  • Loading branch information
robsonos authored Jan 1, 2025
2 parents e69aa2f + 9e8d730 commit 68a714f
Show file tree
Hide file tree
Showing 10 changed files with 499 additions and 81 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Robson Oliveira dos Santos

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
179 changes: 179 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<p align="center">
<h3 align="center">SPIE firmware</h3>
</p>
<p align="center">
<img
alt="Maintenance status"
src="https://img.shields.io/maintenance/yes/2025?style=flat-square">
<a
href="https://github.com/robsonos/spie-firmware/actions/workflows/ci.yml"
style="color: inherit; text-decoration: none;">
<img
alt="GitHub Workflow Status (with event)"
src="https://img.shields.io/github/actions/workflow/status/robsonos/spie-firmware/ci.yml">
</a>
<a
href="LICENSE"
style="color: inherit; text-decoration: none;">
<img
alt="GitHub License"
src="https://img.shields.io/github/license/robsonos/spie-firmware">
</a>
<br />
<a
href="https://github.com/robsonos/spie-firmware/releases"
style="color: inherit; text-decoration: none;">
<img
alt="GitHub Release version"
src="https://img.shields.io/github/v/release/robsonos/spie-firmware">
</a>
<a
href="#contributors"
style="color: inherit; text-decoration: none;">
<img
alt="GitHub contributors from allcontributors.org"
src="https://img.shields.io/github/all-contributors/robsonos/spie-firmware">
</a>
</p>

This repository was initially created to test the features of [spie](https://github.com/robsonos/spie). However, it can be used to bootstrap your `PlatformIO` project with a modern embedded system workflow.
The firmware itself provides a simple implementation of an AT command interface for configuring a sine wave generator.

## Index

- [Features](#features)
- [Getting started](#getting-started)
- [Platformio tasks](#platformio-tasks)
- [AT commands](#at-commands)
- [CD/CI/Release workflow](#cdcirelease-workflow)
- [Troubleshooting](#troubleshooting)

## Features

<p align="center"><br><img src="./docs/demo-serial-plotter.gif" width="500"></p>
<p align="center"><br><img src="./docs/demo-spie-plotter.gif" width="500"></p>

- Configure sine wave generation in real-time using AT commands.
- Command validation and error handling for invalid inputs.
- Unit-tested with mocks using `ArduinoFake`.
- CI/CD workflows with proper versioning and release routines.

## Getting Started

### Steps

1. Clone the repository

```sh
git clone https://github.com/robsonos/spie-firmware
```

2. Open the repository with VSCode and install the recommended extensions

3. Familiarise yourself with [PlatformIO](https://platformio.org/)

[Back to Index](#index)

## Platformio tasks

- Build the code:

```sh
pio run -e uno
```

- Upload code:

```sh
pio run -e uno -t upload
```

- Run `cppcheck`:

```sh
pio check
```

- Run unit tests:

```sh
pio test
```

[Back to Index](#index)

## AT Commands

### Configuration Commands

Set or query configuration parameters using the following AT commands:

| Command | Description | Example | Response |
| ------------------------- | -------------------------------------------------------- | ---------------------- | --------------------- |
| `AT+NUMPHASES=<value>` | Sets the number of phases (positive integer). | `AT+NUMPHASES=3` | `OK` |
| `AT+NUMPHASES?` | Queries the current number of phases. | `AT+NUMPHASES?` | `+NUMPHASES: 3` |
| `AT+SIGNALFREQ=<value>` | Sets the signal frequency (positive integer). | `AT+SIGNALFREQ=50` | `OK` |
| `AT+SIGNALFREQ?` | Queries the current signal frequency. | `AT+SIGNALFREQ?` | `+SIGNALFREQ: 50` |
| `AT+SAMPLINGFREQ=<value>` | Sets the sampling frequency (positive integer). | `AT+SAMPLINGFREQ=1000` | `OK` |
| `AT+SAMPLINGFREQ?` | Queries the current sampling frequency. | `AT+SAMPLINGFREQ?` | `+SAMPLINGFREQ: 1000` |
| `AT+AMPLITUDE=<value>` | Sets the amplitude (zero or positive integer). | `AT+AMPLITUDE=2000` | `OK` |
| `AT+AMPLITUDE?` | Queries the current amplitude. | `AT+AMPLITUDE?` | `+AMPLITUDE: 2000` |
| `AT+OFFSET=<value>` | Sets the offset (integer between -10000 and 10000). | `AT+OFFSET=500` | `OK` |
| `AT+OFFSET?` | Queries the current offset. | `AT+OFFSET?` | `+OFFSET: 500` |
| `AT+ERRORPERCENT=<value>` | Sets the error percentage (float between 0.0 and 100.0). | `AT+ERRORPERCENT=5.5` | `OK` |
| `AT+ERRORPERCENT?` | Queries the current error percentage. | `AT+ERRORPERCENT?` | `+ERRORPERCENT: 5.5` |
| `AT+VERSION?` | Queries the current firmware version. | `AT+VERSION?` | `+VERSION: 1.0.0` |
| `AT+ALL?` | Queries all current configuration parameters. |

### Error Responses

If a command is invalid, the interface responds with a descriptive error message:

- `ERROR: Invalid AT command format.`
- `ERROR: Unknown command.`
- `ERROR: <parameter> must be <valid range>.`

[Back to Index](#index)

## CD/CI/Release workflow

There are many ways CD/CI/Release workflow can be implemented. I chose the most convenient one and here is how it is meant to work:

- `dev`: holds the development code. Pushes to this will trigger the `CI workflow`, test your code, and create a PR to merge it into `main`.
- `main`: holds the code for the latest release. Pushes to this will trigger the `CD workflow` and create a new github release and tag. You should never need to push commits to `main`; use `dev` and create a PR instead. The code on this branch should always come from merges from `dev`.
- Once a new release is done, the `Release` workflow will be triggered to build and add the binaries to the release.
- If you need to maintain more release channels, like `main` is at `v3.x.x` but you need to support `v1.x.x`, I would recommend using a similar approach:
- `main` for `v3.x.x`
- `main/v1` for `v1.x.x`
- `dev` for `v3.x.x` development
- `dev/v1` for `v1.x.x` development
- I may look into exemplifying the above and `pre-releases` in the feature

[Back to Index](#index)

## Troubleshooting

- You may need to update the following for unit testing the code:

```ini
[env:native]
platform = native; or windows_x86, or linux_x86_64 ...
...
```

For more information, check out [PlatformIO's Development Platforms](https://docs.platformio.org/en/latest/platforms/index.html#desktop)

[Back to Index](#index)

## Contributors

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

[Back to Index](#index)
Binary file added docs/demo-serial-plotter.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/demo-spie-plotter.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions lib/Context/Context.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#define FIRMWARE_VERSION "1.0.0" // INFO: line used by builder. Do not change it
#define VERSION "1.0.0" // INFO: line used by builder. Do not change it

#include <Arduino.h>

Expand Down Expand Up @@ -32,9 +32,9 @@ struct Context
Context() : config()
{
config = {
12, // numPhases
3, // numPhases
1, // signalFrequency
500, // samplingFrequency
50, // samplingFrequency
1000, // amplitude
0, // offset
0.0, // errorPercentage
Expand Down
Loading

0 comments on commit 68a714f

Please sign in to comment.