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.
96 lines
2.8 KiB
96 lines
2.8 KiB
/*
|
|
* msp_Force_Sensor.c
|
|
*
|
|
* Created on: Oct 8, 2024
|
|
* Author: akeguo
|
|
*/
|
|
#include "msp_PaintThickness.h"
|
|
#include "bsp_Error.pb.h"
|
|
#include "BHBF_ROBOT.h"
|
|
#include "stdint.h"
|
|
|
|
void decode_PaintThickness(uint8_t *buffer, uint16_t length);
|
|
void GF_PT_Inquiry();//inqure data from the, in fact this is a modbus 03 function;
|
|
|
|
|
|
int32_t* PaintThickness;
|
|
struct UARTHandler *PaintThickness_sensor;
|
|
|
|
DispacherController *PaintThickness_sensor_dispacherController;
|
|
void Paint_Thickness_intialize(struct UARTHandler *Handler)
|
|
{
|
|
//uartHandler_intialize(&Force_sensor,Handler,10);
|
|
PaintThickness_sensor = Handler;
|
|
PaintThickness_sensor->UART_Decode=decode_PaintThickness;
|
|
PaintThickness_sensor->Wait_time = 10; //等待10ms 最低不要低于4;
|
|
PaintThickness_sensor_dispacherController=Handler->dispacherController;
|
|
PaintThickness_sensor_dispacherController->DispacherCallTime = 200;//10 是100ms 难道这个2ms的定时器是10ms的?
|
|
LOG("angle_encoder_intialize");
|
|
PaintThickness_sensor_dispacherController->Dispacher_Enable = 1;
|
|
//log_info("angle_encoder_intialize");
|
|
PaintThickness_sensor_dispacherController->Add_Dispatcher_List(PaintThickness_sensor_dispacherController,GF_PT_Inquiry);
|
|
|
|
|
|
HardWareErrorController->Add_PCOMHardWare(HardWareErrorController,"PaintThickness_sensor",0,PaintThickness_sensor);
|
|
//uartHandler->Insert_HardWare_Entry_UART
|
|
LOG("steering_engine_intialize");
|
|
}
|
|
|
|
uint8_t Inquiry_Order_PT[6]={0X2E, 0X64, 0X30, 0X3C, 0X3A, 0X3E};
|
|
void GF_PT_Inquiry()
|
|
{
|
|
memcpy(&PaintThickness_sensor->Tx_Buf, &Inquiry_Order_PT, 6);
|
|
PaintThickness_sensor->TxCount = 6;
|
|
PaintThickness_sensor->UART_Tx(PaintThickness_sensor);//send the data from the modbus command;
|
|
LOG("GF_PT_Inquiry Second Version");
|
|
|
|
}
|
|
|
|
|
|
void decode_PaintThickness(uint8_t *buffer, uint16_t length)
|
|
{
|
|
//memcpy(data_PaintThickness,buffer,length);
|
|
LOG("start decoding and the length is %d",length);
|
|
/* 校验 */
|
|
//;<:>
|
|
uint8_t crc_check[4] = {';','<',':','>'};
|
|
|
|
/* CRC 校验正确 */
|
|
if (crc_check[3] == buffer[length - 1]
|
|
&& crc_check[2] == buffer[length - 2]
|
|
&& crc_check[1] == buffer[length - 3]
|
|
&& crc_check[0] == buffer[length - 4])
|
|
{
|
|
int startIndex=0;
|
|
|
|
for(int j=5;j<=14;j++)
|
|
{
|
|
if(buffer[length-j] == ';' || buffer[length-j] == 'e')
|
|
{
|
|
startIndex=j;
|
|
break;
|
|
}
|
|
}
|
|
if(startIndex==0)return;
|
|
|
|
char PaintThickness_in[startIndex-5];//应该不会超过10个
|
|
memcpy(PaintThickness_in,&buffer[length-startIndex+1],startIndex-5);
|
|
|
|
*PaintThickness = atof(PaintThickness_in) * 10;
|
|
|
|
|
|
|
|
HardWareErrorController->Set_PCOMHardWare(HardWareErrorController,"PaintThickness_sensor",1);
|
|
LOG("decode_PaintThickness succeeded and the force is %d",*PaintThickness);
|
|
|
|
}
|
|
else
|
|
{
|
|
//Decode Error;
|
|
//log_error("wire sensor decoding failed");
|
|
LOGFF(DL_ERROR,"PaintThickness_sensor decoding failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|