跨文件使用变量

This commit is contained in:
wantong
2024-01-30 17:50:49 +08:00
parent c4ca59d53e
commit 0732984a64
12 changed files with 4415 additions and 4350 deletions

View File

@ -4,7 +4,14 @@
#include "cJSON.h"
#ifndef H750_CJSON_CJSON_TEST_H
#define H750_CJSON_CJSON_TEST_H
struct paramstruct {
int age;
float height;
};
//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

@ -1,6 +1,7 @@
#include <stdio.h>
#include "cJSON_Test.h"
struct paramstruct Parameters;
void cjson(uint8_t g_usart_json_string[])
{
@ -14,15 +15,20 @@ void cjson(uint8_t g_usart_json_string[])
cJSON *city = cJSON_GetObjectItem(json, "city");
cJSON *waihao = cJSON_GetObjectItem(json, "waihao");
if (name != NULL && age != NULL && city != NULL&& waihao != NULL) {
// 打印解析结果
printf("Name: %s\n", name->valuestring);
printf("Age: %d\n", age->valueint);
printf("City: %s\n", city->valuestring);
// 解析嵌套的对象
printf("Waihao:\n");
parseNestedObject(waihao);
// 打印解析结果
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;
}
// 释放 cJSON 对象
cJSON_Delete(json);
} else {
@ -39,4 +45,9 @@ void parseNestedObject(cJSON *nestedObject) {
printf(" waihao1: %s\n", waihao1->valuestring);
printf(" waihao2: %s\n", waihao2->valuestring);
}
}
struct paramstruct *GetParametesptr()
{
return &Parameters;
}

View File

@ -73,7 +73,7 @@ static void MPU_Config(void);
int main(void)
{
/* USER CODE BEGIN 1 */
uint8_t len;
int age;
/* USER CODE END 1 */
@ -108,7 +108,7 @@ int main(void)
/* USER CODE BEGIN 2 */
RetargetInit(&huart1);
int value;
/* USER CODE END 2 */
/* Infinite loop */
@ -118,10 +118,13 @@ int main(void)
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
struct paramstruct *paramstruct;
paramstruct = GetParametesptr();
paramstruct->age=20;
SerialDataProcess();
SerialDataProcess();
age= Change_Age();
printf("Age is %d\r\n",age);
// printf("Hello World\r\n");
}
/* USER CODE END 3 */