Commit cc0ef9e6 authored by Jacob Priddy's avatar Jacob Priddy 👌

New file layout to be testable etc

parent 4c1102fc
Pipeline #6245 passed with stages
in 3 minutes and 56 seconds
...@@ -95,10 +95,13 @@ services: ...@@ -95,10 +95,13 @@ services:
networks: networks:
- doorcode - doorcode
esp32: esp32:
image: espressif/idf:latest build:
context: src/embedded
dockerfile: Dockerfile
tty: true tty: true
container_name: esp32 container_name: esp32
volumes: volumes:
- ./src/embedded:/project - ./src/embedded:/project
# uncomment if you are going to be flashing a board from the container
devices: devices:
- /dev/ttyUSB0:/dev/ttyUSB0 - /dev/ttyUSB0:/dev/ttyUSB0
...@@ -2,5 +2,30 @@ ...@@ -2,5 +2,30 @@
# CMakeLists in this exact order for cmake to work correctly # CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake) if(COMPILE_UNIVERSAL_TESTS)
project(door-controller) set(PROJECT_NAME door-controller-universal-tests)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
project(${PROJECT_NAME} C CXX)
find_package(Catch2 REQUIRED)
set(INCLUDE_DIR main/include)
set(APP_SRC main/src/app)
set(CONNECTOR_TEST main/src/connectors/tests)
target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIR})
file(GLOB_RECURSE FILES
${INCLUDE_DIR}/*.h
${APP_SRC}/*.c
${CONNECTOR_TEST_SRC}/*.c
)
add_executable(${PROJECT_NAME} ${FILES} "main/test_main.c")
target_link_libraries(${PROJECT_NAME} Catch2::Catch2)
else()
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(door-controller)
endif()
FROM espressif/idf:latest
RUN apt-get update && apt-get install -y \
build-essential \
gcc \
g++ \
gdb \
cmake \
&& apt-get clean \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*
# Install catch2
RUN git clone https://github.com/catchorg/Catch2.git /catch2 \
&& cd /catch2 && cmake -Bbuild -H. -DBUILD_TESTING=OFF \
&& cmake --build build/ --target install \
&& cd / \
&& rm -rf /catch2
ENTRYPOINT [ "/opt/esp/entrypoint.sh" ]
CMD [ "/bin/bash" ]
config.h config.h
doorcode_root_cert.pem *.pem
\ No newline at end of file \ No newline at end of file
idf_component_register(SRCS "wifi.c" "main.c" "http.c" "api.c" set(INCLUDE_DIR include)
INCLUDE_DIRS "."
set(APP_SRC src/app)
set(CONNECTOR_SRC src/connectors/esp32)
file(GLOB_RECURSE FILES ${APP_SRC}/*.c ${CONNECTOR_SRC}/*.c)
idf_component_register(SRCS ${FILES} "main.c"
INCLUDE_DIRS ${INCLUDE_DIR}
EMBED_TXTFILES "doorcode_root_cert.pem") EMBED_TXTFILES "doorcode_root_cert.pem")
#ifndef DOOR__WIFI_H_ #ifndef DOOR__WIFI_H_
#define DOOR__WIFI_H_ #define DOOR__WIFI_H_
#include <stdbool.h>
void door_wifi_initialize(void); void door_wifi_initialize(void);
void door_wifi_destroy(void); void door_wifi_destroy(void);
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
#include <freertos/task.h> #include <freertos/task.h>
#include <esp_log.h> #include <esp_log.h>
#include <nvs_flash.h> #include <nvs_flash.h>
#include "wifi.h" #include "connectors/wifi.h"
#include "http.h" #include "connectors/http.h"
#include "api.h" #include "app/api.h"
static const char* TAG = "MAIN_MODULE"; static const char* TAG = "MAIN_MODULE";
...@@ -25,6 +25,8 @@ static void check_code_task(void* pvParameters) ...@@ -25,6 +25,8 @@ static void check_code_task(void* pvParameters)
ESP_LOGI(TAG, "Connected to AP, begin connecting to DoorCode API"); ESP_LOGI(TAG, "Connected to AP, begin connecting to DoorCode API");
bool allowed = door_api_verify_code("123866"); bool allowed = door_api_verify_code("123866");
if (allowed) if (allowed)
{ {
ESP_LOGI(TAG, "We are allowed in the door!"); ESP_LOGI(TAG, "We are allowed in the door!");
...@@ -33,6 +35,9 @@ static void check_code_task(void* pvParameters) ...@@ -33,6 +35,9 @@ static void check_code_task(void* pvParameters)
{ {
ESP_LOGI(TAG, "REJECTED"); ESP_LOGI(TAG, "REJECTED");
} }
ESP_LOGI(TAG, "Making second request");
door_api_verify_code("123867");
ESP_LOGI(TAG, "Done with second request");
door_http_destroy(); door_http_destroy();
door_wifi_destroy(); door_wifi_destroy();
......
#include <string.h> #include <string.h>
#include "api.h" #include "app/api.h"
#include "http.h" #include "connectors/http.h"
#include "config.h" #include "app/config.h"
#define ACCESS_PREFIX "/access/" #define ACCESS_PREFIX "/access/"
#define MAX_CODE_COUNT 500 #define MAX_CODE_COUNT 500
......
#include <esp_http_client.h> #include <esp_http_client.h>
#include <esp_log.h> #include <esp_log.h>
#include <esp_tls.h> #include <esp_tls.h>
#include "http.h" #include <esp_partition.h>
#include "config.h" #include "app/config.h"
#include "wifi.h" #include "connectors/http.h"
#include "connectors/wifi.h"
/** /**
* @brief Input buffer * @brief Input buffer
......
#include <string.h> #include <string.h>
#include "freertos/FreeRTOS.h" #include <freertos/FreeRTOS.h>
#include "freertos/task.h" #include <freertos/task.h>
#include "freertos/event_groups.h" #include <freertos/event_groups.h>
#include "esp_system.h" #include <esp_system.h>
#include "esp_wifi.h" #include <esp_wifi.h>
#include "esp_event.h" #include <esp_event.h>
#include "esp_log.h" #include <esp_log.h>
#include "nvs_flash.h" #include <nvs_flash.h>
#include "config.h" #include "app/config.h"
#include "wifi.h" #include "connectors/wifi.h"
/* FreeRTOS event group to signal when we are connected*/ /* FreeRTOS event group to signal when we are connected*/
static EventGroupHandle_t s_wifi_event_group; static EventGroupHandle_t s_wifi_event_group;
......
0.0.0.1
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment