Merge branch 'master' of gitee.com:hnuyuelurm/basic_framework

This commit is contained in:
NeoZng 2022-12-05 16:35:25 +08:00
commit 3947c48230
6 changed files with 207 additions and 0 deletions

View File

@ -133,6 +133,7 @@ modules/super_cap/super_cap.c \
modules/can_comm/can_comm.c \
modules/message_center/message_center.c \
modules/monitor/monitor.c \
modules/vofa/vofa.c \
application/gimbal/gimbal.c \
application/chassis/chassis.c \
application/shoot/shoot.c \
@ -230,6 +231,7 @@ C_INCLUDES = \
-Imodules/can_comm \
-Imodules/message_center \
-Imodules/monitor \
-Imodules/vofa \
-Imodules/
# compile gcc flags

View File

@ -0,0 +1,47 @@
/*
* @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"
static SuperCapInstance *super_cap_instance = NULL;
static void SuperCapRxCallback(can_instance *_instance)
{
static uint8_t *rxbuff;
static SuperCap_Msg_s *Msg;
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));
super_cap_instance->recv_data_len = supercap_config->recv_data_len;
super_cap_instance->send_data_len = supercap_config->send_data_len;
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)
{
CANSetDLC(instance->can_ins, 8);
memcpy(instance->can_ins->tx_buff, data, instance->send_data_len);
CANTransmit(instance->can_ins);
}
SuperCap_Msg_s SuperCapGet(SuperCapInstance *instance)
{
return instance->cap_msg;
}

View File

@ -0,0 +1,50 @@
/*
* @Descripttion:
* @version:
* @Author: Chenfu
* @Date: 2022-12-02 21:32:47
* @LastEditTime: 2022-12-05 15:25:46
*/
#ifndef SUPER_CAP_H
#define SUPER_CAP_H
#include "bsp_can.h"
typedef struct
{
uint16_t vol;
uint16_t current;
uint16_t power;
}SuperCap_Msg_s;
#pragma pack(1)
typedef struct
{
can_instance* can_ins;
/* 发送部分 */
uint8_t send_data_len;
uint8_t raw_sendbuf;
/* 接收部分 */
uint8_t recv_data_len;
uint8_t raw_recvbuff;
SuperCap_Msg_s cap_msg;
} SuperCapInstance;
#pragma pack()
typedef struct
{
can_instance_config_s can_config;
uint8_t send_data_len;
uint8_t recv_data_len;
} SuperCap_Init_Config_s;
SuperCapInstance *SuperCapInit(SuperCap_Init_Config_s* supercap_config);
void SuperCapSend(SuperCapInstance *instance, uint8_t *data);
#endif // !SUPER_CAP_Hd

View File

@ -0,0 +1,54 @@
<!--
* @Descripttion:
* @version:
* @Author: Chenfu
* @Date: 2022-12-02 21:32:47
* @LastEditTime: 2022-12-05 15:27:57
-->
# super_can
## 代码结构
.h中放置的是数据定义和外部接口以及协议的定义和宏.c中包含一些私有函数。
## 外部接口
```c
SuperCapInstance *SuperCapInit(SuperCap_Init_Config_s* supercap_config);
void SuperCapSend(SuperCapInstance *instance, uint8_t *data);
```
## 私有函数和变量
```c
static SuperCapInstance *super_cap_instance = NULL;
static uint8_t *rxbuff;
static void SuperCapRxCallback(can_instance *_instance)
```
`SuperCapRxCallback()`是super cap初始化can实例时的回调函数用于can接收中断进行协议解析。
## 使用范例
初始化时设置如下:
```c
SuperCap_Init_Config_s capconfig = {
.can_config = {
.can_handle = &hcan1,
.rx_id = 0x301,
.tx_id = 0x302
},
.recv_data_len = 4*sizeof(uint16_t),
.send_data_len = sizeof(uint8_t)
};
SuperCapInstance *ins =SuperCapInit(&capconfig);
```
发送通过`SuperCapSend()`,建议使用强制类型转换:
```c
uint16_t tx = 0x321;
SuperCapSend(ins, (uint8_t*)&tx);
```

33
modules/vofa/vofa.c Normal file
View File

@ -0,0 +1,33 @@
/*
* @Descripttion:
* @version:
* @Author: Chenfu
* @Date: 2022-12-05 12:39:07
* @LastEditTime: 2022-12-05 14:15:53
*/
#include "vofa.h"
/*VOFA浮点协议*/
void vofa_justfloat_output(float *data, uint8_t num , UART_HandleTypeDef *huart )
{
static uint8_t i = 0;
send_float temp[num]; //定义缓冲区数组
uint8_t send_data[4 * num + 4]; //定义通过串口传出去的数组数量是所传数据的字节数加上4个字节的尾巴
for (i = 0; i < num; i++)
{
temp[i].float_t = data[i]; //将所传数据移到缓冲区数组
}
for (i = 0; i < num; i++)
{
send_data[4 * i] = temp[i].uint8_t[0];
send_data[4 * i + 1] = temp[i].uint8_t[1];
send_data[4 * i + 2] = temp[i].uint8_t[2];
send_data[4 * i + 3] = temp[i].uint8_t[3]; //将缓冲区数组内的浮点型数据转成4个字节的无符号整型之后传到要通过串口传出的数组里
}
send_data[4 * num] = 0x00;
send_data[4 * num + 1] = 0x00;
send_data[4 * num + 2] = 0x80;
send_data[4 * num + 3] = 0x7f; //加上协议要求的4个尾巴
HAL_UART_Transmit(huart, (uint8_t *)send_data, 4 * num + 4, 100);
}

21
modules/vofa/vofa.h Normal file
View File

@ -0,0 +1,21 @@
/*
* @Descripttion:
* @version:
* @Author: Chenfu
* @Date: 2022-12-05 12:39:18
* @LastEditTime: 2022-12-05 13:37:36
*/
#ifndef VOFA_H
#define VOFA_H
#include <stdint-gcc.h>
#include "bsp_usart.h"
#include "usart.h"
typedef union
{
float float_t;
uint8_t uint8_t[4];
} send_float;
void vofa_justfloat_output(float *data, uint8_t num , UART_HandleTypeDef *huart);
#endif // !1#define