You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.0 KiB
72 lines
2.0 KiB
|
11 months ago
|
/*
|
||
|
|
* wire_sensor.c
|
||
|
|
*
|
||
|
|
* Created on: Jul 16, 2024
|
||
|
|
* Author: akeguo
|
||
|
|
*/
|
||
|
|
|
||
|
|
|
||
|
|
#include <bsp_Log.h>
|
||
|
|
#include "msp_wire_sensor.h"
|
||
|
|
#include "BHBF_ROBOT.h"
|
||
|
|
//MB_REG_DATA wire_sensor_mb_reg_value; 10H的时候用
|
||
|
|
struct UARTHandler* wire_sensor_UART_Handler;
|
||
|
|
DispacherController* wire_sensor_dispacher;
|
||
|
|
int32_t* Desulfurizer_Wire_Length;
|
||
|
|
int32_t *Desulfurizer_Thickness;
|
||
|
|
|
||
|
|
|
||
|
|
void decode_Length(uint8_t *buffer, uint16_t length)
|
||
|
|
{
|
||
|
|
/* CRC 校验 */
|
||
|
|
uint16_t crc_check = ((buffer[length - 1] << 8) | buffer[length - 2]);
|
||
|
|
/* CRC 校验正确 */
|
||
|
|
if (crc_check == MB_CRC16(buffer, length - 2))
|
||
|
|
{
|
||
|
|
|
||
|
|
*Desulfurizer_Wire_Length = buffer[3] << 8 | buffer[4] ;
|
||
|
|
|
||
|
|
//log_info("wire sensor decoding succeeded, and the length is %d",wire_length);
|
||
|
|
LOG("wire sensor decoding succeeded, and the length is %d",*Desulfurizer_Wire_Length);
|
||
|
|
//wire_sensor_UART_Handler->Set_PCOMHardWare(wire_sensor_UART_Handler,"wire_sensor",1);
|
||
|
|
HardWareErrorController->Set_PCOMHardWare(HardWareErrorController,"wire_sensor",1);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
//Decode Error;
|
||
|
|
//log_error("wire sensor decoding failed");
|
||
|
|
LOGFF(DL_ERROR,"wire sensor decoding failed");
|
||
|
|
HardWareErrorController->Set_PCOMHardWare(HardWareErrorController,"wire_sensor",1);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void wire_sensor_intialize(struct UARTHandler* Handler)
|
||
|
|
{
|
||
|
|
|
||
|
|
wire_sensor_UART_Handler = Handler;
|
||
|
|
wire_sensor_UART_Handler->Wait_time = 10; //等待10ms 最低不要低于4;
|
||
|
|
|
||
|
|
wire_sensor_dispacher=Handler->dispacherController;
|
||
|
|
wire_sensor_dispacher->Add_Dispatcher_List(wire_sensor_dispacher,read_wire_sensor_length);
|
||
|
|
|
||
|
|
|
||
|
|
HardWareErrorController->Add_PCOMHardWare(HardWareErrorController,"wire_sensor",0,wire_sensor);
|
||
|
|
|
||
|
|
LOG("wire_sensor_intialize");
|
||
|
|
//log_info("wire_sensor_intialize");
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void read_wire_sensor_length()
|
||
|
|
{
|
||
|
|
//LOG("read_wire_sensor_length");
|
||
|
|
LOG("read_wire_sensor_length");
|
||
|
|
wire_sensor_UART_Handler->UART_Decode = decode_Length;
|
||
|
|
MB_ReadHoldingReg(&wire_sensor_UART_Handler->Tx_Buf,
|
||
|
|
&wire_sensor_UART_Handler->TxCount, 2, 0, 2); //read from the data;
|
||
|
|
wire_sensor_UART_Handler->UART_Tx(wire_sensor_UART_Handler);
|
||
|
|
|
||
|
|
}
|