diff --git a/.vscode/settings.json b/.vscode/settings.json index 68cce31..a7469f3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,7 +4,9 @@ "files.associations": { "cstring": "cpp", "random": "cpp", - "system_error": "c" + "system_error": "c", + "*.tcc": "cpp", + "streambuf": "cpp" }, "cmake.ignoreCMakeListsMissing": true } \ No newline at end of file diff --git a/SERVER/hc-12/hc-12.c b/SERVER/hc-12/hc-12.c index 7098a8b..e34a1f8 100644 --- a/SERVER/hc-12/hc-12.c +++ b/SERVER/hc-12/hc-12.c @@ -189,6 +189,7 @@ int loop(int fd, CONF *conf, DATA *DATA) } } + // CO if (strstr(receivedString, "CO")) { @@ -246,6 +247,14 @@ int loop(int fd, CONF *conf, DATA *DATA) printf("\n"); } + // Boot Time + if (strstr(receivedString, "Boot Time")) { + if (1 == (sscanf(receivedString, "Boot Time: %llu seconds\n", &DATA->boot_time_))) { + printf("Boot Time: %llu seconds\n", DATA->boot_time_); + } + + } + } receivedString[0] = '\0'; @@ -360,6 +369,7 @@ int main() data->co_1st = 1; data->co2_1st = 1; data->_time = 180; + data->boot_time_ = 0; redirect_stdout_to_file(logfd, "hc-12.log"); pthread_mutex_init(&mutex, NULL); // 初始化互斥锁 diff --git a/SERVER/hc-12/hc-12.h b/SERVER/hc-12/hc-12.h index 7c4c829..026b142 100644 --- a/SERVER/hc-12/hc-12.h +++ b/SERVER/hc-12/hc-12.h @@ -48,6 +48,9 @@ typedef struct DATA { float co2; float ch4_; + // boot time + long long unsigned int boot_time_; + // 超过阈值次数 int ds18b20_num; int ch4_num; diff --git a/SOFTWARE-FreeRTOS/CMakeLists.txt b/SOFTWARE-FreeRTOS/CMakeLists.txt index 06e4647..795b39a 100644 --- a/SOFTWARE-FreeRTOS/CMakeLists.txt +++ b/SOFTWARE-FreeRTOS/CMakeLists.txt @@ -42,6 +42,7 @@ target_Sources(main PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Source/ZE07CO.cpp ${CMAKE_CURRENT_LIST_DIR}/Source/MHZ14B.cpp ${CMAKE_CURRENT_LIST_DIR}/Source/HC-12.cpp + ${CMAKE_CURRENT_LIST_DIR}/Source/boot_time.cpp ) target_include_directories(main PRIVATE @@ -76,6 +77,7 @@ target_link_libraries( hardware_pwm hardware_adc hardware_pio + hardware_timer ) pico_enable_stdio_uart(main 1) diff --git a/SOFTWARE-FreeRTOS/Source/boot_time.cpp b/SOFTWARE-FreeRTOS/Source/boot_time.cpp new file mode 100644 index 0000000..3a0cf48 --- /dev/null +++ b/SOFTWARE-FreeRTOS/Source/boot_time.cpp @@ -0,0 +1,39 @@ + +#include "common.hpp" +#include "HC-12.hpp" +#include "boot_time.hpp" + + +void BOOT_TIME(void *pvParameters) +{ + (void)pvParameters; + + _printTaskStackHighWaterMark("BOOT_TIME"); + + int _HC_12_SEND_NUM = 0; + char BOOT_TIME_TEMP[BUFER] = { 0 }; + + + while (1) { + // 获取自开机以来的微秒数 + uint64_t uptime_us = time_us_64(); + uint64_t total_uptime_sec = uptime_us / 1000000; + + // 打印开机秒数 + printf("Boot Time: %llu seconds\n", total_uptime_sec); + + { + _HC_12_SEND_NUM++; + if (_HC_12_SEND_NUM > 5) { + sprintf(BOOT_TIME_TEMP, "Boot Time: %llu seconds\n", total_uptime_sec); + _HC_12(BOOT_TIME_TEMP); + memset(BOOT_TIME_TEMP, 0, BUFER); + _HC_12_SEND_NUM = 0; + } + + } + + _printTaskStackHighWaterMark("BOOT_TIME"); + vTaskDelay(pdMS_TO_TICKS(1000)); // 每秒延迟 + } +} diff --git a/SOFTWARE-FreeRTOS/Source/boot_time.hpp b/SOFTWARE-FreeRTOS/Source/boot_time.hpp new file mode 100644 index 0000000..5f54315 --- /dev/null +++ b/SOFTWARE-FreeRTOS/Source/boot_time.hpp @@ -0,0 +1,17 @@ +#ifndef BOOT_TIME_H +#define BOOT_TIME_H + +/* Scheduler include files. */ +#include "FreeRTOS.h" +#include "task.h" +#include "semphr.h" +#include "queue.h" + +#include +#include "pico/stdlib.h" + +#define BUFER 256 + +extern void BOOT_TIME(void *pvParameters); + +#endif diff --git a/SOFTWARE-FreeRTOS/Source/main.cpp b/SOFTWARE-FreeRTOS/Source/main.cpp index 2e1c998..80288a3 100644 --- a/SOFTWARE-FreeRTOS/Source/main.cpp +++ b/SOFTWARE-FreeRTOS/Source/main.cpp @@ -19,6 +19,7 @@ #include "ZE07CO.hpp" #include "MHZ14B.hpp" #include "HC-12.hpp" +#include "boot_time.hpp" #ifndef PICO_DEFAULT_LED_PIN #warning pio/hello_pio example requires a board with a regular LED @@ -109,6 +110,7 @@ int main(int argc, char *argv[]) TaskHandle_t CH4_xHandle = NULL; TaskHandle_t CO_xHandle = NULL; TaskHandle_t CO2_xHandle = NULL; + TaskHandle_t BOOT_TIME_xHandle = NULL; // 板载CPU温度 @@ -146,6 +148,12 @@ int main(int argc, char *argv[]) if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) { printf("CO2() Task Error!"); } + + // Boot Time + xReturned = xTaskCreate(BOOT_TIME, "BOOT_TIME task", 512, NULL, tskIDLE_PRIORITY, &BOOT_TIME_xHandle); + if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) { + printf("CO2() Task Error!"); + } vTaskStartScheduler(); diff --git a/SOFTWARE/Source/MAIN.cpp b/SOFTWARE/Source/MAIN.cpp index c9f95c4..55cee90 100644 --- a/SOFTWARE/Source/MAIN.cpp +++ b/SOFTWARE/Source/MAIN.cpp @@ -304,6 +304,7 @@ int wifi_connect() { } } +/* // 主程序 int main(int argc, char *argv[]) { stdio_init_all(); @@ -349,10 +350,8 @@ int main(int argc, char *argv[]) { cyw43_arch_deinit(); return 0; } +*/ - - -/* int main(int argc, char *argv[]) { stdio_init_all(); @@ -469,5 +468,4 @@ int main(int argc, char *argv[]) } return 0; -} -*/ \ No newline at end of file +} \ No newline at end of file