Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ronny-antoon committed Nov 6, 2023
0 parents commit 16e0b1d
Show file tree
Hide file tree
Showing 32 changed files with 2,400 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
38 changes: 38 additions & 0 deletions .github/workflows/build-and-test-embeded.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build and test embeded

on:
workflow_dispatch:
push:

jobs:
build-and-test-embeded:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio

- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install PlatformIO Core
run: pip install --upgrade platformio

- name: Build PlatformIO Project
run: pio run -e embeded_env

- name: Test Embeded
uses: wokwi/wokwi-ci-action@v1
with:
token: ${{ secrets.WOKWI_CLI_TOKEN }}
timeout: 180000
fail_text: FAILED
scenario: 'senario.test.yaml'

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.pio
.vscode
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) 2023 ronny-antoon

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.
38 changes: 38 additions & 0 deletions boards/myboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"build": {
"arduino":{
"ldscript": "esp32_out.ld"
},
"core": "esp32",
"extra_flags": "-DARDUINO_ESP32_DEV",
"f_cpu": "240000000L",
"f_flash": "40000000L",
"flash_mode": "dio",
"mcu": "esp32",
"variant": "doitESP32devkitV1"
},
"connectivity": [
"wifi",
"bluetooth",
"ethernet",
"can"
],
"debug": {
"openocd_board": "esp-wroom-32.cfg"
},
"frameworks": [
"arduino",
"espidf"
],
"name": "DOIT ESP32 DEVKIT V1",
"upload": {
"flash_size": "16MB",
"maximum_ram_size": 327680,
"maximum_size": 16777216,
"require_upload_port": true,
"speed": 460800
},
"url": "http://www.doit.am/",
"vendor": "DOIT"
}

1 change: 1 addition & 0 deletions boards/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### myboard.json file is for platformio partitions
8 changes: 8 additions & 0 deletions diagram.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 1,
"author": "Ronny Antoon",
"editor": "wokwi",
"parts": [ { "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 0, "left": 0, "attrs": {"flashSize":"16"} } ],
"connections": [ [ "esp:TX", "$serialMonitor:RX", "", [] ], [ "esp:RX", "$serialMonitor:TX", "", [] ] ],
"dependencies": {}
}
24 changes: 24 additions & 0 deletions flasher_args.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"write_flash_args" : [ "--flash_mode", "dio",
"--flash_size", "16MB",
"--flash_freq", "40m" ],
"flash_settings" : {
"flash_mode": "dio",
"flash_size": "16MB",
"flash_freq": "40m"
},
"flash_files" : {
"0x1000" : ".pio/build/embeded_env/bootloader.bin",
"0x10000" : ".pio/build/embeded_env/firmware.bin",
"0x8000" : ".pio/build/embeded_env/partitions.bin"
},
"bootloader" : { "offset" : "0x1000", "file" : ".pio/build/embeded_env/bootloader.bin", "encrypted" : "false" },
"app" : { "offset" : "0x10000", "file" : ".pio/build/embeded_env/firmware.bin", "encrypted" : "false" },
"partition-table" : { "offset" : "0x8000", "file" : ".pio/build/embeded_env/partitions.bin", "encrypted" : "false" },
"extra_esptool_args" : {
"after" : "hard_reset",
"before" : "default_reset",
"stub" : true,
"chip" : "esp32"
}
}
149 changes: 149 additions & 0 deletions include/Downloader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#ifndef DOWNLOADER_HPP
#define DOWNLOADER_HPP

/**
* @file Downloader.hpp
* @brief Defines a class for downloading files from a URL using HTTP(S) protocol.
* The class implements the DownloaderInterface interface.
* The class uses the ESP32 WiFiClient and HTTPClient libraries.
* @author Ronny Antoon
*/

#include <WiFiClient.h> // WiFiClient
#include <HTTPClient.h> // HTTPClient
#include <Stream.h> // Stream

#include "DownloaderInterface.hpp"

/**
* @brief The Downloader class implements the DownloaderInterface interface.
*/
class Downloader : public DownloaderInterface
{
public:
/**
* @brief Construct a new Downloader object
*/
Downloader();

/**
* @brief Destroy the Downloader object
*/
~Downloader() override;

/**
* @brief Downloads a file from the specified URL.
*
* @return DOWNLOADER_ERROR indicating the success or failure of the download.
* Possible values:
* - DOWNLOADER_ERROR::OK: Download succeeded.
* - DOWNLOADER_ERROR::NO_URL_PROVIDED: URL for bin file is empty.
* - DOWNLOADER_ERROR::DOWNLOAD_FAILED: Download failed.
* - DOWNLOADER_ERROR::SERVER_ERROR: Server error.
* - DOWNLOADER_ERROR::UNKNOWN: Unknown error.
*/
DOWNLOADER_ERROR download() override;

/**
* @brief Retrieves the version information and stores it in the provided buffer.
*
* @param versionDis Pointer to the buffer where version information will be stored.
* @param maxLen Maximum length of the version information buffer.
* @return DOWNLOADER_ERROR indicating the success or failure of the operation.
* Possible values:
* - DOWNLOADER_ERROR::OK: Version information retrieved successfully.
* - DOWNLOADER_ERROR::NO_URL_PROVIDED: URL for version file is empty.
* - DOWNLOADER_ERROR::INVALID_ARGUMENT: Invalid argument provided.
* - DOWNLOADER_ERROR::DOWNLOAD_FAILED: Download of version information failed.
* - DOWNLOADER_ERROR::SERVER_ERROR: Server error.
* - DOWNLOADER_ERROR::UNKNOWN: Unknown error.
*/
DOWNLOADER_ERROR getVersion(char *versionDis, int maxLen) override;

/**
* @brief Sets the CA (Certificate Authority) certificate for secure connections.
*
* @param cACertificate The CA certificate to be set.
* @return DOWNLOADER_ERROR indicating the success or failure of the operation.
* Possible values:
* - DOWNLOADER_ERROR::OK: CA certificate set successfully.
* - DOWNLOADER_ERROR::INVALID_ARGUMENT: Invalid argument provided.
*/
DOWNLOADER_ERROR setCA(const char *cACertificate) override;

/**
* @brief Sets the URL for the binary file to be downloaded.
*
* @param uRLForBinFile The URL of the binary file to be downloaded.
* @return DOWNLOADER_ERROR indicating the success or failure of the operation.
* Possible values:
* - DOWNLOADER_ERROR::OK: URL for binary file set successfully.
* - DOWNLOADER_ERROR::INVALID_ARGUMENT: Invalid argument provided.
*/
DOWNLOADER_ERROR setURLForBin(const char *uRLForBinFile) override;

/**
* @brief Sets the URL for the version information file.
*
* @param uRLForVersionFile The URL of the version information file.
* @return DOWNLOADER_ERROR indicating the success or failure of the operation.
* Possible values:
* - DOWNLOADER_ERROR::OK: URL for version file set successfully.
* - DOWNLOADER_ERROR::INVALID_ARGUMENT: Invalid argument provided.
*/
DOWNLOADER_ERROR setURLForVersion(const char *uRLForVersionFile) override;

/**
* @brief Sets the timeout for the download operation.
*
* @param timeOut The timeout value in milliseconds.
* @return DOWNLOADER_ERROR indicating the success or failure of the operation.
* Possible values:
* - DOWNLOADER_ERROR::OK: Timeout registered successfully.
* - DOWNLOADER_ERROR::INVALID_ARGUMENT: Timeout value is out of range.
*/
DOWNLOADER_ERROR setTimeout(uint16_t timeOut) override;

/**
* @brief Returns a pointer to the stream for downloading data.
*
* @return A pointer to the stream for downloading data.
*/
Stream *getStreamPtr() override;

/**
* @brief Gets the size of the downloaded stream.
*
* @return The size of the downloaded stream.
*/
int getStreamSize() override;

private:
char _cACertificate[CA_MAX_LENGTH + 1]; // CA certificate
char _uRLForBinFile[URL_MAX_LENGTH + 1]; // URL for the binary file
char _uRLForVersionFile[URL_MAX_LENGTH + 1]; // URL for the version information file
uint16_t _timeOut; // Timeout for the download operation
WiFiClient *_wifiClient; // WiFi client
HTTPClient *_httpClient; // HTTP client
int _streamSize; // Size of the downloaded stream

/**
* @brief Creates a WiFi client with or without SSL, depending on the presence of a CA certificate.
*/
void CreateWifiClient();

/**
* @brief Creates an HTTP client and initializes it with the provided URL.
*
* @param url The URL to initialize the HTTP client with.
* @return DOWNLOADER_ERROR indicating the success or failure of HTTP client creation.
* Possible values:
* - DOWNLOADER_ERROR::OK: HTTP client created successfully.
* - DOWNLOADER_ERROR::UNKNOWN: HTTP client creation failed.
*/
DOWNLOADER_ERROR CreateHttpClient(const char *url);

const char *TAG = "Downloader"; // Tag for logging
};

#endif // DOWNLOADER_HPP
Loading

0 comments on commit 16e0b1d

Please sign in to comment.