20230731_XiaoFuZi_emb/ZheDaXiaoFuZi/Src/Usr/App/XfzTest.c
Rjh913828050 a8560d741e 类型:重构
内容:重新整理项目文件分类
人员:任家豪
2023-10-08 16:10:23 +08:00

315 lines
11 KiB
C

//#include <stdbool.h>
//#include <stdint.h>
//#include <stdio.h>
//#include <string.h>
//#include "McuBspAdc.h"
//#include "McuBspUart.h"
//#include "McuBspSpi.h"
//#include "McuBspSys.h"
//#include "McuBspI2c.h"
//#include "McuW25Q64JvssiqDrv.h"
//#include "McuWH-GN100Drv.h"
//#include "bme68x.h"
//#include "bme68x_defs.h"
//#include "ZthyToolDataTypeSwitch.h"
//#include "McuJY60Drv.h"
//W25Q64JVSSIQ_OBJ gFlashObj;
//static void FlashSpiCs(uint8_t flag);
//static unsigned char FlashReadWrite(uint8_t Data);
//char buf[5] = {0};
//float Lat;
//unsigned char LatFlag;
//float Lon;
//unsigned char LonFlag;
//char buf232[256] = {0};
//char buf485[256] = {0};
//char bufBlueTooth[256] = {0};
//float Ax;
//float Ay;
//float Az;
//float Wx;
//float Wy;
//float Wz;
//float Roll;
//float Pitch;
//float Yaw;
//float AdcValue1;
//float AdcValue2;
//float AdcValue3;
//float AdcValue4;
//float AdcValue5;
//float AdcValue6;
//float AdcValue7;
//float AdcValue8;
//float AdcValue9;
//float AdcValue10;
//float AdcValue11;
//float AdcValue12;
//float AdcValue13;
//float AdcValue14;
//float AdcValue15;
//float AdcValue16;
//float AdcValue17;
//static int Rs232Count = 0;
//static int Rs485Count = 0;
//static int BlueToothCount = 0;
//static int Rs485CountLocal = 0;
//static int BlueToothCountLocal = 0;
//#define ZTHY_MCU_TASK_BME680_IIC_ADDR 0xEC // 已经进行了一位偏移
//#define ZTHY_MCU_TASK_BME680_IIC_TYPE MCU_BSP_I2C_REG // 哪一种IIC通信(主从或者带寄存器)
//#define ZTHY_MCU_TASK_BME680_IIC_ID MCU_BSP_I2C2_ID // 使用那一路IIC进行通信
//static uint8_t gNfields = 0; // 数据内容是否为最新内容
//static struct bme68x_data gData = {0}; // BME680的采集数据
//static struct bme68x_dev gZthyMcuTaskBme680Dev = {0}; // 新建一个设备
//static uint8_t gZthyMcuTaskBme680DevId = ZTHY_MCU_TASK_BME680_IIC_ADDR; // 设备地址
//static uint32_t gZthyMcuTaskBme680Temp = 0; // 温度的4字节底层存储形式
//static uint32_t gZthyMcuTaskBme680Humi = 0; // 湿度的4字节底层存储形式
//static uint32_t gZthyMcuTaskBme680Press = 0; // 压力的4字节底层存储形式
//static int8_t ZthyMcuTaskBme680Init(void);
//static int8_t ZthyMcuTaskBme680Measure(void);
//static BME68X_INTF_RET_TYPE ZthyMcuTaskBme680Read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length,
// void *intf_ptr);
//static BME68X_INTF_RET_TYPE ZthyMcuTaskBme680Write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length,
// void *intf_ptr);
//static void ZthyMcuTaskBme680DelayUs(uint32_t period, void *intf_ptr);
//static void FlashRS232Recv(uint8_t data);
//static void FlashRS485Recv(uint8_t data);
//static void BluetoothRecv(uint8_t data);
//int main(void)
//{
// int rt;
// int i = 0;
// char buf[1024] = {0};
// /* 初始化系统时钟 */
// McuBspSysInit();
// /* 初始化串口输出 */
// McuBspUartInit(MCU_BSP_UART1_ID, NULL, NULL, FlashRS232Recv);
// McuBspUartInit(MCU_BSP_UART4_ID, NULL, NULL, FlashRS485Recv);
// McuBspUartInit(MCU_BSP_UART5_ID, NULL, NULL, BluetoothRecv);
// /* 初始化SPI */
// McuBspSpiInit(MCU_BSP_SPI3_ID);
// gFlashObj.SpiCs = FlashSpiCs;
// gFlashObj.SpiWriteReadByte = FlashReadWrite;
// gFlashObj.DelayUs = HAL_Delay;
// rt = W25Q64_Init(&gFlashObj);
// if (rt < 0) {
// rt = 0;
// }
// /* 初始化定位模块 */
// McuDrvWHGN100Init();
// /* BME680 */
// ZthyMcuTaskBme680Init();
// /* JY60 */
// McuDrvJy60Init();
// /* RS232 */
// McuBspUartStartRecv(MCU_BSP_UART1_ID);
// /*RS485*/
// McuBspUartStartRecv(MCU_BSP_UART4_ID);
// McuBspUartStartRecv(MCU_BSP_UART5_ID);
// /* ADcaiyang */
// McuBspAdcInit();
// /* 蓝牙测试 */
// McuBspUartStartRecv(MCU_BSP_UART4_ID);
// McuBspUartStartRecv(MCU_BSP_UART5_ID);
// McuBspGpioInit(GPIOD, GPIO_PIN_7,
// GPIO_MODE_OUTPUT_PP, GPIO_PULLDOWN,
// GPIO_SPEED_FREQ_HIGH, 0, NULL);
// McuBspGpioSetLevel(GPIOD, GPIO_PIN_7, MCU_BSP_GPIO_OUT_HIGH);
// rt = 0;
// while (1) {
//// rt = McuDrvWHGN100GetLatAndLon(&Lat, &LatFlag, &Lon, &LonFlag);
//// if (rt < 0) {
//// McuBspUartSend(MCU_BSP_UART1_ID, (uint8_t *)"POSITION ERR\r\n", strlen("POSITION ERR\r\n"));
//// } else {
//// McuBspUartSend(MCU_BSP_UART1_ID, (uint8_t *)"POSITION SUCCESS\r\n", strlen("POSITION SUCCESS\r\n"));
//// }
//
// W25Q64_WriteBytes(&gFlashObj, 0x00, (uint8_t *)"qwerasdfzxcv\r\n", strlen("qwerasdfzxcv\r\n"));
// W25Q64_ReadBytes(&gFlashObj, 0x08, (uint8_t *)buf, 5);
// if (buf[0] == 'z') {
// buf[1] = 'x';
// McuBspUartSend(MCU_BSP_UART1_ID, (uint8_t *)"Flash Success\r\n", strlen("Flash Success\r\n"));
// } else {
// McuBspUartSend(MCU_BSP_UART1_ID, (uint8_t *)"Flash ERR\r\n", strlen("Flash ERR\r\n"));
// }
//
// rt = ZthyMcuTaskBme680Measure();
// if (rt == 0) {
// McuBspUartSend(MCU_BSP_UART1_ID, (uint8_t *)"Bme680 Success\r\n", strlen("Bme680 Success\r\n"));
// } else {
// McuBspUartSend(MCU_BSP_UART1_ID, (uint8_t *)"Bme680 ERR\r\n", strlen("Bme680 ERR\r\n"));
// }
//
// McuDrvJy60GetData(&Ax, &Ay, &Az, &Wx, &Wy, &Wz, &Roll, &Pitch, &Yaw);
// sprintf(buf, "%0.2f,%0.2f,%0.2f,%0.2f,%0.2f,%0.2f,%0.2f,%0.2f,%0.2f\r\n",Ax, Ay, Az, Wx, Wy, Wz, Roll, Pitch, Yaw);
// McuBspUartSend(MCU_BSP_UART1_ID, (uint8_t *)buf, strlen(buf));
//
// McuBspAdcGetData(MCU_ADC1, &AdcValue1);
// McuBspAdcGetData(MCU_ADC4, &AdcValue4);
// McuBspAdcGetData(MCU_ADC5, &AdcValue5);
// McuBspAdcGetData(MCU_ADC6, &AdcValue6);
// McuBspAdcGetData(MCU_ADC7, &AdcValue7);
// McuBspAdcGetData(MCU_ADC8, &AdcValue8);
// McuBspAdcGetData(MCU_ADC9, &AdcValue9);
// McuBspAdcGetData(MCU_ADC10, &AdcValue10);
//
// sprintf(buf, "%0.2f,%0.2f,%0.2f,%0.2f,%0.2f,%0.2f,%0.2f,%0.2f\r\n",AdcValue1, AdcValue4,
// AdcValue5, AdcValue6, AdcValue7, AdcValue8, AdcValue9, AdcValue10);
// McuBspUartSend(MCU_BSP_UART1_ID, (uint8_t *)buf, strlen(buf));
//
// while (1) {
// if (Rs485CountLocal != Rs485Count) {
// HAL_Delay(50);
// McuBspUartSend(MCU_BSP_UART5_ID, (uint8_t *)&buf485[Rs485CountLocal], Rs485Count - Rs485CountLocal);
// Rs485Count = 0;
// Rs485CountLocal = 0;
// }
// if (BlueToothCountLocal != BlueToothCount) {
// HAL_Delay(50);
// McuBspUartSend(MCU_BSP_UART4_ID, (uint8_t *)&bufBlueTooth[BlueToothCountLocal], BlueToothCount - BlueToothCountLocal);
// BlueToothCount = 0;
// BlueToothCountLocal = 0;
// }
// i++;
// if (i >= 500) {
// i = 0;
// break;
// }
// }
// }
// return 0;
//}
//static void FlashRS232Recv(uint8_t data)
//{
// Rs232Count = Rs232Count % 256;
// buf232[Rs232Count] = data;
// Rs232Count++;
//}
//static void FlashRS485Recv(uint8_t data)
//{
// Rs485Count = Rs485Count % 256;
// buf485[Rs485Count] = data;
// Rs485Count++;
//}
//static void BluetoothRecv(uint8_t data)
//{
// BlueToothCount = BlueToothCount % 256;
// bufBlueTooth[BlueToothCount] = data;
// BlueToothCount++;
//}
///* Flash片选 */
//static void FlashSpiCs(uint8_t flag)
//{
// McuBspSpiCs(MCU_BSP_SPI3_ID, flag);
//}
///* Flash发送 */
//static unsigned char FlashReadWrite(uint8_t Data)
//{
// return McuBspSpiReadWriteByte(MCU_BSP_SPI3_ID, Data);
//}
///* BME680初始化 */
//static int8_t ZthyMcuTaskBme680Init(void)
//{
// int8_t rslt;
// struct bme68x_conf conf;
// struct bme68x_heatr_conf heatr_conf;
// McuBspI2cInit(ZTHY_MCU_TASK_BME680_IIC_ID);
// gZthyMcuTaskBme680Dev.amb_temp = 25;
// gZthyMcuTaskBme680Dev.read = ZthyMcuTaskBme680Read;
// gZthyMcuTaskBme680Dev.write = ZthyMcuTaskBme680Write;
// gZthyMcuTaskBme680Dev.intf = BME68X_I2C_INTF;
// gZthyMcuTaskBme680Dev.delay_us = ZthyMcuTaskBme680DelayUs;
// gZthyMcuTaskBme680Dev.intf_ptr = &gZthyMcuTaskBme680DevId;
// rslt = bme68x_init(&gZthyMcuTaskBme680Dev);
// if (rslt == BME68X_OK) {
// /* Set the temperature, pressure and humidity & filter settings */
// conf.filter = BME68X_FILTER_SIZE_3;
// conf.odr = BME68X_ODR_NONE;
// conf.os_hum = BME68X_OS_4X;
// conf.os_pres = BME68X_OS_4X;
// conf.os_temp = BME68X_OS_4X;
// /* Set the remaining gas sensor settings and link the heating profile */
// heatr_conf.enable = BME68X_DISABLE;
// heatr_conf.heatr_dur = 0;
// heatr_conf.heatr_temp = 0;
// rslt = bme68x_set_heatr_conf(BME68X_FORCED_MODE, &heatr_conf, &gZthyMcuTaskBme680Dev);
// if (rslt == BME68X_OK) {
// rslt = bme68x_set_conf(&conf, &gZthyMcuTaskBme680Dev);
// if (rslt == BME68X_OK) {
// return rslt;
// }
// }
// }
// return -1;
//}
//static int8_t ZthyMcuTaskBme680Measure(void)
//{
// int8_t rslt;
// gNfields = 0;
// /* 只有在FORCED_MODE下才能进行数据采集 */
// rslt = bme68x_set_op_mode(BME68X_FORCED_MODE, &gZthyMcuTaskBme680Dev);
// if (rslt != BME68X_OK) {
// return -1;
// }
// rslt = bme68x_get_data(BME68X_FORCED_MODE, &gData, &gNfields, &gZthyMcuTaskBme680Dev);
// if (rslt != BME68X_OK) {
// return -1;
// }
// rslt = bme68x_set_op_mode(BME68X_SLEEP_MODE, &gZthyMcuTaskBme680Dev);
// if (rslt != BME68X_OK) {
// return -1;
// }
// ZthyToolFloatToUint32(gData.temperature, &gZthyMcuTaskBme680Temp);
// ZthyToolFloatToUint32(gData.humidity, &gZthyMcuTaskBme680Humi);
// ZthyToolFloatToUint32(gData.pressure, &gZthyMcuTaskBme680Press);
// return 0;
//}
//static BME68X_INTF_RET_TYPE ZthyMcuTaskBme680Read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length,
// void *intf_ptr)
//{
// return (BME68X_INTF_RET_TYPE)McuBspI2cRecvData(ZTHY_MCU_TASK_BME680_IIC_TYPE, ZTHY_MCU_TASK_BME680_IIC_ID,
// *(uint8_t *)intf_ptr, reg_addr, I2C_MEMADD_SIZE_8BIT, reg_data, length);
//}
//static BME68X_INTF_RET_TYPE ZthyMcuTaskBme680Write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length,
// void *intf_ptr)
//{
// return (BME68X_INTF_RET_TYPE)McuBspI2cSendData(ZTHY_MCU_TASK_BME680_IIC_TYPE, ZTHY_MCU_TASK_BME680_IIC_ID,
// *(uint8_t *)intf_ptr, reg_addr, I2C_MEMADD_SIZE_8BIT, (uint8_t *)reg_data, length);
//}
//static void ZthyMcuTaskBme680DelayUs(uint32_t period, void *intf_ptr)
//{
// if (intf_ptr != NULL) {
// intf_ptr = NULL;
// }
// uint32_t i = 35; // 35 = 72 / 2 -1;
// while (period) {
// while (i) {
// i--;
// }
// period--;
// i = 35;
// }
//}