C++ conversions (#111)

* Remove version from artifact name
* Target C++ 20 and higher
* Use cpp string
* Better crash implementation
* String utils in cpp style
* Replace parameter methods with start() method
* MutexType to Mutex::Type
* Kernel c to cpp style
* Cleanup event flag
* More cpp conversions
* Test fixes
* Updated ideas docs
This commit is contained in:
Ken Van Hoeylandt
2024-12-07 12:24:28 +01:00
committed by GitHub
parent d52fe52d96
commit 42e843b463
66 changed files with 272 additions and 258 deletions
@@ -1,5 +1,6 @@
#pragma once
#include "TactilityCore.h"
#include "hal/Configuration.h"
#include "TactilityHeadlessConfig.h"
#include "Dispatcher.h"
+1 -3
View File
@@ -3,10 +3,8 @@
/**
* This code is based on i2c_manager from https://github.com/ropg/i2c_manager/blob/master/i2c_manager/i2c_manager.c (original has MIT license)
*/
#include <Kernel.h>
#include "TactilityCore.h"
#include "I2c.h"
#include "Log.h"
#include "Mutex.h"
namespace tt::hal::i2c {
@@ -7,7 +7,7 @@ namespace tt::hal::sdcard {
#define TAG "sdcard"
static Mutex mutex(MutexTypeRecursive);
static Mutex mutex(Mutex::TypeRecursive);
typedef struct {
const SdCard* sdcard;
@@ -17,8 +17,8 @@ typedef std::unordered_map<std::string, ServiceInstance*> ServiceInstanceMap;
static ManifestMap service_manifest_map;
static ServiceInstanceMap service_instance_map;
static Mutex manifest_mutex(MutexTypeNormal);
static Mutex instance_mutex(MutexTypeNormal);
static Mutex manifest_mutex(Mutex::TypeNormal);
static Mutex instance_mutex(Mutex::TypeNormal);
void addService(const ServiceManifest* manifest) {
TT_LOG_I(TAG, "Adding %s", manifest->id.c_str());
@@ -42,7 +42,7 @@ static void onUpdate(std::shared_ptr<void> context) {
if (new_state == hal::sdcard::StateError) {
TT_LOG_W(TAG, "Sdcard error - unmounting. Did you eject the card in an unsafe manner?");
hal::sdcard::unmount(ms_to_ticks(1000));
hal::sdcard::unmount(kernel::millisToTicks(1000));
}
if (new_state != data->lastState) {
@@ -2,15 +2,10 @@
#include "Wifi.h"
#include "MessageQueue.h"
#include "Mutex.h"
#include "Check.h"
#include "Log.h"
#include "TactilityHeadless.h"
#include "Timer.h"
#include "service/ServiceContext.h"
#include "WifiSettings.h"
#include "TactilityCore.h"
#include "TactilityHeadless.h"
#include "freertos/FreeRTOS.h"
@@ -47,8 +42,8 @@ private:
public:
/** @brief Locking mechanism for modifying the Wifi instance */
Mutex radioMutex = Mutex(MutexTypeRecursive);
Mutex dataMutex = Mutex(MutexTypeRecursive);
Mutex radioMutex = Mutex(Mutex::TypeRecursive);
Mutex dataMutex = Mutex(Mutex::TypeRecursive);
std::unique_ptr<Timer> autoConnectTimer;
/** @brief The public event bus */
std::shared_ptr<PubSub> pubsub = std::make_shared<PubSub>();
@@ -664,7 +659,7 @@ static void dispatchScan(std::shared_ptr<void> context) {
}
// TODO: Thread safety
wifi->last_scan_time = tt::get_ticks();
wifi->last_scan_time = tt::kernel::getTicks();
if (esp_wifi_scan_start(nullptr, false) != ESP_OK) {
TT_LOG_I(TAG, "Can't start scan");
@@ -872,7 +867,7 @@ static bool shouldScanForAutoConnect(std::shared_ptr<Wifi> wifi) {
return false;
}
TickType_t current_time = tt::get_ticks();
TickType_t current_time = tt::kernel::getTicks();
bool scan_time_has_looped = (current_time < wifi->last_scan_time);
bool no_recent_scan = (current_time - wifi->last_scan_time) > (AUTO_SCAN_INTERVAL / portTICK_PERIOD_MS);
@@ -49,7 +49,7 @@ static void publish_event_simple(Wifi* wifi, WifiEventType type) {
static Wifi* wifi_alloc() {
auto* instance = static_cast<Wifi*>(malloc(sizeof(Wifi)));
instance->mutex = tt_mutex_alloc(MutexTypeRecursive);
instance->mutex = tt_mutex_alloc(Mutex::TypeRecursive);
instance->pubsub = std::make_shared<PubSub>();
instance->scan_active = false;
instance->radio_state = WIFI_RADIO_CONNECTION_ACTIVE;
@@ -54,7 +54,7 @@ bool load(const char* ssid, WifiApSettings* settings) {
result = nvs_get_blob(handle, ssid, &encrypted_settings, &length);
uint8_t iv[16];
crypt::get_iv_from_string(ssid, iv);
crypt::getIv(ssid, strlen(ssid), iv);
int decrypt_result = crypt::decrypt(
iv,
(uint8_t*)encrypted_settings.password,
@@ -97,7 +97,7 @@ bool save(const WifiApSettings* settings) {
encrypted_settings.password[TT_WIFI_CREDENTIALS_PASSWORD_LIMIT] = 0;
uint8_t iv[16];
crypt::get_iv_from_data(settings->ssid, strlen(settings->ssid), iv);
crypt::getIv(settings->ssid, strlen(settings->ssid), iv);
int encrypt_result = crypt::encrypt(
iv,
(uint8_t*)settings->password,