Skip to content

Commit

Permalink
feat: separate idf and mongoose implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsan committed Oct 13, 2023
1 parent 5d093bc commit bc57f4f
Show file tree
Hide file tree
Showing 29 changed files with 2,138 additions and 43 deletions.
24 changes: 24 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@
""
],
"configurationProvider": "ms-vscode.cmake-tools"
},
{
"name": "ESP-IDF",
"compilerPath": "C:\\Users\\BINAR\\.espressif\\tools\\xtensa-esp32-elf\\esp-12.2.0_20230208\\xtensa-esp32-elf\\bin\\xtensa-esp32-elf-gcc.exe",
"forcedInclude": [
"${workspaceFolder}/build/config/sdkconfig.h"
],
"includePath": [
"${config:idf.espIdfPath}/components/**",
"${config:idf.espIdfPathWin}/components/**",
"${config:idf.espAdfPath}/components/**",
"${config:idf.espAdfPathWin}/components/**",
"${workspaceFolder}/**"
],
"browse": {
"path": [
"${config:idf.espIdfPath}/components",
"${config:idf.espIdfPathWin}/components",
"${config:idf.espAdfPath}/components/**",
"${config:idf.espAdfPathWin}/components/**",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": false
}
}
],
"version": 4
Expand Down
25 changes: 17 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
cmake_minimum_required(VERSION 3.16.0)

project(ciot_c)
option(CIOT_CONFIG_USE_MONGOOSE "Enable mongoose instead idf on ESP32" OFF)

if(DEFINED ENV{IDF_PATH})
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(ciot_c)
else()
FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
FILE(GLOB_RECURSE infa_src ${CMAKE_SOURCE_DIR}/main/infra/mg/*)
FILE(GLOB_RECURSE ifaces_src ${CMAKE_SOURCE_DIR}/main/interfaces/*)
FILE(GLOB_RECURSE mg_src ${CMAKE_SOURCE_DIR}/main/mongoose/*)
FILE(GLOB app_src ${CMAKE_SOURCE_DIR}/main/*)

include_directories(AFTER
${CMAKE_SOURCE_DIR}/src/data
${CMAKE_SOURCE_DIR}/src/infra
${CMAKE_SOURCE_DIR}/src/interfaces
${CMAKE_SOURCE_DIR}/src/mongoose
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/main/data
${CMAKE_SOURCE_DIR}/main/infra
${CMAKE_SOURCE_DIR}/main/interfaces
${CMAKE_SOURCE_DIR}/main/mongoose
${CMAKE_SOURCE_DIR}/main
)

add_executable(${PROJECT_NAME} ${app_sources})
add_executable(${PROJECT_NAME} ${infa_src}
${ifaces_src}
${ifaces_src}
${mg_src}
${app_src})

if(WIN32)
target_link_libraries(${PROJECT_NAME} ws2_32)
endif()
project(ciot_c)
endif()
10 changes: 10 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FILE(GLOB_RECURSE infa_src ${CMAKE_SOURCE_DIR}/main/infra/idf/*)
FILE(GLOB_RECURSE ifaces_src ${CMAKE_SOURCE_DIR}/main/interfaces/*)
FILE(GLOB app_src ${CMAKE_SOURCE_DIR}/main/*)

idf_component_register(SRCS ${infa_src}
${ifaces_src}
${app_src}
INCLUDE_DIRS data
infra
interfaces .)
12 changes: 6 additions & 6 deletions src/ciot.c → main/ciot.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ciot_err_t ciot_set_iface_list(ciot_t this, ciot_iface_t *iface_list[], int coun

for (size_t i = 0; i < count; i++)
{
this->iface_list.items[i]->id = i;
this->iface_list.items[i]->info.id = i;
ciot_iface_register_event(this->iface_list.items[i], ciot_iface_event_handler, this);
}

Expand All @@ -54,18 +54,18 @@ static ciot_err_t ciot_iface_event_handler(void *sender, ciot_iface_event_t *eve
{
ciot_t this = event_args;
ciot_iface_t *iface_snd = sender;
ciot_iface_t *iface_sel = this->iface_list.items[event->msg.id];
ciot_iface_t *iface_sel = this->iface_list.items[event->msg.iface.id];
bool sync_msg = event->msg.type == CIOT_MSG_TYPE_GET_CONFIG || event->msg.type == CIOT_MSG_TYPE_GET_STATUS;

if (this->state == CIOT_STATE_BUSY)
{
event->msg.error = CIOT_ERR_BUSY;
event->msg.iface = this->iface_busy->base.type;
event->msg.iface = this->iface_busy->info;
event->size = CIOT_MSG_SIZE;
return ciot_iface_send_data(iface_snd, &event->msg, event->size);
}

if (event->msg.id >= this->iface_list.count || event->msg.id < 0)
if (event->msg.iface.id >= this->iface_list.count || event->msg.iface.id < 0)
{
event->msg.error = CIOT_ERR_INVALID_ID;
event->size = CIOT_MSG_SIZE;
Expand All @@ -78,7 +78,7 @@ static ciot_err_t ciot_iface_event_handler(void *sender, ciot_iface_event_t *eve
if (sync_msg)
{
ciot_iface_process_msg(iface_sel, &event->msg, &event->size);
event->msg.iface = iface_sel->base.type;
event->msg.iface = iface_sel->info;
return ciot_iface_send_data(iface_snd, &event->msg, event->size);
}
else
Expand All @@ -93,7 +93,7 @@ static ciot_err_t ciot_iface_event_handler(void *sender, ciot_iface_event_t *eve
if (this->state == CIOT_STATE_BUSY)
{
this->state = CIOT_STATE_IDLE;
event->msg.iface = iface_sel->base.type;
event->msg.iface = iface_sel->info;
return ciot_iface_send_data(this->iface_rsp, &event->msg, event->size);
}
else
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion src/data/ciot_mqttc_data.h → main/data/ciot_mqttc_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
#ifndef __CIOT_MQTT_DATA__H__
#define __CIOT_MQTT_DATA__H__

#include "ciot_config.h"
#include <inttypes.h>
#include <time.h>

#include "ciot_config.h"

#define CIOT_MQTT_CLIENT_ID_LEN 32
#define CIOT_MQTT_URL_LEN 64
Expand Down
12 changes: 8 additions & 4 deletions src/data/ciot_msg_data.h → main/data/ciot_msg_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "ciot_https_data.h"
#include "ciot_httpc_data.h"
#include "ciot_mqttc_data.h"

#define CIOT_MSG_SIZE (sizeof(ciot_msg_t) - sizeof(ciot_msg_data_u))
#define CIOT_MSG_GET_SIZE(type) (CIOT_MSG_SIZE + sizeof(type))

Expand All @@ -39,7 +38,13 @@ typedef enum __attribute__((packed))
CIOT_IFACE_TYPE_HTTP_SERVER,
CIOT_IFACE_TYPE_HTTP_CLIENT,
CIOT_IFACE_TYPE_MQTT,
} ciot_iface_type_t;
} ciot_msg_iface_type_t;

typedef struct __attribute__((packed))
{
uint8_t id;
ciot_msg_iface_type_t type;
} ciot_msg_iface_info_t;

typedef union ciot_msg_data
{
Expand All @@ -51,9 +56,8 @@ typedef union ciot_msg_data

typedef struct __attribute__((packed))
{
uint8_t id;
ciot_msg_type_t type;
ciot_iface_type_t iface;
ciot_msg_iface_info_t iface;
ciot_err_t error;
ciot_msg_data_u data;
} ciot_msg_t;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions main/infra/idf/ciot_httpc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file ciot_httpc.c
* @author your name ([email protected])
* @brief
* @version 0.1
* @date 2023-10-13
*
* @copyright Copyright (c) 2023
*
*/

#include "ciot_httpc.h"

ciot_httpc_t ciot_httpc_new(void *handle)
{
return NULL;
}

ciot_err_t ciot_httpc_start(ciot_httpc_t this, ciot_httpc_cfg_t *cfg)
{
return CIOT_ERR_NOT_IMPLEMENTED;
}

ciot_err_t ciot_httpc_stop(ciot_httpc_t this)
{
return CIOT_ERR_NOT_IMPLEMENTED;
}

ciot_err_t ciot_httpc_process_req(ciot_httpc_t this, ciot_httpc_req_t *req)
{
return CIOT_ERR_NOT_IMPLEMENTED;
}

ciot_err_t ciot_httpc_send_data(ciot_httpc_t this, uint8_t *data, int size)
{
return CIOT_ERR_NOT_IMPLEMENTED;
}
37 changes: 37 additions & 0 deletions main/infra/idf/ciot_https.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file ciot_https.c
* @author your name ([email protected])
* @brief
* @version 0.1
* @date 2023-10-13
*
* @copyright Copyright (c) 2023
*
*/

#include "ciot_https.h"

ciot_https_t ciot_https_new(void *handle)
{
return NULL;
}

ciot_err_t ciot_https_start(ciot_https_t this, ciot_https_cfg_t *cfg)
{
return CIOT_ERR_NOT_IMPLEMENTED;
}

ciot_err_t ciot_https_stop(ciot_https_t this)
{
return CIOT_ERR_NOT_IMPLEMENTED;
}

ciot_err_t ciot_https_process_req(ciot_https_t this, ciot_https_req_t *req)
{
return CIOT_ERR_NOT_IMPLEMENTED;
}

ciot_err_t ciot_https_send_data(ciot_https_t this, uint8_t *data, int size)
{
return CIOT_ERR_NOT_IMPLEMENTED;
}
Loading

0 comments on commit bc57f4f

Please sign in to comment.