From 1edb9c9d3c4e8d3fb8abbe64eec67566330804b2 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Tue, 25 Jun 2024 15:22:24 +0800 Subject: [PATCH] update --- sdk/sdk.cpp | 1 - usrc/components/zcancmder/zcan_protocol_parser.cpp | 79 +++++----- usrc/configs/device_id_mgr.hpp | 4 +- usrc/main.cpp | 165 +++++++-------------- 4 files changed, 97 insertions(+), 152 deletions(-) diff --git a/sdk/sdk.cpp b/sdk/sdk.cpp index 5c806ba..d27555c 100644 --- a/sdk/sdk.cpp +++ b/sdk/sdk.cpp @@ -2,7 +2,6 @@ #include "project_configs.h" -static iflytop::ZGPIO g_debuglight; void sdkinit() { zlog_init(&PC_DEBUG_UART); diff --git a/usrc/components/zcancmder/zcan_protocol_parser.cpp b/usrc/components/zcancmder/zcan_protocol_parser.cpp index 99a728e..69775c7 100644 --- a/usrc/components/zcancmder/zcan_protocol_parser.cpp +++ b/usrc/components/zcancmder/zcan_protocol_parser.cpp @@ -22,44 +22,44 @@ void ZCanProtocolParser::initialize(IZCanReceiver* cancmder) { REGFN(module_clear_error); REGFN(module_stop); - REGFN(step_motor_enable); - REGFN(step_motor_read_pos); - REGFN(step_motor_easy_rotate); - REGFN(step_motor_easy_move_by); - REGFN(step_motor_easy_move_to); - REGFN(step_motor_easy_move_to_zero); - REGFN(step_motor_easy_set_current_pos); - REGFN(step_motor_easy_move_to_io); - REGFN(step_motor_active_cfg); - REGFN(step_motor_stop); - REGFN(step_motor_read_io_state); - REGFN(step_motor_easy_move_to_end_point); - - REGFN(step_motor_read_tmc5130_status); - REGFN(step_motor_read_tmc5130_state); - REGFN(step_motor_read_tmc4361a_status); - REGFN(step_motor_read_tmc4361a_state); - REGFN(step_motor_read_tmc2160_status); - REGFN(step_motor_read_tmc2160_state); - REGFN(step_motor_read_io_index_in_stm32); - - REGFN(mini_servo_enable); - REGFN(mini_servo_read_pos); - REGFN(mini_servo_active_cfg); - REGFN(mini_servo_stop); - REGFN(mini_servo_set_mid_point); - REGFN(mini_servo_read_io_state); - - REGFN(mini_servo_move_to); - REGFN(mini_servo_rotate); - REGFN(mini_servo_rotate_with_torque); - - REGFN(extboard_read_inio); - REGFN(extboard_write_outio); - REGFN(extboard_read_muti_inio); - REGFN(extboard_read_inio_index_in_stm32); - REGFN(extboard_read_outio_index_in_stm32); - REGFN(extboard_read_outio); + // REGFN(step_motor_enable); + // REGFN(step_motor_read_pos); + // REGFN(step_motor_easy_rotate); + // REGFN(step_motor_easy_move_by); + // REGFN(step_motor_easy_move_to); + // REGFN(step_motor_easy_move_to_zero); + // REGFN(step_motor_easy_set_current_pos); + // REGFN(step_motor_easy_move_to_io); + // REGFN(step_motor_active_cfg); + // REGFN(step_motor_stop); + // REGFN(step_motor_read_io_state); + // REGFN(step_motor_easy_move_to_end_point); + + // REGFN(step_motor_read_tmc5130_status); + // REGFN(step_motor_read_tmc5130_state); + // REGFN(step_motor_read_tmc4361a_status); + // REGFN(step_motor_read_tmc4361a_state); + // REGFN(step_motor_read_tmc2160_status); + // REGFN(step_motor_read_tmc2160_state); + // REGFN(step_motor_read_io_index_in_stm32); + + // REGFN(mini_servo_enable); + // REGFN(mini_servo_read_pos); + // REGFN(mini_servo_active_cfg); + // REGFN(mini_servo_stop); + // REGFN(mini_servo_set_mid_point); + // REGFN(mini_servo_read_io_state); + + // REGFN(mini_servo_move_to); + // REGFN(mini_servo_rotate); + // REGFN(mini_servo_rotate_with_torque); + + // REGFN(extboard_read_inio); + // REGFN(extboard_write_outio); + // REGFN(extboard_read_muti_inio); + // REGFN(extboard_read_inio_index_in_stm32); + // REGFN(extboard_read_outio_index_in_stm32); + // REGFN(extboard_read_outio); } @@ -184,7 +184,7 @@ int32_t ZCanProtocolParser::module_active_cfg(cmdcontxt_t* cxt) { /*********************************************************************************************************************** * ZIStepMotor * ***********************************************************************************************************************/ - +#if 0 #define MODULE_CLASS ZIStepMotor int32_t ZCanProtocolParser::step_motor_enable(cmdcontxt_t* cxt) { @@ -385,6 +385,7 @@ int32_t ZCanProtocolParser::extboard_read_outio(cmdcontxt_t* cxt) { } #undef MODULE_CLASS +#endif /*********************************************************************************************************************** * ZIPipetteCtrlModule * diff --git a/usrc/configs/device_id_mgr.hpp b/usrc/configs/device_id_mgr.hpp index 6e6f375..86af593 100644 --- a/usrc/configs/device_id_mgr.hpp +++ b/usrc/configs/device_id_mgr.hpp @@ -26,4 +26,6 @@ void zdevice_id_mgr_init(); void zdevice_id_mgr_recfg_device_id(int32_t id); -int32_t zdevice_id_mgr_get_device_id(); \ No newline at end of file +int32_t zdevice_id_mgr_get_device_id(); + +static inline int32_t device_id() { return zdevice_id_mgr_get_device_id(); } \ No newline at end of file diff --git a/usrc/main.cpp b/usrc/main.cpp index 7ffb7a8..5f8702f 100644 --- a/usrc/main.cpp +++ b/usrc/main.cpp @@ -3,6 +3,7 @@ #include "configs/device_id_mgr.hpp" #include "public_service/public_service.hpp" +#include "sdk/sdk.hpp" #include "sysmgr/sys_mgr.hpp" // // @@ -16,42 +17,9 @@ extern "C" { void StartDefaultTask(void const* argument) { umain(); } } -int32_t deviceId = 0; - static void board_init() { + int32_t deviceId = zdevice_id_mgr_get_device_id(); switch (deviceId) { - // case 10: - // subboard10_hbot_board_init(); - // break; - // case 20: // 板夹仓 - // subboard20_plate_clamp_case_board_init(); - // break; - // case 30: // 摇匀模组 - // subboard30_shake_module_board_init(); - // break; - // case 40: // 温度控制板40 - // case 50: // 温度控制板50 - // subboard40_and_50_temperature_ctrl_board_init(); - // break; - // case 60: // 进出料模组 - // subboard60_inlet_and_outlet_module_board_init(); - // break; - // case 70: // 孵化转盘 - // subboard70_incubation_turntable_board_init(); - // break; - // case 80: - // subboard80_cliptip_board_init(); - // break; - // case 90: - // subboard90_optical_module_board_init(); - // break; - // case 100: - // subboard100_id_card_reader_board_init(); - // break; - // case 200: - // subboard200_ext_tmc5160_board_init(); - // break; - default: common_hardware_init(); break; @@ -59,90 +27,65 @@ static void board_init() { } static void board_post_init() { + int32_t deviceId = zdevice_id_mgr_get_device_id(); GService::inst()->initialize(); switch (deviceId) { - // case 10: - // Subboard10Hbot::ins()->initialize(); - // break; - // case 20: - // Subboard20PlateClampCase::ins()->initialize(); - // break; - // case 30: // 摇匀模组 - // Subboard30ShakeModule::ins()->initialize(); - // break; - // case 40: // 温度控制板40 - // case 50: // 温度控制板50 - // Subboard40And50TemperatureCtrl::ins()->initialize(); - // break; - // case 60: // 进出料模组 - // Subboard60InjectAndOutletModule::ins()->initialize(); - // break; - // case 70: // 孵化转盘 - // Subboard70IncubationTurntable::ins()->initialize(); - // break; - // case 80: - // Subboard80Cliptip::ins()->initialize(); - // break; - // case 100: - // Subboard100IdCardReader::ins()->initialize(); - // break; - // case 200: - // Subboard200ExtTmc5160::ins()->initialize(); - // break; - // case 90: - // Subboard90OpticalModule::ins()->initialize(); - break; default: break; } } -void umain() { - // deviceId = zdevice_id_mgr_get_device_id(); - - // board_init(); - - // Pin_t debugLight = PC_DEBUG_LIGHT_GPIO; - // if (deviceId == 20) { - // debugLight = PC_SUBBOARD_20_70_LIGHT_GPIO; - // } - - // zos_cfg_t zoscfg = {0}; - // chip_cfg_t chipcfg = {}; - // chipcfg.us_dleay_tim = &PC_SYS_DELAY_US_TIMER; - // chipcfg.tim_irq_scheduler_tim = &PC_SYS_TIM_IRQ_SCHEDULER_TIMER; - // chipcfg.huart = &PC_DEBUG_UART; - // chipcfg.debuglight = debugLight; - - // chip_init(&chipcfg); - // zos_init(&zoscfg); - // zdevice_id_mgr_init(); - - // ZEARLY_LOGI("SYS", "chip init ok"); - // ZEARLY_LOGI("SYS", "= manufacturer : %s", PC_MANUFACTURER); - // ZEARLY_LOGI("SYS", "= project name : %s", PC_PROJECT_NAME); - // ZEARLY_LOGI("SYS", "= version : %d", PC_VERSION); - // ZEARLY_LOGI("SYS", "= freq : %d", HAL_RCC_GetSysClockFreq()); - // ZEARLY_LOGI("SYS", "= build time : %s", __DATE__ " " __TIME__); - // ZEARLY_LOGI("SYS", "= device id : %d", deviceId); - - // if (deviceId <= 0) { - // chip_set_error(); - // ZEARLY_LOGE("SYS", "device id is not set"); - // while (true) { - // zos_delay(1); - // } - // } - - // board_post_init(); +static iflytop::ZGPIO debuglight; +static bool errorFlag; +static inline void debugLightLoop() { + static bool light = false; + static uint32_t lastcall = 0; + + if (errorFlag) { + if (zos_haspassedms(lastcall) > 30) { + light = !light; + debuglight.setState(light); + lastcall = zos_get_tick(); + } + } else { + if (zos_haspassedms(lastcall) > 300) { + light = !light; + debuglight.setState(light); + lastcall = zos_get_tick(); + } + } +} - // ZLOGI(TAG, "======================= sysinfo ======================= "); - // SysMgr::ins()->initedFinished(); - // SysMgr::ins()->dumpSysInfo(); - // ZLOGI(TAG, "="); +void umain() { + // + board_init(); + + sdkinit(); + + debuglight.initAsOutput(PC_DEBUG_LIGHT_GPIO, iflytop::ZGPIO::kMode_nopull, false, false); + + ZLOGI("SYS", "chip init ok"); + ZLOGI("SYS", "= manufacturer : %s", PC_MANUFACTURER); + ZLOGI("SYS", "= project name : %s", PC_PROJECT_NAME); + ZLOGI("SYS", "= version : %d", PC_VERSION); + ZLOGI("SYS", "= freq : %d", HAL_RCC_GetSysClockFreq()); + ZLOGI("SYS", "= build time : %s", __DATE__ " " __TIME__); + ZLOGI("SYS", "= device id : %d", zdevice_id_mgr_get_device_id()); + + if (zdevice_id_mgr_get_device_id() <= 0) { + ZLOGE("SYS", "device id is not set"); + errorFlag = true; + } else { + board_post_init(); + ZLOGI(TAG, "======================= sysinfo ======================= "); + SysMgr::ins()->initedFinished(); + SysMgr::ins()->dumpSysInfo(); + ZLOGI(TAG, "="); + } - // while (true) { - // GService::inst()->getZCanReceiver()->loop(); - // zos_delay(1); - // } + while (true) { + GService::inst()->getZCanReceiver()->loop(); + osDelay(1); + debugLightLoop(); + } }