温度,pn,sn,生产时间和厂家,积分时间,像素长度等变量

This commit is contained in:
wantong
2024-01-31 15:17:21 +08:00
parent 0732984a64
commit c5b2a4e98b
42 changed files with 5275 additions and 8507 deletions

View File

@ -0,0 +1,12 @@
//
// Created by zhu on 2024/1/31.
//
#ifndef H750_CJSON_CONTROL_ADJUSTMENT_H
#define H750_CJSON_CONTROL_ADJUSTMENT_H
#include "stdint.h"
#include "stdio.h"
void Control_St(uint8_t st_time);
#endif //H750_CJSON_CONTROL_ADJUSTMENT_H

12
Core/Inc/Get_Parameters.h Normal file
View File

@ -0,0 +1,12 @@
//
// Created by zhu on 2024/1/31.
//
#ifndef H750_CJSON_GET_PARAMETERS_H
#define H750_CJSON_GET_PARAMETERS_H
#include "stdio.h"
float Get_Temperature();
#endif //H750_CJSON_GET_PARAMETERS_H

View File

@ -0,0 +1,16 @@
//
// Created by zhu on 2024/1/31.
//
#ifndef H750_CJSON_STORE_INFORMATION_H
#define H750_CJSON_STORE_INFORMATION_H
void Printf_Pn_Number();
void Printf_Sn_Number();
void Printf_Product_Time();
void Printf_Manufacturer();
void Printf_Device_Pixel_Length();
#endif //H750_CJSON_STORE_INFORMATION_H

View File

@ -5,13 +5,17 @@
#ifndef H750_CJSON_CJSON_TEST_H
#define H750_CJSON_CJSON_TEST_H
struct paramstruct {
int age;
float height;
int temperature;
int pn;
int sn;
int production_date;
int manufacturer;
int Device_Pixel_Length;
uint8_t Set_Integration_Time;
};
//void cjson(const char * g_usart_json_string);
void cjson(uint8_t g_usart_json_string[]);
void parseNestedObject(cJSON *nestedObject);
int Change_Age();
struct paramstruct *GetParametesptr();
void SV_Change_Age();
#endif //H750_CJSON_CJSON_TEST_H

View File

@ -56,6 +56,7 @@ void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void USART1_IRQHandler(void);
void USART3_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */

View File

@ -34,6 +34,8 @@ extern "C" {
extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart3;
/* USER CODE BEGIN Private defines */
#define USART_REC_LEN 200 /* 定义<E5AE9A><E4B989>??大接<E5A4A7><E68EA5>??200字节数据 */
#define USART_EN_RX 1 /* 使能串口接收 */
@ -42,6 +44,7 @@ extern UART_HandleTypeDef huart1;
/* USER CODE END Private defines */
void MX_USART1_UART_Init(void);
void MX_USART3_UART_Init(void);
/* USER CODE BEGIN Prototypes */
extern uint8_t g_usart_rx_buf[USART_REC_LEN]; /* 串口缓冲<E7BC93><E586B2>?? */

View File

@ -0,0 +1,11 @@
//
// Created by zhu on 2024/1/31.
//
#include "Control_Adjustment.h"
void Control_St(uint8_t st_time){
int st= 0;
st = st_time;
printf("st = %d\n",st);
}

View File

@ -0,0 +1,9 @@
//
// Created by zhu on 2024/1/31.
//
#include "Get_Parameters.h"
float Get_Temperature(){
return 1.00;
}

View File

@ -1,25 +1,28 @@
//
// Created by zhu on 2024/1/29.
//
#include <stdbool.h>
#include "usart.h"
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "cJSON_Test.h"
#include "SerialDataProcess.h"
void SerialDataProcess()
{
uint8_t len;
int value;
if (g_usart_rx_sta & 0x8000) /* <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
{
len = g_usart_rx_sta & 0x3FFF; /* <20><>ȡ<EFBFBD><C8A1>Ч<EFBFBD><D0A7><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> */
g_usart_rx_buf[len] = '\0'; /* ĩβ<C4A9><CEB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
printf("<EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD>JSON<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
printf(" %s\r\n",g_usart_rx_buf);
// printf("<EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD>JSON<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
// printf(" %s\r\n",g_usart_rx_buf);
cjson(g_usart_rx_buf);
g_usart_rx_sta = 0;
memset(g_usart_rx_buf, 0, sizeof(g_usart_rx_buf));
}
}

View File

@ -0,0 +1,35 @@
//
// Created by zhu on 2024/1/31.
//
#include "Store_Information.h"
#include <string.h>
#include <stdio.h>
char pn_number[12]; // 11 字节存储 pn 号,再加一个字节用于存放字符串结束符 '\0'
char sn_number[9];
char Product_Time[9];
char Manufacturer[7];
char Device_Pixel_Length[4];
uint8_t Set_Integration_Time = 1;
void Printf_Pn_Number() {
strcpy(pn_number, "12345678901");
printf("%s\n", pn_number);
}
void Printf_Sn_Number() {
strcpy(sn_number, "12345678");
printf("%s\n", sn_number);
}
void Printf_Product_Time() {
strcpy(Product_Time, "20240131");
printf("%s\n", Product_Time);
}
void Printf_Manufacturer() {
strcpy(Manufacturer, "Iris");
printf("%s\n", Manufacturer);
}
void Printf_Device_Pixel_Length() {
strcpy(Device_Pixel_Length, "512");
printf("%s\n", Device_Pixel_Length);
}

View File

@ -1,7 +1,9 @@
#include <stdio.h>
#include "cJSON_Test.h"
struct paramstruct Parameters;
#include "string.h"
#include "Store_Information.h"
struct paramstruct Parameters; //声明结构体对象
void cjson(uint8_t g_usart_json_string[])
{
@ -10,20 +12,33 @@ void cjson(uint8_t g_usart_json_string[])
cJSON *json = cJSON_Parse(json_string);
if (json != NULL) {
// 获取 JSON 对象中的值
cJSON *name = cJSON_GetObjectItem(json, "name");
cJSON *age = cJSON_GetObjectItem(json, "age");
cJSON *city = cJSON_GetObjectItem(json, "city");
cJSON *waihao = cJSON_GetObjectItem(json, "waihao");
if (name != NULL && age != NULL && city != NULL&& waihao != NULL) {
cJSON *temperature = cJSON_GetObjectItem(json, "temperature");// char * name 是结构体指针通过name->valuestring访问结构体中成员的字符串
cJSON *pn = cJSON_GetObjectItem(json, "pn");
cJSON *sn = cJSON_GetObjectItem(json, "sn");
cJSON *production_date = cJSON_GetObjectItem(json, "production_date");
cJSON *manufacturer = cJSON_GetObjectItem(json, "manufacturer");
cJSON *Device_Pixel_Length = cJSON_GetObjectItem(json, "device_pixel_length");
cJSON *Set_Integration_Time = cJSON_GetObjectItem(json, "set_integration_time");
if (temperature != NULL && pn != NULL && sn != NULL&& production_date != NULL
&& manufacturer != NULL&&Device_Pixel_Length!=NULL&&Set_Integration_Time!=NULL) {
// 打印解析结果
printf("Name: %s\n", name->valuestring);
printf("Age: %d\n", age ->valueint);
printf("City: %s\n", city->valuestring);
// 解析嵌套的对象
printf("Waihao:\n");
parseNestedObject(waihao);
Parameters.age= age->valueint;
Parameters.height=age->valueint;
printf("Temperature: %d\n", temperature->valueint);
printf("Pn:%d\n", pn ->valueint);
printf("Sn:%d\n", sn ->valueint);
printf("Production_date:%d\n", production_date ->valueint);
printf("Manufacturer:%d\n", manufacturer ->valueint);
printf("Device_Pixel_Length:%d\n", Device_Pixel_Length ->valueint);
printf("Set_Integration_Time:%d\n", Set_Integration_Time ->valueint);
Parameters.sn = sn ->valueint;
Parameters.pn = pn->valueint;
Parameters.temperature = temperature->valueint;
Parameters.production_date = production_date->valueint;
Parameters.manufacturer = manufacturer->valueint;
Parameters.Device_Pixel_Length = Device_Pixel_Length->valueint;
Parameters.Set_Integration_Time = Set_Integration_Time->valueint;
}
@ -36,16 +51,7 @@ void cjson(uint8_t g_usart_json_string[])
printf("JSON parsing error.\n");
}
}
void parseNestedObject(cJSON *nestedObject) {
cJSON *waihao1 = cJSON_GetObjectItem(nestedObject, "waihao1");
cJSON *waihao2 = cJSON_GetObjectItem(nestedObject, "waihao2");
if (waihao1 != NULL && waihao2 != NULL) {
// 打印嵌套对象的属性
printf(" waihao1: %s\n", waihao1->valuestring);
printf(" waihao2: %s\n", waihao2->valuestring);
}
}
struct paramstruct *GetParametesptr()
{

View File

@ -44,6 +44,7 @@ void MX_GPIO_Init(void)
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);

View File

@ -28,9 +28,13 @@
#include <stdio.h>
#include "SerialDataProcess.h"
#include <stdint.h>
#include <stdbool.h>
#include "stdlib.h"
#include "Store_Information.h"
#include "string.h"
#include "Get_Parameters.h"
#include "Control_Adjustment.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@ -56,7 +60,6 @@
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MPU_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
@ -77,9 +80,6 @@ int main(void)
/* USER CODE END 1 */
/* MPU Configuration--------------------------------------------------------*/
MPU_Config();
/* Enable I-Cache---------------------------------------------------------*/
SCB_EnableICache();
@ -105,8 +105,9 @@ int main(void)
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_USART3_UART_Init();
/* USER CODE BEGIN 2 */
RetargetInit(&huart1);
RetargetInit(&huart3);//用串口3来进行信息的控制和输出。串口1进行图像的输出。
/* USER CODE END 2 */
@ -118,13 +119,35 @@ int main(void)
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
struct paramstruct *paramstruct;
paramstruct = GetParametesptr();
paramstruct->age=20;
SerialDataProcess();
age= Change_Age();
printf("Age is %d\r\n",age);
struct paramstruct *ParamStructPtr;
ParamStructPtr = GetParametesptr();
// paramstruct ->age = 20;
if(ParamStructPtr->pn == 1 ){
Printf_Pn_Number();
}
if(ParamStructPtr->sn == 1){
Printf_Sn_Number();
}
if(ParamStructPtr->production_date ==1){
Printf_Product_Time();
}
if(ParamStructPtr->manufacturer ==1){
Printf_Manufacturer();
}
if(ParamStructPtr->Device_Pixel_Length ==1){
Printf_Device_Pixel_Length();
}
if(ParamStructPtr->temperature==1){
printf("Temperature:%.1f\r\n",Get_Temperature());
}
if(ParamStructPtr->Set_Integration_Time!=0){
Control_St(ParamStructPtr->Set_Integration_Time);
}
//free(ParamStructPtr);
// printf("Hello World\r\n");
}
/* USER CODE END 3 */
@ -197,35 +220,6 @@ void SystemClock_Config(void)
/* USER CODE END 4 */
/* MPU Configuration */
void MPU_Config(void)
{
MPU_Region_InitTypeDef MPU_InitStruct = {0};
/* Disables the MPU */
HAL_MPU_Disable();
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
MPU_InitStruct.BaseAddress = 0x24000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/* Enables the MPU */
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}
/**
* @brief This function is executed in case of error occurrence.
* @retval None

View File

@ -56,6 +56,7 @@
/* External variables --------------------------------------------------------*/
extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart3;
/* USER CODE BEGIN EV */
/* USER CODE END EV */
@ -212,6 +213,20 @@ void USART1_IRQHandler(void)
/* USER CODE END USART1_IRQn 1 */
}
/**
* @brief This function handles USART3 global interrupt.
*/
void USART3_IRQHandler(void)
{
/* USER CODE BEGIN USART3_IRQn 0 */
/* USER CODE END USART3_IRQn 0 */
HAL_UART_IRQHandler(&huart3);
/* USER CODE BEGIN USART3_IRQn 1 */
/* USER CODE END USART3_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

View File

@ -37,6 +37,7 @@ uint8_t g_rx_buffer[RXBUFFERSIZE];
/* USER CODE END 0 */
UART_HandleTypeDef huart1;
UART_HandleTypeDef huart3;
/* USART1 init function */
@ -82,6 +83,50 @@ void MX_USART1_UART_Init(void)
/* USER CODE END USART1_Init 2 */
}
/* USART3 init function */
void MX_USART3_UART_Init(void)
{
/* USER CODE BEGIN USART3_Init 0 */
/* USER CODE END USART3_Init 0 */
/* USER CODE BEGIN USART3_Init 1 */
/* USER CODE END USART3_Init 1 */
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.Mode = UART_MODE_TX_RX;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart3) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart3, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart3, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart3) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART3_Init 2 */
HAL_UART_Receive_IT(&huart3, (uint8_t *)g_rx_buffer, RXBUFFERSIZE);
/* USER CODE END USART3_Init 2 */
}
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
@ -115,7 +160,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
@ -126,6 +171,43 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
/* USER CODE END USART1_MspInit 1 */
}
else if(uartHandle->Instance==USART3)
{
/* USER CODE BEGIN USART3_MspInit 0 */
/* USER CODE END USART3_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3;
PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* USART3 clock enable */
__HAL_RCC_USART3_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**USART3 GPIO Configuration
PB10 ------> USART3_TX
PB11 ------> USART3_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USART3 interrupt Init */
HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART3_IRQn);
/* USER CODE BEGIN USART3_MspInit 1 */
/* USER CODE END USART3_MspInit 1 */
}
}
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
@ -151,14 +233,34 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
/* USER CODE END USART1_MspDeInit 1 */
}
else if(uartHandle->Instance==USART3)
{
/* USER CODE BEGIN USART3_MspDeInit 0 */
/* USER CODE END USART3_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART3_CLK_DISABLE();
/**USART3 GPIO Configuration
PB10 ------> USART3_TX
PB11 ------> USART3_RX
*/
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
/* USART3 interrupt Deinit */
HAL_NVIC_DisableIRQ(USART3_IRQn);
/* USER CODE BEGIN USART3_MspDeInit 1 */
/* USER CODE END USART3_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart->Instance == USART1) /* <20><><EFBFBD><EFBFBD><EFBFBD>Ǵ<EFBFBD>??1 */
if(huart->Instance == USART3) /* <20><><EFBFBD><EFBFBD><EFBFBD>Ǵ<EFBFBD><EFBFBD><EFBFBD>1 */
{
if((g_usart_rx_sta & 0x8000) == 0) /* <20><><EFBFBD><EFBFBD>δ<EFBFBD><CEB4>?? */
if((g_usart_rx_sta & 0x8000) == 0) /* <20><><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD> */
{
if(g_usart_rx_sta & 0x4000) /* <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>0x0d */
{
@ -189,7 +291,7 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
}
}
HAL_UART_Receive_IT(&huart1, (uint8_t *)g_rx_buffer, RXBUFFERSIZE);
HAL_UART_Receive_IT(&huart3, (uint8_t *)g_rx_buffer, RXBUFFERSIZE);
}
}