Skip to content

Commit

Permalink
feat: WiFi and MQTT AT frontend, bug fixes
Browse files Browse the repository at this point in the history
* feat: network & mqtt frontend, bug fixes

* refactor: make misc functions visable in global namespace

* refactor: rename transport to serial

* refactor: mux transport (not use inheritance since init() is already declared in base), cleanup

* feat: automated versioning

* chore: cleanup

* fix: avoid fallthrough in switch after failure
  • Loading branch information
iChizer0 authored Nov 9, 2023
1 parent f901379 commit df759cb
Show file tree
Hide file tree
Showing 24 changed files with 642 additions and 92 deletions.
2 changes: 1 addition & 1 deletion core/data/el_data_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static inline constexpr el_storage_kv_t<ValueType> el_make_storage_kv(const char

using namespace edgelab::utility;

static inline uint32_t djb2_hash(const uint8_t* bytes) {
static constexpr inline uint32_t djb2_hash(const uint8_t* bytes) {
uint32_t hash = 0x1505;
uint8_t byte{};
while ((byte = *bytes++)) hash = ((hash << 5) + hash) + byte;
Expand Down
3 changes: 2 additions & 1 deletion core/el_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
#include "el_config_internal.h"
#include "el_debug.h"
#include "el_types.h"
#include "el_version.h"
#include "porting/el_misc.h"

#define EL_VERSION __TIMESTAMP__
#define EL_VERSION __EL_VERSION__
#define EL_VERSION_LENTH_MAX 32

#define EL_CONCAT(a, b) a##b
Expand Down
2 changes: 1 addition & 1 deletion core/el_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
#define EL_LOGI(...)
#endif
#if CONFIG_EL_DEBUG >= 4
#define LOG_D(...) \
#define EL_LOGD(...) \
do { \
el_printf(EL_DEBUG_COLOR_GREEN "V "); \
EL_DEBUG_MORE_INFO(); \
Expand Down
70 changes: 70 additions & 0 deletions core/el_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 nullptr, Seeed Technology Co.,Ltd
*
* 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.
*
*/

#ifndef _EL_VERSION_H_
#define _EL_VERSION_H_

#include <cstdint>

namespace edgelab {

namespace constants {

constexpr static uint16_t YEAR =
(__DATE__[7] - '0') * 1000 + (__DATE__[8] - '0') * 100 + (__DATE__[9] - '0') * 10 + (__DATE__[10] - '0');

constexpr static uint16_t MONTH = (__DATE__[0] == 'J') ? ((__DATE__[1] == 'a') ? 1 : ((__DATE__[2] == 'n') ? 6 : 7))
: (__DATE__[0] == 'F') ? 2
: (__DATE__[0] == 'M') ? ((__DATE__[2] == 'r') ? 3 : 5)
: (__DATE__[0] == 'A') ? ((__DATE__[2] == 'p') ? 4 : 8)
: (__DATE__[0] == 'S') ? 9
: (__DATE__[0] == 'O') ? 10
: (__DATE__[0] == 'N') ? 11
: (__DATE__[0] == 'D') ? 12
: 0;

constexpr static uint16_t DAY =
(__DATE__[4] == ' ') ? (__DATE__[5] - '0') : (__DATE__[4] - '0') * 10 + (__DATE__[5] - '0');

constexpr static char VERSION[]{'v',
YEAR / 1000 + '0',
(YEAR % 1000) / 100 + '0',
(YEAR % 100) / 10 + '0',
YEAR % 10 + '0',
'.',
MONTH / 10 + '0',
MONTH % 10 + '0',
'.',
DAY / 10 + '0',
DAY % 10 + '0',
'\0'};

} // namespace constants

} // namespace edgelab

constexpr static auto& __EL_VERSION__ = edgelab::constants::VERSION;

#endif
24 changes: 15 additions & 9 deletions porting/el_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class Device {
uint32_t get_device_id() const { return _device_id; }
uint32_t get_chip_revision_id() const { return _revision_id; }

Camera* get_camera() { return _camera; }
Display* get_display() { return _display; }
Transport* get_transport() { return _transport; }
Network* get_network() { return _network; }
Camera* get_camera() { return _camera; }
Display* get_display() { return _display; }
Serial* get_serial() { return _serial; }
Network* get_network() { return _network; }

el_sensor_info_t get_sensor_info(uint8_t id) const {
auto it = std::find_if(_registered_sensors.begin(), _registered_sensors.end(), [&](const el_sensor_info_t& s) {
Expand Down Expand Up @@ -102,16 +102,22 @@ class Device {

protected:
Device()
: _device_name(""), _device_id(0), _revision_id(0), _camera(nullptr), _display(nullptr), _transport(nullptr), _network{nullptr} {}
: _device_name(""),
_device_id(0),
_revision_id(0),
_camera(nullptr),
_display(nullptr),
_serial(nullptr),
_network{nullptr} {}

const char* _device_name;
uint32_t _device_id;
uint32_t _revision_id;

Camera* _camera;
Display* _display;
Transport* _transport;
Network* _network;
Camera* _camera;
Display* _display;
Serial* _serial;
Network* _network;

std::forward_list<el_sensor_info_t> _registered_sensors;
};
Expand Down
2 changes: 0 additions & 2 deletions porting/el_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#endif

#ifdef __cplusplus
namespace edgelab {
extern "C" {
#endif

Expand Down Expand Up @@ -65,7 +64,6 @@ void el_status_led(bool on);

#ifdef __cplusplus
}
}
#endif

#endif
4 changes: 2 additions & 2 deletions porting/espressif/el_device_esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ void DeviceEsp::init() {
static DisplayEsp display{};
this->_display = &display;

static SerialEsp transport{
static SerialEsp serial{
usb_serial_jtag_driver_config_t{.tx_buffer_size = 8192, .rx_buffer_size = 8192}
};
this->_transport = &transport;
this->_serial = &serial;

static NetworkEsp network{};
this->_network = &network;
Expand Down
4 changes: 0 additions & 4 deletions porting/espressif/el_misc_esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include "el_config_porting.h"
#include "porting/el_misc.h"

namespace edgelab {

EL_ATTR_WEAK void el_sleep(uint32_t ms) { vTaskDelay(ms / portTICK_PERIOD_MS); }

EL_ATTR_WEAK uint64_t el_get_time_ms(void) { return (uint64_t)esp_timer_get_time() / 1000; }
Expand Down Expand Up @@ -73,5 +71,3 @@ EL_ATTR_WEAK void el_status_led(bool on) {
gpio_set_direction(LED_0_PIN, GPIO_MODE_OUTPUT);
gpio_set_level(LED_0_PIN, on ? 0 : 1);
}

} // namespace edgelab
4 changes: 2 additions & 2 deletions porting/himax/we1/el_device_we1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ void DeviceWE1::init() {
this->_registered_sensors.emplace_front(el_sensor_info_t{
.id = ++sensor_id, .type = el_sensor_type_t::EL_SENSOR_TYPE_CAM, .state = el_sensor_state_t::EL_SENSOR_STA_REG});

static SerialWE1 transport{};
this->_transport = &transport;
static SerialWE1 serial{};
this->_serial = &serial;
}

void DeviceWE1::restart() {
Expand Down
4 changes: 0 additions & 4 deletions porting/himax/we1/el_misc_we1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ extern "C" {
#include "el_config_porting.h"
#include "porting/el_misc.h"

namespace edgelab {

EL_ATTR_WEAK void el_sleep(uint32_t ms) { board_delay_cycle(ms * 400000); }

EL_ATTR_WEAK uint64_t el_get_time_ms(void) { return (uint64_t)board_get_cur_us() / 1000; }
Expand Down Expand Up @@ -71,5 +69,3 @@ EL_ATTR_WEAK void el_free(void* ptr) { free(ptr); }
EL_ATTR_WEAK void el_reset(void) { exit(0); }

EL_ATTR_WEAK void el_status_led(bool on) { EMBARC_PRINTF("TEST LED STAT: %s", on ? "on" : "off"); }

} // namespace edgelab
4 changes: 2 additions & 2 deletions porting/himax/we2/el_device_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ void DeviceWE2::init() {
this->_registered_sensors.emplace_front(el_sensor_info_t{
.id = ++sensor_id, .type = el_sensor_type_t::EL_SENSOR_TYPE_CAM, .state = el_sensor_state_t::EL_SENSOR_STA_REG});

static SerialWE2 transport{};
this->_transport = &transport;
static SerialWE2 serial{};
this->_serial = &serial;

static NetworkWE2 network{};
this->_network = &network;
Expand Down
4 changes: 0 additions & 4 deletions porting/himax/we2/el_misc_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ extern "C" {
#include "el_config_porting.h"
#include "porting/el_misc.h"

namespace edgelab {

EL_ATTR_WEAK void el_sleep(uint32_t ms) {
#if CONFIG_EL_HAS_FREERTOS_SUPPORT
vTaskDelay(ms / portTICK_PERIOD_MS);
Expand Down Expand Up @@ -115,8 +113,6 @@ EL_ATTR_WEAK void el_reset(void) { exit(0); }

EL_ATTR_WEAK void el_status_led(bool on) { el_printf("TEST LED STAT: %s\n", on ? "on" : "off"); }

} // namespace edgelab

#if CONFIG_EL_HAS_FREERTOS_SUPPORT

EL_ATTR_WEAK void* operator new[](size_t size) { return pvPortMalloc(size); }
Expand Down
6 changes: 5 additions & 1 deletion sscma/callback/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#include <cstring>
#include <string>

#include "core/utils/el_hash.h"
#include "sscma/definations.hpp"
#include "sscma/static_resource.hpp"
#include "sscma/utility.hpp"

namespace sscma::callback {

using namespace edgelab;
using namespace sscma::utility;

void set_action(const std::vector<std::string>& argv) {
Expand Down Expand Up @@ -58,7 +60,9 @@ void set_action(const std::vector<std::string>& argv) {
if (static_resource->is_ready.load()) [[likely]] {
char action[CONFIG_SSCMA_CMD_MAX_LENGTH]{};
std::strncpy(
action, argv[1].c_str(), argv[1].length() < CONFIG_SSCMA_CMD_MAX_LENGTH ? argv[1].length() : CONFIG_SSCMA_CMD_MAX_LENGTH - 1);
action,
argv[1].c_str(),
argv[1].length() < CONFIG_SSCMA_CMD_MAX_LENGTH ? argv[1].length() : CONFIG_SSCMA_CMD_MAX_LENGTH - 1);
ret =
static_resource->storage->emplace(el_make_storage_kv(SSCMA_STORAGE_KEY_ACTION, action)) ? EL_OK : EL_EIO;
}
Expand Down
2 changes: 2 additions & 0 deletions sscma/callback/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
#include <atomic>
#include <string>

#include "core/el_version.h"
#include "sscma/definations.hpp"
#include "sscma/static_resource.hpp"
#include "sscma/utility.hpp"

namespace sscma::callback {

using namespace edgelab;
using namespace sscma::utility;

void print_help(const std::forward_list<repl_cmd_t>& cmd_list) {
Expand Down
2 changes: 2 additions & 0 deletions sscma/callback/info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
#include <cstring>
#include <string>

#include "core/utils/el_hash.h"
#include "sscma/definations.hpp"
#include "sscma/static_resource.hpp"
#include "sscma/utility.hpp"

namespace sscma::callback {

using namespace edgelab;
using namespace sscma::utility;

void set_info(const std::vector<std::string>& argv) {
Expand Down
12 changes: 8 additions & 4 deletions sscma/callback/invoke.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,28 +153,32 @@ class Invoke final : public std::enable_shared_from_this<Invoke> {
register_config_cmds(algorithm);
direct_reply(algorithm_config_2_json_str(algorithm));
if (is_everything_ok()) [[likely]]
return event_loop_cam(algorithm);
event_loop_cam(algorithm);
return;
}
case EL_ALGO_TYPE_PFLD: {
auto algorithm{std::make_shared<AlgorithmFOMO>(static_resource->engine)};
register_config_cmds(algorithm);
direct_reply(algorithm_config_2_json_str(algorithm));
if (is_everything_ok()) [[likely]]
return event_loop_cam(algorithm);
event_loop_cam(algorithm);
return;
}
case EL_ALGO_TYPE_YOLO: {
auto algorithm{std::make_shared<AlgorithmYOLO>(static_resource->engine)};
register_config_cmds(algorithm);
direct_reply(algorithm_config_2_json_str(algorithm));
if (is_everything_ok()) [[likely]]
return event_loop_cam(algorithm);
event_loop_cam(algorithm);
return;
}
case EL_ALGO_TYPE_IMCLS: {
auto algorithm{std::make_shared<AlgorithmFOMO>(static_resource->engine)};
register_config_cmds(algorithm);
direct_reply(algorithm_config_2_json_str(algorithm));
if (is_everything_ok()) [[likely]]
return event_loop_cam(algorithm);
event_loop_cam(algorithm);
return;
}
default:
_ret = EL_ENOTSUP;
Expand Down
Loading

0 comments on commit df759cb

Please sign in to comment.