|
|
|
|
/******************************************************************************
|
|
|
|
|
|
|
|
|
|
版权所有 (C), 2018-2099, Radkil
|
|
|
|
|
|
|
|
|
|
******************************************************************************
|
|
|
|
|
文 件 名 : client_setting.c
|
|
|
|
|
版 本 号 : 初稿
|
|
|
|
|
作 者 : radkil
|
|
|
|
|
生成日期 : 2026年8月20日
|
|
|
|
|
最近修改 :
|
|
|
|
|
功能描述 : PVIV中间层
|
|
|
|
|
|
|
|
|
|
修改历史 :
|
|
|
|
|
1.日 期 : 2026年8月20日
|
|
|
|
|
作 者 : radkil
|
|
|
|
|
修改内容 : 创建文件
|
|
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
#include "BHBF.h"
|
|
|
|
|
#include "pb.h"
|
|
|
|
|
#include "pb_decode.h"
|
|
|
|
|
#include "bsp_PV.pb.h"
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 外部变量说明 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 外部函数原型说明 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 内部函数原型说明 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 全局变量 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 模块级变量 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
static PV_struct_define decoded_PV_variable = { 0 };
|
|
|
|
|
static PV_struct_define decoded_PV = { 0 };
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 常量定义 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 宏定义 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
int check_PV(char *_pBuffer, uint32_t _iSize)
|
|
|
|
|
{
|
|
|
|
|
if (_iSize < 4) return -1;
|
|
|
|
|
if (_pBuffer[0] != 0x55) return -1;
|
|
|
|
|
if (_pBuffer[1] != 0x55) return -1;
|
|
|
|
|
|
|
|
|
|
uint16_t crc_check = ((_pBuffer[_iSize - 1] << 8) | _pBuffer[_iSize - 2]);
|
|
|
|
|
uint16_t crc_check1 = Rd_modbusCRC16((uint8_t *)_pBuffer, _iSize - 2);
|
|
|
|
|
if (crc_check == crc_check1)
|
|
|
|
|
{
|
|
|
|
|
return _iSize;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void decode_PV(const char *_pBuffer, uint32_t _iSize)
|
|
|
|
|
{
|
|
|
|
|
if (_pBuffer[2] == 0x01 && _pBuffer[3] == 0x01) //01 01 设置PV
|
|
|
|
|
{
|
|
|
|
|
pb_istream_t i_pv_stream;
|
|
|
|
|
|
|
|
|
|
i_pv_stream = pb_istream_from_buffer((const pb_byte_t *)&_pBuffer[4], _iSize - 6);
|
|
|
|
|
pb_decode(&i_pv_stream, PV_struct_define_fields, &decoded_PV_variable);
|
|
|
|
|
|
|
|
|
|
if(decoded_PV_variable.TimeStamp>decoded_PV.TimeStamp)
|
|
|
|
|
{
|
|
|
|
|
decoded_PV=decoded_PV_variable;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (*(_pBuffer + 2) == 0x02 && *(_pBuffer + 3) == 0x01) //设置PV
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (*(_pBuffer + 2) == 0x03 && *(_pBuffer + 3) == 0x01) //返回IV
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// Motor_CmdData_t tMotor_CmdData_t = {0};
|
|
|
|
|
// tMotor_CmdData_t.m_ucMotorIndex = 1;
|
|
|
|
|
// tMotor_CmdData_t.m_iValue = 10;
|
|
|
|
|
// MsgCenter_SendTo(MODULE_NAME_MOTOR, MOTOR_CMD_SET_SPEED, (void *)&tMotor_CmdData_t, sizeof(Motor_CmdData_t));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Send_PV(void *argument)
|
|
|
|
|
{
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Rd_Delay(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|