From c9c1e00d6a977fd7e24181317a19adb853cf8876 Mon Sep 17 00:00:00 2001 From: yelvlab Date: Wed, 1 Jan 2025 02:10:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=89=E9=97=AE=E9=A2=98=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=8C=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + inc/main.h | 1 + src/main.c | 4 +--- src/rs485_protocol.c | 26 ++++++++++++-------------- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 985cac9..09bfcfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ set(TARGET_C_SRC ${CMAKE_SOURCE_DIR}/src/i2c.c ${CMAKE_SOURCE_DIR}/src/fwdgt.c ${CMAKE_SOURCE_DIR}/src/rs485_protocol.c + ${CMAKE_SOURCE_DIR}/src/ultrasonic_analog.c ${CMAKE_SOURCE_DIR}/src/gd60914.c ${CMAKE_SOURCE_DIR}/src/ultrasonic_analog.c ) diff --git a/inc/main.h b/inc/main.h index 5e00524..9460a1f 100644 --- a/inc/main.h +++ b/inc/main.h @@ -43,6 +43,7 @@ OF SUCH DAMAGE. #include "usart.h" #include "fwdgt.h" #include "board_config.h" +#include "ultrasonic_analog.h" #include "gd60914.h" #include "ultrasonic_analog.h" diff --git a/src/main.c b/src/main.c index 7bd8ed8..14e97f2 100644 --- a/src/main.c +++ b/src/main.c @@ -41,13 +41,11 @@ int main(void) // gpio_bit_write(RS485_EN_PORT, RS485_EN_PIN, RESET); while(1){ - // printf("hello world!\r\n"); - // delay_ms(500); gd60914_get_object_tempture(); + delay_ms(50); ultrasonic_pwm_out_cycles(ULTRASONIC_TX_CYCLES); - // delay_ms(2); watchdog_reload(); } diff --git a/src/rs485_protocol.c b/src/rs485_protocol.c index 06bf928..b94265d 100644 --- a/src/rs485_protocol.c +++ b/src/rs485_protocol.c @@ -21,8 +21,7 @@ void process_command(uint8_t *cmd, size_t length) { sprintf(combined_str, "%c%c", cmd[3], cmd[4]); if (strcmp(combined_str, "M1") == 0) { ultrasonic_distance_report(); - } else if (strcmp(combined_str, "M2") == 0) - { + } else if (strcmp(combined_str, "M2") == 0) { gd60914_tempture_report(); } else if (strcmp(combined_str, "M3") == 0) { @@ -92,6 +91,17 @@ validation_result_t validate_data_length(uint8_t *data) { } } +void gd60914_tempture_report(void) { + static uint8_t package_header[3] = {0xB5, 0xF0, 0x02}; + + uint8_t combined_data[5]; + memcpy(combined_data, package_header, 3); + memcpy(combined_data + 3, g_temperature_uint8, 2); + + printf("%c%c%c", package_header[0], package_header[1], package_header[2]); + printf("%c%c", g_temperature_uint8[1], g_temperature_uint8[0]); + printf("%c", calculate_crc(combined_data, 6)); +} // void eddy_current_value_report(void) { // static uint32_t eddy_current_value_uint32 = 0; // @@ -131,15 +141,3 @@ void ultrasonic_distance_report(void) { printf("%c%c%c%c", package_data[0], package_data[1], package_data[2], package_data[3]); printf("%c", calculate_crc(combined_data, 8)); } - -void gd60914_tempture_report(void) { - static uint8_t package_header[3] = {0xB5, 0xF0, 0x02}; - - uint8_t combined_data[5]; - memcpy(combined_data, package_header, 3); - memcpy(combined_data + 3, g_temperature_uint8, 2); - - printf("%c%c%c", package_header[0], package_header[1], package_header[2]); - printf("%c%c", g_temperature_uint8[1], g_temperature_uint8[0]); - printf("%c", calculate_crc(combined_data, 6)); -} \ No newline at end of file