2022-12-05 15:59:47 +08:00
|
|
|
/*
|
|
|
|
* @Descripttion:
|
|
|
|
* @version:
|
|
|
|
* @Author: Chenfu
|
|
|
|
* @Date: 2022-12-02 21:32:47
|
|
|
|
* @LastEditTime: 2022-12-05 15:29:49
|
|
|
|
*/
|
|
|
|
#include "super_cap.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "stdlib.h"
|
2022-12-14 13:33:19 +08:00
|
|
|
|
2023-02-14 11:13:32 +08:00
|
|
|
static SuperCapInstance *super_cap_instance = NULL; // 可以由app保存此指针
|
2022-12-05 15:59:47 +08:00
|
|
|
|
2022-12-05 21:01:26 +08:00
|
|
|
static void SuperCapRxCallback(CANInstance *_instance)
|
2022-12-05 15:59:47 +08:00
|
|
|
{
|
2023-03-23 18:22:24 +08:00
|
|
|
uint8_t *rxbuff;
|
|
|
|
SuperCap_Msg_s *Msg;
|
2022-12-05 15:59:47 +08:00
|
|
|
rxbuff = _instance->rx_buff;
|
|
|
|
Msg = &super_cap_instance->cap_msg;
|
|
|
|
Msg->vol = (uint16_t)(rxbuff[0] << 8 | rxbuff[1]);
|
|
|
|
Msg->current = (uint16_t)(rxbuff[2] << 8 | rxbuff[3]);
|
|
|
|
Msg->power = (uint16_t)(rxbuff[4] << 8 | rxbuff[5]);
|
|
|
|
}
|
|
|
|
|
|
|
|
SuperCapInstance *SuperCapInit(SuperCap_Init_Config_s *supercap_config)
|
|
|
|
{
|
|
|
|
super_cap_instance = (SuperCapInstance *)malloc(sizeof(SuperCapInstance));
|
|
|
|
memset(super_cap_instance, 0, sizeof(SuperCapInstance));
|
2023-01-01 12:45:07 +08:00
|
|
|
|
2022-12-05 15:59:47 +08:00
|
|
|
supercap_config->can_config.can_module_callback = SuperCapRxCallback;
|
|
|
|
super_cap_instance->can_ins = CANRegister(&supercap_config->can_config);
|
|
|
|
return super_cap_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuperCapSend(SuperCapInstance *instance, uint8_t *data)
|
|
|
|
{
|
2022-12-05 21:01:26 +08:00
|
|
|
memcpy(instance->can_ins->tx_buff, data, 8);
|
2023-01-03 22:53:49 +08:00
|
|
|
CANTransmit(instance->can_ins,1);
|
2022-12-05 15:59:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SuperCap_Msg_s SuperCapGet(SuperCapInstance *instance)
|
|
|
|
{
|
|
|
|
return instance->cap_msg;
|
|
|
|
}
|