/* 加入队列 处理 */ #ifndef __OSCAR__H #define __OSCAR__H #ifdef __cplusplus extern "C" { #endif #include "FreeRTOS.h" #include "task.h" #include "main.h" #include "cmsis_os.h" #include "usart.h" #include "elog.h" #include #include "bsp_uart.h" #define Oscar_USE_MAX485 0 #define Oscar_USE_MAX3160_232 0 #define Oscar_USE_MAX3160_485 1 #define Oscar_Rcv_Buf_Size (3+244+2) // #define Oscar_Command_Number 1 static void Oscar_MAX3160_232(void) { HAL_GPIO_WritePin(SEL_232_485_GPIO_Port,SEL_232_485_Pin, RESET); HAL_GPIO_WritePin(HDPLX_GPIO_Port,HDPLX_Pin, RESET); } typedef enum { Oscar_Event_Ready , Oscar_Event_Test, Oscar_Event_Test_OK , Oscar_Event_Get_Data, Oscar_Event_Check_Data , } Module_Oscar_Event_TypeDef; typedef enum { Oscar_State_Waiting , Oscar_State_Test , Oscar_State_Test_Start , Oscar_State_SN_Getting , Oscar_State_SN_OK , Oscar_State_Ready , Oscar_State_Get_WAVELENGTH , // Oscar_State_Get_WAVELENGTH_Wait , // Oscar_State_Get_WAVELENGTH_OK, // Oscar_State_Get_WAVELENGTH_Check , Oscar_State_Get_DATA , Oscar_State_Get_DATA_Trans, Oscar_State_Get_DATA_Wait , Oscar_State_Get_DATA_OK, Oscar_State_Get_DATA_Check , Oscar_State_Get_Queue_MSG , Oscar_State_Stop , Oscar_State_Timeout , Oscar_State_Error , } Module_Oscar_State_TypeDef; extern UART_HELPER_TypeDef *Oscar_uart_helper; typedef struct { int (*init)(void); void (*port)(void); int (*test)(void); void (*start)(void); void (*stop)(void); osMessageQueueId_t transQueue; // 队列可选 volatile Module_Oscar_State_TypeDef state; uint8_t data_ok; /* 接收数据完整可以处理 */ uint8_t result_buf[1024]; uint16_t size_received; uint64_t timebase_ticks; uint64_t timeout_ticks; uint8_t event_flag; uint8_t wavelength_ok; Record_Trans_Rcv_TypeDef transRecord[3]; uint8_t oscarsn_buf[15]; uint8_t Oscar_Wavelength_Buf[3][ Oscar_Rcv_Buf_Size ]; uint8_t Oscar_Data_Buf[3][ Oscar_Rcv_Buf_Size ]; }Oscar_TypeDef; extern Oscar_TypeDef oscar ; int Oscar_Init( void ); void Oscar_Task( void); void Oscar_Port( void); int Oscar_Test( ); void Oscar_Start( ); void Oscar_Stop( ); void Oscar_Wavelength( ); void Oscar_Set_Sendbuf( uint8_t * buf, uint16_t size ); void Oscar_Set_Rcvbuf( uint8_t * buf, uint16_t size ); void Oscar_Set_Timeout_ms( uint64_t ms_ticks ); int Oscar_Validate( ); int Oscar_Transmit(); int Oscar_Receive(); void Oscar_Trans_GPIO(void) ; void Oscar_Trans_Cplt_GPIO(void) ; int Oscar_CallBack( Oscar_TypeDef *pOscar , uint8_t *buf, uint16_t size ); #ifdef __cplusplus } #endif #endif /* temp.init(); temp.port(); temp.test(); uint64_t ticks = osKernelGetTickCount(); while ( temp.state != PH_State_Ready ) { if ( ( osKernelGetTickCount() -ticks) > 3000 ) { log_e(" pH test error.... ") ; break; } } log_w(" pH test ok.... ") ; // osMessageQueueId_t TestQQueueueueHandle; // osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr); // osMessageQueueGet(TestQueueHandle,osWaitForever); // osStatus_t osMessageQueueGet ( osMessageQueueId_t mq_id, // void * msg_ptr, //储存读取结果的变量地址 // uint8_t * msg_prio, // ==NULL // uint32_t timeout //阻塞超时时间 // ); // osStatus_t osMessageQueuePut ( osMessageQueueId_t mq_id, // const void * msg_ptr, //储存写入内容的变量地址 // uint8_t msg_prio, //==0U // uint32_t timeout //阻塞超时时间 // ); // uint8_t Oscar_SN_command[8] = {0x01, 0x03, 0x00, 0x0A, 0x00, 0x05, 0xA5, 0xCB}; // uint8_t Oscar_Wavelength_sendbuf[3][8] = { // // // 01 03 08 36 00 7A 26 47 (2102 122) // // 01 03 08 B0 00 7A C7 AE (2224 122) // // 01 03 09 2A 00 7A E6 7D (2346 122) // // { 0x01, 0x03, 0x08, 0x36, 0x00, 0x7A, 0x26, 0x47 }, // { 0x01, 0x03, 0x08, 0xB0, 0x00, 0x7A, 0xC7, 0xAE }, // { 0x01, 0x03, 0x09, 0x2A, 0x00, 0x7A, 0xE6, 0x7D } // }; // uint8_t Oscar_Data_sendbuf[3][8] = { // // //01 03 0A 36 00 7A 27 FF (2614 122) // //01 03 0A B0 00 7A C6 16 (2736 122) // //01 03 0B 2A 00 7A E7 C5 (2858 122) // // { 0x01, 0x03, 0x0A, 0x36, 0x00, 0x7A, 0x27, 0xFF }, // { 0x01, 0x03, 0x0A, 0xB0, 0x00, 0x7A, 0xC6, 0x16 }, // { 0x01, 0x03, 0x0B, 0x2A, 0x00, 0x7A, 0xE7, 0xC5 } // }; // uint8_t Oscar_sn_buf[15] = {0}; */