加入vofa
This commit is contained in:
91
Header/vofa_client.h
Normal file
91
Header/vofa_client.h
Normal file
@@ -0,0 +1,91 @@
|
||||
#ifndef __VOFA_CLIENT_H__
|
||||
#define __VOFA_CLIENT_H__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define VOFA_CLIENT_COM_INTERFACE (1) // 0:串口 1:USB-CDC 2:自定义
|
||||
#define VOFA_RECEIVE_CH (32) // 接收通道数,最大256个通道
|
||||
#define VOFA_SEND_CH (32) // 发送通道数
|
||||
|
||||
#if VOFA_CLIENT_COM_INTERFACE == 0
|
||||
#include "uart.h"
|
||||
|
||||
#define VOFA_CLIENT_UART_PORT UART_1 // 串口号
|
||||
#define VOFA_CLIENT_UART_BAUDRATE 115200 // 波特率
|
||||
#define VOFA_CLIENT_UART_RX UART1_RX_P30 // 串口接收引脚
|
||||
#define VOFA_CLIENT_UART_TX UART1_TX_P31 // 串口发送引脚
|
||||
#define VOFA_CLIENT_UART_TIM TIM_0 // 串口定时器
|
||||
|
||||
#elif VOFA_CLIENT_COM_INTERFACE == 1
|
||||
#include "stc32_stc8_usb.h"
|
||||
|
||||
|
||||
#elif VOFA_CLIENT_COM_INTERFACE == 2
|
||||
// 填写自定义接口的相关信息
|
||||
|
||||
#endif
|
||||
|
||||
typedef union
|
||||
{
|
||||
uint8 send[4];
|
||||
float fdata;
|
||||
}float_data;
|
||||
|
||||
extern float vofa_data[VOFA_RECEIVE_CH]; // 记录接收数据
|
||||
extern uint8 vofa_receive_new_data[VOFA_RECEIVE_CH]; // 接收新数据标志位,需手动置零
|
||||
extern float vofa_last_data; // 最后一次接收数据
|
||||
extern uint8 vofa_last_ch; // 最后一次接收通道
|
||||
|
||||
extern uint8 rev_count;
|
||||
|
||||
typedef enum{
|
||||
Format_Invalid,
|
||||
Format_Mono,
|
||||
Format_MonoLSB,
|
||||
Format_Indexed8,
|
||||
Format_RGB32,
|
||||
Format_ARGB32,
|
||||
Format_ARGB32_Premultiplied,
|
||||
Format_RGB16,
|
||||
Format_ARGB8565_Premultiplied,
|
||||
Format_RGB666,
|
||||
Format_ARGB6666_Premultiplied,
|
||||
Format_RGB555,
|
||||
Format_ARGB8555_Premultiplied,
|
||||
Format_RGB888,
|
||||
Format_RGB444,
|
||||
Format_ARGB4444_Premultiplied,
|
||||
Format_RGBX8888,
|
||||
Format_RGBA8888,
|
||||
Format_RGBA8888_Premultiplied,
|
||||
Format_BGR30,
|
||||
Format_A2BGR30_Premultiplied,
|
||||
Format_RGB30,
|
||||
Format_A2RGB30_Premultiplied,
|
||||
Format_Alpha8,
|
||||
Format_Grayscale8,
|
||||
|
||||
// 以下格式发送时,IMG_WIDTH和IMG_HEIGHT不需要强制指定,设置为-1即可
|
||||
Format_BMP,
|
||||
Format_GIF,
|
||||
Format_JPG,
|
||||
Format_PNG,
|
||||
Format_PBM,
|
||||
Format_PGM,
|
||||
Format_PPM,
|
||||
Format_XBM,
|
||||
Format_XPM,
|
||||
Format_SVG,
|
||||
} ImgFormat ;
|
||||
|
||||
void VOFA_Data_Init(void);
|
||||
uint8 VOFA_Connection_Init(void);
|
||||
uint8 VOFA_Client_Init(void); // VOFA客户端初始化函数
|
||||
void VOFA_Set_JustFloat_Data(int CH, float dataa); // 设置某通道数据
|
||||
void VOFA_Set_JustFloat_Datas_From_Start(int num,...); // 设置从第一个通道开始的多个通道数据
|
||||
void VOFA_Send_Datas(int num); // 从第一个通道开始发送数据指定数量的数据
|
||||
void VOFA_Send_JustFloat_Image(uint32 IMG_ID, uint32 IMG_WIDTH, uint32 IMG_HEIGHT,uint32 IMG_DATA_SIZE, ImgFormat IMG_FORMAT,uint8* IMG_DATA); // 发送图像数据
|
||||
void VOFA_Receiver_Callback(void); // 接收回调函数,需要在主循环或者接受中断中调用
|
||||
|
||||
|
||||
#endif
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,9 @@
|
||||
#include "isr.h"
|
||||
#include "command.h"
|
||||
#include "ina226.h"
|
||||
#include "oled_iic_SSD1306.h"
|
||||
|
||||
extern uint8 send_flag;
|
||||
|
||||
//UART1中断
|
||||
void UART1_Isr() interrupt 4
|
||||
@@ -108,7 +111,7 @@ void INT4_Isr() interrupt 16
|
||||
|
||||
void TM0_Isr() interrupt 1
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
void TM1_Isr() interrupt 3
|
||||
{
|
||||
@@ -118,12 +121,12 @@ void TM1_Isr() interrupt 3
|
||||
void TM2_Isr() interrupt 12
|
||||
{
|
||||
TIM2_CLEAR_FLAG; //清除中断标志
|
||||
|
||||
|
||||
}
|
||||
void TM3_Isr() interrupt 19
|
||||
{
|
||||
TIM3_CLEAR_FLAG; //清除中断标志
|
||||
|
||||
}
|
||||
|
||||
void TM4_Isr() interrupt 20
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
#include "iic_soft.h"
|
||||
#include "printfs.h"
|
||||
#include "pwm.h"
|
||||
#include "vofa_client.h"
|
||||
|
||||
uint8 send_flag = 0;
|
||||
|
||||
uint8 mode[2] = INA226_DEF_MODE;
|
||||
// uint8 m5[2] = {0x0D, 0x1B};
|
||||
@@ -23,11 +25,15 @@ void main()
|
||||
P05 = 0;
|
||||
oled_init();
|
||||
INA226_Init(&ina226[0], INA226_DEF_ADDR, mode, 20, 5, 1.0683, 1.002393);
|
||||
VOFA_Client_Init();
|
||||
|
||||
pit_timer_ms(TIM_1,INA226_READ_TIME_MS);
|
||||
|
||||
pwm_init(PWMA_CH1P_P60,100000,5000);
|
||||
// pit_timer_ms(TIM_3,1000);
|
||||
|
||||
pwm_init(PWMA_CH1P_P60,500000,6000);
|
||||
|
||||
// pwm_init(PWMA_CH1P_P60,500000,6000);
|
||||
// oled_fill(0xff);
|
||||
|
||||
// iic_init(IIC_1,10);
|
||||
@@ -38,6 +44,38 @@ void main()
|
||||
// iic_scan();
|
||||
while(1)
|
||||
{
|
||||
// oled_p6x8str(0, 7, "BLOCK");
|
||||
VOFA_Set_JustFloat_Data(0, ina226[0].result.voltage_V);
|
||||
VOFA_Set_JustFloat_Data(1, ina226[0].result.current_A);
|
||||
VOFA_Set_JustFloat_Data(2, ina226[0].result.power_W);
|
||||
VOFA_Send_Datas(3);
|
||||
send_flag = 1;
|
||||
|
||||
// oled_printf_float(0, 0, ina226[0].result.voltage_V,2,4);oled_p6x8str(55, 0, "V");
|
||||
// oled_printf_float(0, 1, ina226[0].result.current_A,2,4);oled_p6x8str(55, 1, "A");
|
||||
// oled_printf_float(0, 2, ina226[0].result.power_W,2,4);oled_p6x8str(55, 2, "W");
|
||||
// oled_printf_float(0, 3, ina226[0].result.energy_J,5,2);oled_p6x8str(55, 3, "J");
|
||||
// oled_printf_float(0, 4, ina226[0].result.energy_J/3600.0f,5,3);oled_p6x8str(55, 4, "Wh");
|
||||
// oled_printf_float(0, 5, ina226[0].result.quantity_C,5,2);oled_p6x8str(55, 5, "C");
|
||||
// if(send_flag)
|
||||
// {
|
||||
oled_p6x8str(0, 7, "SENT");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// oled_p6x8str(0, 7, "BLOCK");
|
||||
// }
|
||||
send_flag = 0;
|
||||
if(vofa_receive_new_data[1])
|
||||
{
|
||||
vofa_receive_new_data[1] = 0;
|
||||
pwm_duty(PWMA_CH1P_P60, (uint32)(vofa_data[1]));
|
||||
}
|
||||
if(vofa_receive_new_data[2])
|
||||
{
|
||||
vofa_receive_new_data[2] = 0;
|
||||
pwm_freq(PWMA_CH1P_P60, (uint32)(vofa_data[2]),(uint32)(vofa_data[1]));
|
||||
}
|
||||
// soft_iic_scan(&ina226_soft_config);
|
||||
// uint8 vot[2] = {0};
|
||||
// uint8 cru[2] = {0};
|
||||
@@ -60,12 +98,7 @@ void main()
|
||||
// powt = (int16)(pow[0] << 8 | pow[1]);
|
||||
// powf = (float)powt * 0.30518*25 /1000.0f;
|
||||
|
||||
oled_printf_float(0, 0, ina226[0].result.voltage_V,2,4);oled_p6x8str(55, 0, "V");
|
||||
oled_printf_float(0, 1, ina226[0].result.current_A,2,4);oled_p6x8str(55, 1, "A");
|
||||
oled_printf_float(0, 2, ina226[0].result.power_W,2,4);oled_p6x8str(55, 2, "W");
|
||||
oled_printf_float(0, 3, ina226[0].result.energy_J,5,2);oled_p6x8str(55, 3, "J");
|
||||
oled_printf_float(0, 4, ina226[0].result.energy_J/3600.0f,5,3);oled_p6x8str(55, 4, "Wh");
|
||||
oled_printf_float(0, 5, ina226[0].result.quantity_C,5,2);oled_p6x8str(55, 5, "C");
|
||||
|
||||
// // oled_int16(0, 0, (int16)(vot[0] << 8 | vot[1]));
|
||||
// oled_int16(0, 1, vot[0]);
|
||||
// oled_int16(40, 1, vot[1]);
|
||||
@@ -84,7 +117,7 @@ void main()
|
||||
// {
|
||||
// oled_fill(0x00);
|
||||
// }
|
||||
// delay_ms(1000);
|
||||
delay_ms(3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "stc32_stc8_usb.h"
|
||||
|
||||
char *USER_DEVICEDESC = NULL;
|
||||
char *USER_PRODUCTDESC = NULL;
|
||||
char *USER_DEVICEDESC = "PowerMonitor";
|
||||
char *USER_PRODUCTDESC = "LHYe200";
|
||||
char *USER_STCISPCMD = "@STCISP#";
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ char *USER_STCISPCMD = "@STCISP#";
|
||||
只有返回0时才需要调用usb_OUT_done()进行手动收尾
|
||||
强烈建议usb_OUT_callback返回1
|
||||
************************************************/
|
||||
BOOL usb_OUT_callback()
|
||||
{
|
||||
USB_SendData(UsbOutBuffer,OutNumber); //发送数据缓冲区,长度(接收数据原样返回, 用于测试)
|
||||
// BOOL usb_OUT_callback()
|
||||
// {
|
||||
// USB_SendData(UsbOutBuffer,OutNumber); //发送数据缓冲区,长度(接收数据原样返回, 用于测试)
|
||||
|
||||
return 1;
|
||||
}
|
||||
// return 1;
|
||||
// }
|
||||
224
Source/vofa_client.c
Normal file
224
Source/vofa_client.c
Normal file
@@ -0,0 +1,224 @@
|
||||
#include "vofa_client.h"
|
||||
#include "fifo.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
float vofa_data[VOFA_RECEIVE_CH] = {0}; // 记录接收数据
|
||||
float vofa_last_data = 0;
|
||||
uint8 vofa_last_ch = -1;
|
||||
uint8 vofa_receive_new_data[VOFA_RECEIVE_CH] = {0}; // 接收新数据标志位
|
||||
uint8 rev_count = 0; // 接收计数
|
||||
uint8 rev_buffer[8] = {0}; // 接收缓冲区
|
||||
|
||||
uint8 failed_flag = 1;
|
||||
|
||||
|
||||
float_data fdata[VOFA_RECEIVE_CH + 1];
|
||||
// uint8 endian_flag = 0; // 大小端标志位
|
||||
uint8 tail[4] = {0x00, 0x00, 0x80, 0x7f};
|
||||
|
||||
// static inline void Chage_BS(uint8 *dataa)
|
||||
// {
|
||||
// if(endian_flag)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// for(int i = 0; i < 2; i++)
|
||||
// {
|
||||
// uint8 temp = dataa[i];
|
||||
// dataa[i] = dataa[3 - i];
|
||||
// dataa[3 - i] = temp;
|
||||
// }
|
||||
// }
|
||||
|
||||
void VOFA_Data_Init()
|
||||
{
|
||||
// unsigned int x = 1;
|
||||
// uint8 *endian_check = (uint8*)&x;
|
||||
// if(endian_check[0] != 1)
|
||||
// {
|
||||
// endian_flag = 0;
|
||||
// }
|
||||
// printf("flag:%d\n\r",endian_flag);
|
||||
memcpy(fdata[VOFA_SEND_CH].send, tail, sizeof(tail));
|
||||
|
||||
memset(vofa_data, 0, sizeof(vofa_data)); // 清除接收数据
|
||||
memset(vofa_receive_new_data, 0, sizeof(vofa_receive_new_data)); // 清除接收新数据标志位
|
||||
}
|
||||
|
||||
|
||||
uint8 VOFA_Connection_Init()
|
||||
{
|
||||
#if VOFA_CLIENT_COM_INTERFACE == 0
|
||||
// 使用串口通信
|
||||
uart_init(VOFA_CLIENT_UART_PORT, VOFA_CLIENT_UART_RX, VOFA_CLIENT_UART_TX, VOFA_CLIENT_UART_BAUDRATE, VOFA_CLIENT_UART_TIM); // 串口初始化
|
||||
#elif VOFA_CLIENT_COM_INTERFACE == 1
|
||||
// 使用USB-CDC通信
|
||||
// 初始化放clock_init.c里了
|
||||
|
||||
|
||||
#elif VOFA_CLIENT_COM_INTERFACE == 2
|
||||
// 填写自定义接口的初始化代码
|
||||
|
||||
#endif
|
||||
failed_flag = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
uint8 VOFA_Client_Init()
|
||||
{
|
||||
VOFA_Data_Init();
|
||||
return VOFA_Connection_Init();
|
||||
}
|
||||
|
||||
void VOFA_Sender(uint8 *p, uint32 len)
|
||||
{
|
||||
uint8 c_count = 0;
|
||||
uint32 t_count = 0;
|
||||
uint8 send_buff[60] = {0};
|
||||
if(failed_flag) // 如果初始化失败则不发送数据
|
||||
{
|
||||
return;
|
||||
}
|
||||
#if VOFA_CLIENT_COM_INTERFACE == 0
|
||||
uart_write_buffer(VOFA_CLIENT_UART_PORT,p,len);
|
||||
#elif VOFA_CLIENT_COM_INTERFACE == 1
|
||||
while(t_count<len)
|
||||
{
|
||||
send_buff[c_count++] = p[t_count++];
|
||||
if(c_count>=60 || t_count>=len)
|
||||
{
|
||||
USB_SendData(send_buff,c_count);
|
||||
c_count = 0;
|
||||
memset(send_buff,0,sizeof(send_buff));
|
||||
}
|
||||
}
|
||||
#elif VOFA_CLIENT_COM_INTERFACE == 2
|
||||
// 填写自定义接口的发送代码
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void VOFA_Receiver_Callback()
|
||||
{
|
||||
uint8 rev_tmp = 0;
|
||||
uint8 tmp[4] = {0};
|
||||
uint8 i = 0;
|
||||
if(failed_flag) // 如果初始化失败则不发送数据
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if VOFA_CLIENT_COM_INTERFACE == 0
|
||||
// while(uart_query_byte(VOFA_CLIENT_UART_PORT, &rev_tmp))
|
||||
// {
|
||||
#elif VOFA_CLIENT_COM_INTERFACE == 1
|
||||
for(i=0;i<OutNumber;i++)
|
||||
{
|
||||
rev_tmp=UsbOutBuffer[i];
|
||||
#elif VOFA_CLIENT_COM_INTERFACE == 2
|
||||
// 填写自定义接口的接收代码,每次获取一个字节循环进行处理
|
||||
#endif
|
||||
if(rev_tmp == 0xA6 && rev_buffer[0] != 0xA6) // 判断帧头
|
||||
{
|
||||
rev_count = 0; // 未收到帧头或者未正确包含帧头则重新接收
|
||||
}
|
||||
rev_buffer[rev_count++] = rev_tmp; // 保存数据
|
||||
if(rev_count >= 7) // 判断是否接收到指定数量的数据
|
||||
{
|
||||
if(rev_buffer[0] == 0xA6) // 判断帧头是否正确
|
||||
{
|
||||
if(rev_buffer[1] == rev_buffer[6] && rev_buffer[1] < VOFA_RECEIVE_CH)
|
||||
{
|
||||
tmp[3] = rev_buffer[2]; // 低字节
|
||||
tmp[2] = rev_buffer[3]; // 高字节
|
||||
tmp[1] = rev_buffer[4]; // 低字节
|
||||
tmp[0] = rev_buffer[5]; // 高字节
|
||||
// Chage_BS(tmp);
|
||||
vofa_last_ch = rev_buffer[1]; // 保存上次接收通道
|
||||
memcpy(&vofa_data[vofa_last_ch], tmp, 4); // 拷贝数据
|
||||
vofa_receive_new_data[rev_buffer[1]] = 1; // 接收新数据标志位置位
|
||||
vofa_last_data = vofa_data[vofa_last_ch]; // 保存上次接收数据
|
||||
}
|
||||
}
|
||||
rev_count = 0; // 清除缓冲区计数值
|
||||
rev_buffer[0] = 0; // 清除缓冲区数据
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void VOFA_Set_JustFloat_Data(int CH, float dataa)
|
||||
{
|
||||
int j = 0;
|
||||
fdata[CH].fdata = dataa;
|
||||
for(j = 0; j < 2; j++)
|
||||
{
|
||||
uint8 temp = fdata[CH].send[j];
|
||||
fdata[CH].send[j] = fdata[CH].send[3 - j];
|
||||
fdata[CH].send[3 - j] = temp;
|
||||
}
|
||||
// Chage_BS(fdata[CH].send);
|
||||
}
|
||||
|
||||
void VOFA_Set_JustFloat_Datas_From_Start(int num,...)
|
||||
{
|
||||
va_list Valist;
|
||||
int i = 0,j = 0;
|
||||
va_start(Valist, num);
|
||||
|
||||
for(i = 0; i < num; ++i)
|
||||
{
|
||||
fdata[i].fdata = va_arg(Valist, float);
|
||||
for(j = 0; j < 2; j++)
|
||||
{
|
||||
uint8 temp = fdata[i].send[j];
|
||||
fdata[i].send[j] = fdata[i].send[3 - j];
|
||||
fdata[i].send[3 - j] = temp;
|
||||
}
|
||||
// Chage_BS(fdata[i].send);
|
||||
}
|
||||
va_end(Valist);
|
||||
}
|
||||
|
||||
void VOFA_Send_JustFloat_Image(uint32 IMG_ID, uint32 IMG_WIDTH, uint32 IMG_HEIGHT,uint32 IMG_DATA_SIZE, ImgFormat IMG_FORMAT,uint8* IMG_DATA)
|
||||
{
|
||||
uint32 preFrame[7];
|
||||
uint8 preFrameData[28] = {0};
|
||||
preFrame[0] = IMG_ID;
|
||||
preFrame[1] = IMG_DATA_SIZE;
|
||||
preFrame[2] = IMG_WIDTH;
|
||||
preFrame[3] = IMG_HEIGHT;
|
||||
preFrame[4] = (uint32)IMG_FORMAT;
|
||||
preFrame[5] = 0x7F800000;
|
||||
preFrame[6] = 0x7F800000;
|
||||
// = {
|
||||
// IMG_ID,
|
||||
// IMG_DATA_SIZE,
|
||||
// IMG_WIDTH,
|
||||
// IMG_HEIGHT,
|
||||
// (int)IMG_FORMAT,
|
||||
// 0x7F800000,
|
||||
// 0x7F800000
|
||||
// };
|
||||
|
||||
memcpy(preFrameData, preFrame, sizeof(uint32)*7); // 拷贝预处理数据
|
||||
VOFA_Sender(preFrameData, sizeof(uint32)*7); // 发送预处理数据
|
||||
VOFA_Sender(IMG_DATA, IMG_DATA_SIZE); // 发送图像数据
|
||||
}
|
||||
|
||||
void VOFA_Send_Datas(int num)
|
||||
{
|
||||
uint8 *p = fdata[0].send;
|
||||
memcpy(fdata[num].send, tail, sizeof(tail));
|
||||
VOFA_Sender(p, 4 * (num + 1));
|
||||
}
|
||||
|
||||
BOOL usb_OUT_callback()
|
||||
{
|
||||
VOFA_Receiver_Callback();
|
||||
|
||||
return 1;
|
||||
}
|
||||
BIN
mu/设计1.ms14
Normal file
BIN
mu/设计1.ms14
Normal file
Binary file not shown.
BIN
mu/设计1.ms14 (Security copy)
Normal file
BIN
mu/设计1.ms14 (Security copy)
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user