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.
76 lines
2.2 KiB
76 lines
2.2 KiB
1 week ago
|
/*
|
||
|
* msp_Force_Sensor.c
|
||
|
*
|
||
|
* Created on: Oct 8, 2024
|
||
|
* Author: akeguo
|
||
|
*/
|
||
|
#include "msp_Force_Sensor.h"
|
||
|
#include "bsp_Error.pb.h"
|
||
|
#include "BHBF_ROBOT.h"
|
||
|
|
||
|
|
||
|
void decode_force(uint8_t *buffer, uint16_t length);
|
||
|
void GF_FS_Inquiry();//inqure data from the, in fact this is a modbus 03 function;
|
||
|
|
||
|
|
||
|
int32_t* ForceValue_in;
|
||
|
struct UARTHandler *Force_sensor;
|
||
|
|
||
|
DispacherController *Force_sensor_dispacherController;
|
||
|
void force_sensor_intialize(struct UARTHandler *Handler)
|
||
|
{
|
||
|
//uartHandler_intialize(&Force_sensor,Handler,10);
|
||
|
Force_sensor = Handler;
|
||
|
Force_sensor->UART_Decode=decode_force;
|
||
|
Force_sensor->Wait_time = 10; //等待10ms 最低不要低于4;
|
||
|
Force_sensor_dispacherController=Handler->dispacherController;
|
||
|
Force_sensor_dispacherController->DispacherCallTime = 50;//10 是100ms 难道这个2ms的定时器是10ms的?
|
||
|
LOG("angle_encoder_intialize");
|
||
|
Force_sensor_dispacherController->Dispacher_Enable = 1;
|
||
|
//log_info("angle_encoder_intialize");
|
||
|
Force_sensor_dispacherController->Add_Dispatcher_List(Force_sensor_dispacherController,GF_FS_Inquiry);
|
||
|
|
||
|
|
||
|
HardWareErrorController->Add_PCOMHardWare(HardWareErrorController,"force_sensor",0,force_sensor);
|
||
|
//uartHandler->Insert_HardWare_Entry_UART
|
||
|
LOG("steering_engine_intialize");
|
||
|
}
|
||
|
|
||
|
uint8_t Inquiry_Order[8]={0X01, 0X03, 0X07, 0XD0, 0X00, 0X02, 0XC4, 0X86};
|
||
|
void GF_FS_Inquiry()
|
||
|
{
|
||
|
|
||
|
MB_ReadHoldingReg(&Force_sensor->Tx_Buf,
|
||
|
&Force_sensor->TxCount, 1, 0x07D0, 2); //03 command ; read 2 registers
|
||
|
|
||
|
Force_sensor->UART_Tx(Force_sensor);//send the data from the modbus command;
|
||
|
LOG("GF_FS_Inquiry Second Version");
|
||
|
|
||
|
}
|
||
|
|
||
|
uint8_t data[20];
|
||
|
void decode_force(uint8_t *buffer, uint16_t length)
|
||
|
{
|
||
|
memcpy(data,buffer,length);
|
||
|
LOG("start decoding and the length is %d",length);
|
||
|
/* CRC 校验 */
|
||
|
uint16_t crc_check = ((buffer[length - 1] << 8) | buffer[length - 2]);
|
||
|
/* CRC 校验正确 */
|
||
|
if (crc_check == MB_CRC16(buffer, length - 2))
|
||
|
{
|
||
|
*ForceValue_in = (int32_t)((int32_t)buffer[3]<<24|buffer[4]<<16|buffer[5]<<8|buffer[6]);
|
||
|
|
||
|
HardWareErrorController->Set_PCOMHardWare(HardWareErrorController,"force_sensor",1);
|
||
|
LOG("decode_force succeeded and the force is %d",*ForceValue_in);
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//Decode Error;
|
||
|
//log_error("wire sensor decoding failed");
|
||
|
LOGFF(DL_ERROR,"force_sensor decoding failed");
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|