9ceb218f80
Co-authored-by: Cursor <cursoragent@cursor.com>
1462 lines
49 KiB
C
1462 lines
49 KiB
C
#include "plat_comm/gwsdk/bs_gwsdk_ctrl.h"
|
||
#include "plat_comm/gwsdk/bs_gwsdk_interface.h"
|
||
#include "plat_comm/plat_comm_task.h"
|
||
#include "plat_comm/impl/bs_connect_impl.h"
|
||
#include "plat_comm/impl/bs_public_impl.h"
|
||
|
||
#if (BS_GWSDK_EN)
|
||
|
||
#include "dev_model_api.h"
|
||
|
||
S_GWSDK_CTRL_DATA *s_gwsdk_ctrl = NULL; //数据控制指针
|
||
|
||
|
||
|
||
#if 1 //sdk库回调函数实现
|
||
#define DEVICE_EXAMPLE_TRACE(...) \
|
||
do \
|
||
{ \
|
||
HAL_Printf("\033[1;32;40m%s.%d: ", __func__, __LINE__); \
|
||
HAL_Printf(__VA_ARGS__); \
|
||
HAL_Printf("\033[0m\r\n"); \
|
||
} while (0)
|
||
|
||
|
||
/*************************把protocol_data_def.h内声明的函数实现***************************/
|
||
/** 建连成功事件回调 */
|
||
static int evs_connected_event_handler(void)
|
||
{
|
||
//Comm_Time t_time;
|
||
//U32_T data;
|
||
|
||
s_gwsdk_ctrl->gw_connet_flag = 1;
|
||
|
||
s_bs_task_ctrl.s_bs_ctrl[s_gwsdk_ctrl->u8_bs_flag].s_gundata[0].online_flag = 0; //未上送订单检查
|
||
s_bs_task_ctrl.s_bs_ctrl[s_gwsdk_ctrl->u8_bs_flag].s_gundata[1].online_flag = 0;
|
||
|
||
Plat_Comm_LOG("接收:SDK平台连接成功\n");
|
||
return 0;
|
||
}
|
||
/** 断开连接事件回调 */
|
||
static int evs_disconnected_event_handler(void)
|
||
{
|
||
Comm_Time t_time;
|
||
GetCurrentTime(&t_time);
|
||
|
||
s_gwsdk_ctrl->gw_connet_flag = -1;
|
||
s_bs_task_ctrl.s_bs_ctrl[s_gwsdk_ctrl->u8_bs_flag].u8_log_on_flag = 0;
|
||
s_bs_task_ctrl.s_bs_ctrl[s_gwsdk_ctrl->u8_bs_flag].u8_TCP_connect_flag = 0;
|
||
//轻质化群充测试过程中发现与平台连接超时后不重连
|
||
//检查发现iotx_linkkit_ctx_t结构体中is_opened,is_connected未复位,原因未知,为确保现场使用,此地暂时强制复位
|
||
//v_connected_reset();
|
||
Plat_Comm_LOG("接收:SDK断开连接\n");
|
||
return 0;
|
||
}
|
||
/** 事件回调:接收到云端回复属性上报应答 **/
|
||
static int evs_report_reply_event_handler(const int msgid, const int code, const char *reply,
|
||
const int reply_len)
|
||
{
|
||
//Plat_Comm_LOG("属性上报应答= %d\n",code);
|
||
return 0;
|
||
}
|
||
/** 事件回调:接收到云端回复的事件上报应答 **/
|
||
static int evs_trigger_event_reply_event_handler(const int msgid, const int code, const char *eventid,
|
||
const int eventid_len, const char *message, const int message_len)
|
||
{
|
||
Plat_Comm_LOG("事件上报应答 %d\n",code);
|
||
return 0;
|
||
}
|
||
/** 事件回调: SDK内部运行状态打印 **/
|
||
static int evs_sdk_state_dump(int ev, const char *msg)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
/** 事件回调: 证书设置 **/
|
||
static int evs_device_cert_set(const evs_device_meta meta)
|
||
{
|
||
//int i=0;
|
||
S_SDK_DATA sdk_data ;
|
||
|
||
memset(&sdk_data , 0 ,sizeof(S_SDK_DATA));
|
||
|
||
//产品密钥
|
||
int len = strlen(sdk_data.product_key);
|
||
memset(sdk_data.product_key, 0x0, sizeof(sdk_data.product_key));
|
||
strncpy(sdk_data.product_key, meta.product_key, IOTX_PRODUCT_KEY_LEN);
|
||
sdk_data.product_key[IOTX_PRODUCT_KEY_LEN] = '\0';
|
||
|
||
//资产码
|
||
len = strlen(sdk_data.device_name);
|
||
memset(sdk_data.device_name, 0x0, sizeof(sdk_data.device_name));
|
||
strncpy(sdk_data.device_name, meta.device_name, IOTX_DEVICE_NAME_LEN);
|
||
sdk_data.device_name[IOTX_DEVICE_NAME_LEN] = '\0';
|
||
|
||
|
||
len = strlen(meta.device_secret);
|
||
memset(sdk_data.device_secret, 0x0, sizeof(meta.device_secret));
|
||
strncpy(sdk_data.device_secret, meta.device_secret, IOTX_DEVICE_SECRET_LEN);
|
||
sdk_data.device_secret[len] = '\0';
|
||
|
||
v_bs_gwsdk_set_para(0,&sdk_data); //存储三元组
|
||
return 0;
|
||
}
|
||
/** 事件回调: 证书读取 **/
|
||
static int evs_device_cert_get(evs_device_meta *meta)
|
||
{
|
||
//在这里实现证书三元组的读取,下面为示例获取成功返回0,如果证书为空返回-1
|
||
//U8_T i;
|
||
S_SDK_DATA sdk_data ;
|
||
|
||
memset(&sdk_data , 0 ,sizeof(S_SDK_DATA));
|
||
v_bs_gwsdk_set_para(1, &sdk_data); //获取三元组
|
||
|
||
int len = strlen(sdk_data.product_key);
|
||
if (len < 5)
|
||
{
|
||
return -1;
|
||
}
|
||
|
||
memset(meta->product_key, 0x0, sizeof(meta->product_key));
|
||
strncpy(meta->product_key, sdk_data.product_key, IOTX_PRODUCT_KEY_LEN);
|
||
meta->product_key[len] = '\0';
|
||
|
||
len = strlen(sdk_data.device_name);
|
||
if (len < 2)
|
||
{
|
||
return -1;
|
||
}
|
||
memset(meta->device_name, 0x0, sizeof(meta->device_name));
|
||
strncpy(meta->device_name, sdk_data.device_name, IOTX_DEVICE_NAME_LEN);
|
||
meta->device_name[len] = '\0';
|
||
|
||
|
||
len = strlen(sdk_data.device_secret);
|
||
if (len < 5)
|
||
{
|
||
return -1;
|
||
}
|
||
memset(meta->device_secret, 0x0, sizeof(meta->device_secret));
|
||
strncpy(meta->device_secret, sdk_data.device_secret, IOTX_DEVICE_SECRET_LEN);
|
||
meta->device_secret[len] = '\0';
|
||
|
||
return 0;
|
||
}
|
||
/** 事件回调: 设备注册码获取 **/
|
||
static int evs_device_reg_code_get(char *device_reg_code)
|
||
{
|
||
//在这里实现注册码的读取操作,读取成功返回注册码长度,如果注册码为NULL或读取失败返回-1
|
||
S_SDK_DATA sdk_data ;
|
||
|
||
memset(&sdk_data , 0 ,sizeof(S_SDK_DATA));
|
||
v_bs_gwsdk_set_para(1, &sdk_data); //获取三元组
|
||
|
||
int len = strlen(sdk_data.device_reg_code);
|
||
memset(device_reg_code, 0x0, IOTX_DEVICE_REG_CODE_LEN);
|
||
strncpy(device_reg_code, sdk_data.device_reg_code, IOTX_DEVICE_REG_CODE_LEN);
|
||
device_reg_code[len] = '\0';
|
||
|
||
return strlen(device_reg_code);
|
||
}
|
||
/** 事件回调: 设备唯一编码获取 **/
|
||
static int evs_device_uid_get(char *device_uid)
|
||
{
|
||
//在这里实现注册码的读取操作,读取成功返回注册码长度,如果注册码为NULL或读取失败返回-1
|
||
|
||
S_SDK_DATA sdk_data ;
|
||
|
||
memset(&sdk_data , 0 ,sizeof(S_SDK_DATA));
|
||
v_bs_gwsdk_set_para(1, &sdk_data); //获取三元组
|
||
|
||
int len = strlen(sdk_data.device_uid);
|
||
memset(device_uid, 0x0, IOTX_DEVICE_UID_LEN);
|
||
strncpy(device_uid, sdk_data.device_uid, IOTX_DEVICE_UID_LEN);
|
||
device_uid[len] = '\0';
|
||
return strlen(device_uid);
|
||
}
|
||
/******************************************需用户实现的回调函数*************************************************/
|
||
/**设备日志查询
|
||
* @brief Reply IOT platform log query service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_query_log(evs_service_query_log *param, evs_service_feedback_query_log *result)
|
||
{
|
||
result->gunNo = param->gunNo;
|
||
result->startDate = param->startDate;
|
||
result->stopDate = param->stopDate;
|
||
result->askType = param->askType;
|
||
|
||
return 0;
|
||
}
|
||
|
||
/** 设备维护指令服务
|
||
* @brief Reply IOT platform device control service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_dev_maintain(evs_service_dev_maintain *param)
|
||
{
|
||
/*
|
||
11: 重启
|
||
12: 检修 (充电设备可以提供服务)
|
||
13: 冻结(充电设备不提供充电服务)
|
||
14: 投运 (充电设备提供服务)
|
||
15: 停运 (充电设备不提供充电服务)
|
||
16: 退运 (充电设备不提供充电服务)
|
||
17: 恢复出厂设置
|
||
18: 硬重启(充电桩断电重启)
|
||
*/
|
||
|
||
|
||
return 0;
|
||
}
|
||
|
||
/** 枪锁控制
|
||
* @brief Reply IOT platform chargeGun e-lock control service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_lockCtrl(evs_service_lockCtrl *param)//在收到云端下发的请求回调中发送枪锁控制结果
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
|
||
/** 接收计费模型
|
||
* @brief Reply IOT platform feemodel issue service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_issue_feeModel(evs_service_issue_feeModel *param, evs_service_feedback_feeModel *result)
|
||
{
|
||
int i=0;
|
||
int j=0;
|
||
Plat_Comm_LOG("接收费率信息\n");
|
||
|
||
U8_T fee_id[NUM_64] = {0};
|
||
|
||
u8_get_str_data(0, E_STR_FEE_ID,0,fee_id,NUM_64); //获取系统资产吗
|
||
|
||
#if 1
|
||
if(u8_feeModle_save(param)) //存储费率
|
||
{
|
||
s_gwsdk_ctrl->txFlag_askFeeMode = 1; //标识置1,不再发送
|
||
}
|
||
|
||
if(strcmp((char *)fee_id , param->feeModelId ) != 0) //费率信息不一致 更新固件信息
|
||
{
|
||
s_gwsdk_ctrl->txFlag_firwareInfo = 0;
|
||
}
|
||
|
||
#endif
|
||
|
||
/*获取向平台的反馈参数*/
|
||
for(i=0;i<EVS_MAX_MODEL_ID_LEN;i++)
|
||
{
|
||
result->feeModelId[i]=param->feeModelId[i];
|
||
}
|
||
result->result = 10;
|
||
return 0;
|
||
}
|
||
|
||
/** sdk启动充电
|
||
* @brief Reply IOT platform remote start-charge service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_startCharge(evs_service_startCharge *param, evs_service_feedback_startCharge *result)
|
||
{
|
||
|
||
Plat_Comm_LOG("%d枪 接收启动充电控制\n", param->gunNo);
|
||
|
||
u8_gwsdk_start_charge_ctrl(param);
|
||
//回复
|
||
result->gunNo = param->gunNo;
|
||
memcpy(result->preTradeNo, param->preTradeNo, sizeof(result->preTradeNo)); //平台流水号
|
||
memcpy(result->tradeNo, param->preTradeNo, sizeof(result->tradeNo)); //设备流水号 - 这里用的平台流水号赋值
|
||
|
||
return 0;
|
||
}
|
||
|
||
|
||
/** 鉴权充电服务
|
||
* @brief Reply IOT platform authorization charge service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_authCharge(evs_service_authCharge *param, evs_service_feedback_authCharge *result)
|
||
{
|
||
U32_T u32_data = (E_SDK_START_TYPE)(E_SDK_STTY_VIN);
|
||
|
||
v_meterlog_set_char_log_info(param->gunNo - 1, E_METERLOG_SET_LOG_INFO_u32_sdk_startType , &u32_data, NULL);//启动方式
|
||
v_meterlog_set_char_log_info(param->gunNo - 1, E_METERLOG_SET_LOG_INFO_char_preTradeNo , NULL, (U8_T *)param->preTradeNo);//获得启动流水号
|
||
|
||
s_bs_task_ctrl.s_bs_ctrl[s_gwsdk_ctrl->u8_bs_flag].s_gundata[param->gunNo - 1].txFlag_autoRwsult = param->result;//鉴权结果
|
||
s_bs_task_ctrl.s_bs_ctrl[s_gwsdk_ctrl->u8_bs_flag].s_gundata[param->gunNo - 1].txFlag_autoStart = 0; //桩主动申请启动充电标志清0
|
||
|
||
//回复信息
|
||
memcpy(result->preTradeNo, param->preTradeNo, sizeof(result->preTradeNo));//流水号
|
||
memcpy(result->tradeNo, param->tradeNo, sizeof(result->tradeNo));//流水号
|
||
result->gunNo = param->gunNo;
|
||
|
||
return 0;
|
||
}
|
||
|
||
/** sdk停止充电
|
||
* @brief Reply IOT platform remote stop-charge service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_stopCharge(evs_service_stopCharge *param, evs_service_feedback_stopCharge *result)
|
||
{
|
||
Plat_Comm_LOG("%d枪 接收停止充电控制\n", param->gunNo);
|
||
u8_gwsdk_stop_chaege_ctrl(param);
|
||
|
||
//回复
|
||
result->gunNo = param->gunNo;
|
||
memcpy(result->preTradeNo, param->preTradeNo, sizeof(result->preTradeNo));
|
||
memcpy(result->tradeNo, param->preTradeNo, sizeof(result->tradeNo));
|
||
|
||
return 0;
|
||
}
|
||
|
||
|
||
/** 预约充电
|
||
* @brief Reply IOT platform reservation charge service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_rsvCharge(evs_service_rsvCharge *param, evs_service_feedback_rsvCharge *result)
|
||
{
|
||
|
||
return 0;
|
||
}
|
||
|
||
/** 交易记录上送成功确认
|
||
* @brief Reply IOT platform transaction confirm service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_confirmTrade(evs_service_confirmTrade *param, void *result)
|
||
{
|
||
S_LOG_DATA t_log ; //获取充电日志数据
|
||
|
||
v_bs_get_gun_log_data(param->gunNo-1 , &t_log);
|
||
|
||
if(param->errcode==10)//交易记录确认正确
|
||
{
|
||
//保存充电次数和充电时长
|
||
if(s_bs_task_ctrl.s_bs_ctrl[s_gwsdk_ctrl->u8_bs_flag].s_gundata[param->gunNo-1].txFlag_tradUpload != 0)
|
||
{
|
||
s_gwsdk_ctrl->s_gwsdk_gun[param->gunNo-1].u16_charge_cnt += 1;//充电次数加一
|
||
s_gwsdk_ctrl->s_gwsdk_gun[param->gunNo-1].u32_charge_time += t_log.u16_ChargedTime ; //充电时间累加
|
||
}
|
||
|
||
s_bs_task_ctrl.s_bs_ctrl[s_gwsdk_ctrl->u8_bs_flag].s_gundata[param->gunNo-1].txFlag_tradUpload = 0;
|
||
Plat_Comm_LOG("%d枪交易记录已确认!\n",(param->gunNo-1));
|
||
}
|
||
else
|
||
{
|
||
s_bs_task_ctrl.s_bs_ctrl[s_gwsdk_ctrl->u8_bs_flag].s_gundata[param->gunNo-1].txFlag_tradUpload = 1;
|
||
Plat_Comm_LOG("%d枪交易记录未确认!\n",(param->gunNo-1));
|
||
}
|
||
|
||
v_bs_logUploadOk_updateInfo(s_bs_task_ctrl.s_bs_ctrl[s_gwsdk_ctrl->u8_bs_flag].s_gundata[param->gunNo-1].u16_cmplte_bill_index); //上送成功,更新管理文件及上送标记
|
||
|
||
return 0;
|
||
}
|
||
|
||
/**地锁控制服务
|
||
* @brief Reply IOT platform smart ground locker service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_grounLock_ctrl(evs_service_groundLock_ctrl *param, evs_service_feedback_groundLock_ctrl *result)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
/** TODO 智能门锁控制服务(门禁?)
|
||
* @brief Reply IOT platform smart gate locker service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_gateLock_ctrl(evs_service_gateLock_ctrl *param, evs_service_feedback_gateLock_ctrl *result)
|
||
{
|
||
result->lockNo = 1;
|
||
result->result = 10;
|
||
// DEVICE_EXAMPLE_TRACE("evs_gate_lock_service:param is ctrlFlag: %d, result is lockNo: %d \n", param->ctrlFlag, param->lockNo);
|
||
return 0;
|
||
}
|
||
|
||
/************直流功率调节控制与交流有序充电共用回调****************/
|
||
/**有序充电策略服务
|
||
* @brief Reply IOT platform order-charge strategy service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_orderCharge(evs_service_orderCharge *param, evs_service_feedback_orderCharge *result)
|
||
{
|
||
U8_T flag = 1;
|
||
|
||
if(flag){//设置成功
|
||
result->result = 10;
|
||
result->reason = 10;
|
||
}
|
||
else{
|
||
result->result = 11;
|
||
result->reason = 11;
|
||
}
|
||
|
||
return 1;
|
||
}
|
||
|
||
/**设备配置信息查询服务
|
||
* @brief Reply IOT platform device configuration get service by result through SDK.
|
||
*---
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_get_config(evs_data_dev_config *result)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
/**获取维护状态
|
||
* @brief Reply IOT platform device configuration get service by result through SDK.
|
||
*---
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_get_maintain_status(evs_service_feedback_maintain_query *result)
|
||
{
|
||
if(s_gwsdk_ctrl->u8_bs_state_type == 0)
|
||
{
|
||
result->ctrlType = 14;
|
||
result->result = 10;
|
||
}
|
||
else
|
||
{
|
||
result->ctrlType = s_gwsdk_ctrl->u8_bs_state_type;
|
||
result->result = 10;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
/** 设备配置数据更新
|
||
* @brief Reply IOT platform update devicce configuration service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_update_config(evs_data_dev_config *param, int *result)
|
||
{
|
||
|
||
|
||
*result = 10;
|
||
return 0;
|
||
}
|
||
|
||
/** 事件回调: 功能配置更新服务
|
||
* @brief Reply IOT platform update devicce function configuration service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_update_fun_config(evs_service_dev_fun_config *param, evs_service_feedback_dev_fun_config *result)
|
||
{
|
||
return 0;
|
||
}
|
||
/** 事件回调: 查询设备功能配置服务
|
||
* @brief Reply IOT platform get devicce function configuration service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_get_fun_config(evs_service_get_dev_fun_config *param, evs_service_dev_fun_config *result)
|
||
{
|
||
|
||
return 0;
|
||
}
|
||
|
||
/** 事件回调: 蓝牙秘钥更新服务
|
||
* @brief Reply IOT platform update ble secret service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_ble_secret_update(evs_service_blesecret_update *param, evs_service_feedback_blesecret_update *result)
|
||
{
|
||
// HAL_Printf("blesecretKey : %s , updateTime : %d\n", param->bleSecretKey, param->updateTime);
|
||
memcpy(result->bleSecretKey, param->bleSecretKey, sizeof(param->bleSecretKey));
|
||
result->result = 10;
|
||
return 0;
|
||
}
|
||
|
||
/** 事件回调: 蓝牙MAC鉴权列表查询服务
|
||
* @brief Reply IOT platform ble auth list get service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_ble_plug_charge_info_get(evs_event_ble_plug_charge_info *result)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
/** 事件回调: 蓝牙MAC鉴权列表确认服务
|
||
* @brief Reply IOT platform ble auth list confirm service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_ble_plug_charge_info_conf(evs_service_ble_plug_charge_info_conf *param)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
/** 事件回调: 蓝牙MAC鉴权列表清除服务
|
||
* @brief Reply IOT platform ble auth list clean service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_ble_auth_list_clean(evs_service_blelist_clean *param, evs_service_feedback_blelist_clean *result)
|
||
{
|
||
result->cleanType = param->cleanType;
|
||
result->result = 10;
|
||
return 0;
|
||
}
|
||
|
||
/** 事件回调: 蓝牙即插即充重置服务
|
||
* @brief Reply IOT platform ble reset service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_ble_reset(evs_service_feedback_ble_reset *result)
|
||
{
|
||
result->result = 10;
|
||
return 0;
|
||
}
|
||
|
||
/** 事件回调: 查询设备计费模型服务
|
||
* @brief Reply IOT platform query feemodel service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_fee_model_query(evs_service_feedback_feeModel_qurey *result)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
/**
|
||
* @brief Reply IOT platform reserve charge service by param through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_reserve_charge(evs_service_rsvCharge *param, evs_service_feedback_rsvCharge *result)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
/** ota升级 需要动态申请内存,根据设备当前状态通过返回值确定是否升级
|
||
* @brief perform the ota order from IOT platform .
|
||
*---
|
||
* @param [in] version: @n the new firmware version received from IOT platform.
|
||
*
|
||
* @param [out] buffer: @n the ota buffer that need you to apply by malloc.
|
||
|
||
* @param [out] buffer_length: @n the buffer length of ota.
|
||
* @return do not update device -1 update device 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_ota_update(const char *version)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
/** 时间同步
|
||
* @brief send timestamp that Recived from IOT platform to user by timestamp through SDK.
|
||
*---
|
||
* @param [in] param: @n the param received from IOT platform.
|
||
* @param [out] result: @n the result data will be written by user of SDK.
|
||
* @return failed -1 success 0.
|
||
* @see None.
|
||
* @note None.
|
||
*/
|
||
int callback_service_time_sync(const unsigned int timestamp)//时间同步,如果是B枪的,告知B板, 还是是两板用一个对时???TODO
|
||
{
|
||
U8_T i,u8_flow_state;
|
||
s_bs_task_ctrl.s_gwsdk_ctrl.txFlag_synTime = 1;
|
||
for (i = 0; i < s_bs_task_ctrl.u8_gunCnt; i++)
|
||
{
|
||
u8_flow_state = u32_bs_get_sys_data(i,E_BS_GET_SYS_DATA_GUN_FLOW_STATE,0); //枪运行状态 0空闲 1插枪 2绝缘启机 3绝缘停止 4预充启动 5充电中 6充电停止 7停止完成
|
||
if(u8_flow_state > 1 && u8_flow_state != 7) //存在枪充电中 则不进行校时
|
||
return 0;
|
||
}
|
||
|
||
Comm_Time currtime;
|
||
xSeconds2Date(timestamp, &currtime); //将时间戳转换为当前时间
|
||
v_bs_set_time(&currtime);
|
||
|
||
Plat_Comm_LOG("接收:SDK下发校时\n");
|
||
Plat_Comm_LOG("时间戳=%d,转换为%d-%d-%d-%d-%d-%d\n",
|
||
timestamp,currtime.iYear,currtime.ucMonth,currtime.ucDay,currtime.ucHour,currtime.ucMin,currtime.ucSec);
|
||
|
||
return 0;
|
||
}
|
||
/*电表数据召测*/
|
||
int callback_meter_ack_srv(evs_service_meter_get *request, evs_service_feedback_meter_get *feedback)
|
||
{
|
||
return 0;
|
||
}
|
||
/* 充电桩部件配置服务*/
|
||
int callback_service_pile_parts_conf(evs_service_config_parts *request, evs_service_feedback_config_parts *feedback)
|
||
{
|
||
return 0;
|
||
}
|
||
/* 充电桩部件配置查询服务*/
|
||
int callback_service_pile_parts_conf_get(evs_service_parts_config_get *request, evs_service_feedback_config_parts_get *feedback)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
#endif
|
||
|
||
#if 1 //
|
||
//发送周期计数累加 1秒加一
|
||
static void v_sdk_timer_add()
|
||
{
|
||
U8_T i;
|
||
static ULONG time_old = 0;
|
||
ULONG time_ing = get_current_seconds(); //获取当前秒数
|
||
if(time_old != time_ing)
|
||
{
|
||
time_old = time_ing;
|
||
for (i = 0; i < GWSDK_TIMERCNT_NUM; i++)
|
||
{
|
||
if(s_gwsdk_ctrl->s_timerCnt[i].u16_timerCnt < s_gwsdk_ctrl->s_timerCnt[i].u16_timeNUM)
|
||
{
|
||
s_gwsdk_ctrl->s_timerCnt[i].u16_timerCnt ++;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//获取发送周期计数到时标志
|
||
static U8_T u8_sdk_timer_ctrl(SDK_SEND_TIMER cmd ,FLAG_CTLR flag)
|
||
{
|
||
U8_T ret = 0;
|
||
if(flag == CLEAR_FALG) //清空对应计时计数
|
||
{
|
||
s_gwsdk_ctrl->s_timerCnt[(U8_T)cmd].u16_timerCnt = 0;
|
||
ret = 1;
|
||
}
|
||
else if(s_gwsdk_ctrl->s_timerCnt[(U8_T)cmd].u16_timeNUM != 0 &&
|
||
s_gwsdk_ctrl->s_timerCnt[(U8_T)cmd].u16_timerCnt >= s_gwsdk_ctrl->s_timerCnt[(U8_T)cmd].u16_timeNUM)
|
||
{
|
||
s_gwsdk_ctrl->s_timerCnt[(U8_T)cmd].u16_timerCnt = 0;
|
||
ret = 1;
|
||
}
|
||
return ret;
|
||
}
|
||
#endif
|
||
|
||
#if 1 //回调函数注册
|
||
/****************************************************
|
||
*函数名称: v_evs_register()
|
||
*功能说明: sdk 自己库中回调函数功能实现
|
||
*参数说明:
|
||
* 输入参数:
|
||
* 输出参数:
|
||
****************************************************/
|
||
void v_evs_register() //注册回调函数
|
||
{
|
||
/* 注册回调函数 */
|
||
/** 事件回调: SDK充电枪电子锁控制回调 **/
|
||
EVS_RegisterCallback(EVS_CTRL_LOCK_SRV, callback_service_lockCtrl);
|
||
/** 事件回调: 充电桩智能门锁控制回调 **/
|
||
EVS_RegisterCallback(EVS_GATE_LOCK_SRV, callback_service_gateLock_ctrl);
|
||
/** 事件回调: 启动充电回调 **/
|
||
EVS_RegisterCallback(EVS_START_CHARGE_SRV, callback_service_startCharge);
|
||
/** 事件回调: 平台下发停止充电命令回调 **/
|
||
EVS_RegisterCallback(EVS_STOP_CHARGE_SRV, callback_service_stopCharge);
|
||
/** 事件回调: 平台下发启动充电鉴权结果回调 **/
|
||
EVS_RegisterCallback(EVS_AUTH_RESULT_SRV, callback_service_authCharge);
|
||
/** 事件回调: 查询设备配置服务 **/
|
||
EVS_RegisterCallback(EVS_CONF_GET_SRV, callback_service_get_config);
|
||
/** 事件回调: 参数配置服务 **/
|
||
EVS_RegisterCallback(EVS_CONF_UPDATE_SRV, callback_service_update_config);
|
||
/** 事件回调: 交易记录回调 **/
|
||
EVS_RegisterCallback(EVS_ORDER_CHECK_SRV, callback_service_confirmTrade);
|
||
/** 事件回调: 计量计费模型更新服务回调 **/
|
||
EVS_RegisterCallback(EVS_FEE_MODEL_UPDATE_SRV, callback_service_issue_feeModel);
|
||
/** 事件回调: 查询设备维护状态 **/
|
||
EVS_RegisterCallback(EVS_MAINTAIN_RESULT_SRV, callback_service_get_maintain_status);
|
||
/** 事件回调: 功能配置更新服务 **/
|
||
EVS_RegisterCallback(EVS_FUN_CONF_UPDATE_SRV, callback_service_update_fun_config);
|
||
/** 事件回调: 查询设备功能配置服务 **/
|
||
EVS_RegisterCallback(EVS_FUN_CONF_GET_SRV, callback_service_get_fun_config);
|
||
/** 事件回调: 查询设备计费模型服务 **/
|
||
EVS_RegisterCallback(EVS_FEE_MODEL_QUERY_SRV, callback_service_fee_model_query);
|
||
/** 事件回调: 预约充电服务 **/
|
||
EVS_RegisterCallback(EVS_RSV_CHARGE_SRV, callback_service_rsvCharge);
|
||
|
||
/** 事件回调: 蓝牙秘钥更新服务 **/
|
||
EVS_RegisterCallback(EVS_BLE_SECRET_UPDATE_SRV, callback_service_ble_secret_update);
|
||
/** 事件回调: 蓝牙MAC鉴权列表查询服务 **/
|
||
EVS_RegisterCallback(EVS_BLE_PLUG_CHG_INFO_GET_SRV, callback_service_ble_plug_charge_info_get);
|
||
/** 事件回调: 蓝牙MAC鉴权列表确认服务 **/
|
||
EVS_RegisterCallback(EVS_BLE_PLUG_CHG_INFO_CONF_SRV, callback_service_ble_plug_charge_info_conf);
|
||
/** 事件回调: 蓝牙MAC鉴权列表清除服务 **/
|
||
EVS_RegisterCallback(EVS_BLE_AUTH_LIST_CLEAN_SRV, callback_service_ble_auth_list_clean);
|
||
/** 事件回调: 蓝牙即插即充重置服务 **/
|
||
EVS_RegisterCallback(EVS_BLE_RESET_SRV, callback_service_ble_reset);
|
||
|
||
/** 事件回调: SDK内部运行状态打印 **/
|
||
EVS_RegisterCallback(EVS_STATE_EVERYTHING, evs_sdk_state_dump);
|
||
/** 建连成功事件回调 */
|
||
EVS_RegisterCallback(EVS_CONNECT_SUCC, evs_connected_event_handler);
|
||
/** 断开连接事件回调 */
|
||
EVS_RegisterCallback(EVS_DISCONNECTED, evs_disconnected_event_handler);
|
||
/** 事件回调:接收到云端回复的事件上报应答 **/
|
||
EVS_RegisterCallback(EVS_TRIGGER_EVENT_REPLY, evs_trigger_event_reply_event_handler);
|
||
/** 事件回调:接收到云端回复属性上报应答 **/
|
||
EVS_RegisterCallback(EVS_REPORT_REPLY, evs_report_reply_event_handler);
|
||
/** 事件回调:设备证书读取 **/
|
||
EVS_RegisterCallback(EVS_CERT_GET, evs_device_cert_get);
|
||
/** 事件回调:设备证书设置 **/
|
||
EVS_RegisterCallback(EVS_CERT_SET, evs_device_cert_set);
|
||
/** 事件回调:设备注册码获取 **/
|
||
EVS_RegisterCallback(EVS_DEVICE_REG_CODE_GET, evs_device_reg_code_get);
|
||
/** 事件回调:设备唯一码获取 **/
|
||
EVS_RegisterCallback(EVS_DEVICE_UID_GET, evs_device_uid_get);
|
||
/** 事件回调:时钟同步回调 **/
|
||
EVS_RegisterCallback(EVS_TIME_SYNC, callback_service_time_sync);
|
||
/** 事件回调:ota升级服务回调 **/
|
||
EVS_RegisterCallback(EVS_OTA_UPDATE, callback_service_ota_update);
|
||
/** 事件回调:电表数据召测 **/
|
||
EVS_RegisterCallback(EVS_Meter_ASK_SRV,callback_meter_ack_srv);
|
||
/** 事件回调:日志数据召测 **/
|
||
EVS_RegisterCallback(EVS_QUE_DATA_SRV,callback_service_query_log);
|
||
/** 事件回调:设备维护配置 **/
|
||
EVS_RegisterCallback(EVS_DEV_MAINTAIN_SRV,callback_service_dev_maintain);
|
||
/** 事件回调: 充电桩部件配置服务*/
|
||
EVS_RegisterCallback(EVS_PILE_PARTS_CONF_SRV,callback_service_pile_parts_conf);
|
||
/** 事件回调: 充电桩部件配置查询服务*/
|
||
EVS_RegisterCallback(EVS_PILE_PARTS_CONF_GET_SRV,callback_service_pile_parts_conf_get);
|
||
|
||
/** 事件回调: 功率调节*/
|
||
EVS_RegisterCallback(EVS_ORDERLY_CHARGE_SRV,callback_service_orderCharge);
|
||
|
||
|
||
}
|
||
#endif
|
||
|
||
#if 1 //发送组帧相关
|
||
static void v_firmware_info_send() //固件信息
|
||
{
|
||
evs_event_firmware_info fireware_info; //固件信息
|
||
gw_get_firmware_data(&fireware_info);
|
||
Plat_Comm_LOG("固件信息上报\n");
|
||
evs_send_event(EVS_CMD_EVENT_FIRMWARE_INFO, &fireware_info); //固件信息
|
||
}
|
||
static void v_ver_info_send() //版本信息
|
||
{
|
||
evs_event_ver_info ver_info;
|
||
gw_get_ver_data(&ver_info);
|
||
|
||
Plat_Comm_LOG("版本信息上报\n");
|
||
evs_send_event(EVS_CMD_EVENT_VER_INFO, &ver_info);
|
||
}
|
||
static void vPack_event_ask_dev_config() //设备配置请求
|
||
{
|
||
evs_send_event(EVS_CMD_EVENT_ASK_DEV_CONFIG,NULL);
|
||
}
|
||
static void v_devMduInfoEvt_send() //设备组件信息
|
||
{
|
||
evs_event_devmdu_info devInfo_data;
|
||
gw_get_devInfo_data(&devInfo_data);
|
||
Plat_Comm_LOG("发送:设备组件信息上报\n");
|
||
evs_send_event(EVS_CMD_EVENT_DEVMDU_INFO, &devInfo_data);
|
||
}
|
||
static void v_time_sync_send() //校时
|
||
{
|
||
Plat_Comm_LOG("校时发送\n");
|
||
evs_linkkit_time_sync();
|
||
}
|
||
static void vInitAskFeeModel() //费率请求
|
||
{
|
||
evs_event_ask_feeModel ask_feeModel;
|
||
memset(&ask_feeModel , 0 ,sizeof(evs_event_ask_feeModel));
|
||
Plat_Comm_LOG("费率请求\n");
|
||
//memcpy(ask_feeModel.feeModelId, g_t_share_data.t_sys_var_cfg.s_fee_model.u8_model_no, strlen((char*)g_t_share_data.t_sys_var_cfg.s_fee_model.u8_model_no));
|
||
evs_send_event(EVS_CMD_EVENT_ASK_FEEMODEL, &ask_feeModel);
|
||
}
|
||
static void vPack_event_alarm(U8_T u8_gunNo) //故障告警记录上送
|
||
{
|
||
evs_event_alarm event_alarm;
|
||
|
||
gw_get_alarm_data(&event_alarm,u8_gunNo);
|
||
|
||
Plat_Comm_LOG("%d发送故障总数:faultSum=%d\n",u8_gunNo,event_alarm.faultSum);
|
||
evs_send_event(EVS_CMD_EVENT_ALARM, &event_alarm);
|
||
|
||
}
|
||
static void vPack_pile_property() //直流设备属性上报
|
||
{
|
||
evs_property_dcPile dcPile_data;
|
||
gw_getPilePropertyData(&dcPile_data);
|
||
Plat_Comm_LOG("发送:直流设备属性上报\n");
|
||
evs_send_property(EVS_CMD_PROPERTY_DCPILE, &dcPile_data);
|
||
}
|
||
static void v_real_log_send(U8_T gunNo) //获取正常充电订单信息
|
||
{
|
||
evs_event_tradeInfo tradeInfo_data;
|
||
gw_get_log_info(0,gunNo,&tradeInfo_data);
|
||
|
||
if(tradeInfo_data.reason == E_FAULT_13067) //如果停止原因为即插即充鉴权失败则不上送订单
|
||
return;
|
||
|
||
evs_send_event(EVS_CMD_EVENT_TRADEINFO, &tradeInfo_data);
|
||
Plat_Comm_LOG("%d枪充电订单上送,订单号=%s\n",gunNo,tradeInfo_data.preTradeNo);
|
||
}
|
||
static void vPack_event_startChargeAuthEvt(U8_T gunNo) //组即插即充数据上传帧
|
||
{
|
||
evs_event_startCharge AuthData;
|
||
gw_get_Auth_Data(&AuthData,gunNo);
|
||
evs_send_event(EVS_CMD_EVENT_STARTCHARGE, &AuthData);
|
||
Plat_Comm_LOG("%d枪发送:即插即充启动 vin= %s\n",gunNo,AuthData.authCode);
|
||
}
|
||
static void vPack_property_dc_nonWork(U8_T u8_gunNo) //非工作状态上送
|
||
{
|
||
|
||
evs_property_dc_nonWork nonWork_data;
|
||
gw_get_dc_nonWork(&nonWork_data,u8_gunNo);
|
||
evs_send_property(EVS_CMD_PROPERTY_DC_NONWORK, &nonWork_data);
|
||
Plat_Comm_LOG("%d发送:非充电中实时属性上报\n",u8_gunNo);
|
||
}
|
||
static void vPack_property_dc_Work(U8_T u8_gunNo) //工作中实时状态上送
|
||
{
|
||
evs_property_dc_work work_data;
|
||
|
||
gw_get_dc_work(&work_data,u8_gunNo);
|
||
Plat_Comm_LOG("发送:%d枪充电中实时监测属性上报\n",u8_gunNo);
|
||
evs_send_property(EVS_CMD_PROPERTY_DC_WORK, &work_data);
|
||
}
|
||
static void vPack_event_BMS_data(U8_T gunNo) //bms属性上报
|
||
{
|
||
return;
|
||
|
||
evs_property_BMS BMSData;
|
||
|
||
gw_get_dc_BMS_Data(&BMSData, gunNo);
|
||
evs_send_property(EVS_CMD_PROPERTY_BMS, &BMSData);
|
||
Plat_Comm_LOG("%d枪发送:BMS上报\n",gunNo);
|
||
}
|
||
static void vPack_outMeter_data(U8_T gunNo) //电表数据上报
|
||
{
|
||
#if 0 //交流电表值
|
||
evs_property_dc_input_meter work_data;
|
||
gw_get_meter_data(&work_data,gunNo);
|
||
evs_send_property(EVS_CMD_PROPERTY_DC_INPUT_METER, &work_data);
|
||
logMsg_bs("%d枪发送:电表数据上报= %d\n",gunNo,work_data.sumMeter);
|
||
#endif
|
||
|
||
evs_property_meter work_data;
|
||
gw_get_DC_meter_data(&work_data,gunNo);
|
||
evs_send_property(EVS_CMD_PROPERTY_DC_OUTMETER, &work_data);
|
||
Plat_Comm_LOG("%d枪发送:电表数据上报= %d\n",gunNo,work_data.sumMeter);
|
||
}
|
||
static void vPack_event_startResult(U8_T gunNo) //充电启动结果
|
||
{
|
||
evs_event_startResult event_startResult;
|
||
|
||
gw_get_startResult_info(gunNo,&event_startResult);
|
||
evs_send_event(EVS_CMD_EVENT_STARTRESULT, &event_startResult);
|
||
Plat_Comm_LOG("%d枪启动结果上送,res= %d ,故障= %d",gunNo,event_startResult.startResult,event_startResult.faultCode);
|
||
printf("%d枪启动结果上送,res= %d ,故障= %d\r\n",gunNo+1,event_startResult.startResult,event_startResult.faultCode);
|
||
}
|
||
static void vPack_event_stopResult(U8_T gunNo) //停止充电结果
|
||
{
|
||
evs_event_stopCharge event_stopResult;
|
||
|
||
gw_get_stopResult_info(gunNo,&event_stopResult);
|
||
evs_send_event(EVS_CMD_EVENT_STOPCHARGE, &event_stopResult);
|
||
Plat_Comm_LOG("%d枪停止结果上送,res= %d",gunNo,event_stopResult.stopResult);
|
||
printf("%d枪停止结果上送,res= %d\r\n",gunNo+1,event_stopResult.stopResult);
|
||
}
|
||
static void vPack_event_DCpile_change(U8_T gunNo) //充电枪连接信息变更上送
|
||
{
|
||
evs_event_pile_stutus_change pile_status_change;
|
||
gw_get_gunlink_data(&pile_status_change,gunNo);
|
||
//Plat_Comm_LOG("%d枪,插枪动作= %d ,时间戳= %u\n",gunNo,pile_status_change.connCheckStatus,pile_status_change.yxOccurTime);
|
||
evs_send_event(EVS_CMD_EVENT_DCPILE_CHANGE, &pile_status_change);//充电枪状态事件上传
|
||
}
|
||
#endif
|
||
|
||
#if 1 //发送控制相关
|
||
|
||
/**
|
||
* ************************************************************************
|
||
* @brief - 故障信息变化检查
|
||
*
|
||
*
|
||
* @return U8_T - 0未变化 1变化
|
||
*
|
||
* @author jiankalka
|
||
* @date 2025-09-20
|
||
* ************************************************************************
|
||
*/
|
||
static U8_T u8_cheak_fault()
|
||
{
|
||
static U8_T u8_old_fault_num=0;
|
||
U8_T u8_fault_num,ret = 0;
|
||
|
||
u8_fault_num = u32_bs_get_sys_data(0,E_BS_GET_SYS_DATA_NOW_FAULT_ALARM_NUM,0) +
|
||
u32_bs_get_sys_data(0,E_BS_GET_SYS_DATA_NOW_FAULT_ALARM_NUM,1); //获取故障 告警数量
|
||
|
||
if(u8_fault_num != u8_old_fault_num)
|
||
{
|
||
u8_old_fault_num = u8_fault_num;
|
||
ret = 1;
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
/**
|
||
* ************************************************************************
|
||
* @brief - 充电启停结果上送检查
|
||
*
|
||
* @param[in] u8_gunNo - 枪号
|
||
*
|
||
* @return U8_T - 0未变化 1上送启动结果 2上送停止结果
|
||
*
|
||
* @author jiankalka
|
||
* @date 2025-09-20
|
||
* ************************************************************************
|
||
*/
|
||
static U8_T u8_charge_start_cheak(U8_T u8_gunNo)
|
||
{
|
||
static U8_T u8_old_flow_state[GUN_MAX_CNT] = {0};
|
||
U8_T u8_get_flow_state = u8_bs_get_flow_state(u8_gunNo); //获取终端状态 0 空闲 1开始充电 2充电中
|
||
U8_T u8_ret = 0;
|
||
|
||
if(u8_get_flow_state != u8_old_flow_state[u8_gunNo])
|
||
{
|
||
if((u8_old_flow_state[u8_gunNo] == 1) &&
|
||
(u8_get_flow_state == 0 || u8_get_flow_state == 2) ) //从启动中变到充中 或 空闲 -上送启动结果
|
||
{
|
||
u8_ret = 1;
|
||
}
|
||
else if((u8_old_flow_state[u8_gunNo] == 2) &&
|
||
(u8_get_flow_state == 0 ) ) //从充电中变为 空闲 -上送停止结果
|
||
{
|
||
u8_ret = 2;
|
||
}
|
||
u8_old_flow_state[u8_gunNo] = u8_get_flow_state;
|
||
}
|
||
|
||
return u8_ret;
|
||
}
|
||
/**
|
||
* ************************************************************************
|
||
* @brief - 抢连接变化检查
|
||
*
|
||
* @param[in] u8_gunNo - 抢号 0-N
|
||
*
|
||
* @return U8_T - 0未变化 1已经变化
|
||
*
|
||
* @author jiankalka
|
||
* @date 2025-09-20
|
||
* ************************************************************************
|
||
*/
|
||
static U8_T u8_cheak_gunlink(U8_T u8_gunNo)
|
||
{
|
||
static U8_T u8_old_gunLink[GUN_MAX_CNT] = {0};
|
||
U8_T u8_gunLink = u32_bs_get_sys_data(u8_gunNo,E_BS_GET_SYS_DATA_GUN_STATE,0); //获取枪连接状态 0未连接 1已连接
|
||
|
||
if(u8_gunLink != u8_old_gunLink[u8_gunNo])
|
||
{
|
||
u8_old_gunLink[u8_gunNo] = u8_gunLink;
|
||
return 1;
|
||
}
|
||
return 0;
|
||
}
|
||
static void v_sdk_send_mag_ctrl()
|
||
{
|
||
U8_T i,u8_data; //临时变量 使用前注意赋值
|
||
U8_T u8_gunCnt = s_bs_task_ctrl.u8_gunCnt;
|
||
U8_T u8_get_flow_state[GUN_MAX_CNT];
|
||
S_BS_CTRL_DATA *s_bs_ctrl = &s_bs_task_ctrl.s_bs_ctrl[s_gwsdk_ctrl->u8_bs_flag]; //获取控制数据
|
||
|
||
v_cheak_state_change(); //枪状态变位检查
|
||
|
||
//固件信息上送 上送一次
|
||
if(s_gwsdk_ctrl->txFlag_firwareInfo == 0)
|
||
{
|
||
v_firmware_info_send() ;
|
||
s_gwsdk_ctrl->txFlag_firwareInfo = 1;
|
||
return;
|
||
}
|
||
|
||
//版本信息上送标志 上送一次
|
||
if(s_gwsdk_ctrl->txFlag_versInfo == 0)
|
||
{
|
||
v_ver_info_send();
|
||
s_gwsdk_ctrl->txFlag_versInfo = 1;
|
||
return;
|
||
}
|
||
|
||
//配置信息更新请求 上送一次
|
||
if(s_gwsdk_ctrl->txFlag_cfgInfoUpdate == 0)
|
||
{
|
||
vPack_event_ask_dev_config();
|
||
s_gwsdk_ctrl->txFlag_cfgInfoUpdate = 1;
|
||
return;
|
||
}
|
||
|
||
//设备组件信息上报 上送一次
|
||
if(s_gwsdk_ctrl->txFlag_devMduInfoEvt == 0)
|
||
{
|
||
v_devMduInfoEvt_send();
|
||
s_gwsdk_ctrl->txFlag_devMduInfoEvt = 1;
|
||
return;
|
||
}
|
||
|
||
//校时请求
|
||
if(s_gwsdk_ctrl->txFlag_synTime == 0) //未校时 5秒发一下 已经校时,24小时校时一次
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_REQUSET].u16_timeNUM = 5; //秒 校时
|
||
else
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_REQUSET].u16_timeNUM = 0xFFFF; //秒 校时
|
||
|
||
if(u8_sdk_timer_ctrl(SDK_TIMER_REQUSET,GET_FLAG) == 1)
|
||
{
|
||
v_time_sync_send();
|
||
return;
|
||
}
|
||
|
||
//请求费率
|
||
if(s_gwsdk_ctrl->txFlag_askFeeMode == 0 &&
|
||
u8_sdk_timer_ctrl(SDK_TIMER_FEE_REQ,GET_FLAG) == 1)
|
||
{
|
||
vInitAskFeeModel();
|
||
return;
|
||
}
|
||
|
||
//直流设备属性上报 且600秒周期
|
||
if(u8_sdk_timer_ctrl(SDK_TIMER_DC_DEV_INFO,GET_FLAG) == 1)
|
||
{
|
||
vPack_pile_property() ;
|
||
return;
|
||
}
|
||
|
||
/*以下是多枪状态信息上传 采用的是上送数据种类优先的方案,而不是上送枪位置优先的方案
|
||
*/
|
||
//交易记录
|
||
for(i=0; i<u8_gunCnt; i++)
|
||
{
|
||
u8_data = 0;
|
||
if(s_bs_ctrl->s_gundata[i].txFlag_tradUpload == 1)
|
||
{
|
||
if( s_bs_ctrl->s_gundata[i].u8_tradUpload_cnt < 6) //充电中 只发6次
|
||
u8_data = 1;
|
||
}
|
||
else
|
||
s_bs_ctrl->s_gundata[i].u8_tradUpload_cnt = 0;
|
||
|
||
if(u8_data == 1 && u8_sdk_timer_ctrl((SDK_SEND_TIMER) (SDK_TIMER_TRADE_INFO + i),GET_FLAG) == 1)
|
||
{
|
||
v_real_log_send(i);
|
||
s_bs_ctrl->s_gundata[i].u8_tradUpload_cnt ++;
|
||
return;
|
||
}
|
||
}
|
||
|
||
//即插即充
|
||
for(i=0; i<u8_gunCnt; i++)
|
||
{
|
||
u8_data = 0;
|
||
if(s_bs_ctrl->s_gundata[i].txFlag_autoStart == 1)
|
||
{
|
||
vPack_event_startChargeAuthEvt(i);
|
||
s_bs_ctrl->s_gundata[i].txFlag_autoStart = 0;
|
||
return;
|
||
}
|
||
}
|
||
|
||
//充电/空闲实时信息上报
|
||
for(i=0; i<u8_gunCnt; i++)
|
||
{
|
||
u8_get_flow_state[i] = u8_bs_get_flow_state(i); //获取终端状态 0 空闲 1开始充电 2充电中
|
||
|
||
if(u8_get_flow_state[i] == 2) //充电中
|
||
{
|
||
//当状态由变化时 前3帧按10秒发送--u8_real_state_cnt 0x00-0x0F 充电中计数 0x10-0x1F 非充电中计数
|
||
s_gwsdk_ctrl->s_gwsdk_gun[i].u8_real_state_cnt &= 0x0F; //清除高位计数值
|
||
if(s_gwsdk_ctrl->s_gwsdk_gun[i].u8_real_state_cnt < 3)
|
||
{
|
||
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_REAL_WORK_GUN + i].u16_timeNUM = 10; //前3帧 10秒周期上送
|
||
}
|
||
else
|
||
{
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_REAL_WORK_GUN + i].u16_timeNUM = s_gwsdk_ctrl->u16_work_info_period; //上送周期等于充电数据上送周期设置值
|
||
}
|
||
|
||
if(u8_sdk_timer_ctrl((SDK_SEND_TIMER)(SDK_TIMER_REAL_WORK_GUN + i),GET_FLAG) == 1)
|
||
{
|
||
vPack_property_dc_Work(i);
|
||
if(s_gwsdk_ctrl->s_gwsdk_gun[i].u8_real_state_cnt < 3)
|
||
s_gwsdk_ctrl->s_gwsdk_gun[i].u8_real_state_cnt ++;
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//当状态由变化时 前3帧按10秒发送--u8_real_state_cnt 0x00-0x0F 充电中计数 0x10-0x1F 非充电中计数
|
||
s_gwsdk_ctrl->s_gwsdk_gun[i].u8_real_state_cnt &= 0xF0; //清除高位计数值
|
||
if(s_gwsdk_ctrl->s_gwsdk_gun[i].u8_real_state_cnt < 0x30)
|
||
{
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_REAL_WORK_GUN + i].u16_timeNUM = 10; //前3帧 10秒周期上送
|
||
}
|
||
else
|
||
{
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_REAL_WORK_GUN + i].u16_timeNUM = s_gwsdk_ctrl->u16_free_info_period; //上送周期等于充电数据上送周期设置值
|
||
}
|
||
|
||
if(u8_sdk_timer_ctrl((SDK_SEND_TIMER)(SDK_TIMER_REAL_WORK_GUN + i),GET_FLAG) == 1)
|
||
{
|
||
vPack_property_dc_nonWork(i);
|
||
if(s_gwsdk_ctrl->s_gwsdk_gun[i].u8_real_state_cnt < 0x30)
|
||
s_gwsdk_ctrl->s_gwsdk_gun[i].u8_real_state_cnt += 0x10;
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
//BMS属性上报
|
||
for(i=0; i<u8_gunCnt; i++)
|
||
{
|
||
u8_data = 0;
|
||
u8_get_flow_state[i] = u8_bs_get_flow_state(i); //获取终端状态 0 空闲 1开始充电 2充电中
|
||
|
||
if(u8_get_flow_state[i] == 2 )
|
||
{
|
||
if( s_bs_ctrl->s_gundata[i].u8_bms_sendCnt < 6) //充电中 只发6次
|
||
u8_data = 1;
|
||
}
|
||
else
|
||
s_bs_ctrl->s_gundata[i].u8_bms_sendCnt = 0;
|
||
|
||
if(u8_data == 1 && u8_sdk_timer_ctrl((SDK_SEND_TIMER)(SDK_TIMER_PROPERTY_BMS + i),GET_FLAG) == 1)
|
||
{
|
||
vPack_event_BMS_data(i);
|
||
s_bs_ctrl->s_gundata[i].u8_bms_sendCnt ++;
|
||
return;
|
||
}
|
||
}
|
||
|
||
//电表数据上送
|
||
for(i=0; i<u8_gunCnt; i++)
|
||
{
|
||
if(u8_sdk_timer_ctrl((SDK_SEND_TIMER)(SDK_TIMER_METER_INFO + i),GET_FLAG) == 1)
|
||
{
|
||
vPack_outMeter_data(i);
|
||
return;
|
||
}
|
||
}
|
||
|
||
// 启动结果 -- 枪连接变化
|
||
for(i=0; i<s_bs_task_ctrl.u8_gunCnt; i++)
|
||
{
|
||
u8_data = u8_charge_start_cheak(i);
|
||
if(u8_data == 1) //上送启动结果
|
||
{
|
||
vPack_event_startResult(i);
|
||
return;
|
||
}
|
||
else if(u8_data == 2 && s_bs_ctrl->s_gundata[i].txFlag_tradUpload == 1) //上送停止结果,防止上送停机结果时停机原因未赋值
|
||
{
|
||
vPack_event_stopResult(i);
|
||
return;
|
||
}
|
||
|
||
if(u8_cheak_gunlink(i) == 1)// 枪连接状态变位检查
|
||
{
|
||
vPack_event_DCpile_change(i);
|
||
return;
|
||
}
|
||
}
|
||
|
||
//故障告警信息上送
|
||
u8_data = u8_cheak_fault();
|
||
for(i=0; i<u8_gunCnt; i++)
|
||
{
|
||
if(u8_data == 1 || u8_sdk_timer_ctrl((SDK_SEND_TIMER)(SDK_TIMER_FAULT_INFO + i),GET_FLAG) == 1)
|
||
{
|
||
u8_sdk_timer_ctrl((SDK_SEND_TIMER)(SDK_TIMER_FAULT_INFO + i),CLEAR_FALG); //清空计数
|
||
vPack_event_alarm(i);
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
#endif
|
||
|
||
#if 1 //外部控制
|
||
/****************************************************
|
||
*函数名称: v_sdk_init_data()
|
||
*功能说明: 程序运行前 参数初始化
|
||
*参数说明:
|
||
* 输入参数:
|
||
* 输出参数: 0失败 1成功
|
||
****************************************************/
|
||
void v_sdk_init_data(U8_T bs_flag)
|
||
{
|
||
U8_T i;
|
||
v_evs_register(); //注册回调函数
|
||
|
||
s_gwsdk_ctrl = &s_bs_task_ctrl.s_gwsdk_ctrl; //获取控制数据
|
||
|
||
memset(s_gwsdk_ctrl,0,sizeof(S_GWSDK_CTRL_DATA));
|
||
s_gwsdk_ctrl->u8_bs_flag = bs_flag; //
|
||
|
||
//s_bs_task_ctrl.s_bs_ctrl[bs_flag].u8_netType = 0; //4G
|
||
s_bs_task_ctrl.s_bs_ctrl[bs_flag].fd = -1;
|
||
s_bs_task_ctrl.s_bs_ctrl[bs_flag].ulong_restart_timer = get_current_seconds();
|
||
|
||
//周期发送控制初始化
|
||
s_gwsdk_ctrl->u16_work_info_period = 30; //工作实时状态 上送周期
|
||
s_gwsdk_ctrl->u16_free_info_period = 180; //空闲实时状态 上送周期
|
||
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_REQUSET].u16_timeNUM = 0xFFFF; //秒 校时
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_REQUSET].u16_timerCnt = 0xFFFF; //确保立马执行 18小时
|
||
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_FEE_REQ].u16_timeNUM = 30; //秒 费率请求
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_DC_DEV_INFO].u16_timeNUM = 600; //秒 直流设备属性上报
|
||
|
||
for ( i = 0; i < GUN_MAX_CNT; i++)
|
||
{
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_REAL_WORK_GUN + i].u16_timeNUM = 30; //秒 工作实时状态
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_REAL_WORK_GUN + i].u16_timerCnt = 0xFFFF;
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_TRADE_INFO + i].u16_timeNUM = 30; //秒 订单信息上送
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_PROPERTY_BMS + i].u16_timeNUM = 30; //秒 BMS 属性周期上送
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_METER_INFO + i].u16_timeNUM = 60*60; //秒 电表低值上送
|
||
s_gwsdk_ctrl->s_timerCnt[SDK_TIMER_FAULT_INFO + i].u16_timeNUM = 600; //秒 故障信息上报
|
||
}
|
||
}
|
||
/****************************************************
|
||
*函数名称: v_sdk_tcp_connect()
|
||
*功能说明: TCP连接功能实现 - 检查三元组
|
||
*参数说明:
|
||
* 输入参数:
|
||
* 输出参数: 0失败 1成功
|
||
****************************************************/
|
||
U8_T v_sdk_tcp_connect()
|
||
{
|
||
char res = -1;
|
||
U8_T u8_ret = 0;
|
||
char reg_code[NUM_64] = {0};
|
||
char dev_uid[NUM_64] = {0};
|
||
|
||
u8_get_str_data(GUN_NULL, E_STR_SDK_PARA_device_reg_code,0,(U8_T *)reg_code,NUM_64); //获取注册码
|
||
u8_get_str_data(GUN_NULL, E_STR_SDK_PARA_device_uid ,0,(U8_T *)dev_uid, NUM_64); //获取桩编号
|
||
|
||
#ifdef ACCESS_PLATFORM
|
||
int test_type = 1; //连接接入调试平台
|
||
#else
|
||
#ifdef PLATFORM_IS_DEBUG
|
||
int test_type = 2; //连接测试平台
|
||
#else
|
||
int test_type = 0; //连接正式平台
|
||
#endif
|
||
#endif
|
||
//注册码、sn码申请三元组区分
|
||
if(strlen((const char*)reg_code) != 0)
|
||
res = evs_linkkit_new(test_type, 0);//注册码
|
||
else if(strlen((const char*)dev_uid) != 0)
|
||
res = evs_linkkit_new(test_type, 1);//桩编号
|
||
|
||
if(res == 0)
|
||
u8_ret = 1;
|
||
|
||
return u8_ret;
|
||
}
|
||
/****************************************************
|
||
*函数名称: v_sdk_logo_on()
|
||
*功能说明: 平台桩信息登录 -
|
||
*参数说明:
|
||
* 输入参数:
|
||
* 输出参数: 0失败 1成功
|
||
****************************************************/
|
||
U8_T v_sdk_logo_on()
|
||
{
|
||
evs_mainloop();//联网 - 登录包含其中 问:如何返回结果,内部定义一个联网标识,接收到登录成功结果后 返回1
|
||
|
||
static U32_T u32_timer = 0;
|
||
static U8_T u8_timer = 0;
|
||
|
||
if(u8_timer >5) //5*2 10分钟离线,系统重启
|
||
{
|
||
v_sys_reboot();
|
||
}
|
||
else if(u32_timer == 0)
|
||
{
|
||
u32_timer = get_current_seconds();
|
||
}
|
||
else if(u32_safe_seconds_since(u32_timer) > 60*2) //2分钟离线,重新配置串口
|
||
{
|
||
v_4g_config();
|
||
//MX_UART7_Init();
|
||
u8_timer ++;
|
||
u32_timer = get_current_seconds();
|
||
}
|
||
|
||
if(s_gwsdk_ctrl->gw_connet_flag == 1)
|
||
{
|
||
u32_timer = 0;
|
||
u8_timer = 0;
|
||
return 1;
|
||
}
|
||
else
|
||
return 0;
|
||
|
||
}
|
||
/****************************************************
|
||
*函数名称: v_sdk_recv_data()
|
||
*功能说明: 数据接收处理 -
|
||
*参数说明:
|
||
* 输入参数:
|
||
* 输出参数:
|
||
****************************************************/
|
||
void v_sdk_recv_data()
|
||
{
|
||
static U8_T u8_cnt1 = 0;
|
||
v_sdk_timer_add() ; //周期计数累加
|
||
|
||
if(u8_cnt1++ < 5) //100ms sdk数据发生量较大 常规100ms周期可能不足以发送完所需数据 因此做延时上送
|
||
return;
|
||
u8_cnt1 = 0;
|
||
evs_mainloop();//联网 - 接收包含
|
||
}
|
||
/**
|
||
* ************************************************************************
|
||
* @brief - 发送控制函数
|
||
*
|
||
*
|
||
*
|
||
* @author jiankalka
|
||
* @date 2025-09-19
|
||
* ************************************************************************
|
||
*/
|
||
void v_sdk_send_ctrl()
|
||
{
|
||
static U8_T u8_cnt = 0;
|
||
v_sdk_timer_add() ; //周期计数累加
|
||
|
||
if(u8_cnt++ < 5) //100ms sdk数据发生量较大 常规100ms周期可能不足以发送完所需数据 因此做延时上送
|
||
return;
|
||
u8_cnt = 0;
|
||
|
||
v_sdk_send_mag_ctrl(); //发送控制
|
||
}
|
||
/****************************************************
|
||
*函数名称: v_sdk_private_crel()
|
||
*功能说明: sdk私有协议逻辑控制 - 固件、版本、设备组件信息上报
|
||
*参数说明:
|
||
* 输入参数:
|
||
* 输出参数:
|
||
****************************************************/
|
||
void v_sdk_private_crel(U8_T u8_flag)
|
||
{
|
||
|
||
}
|
||
#endif
|
||
|
||
#endif
|