跨文件使用变量

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

21
.idea/workspace.xml generated
View File

@ -14,7 +14,20 @@
</configurations> </configurations>
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="95f61bdd-cab5-46fc-8e2d-162d6bceffdc" name="变更" comment="" /> <list default="true" id="95f61bdd-cab5-46fc-8e2d-162d6bceffdc" name="变更" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Core/Inc/cJSON_Test.h" beforeDir="false" afterPath="$PROJECT_DIR$/Core/Inc/cJSON_Test.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Core/Src/cJSON_Test.c" beforeDir="false" afterPath="$PROJECT_DIR$/Core/Src/cJSON_Test.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Core/Src/main.c" beforeDir="false" afterPath="$PROJECT_DIR$/Core/Src/main.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmake-build-debug/.ninja_deps" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/.ninja_deps" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmake-build-debug/.ninja_log" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/.ninja_log" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/H750_CJSON.elf.dir/Core/Src/cJSON_Test.c.obj" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/H750_CJSON.elf.dir/Core/Src/cJSON_Test.c.obj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/H750_CJSON.elf.dir/Core/Src/main.c.obj" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/CMakeFiles/H750_CJSON.elf.dir/Core/Src/main.c.obj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmake-build-debug/H750_CJSON.bin" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/H750_CJSON.bin" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmake-build-debug/H750_CJSON.elf" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/H750_CJSON.elf" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmake-build-debug/H750_CJSON.hex" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/H750_CJSON.hex" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmake-build-debug/H750_CJSON.map" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/H750_CJSON.map" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -41,6 +54,9 @@
</option> </option>
</component> </component>
<component name="ExecutionTargetManager" SELECTED_TARGET="CMakeBuildProfile:Debug" /> <component name="ExecutionTargetManager" SELECTED_TARGET="CMakeBuildProfile:Debug" />
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration"> <component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" /> <option name="stateVersion" value="1" />
</component> </component>
@ -50,6 +66,7 @@
<option name="minorVersion" value="1.3" /> <option name="minorVersion" value="1.3" />
</component> </component>
<component name="ProjectId" id="2bbnz1CSIanAtOkE69ZDKoVBtNN" /> <component name="ProjectId" id="2bbnz1CSIanAtOkE69ZDKoVBtNN" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState"> <component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
@ -113,7 +130,7 @@
<option name="number" value="Default" /> <option name="number" value="Default" />
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1706492904795</updated> <updated>1706492904795</updated>
<workItem from="1706492946668" duration="18120000" /> <workItem from="1706492946668" duration="23692000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@ -4,7 +4,14 @@
#include "cJSON.h" #include "cJSON.h"
#ifndef H750_CJSON_CJSON_TEST_H #ifndef H750_CJSON_CJSON_TEST_H
#define 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(const char * g_usart_json_string);
void cjson(uint8_t g_usart_json_string[]); void cjson(uint8_t g_usart_json_string[]);
void parseNestedObject(cJSON *nestedObject); void parseNestedObject(cJSON *nestedObject);
int Change_Age();
struct paramstruct *GetParametesptr();
void SV_Change_Age();
#endif //H750_CJSON_CJSON_TEST_H #endif //H750_CJSON_CJSON_TEST_H

View File

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include "cJSON_Test.h" #include "cJSON_Test.h"
struct paramstruct Parameters;
void cjson(uint8_t g_usart_json_string[]) void cjson(uint8_t g_usart_json_string[])
{ {
@ -16,13 +17,18 @@ void cjson(uint8_t g_usart_json_string[])
if (name != NULL && age != NULL && city != NULL&& waihao != NULL) { if (name != NULL && age != NULL && city != NULL&& waihao != NULL) {
// 打印解析结果 // 打印解析结果
printf("Name: %s\n", name->valuestring); printf("Name: %s\n", name->valuestring);
printf("Age: %d\n", age->valueint); printf("Age: %d\n", age ->valueint);
printf("City: %s\n", city->valuestring); printf("City: %s\n", city->valuestring);
// 解析嵌套的对象 // 解析嵌套的对象
printf("Waihao:\n"); printf("Waihao:\n");
parseNestedObject(waihao); parseNestedObject(waihao);
Parameters.age= age->valueint;
Parameters.height=age->valueint;
} }
// 释放 cJSON 对象 // 释放 cJSON 对象
cJSON_Delete(json); cJSON_Delete(json);
} else { } else {
@ -40,3 +46,8 @@ void parseNestedObject(cJSON *nestedObject) {
printf(" waihao2: %s\n", waihao2->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) int main(void)
{ {
/* USER CODE BEGIN 1 */ /* USER CODE BEGIN 1 */
uint8_t len; int age;
/* USER CODE END 1 */ /* USER CODE END 1 */
@ -108,7 +108,7 @@ int main(void)
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
RetargetInit(&huart1); RetargetInit(&huart1);
int value;
/* USER CODE END 2 */ /* USER CODE END 2 */
/* Infinite loop */ /* Infinite loop */
@ -118,10 +118,13 @@ int main(void)
/* USER CODE END WHILE */ /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */ /* 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"); // printf("Hello World\r\n");
} }
/* USER CODE END 3 */ /* USER CODE END 3 */

Binary file not shown.

View File

@ -61,3 +61,15 @@
425 1070 7282236983239327 H750_CJSON.elf 12a917912d28b371 425 1070 7282236983239327 H750_CJSON.elf 12a917912d28b371
4 262 7282237574918432 CMakeFiles/H750_CJSON.elf.dir/Core/Src/cJSON_Test.c.obj 57ce2d68122c7b8a 4 262 7282237574918432 CMakeFiles/H750_CJSON.elf.dir/Core/Src/cJSON_Test.c.obj 57ce2d68122c7b8a
262 649 7282237577449468 H750_CJSON.elf 12a917912d28b371 262 649 7282237577449468 H750_CJSON.elf 12a917912d28b371
6 1539 7283072638664448 CMakeFiles/H750_CJSON.elf.dir/Core/Src/main.c.obj 3b1b3dd76e950676
1540 2833 7283072650010640 H750_CJSON.elf 12a917912d28b371
5 892 7283072777842554 CMakeFiles/H750_CJSON.elf.dir/Core/Src/main.c.obj 3b1b3dd76e950676
893 1710 7283072781176118 H750_CJSON.elf 12a917912d28b371
5 2149 7283084458953115 CMakeFiles/H750_CJSON.elf.dir/Core/Src/cJSON_Test.c.obj 57ce2d68122c7b8a
3 184 7283085341377394 CMakeFiles/H750_CJSON.elf.dir/Core/Src/cJSON_Test.c.obj 57ce2d68122c7b8a
12 310 7283085342667839 CMakeFiles/H750_CJSON.elf.dir/Core/Src/main.c.obj 3b1b3dd76e950676
310 2482 7283085363039108 H750_CJSON.elf 12a917912d28b371
14 367 7283087578759113 CMakeFiles/H750_CJSON.elf.dir/Core/Src/cJSON_Test.c.obj 57ce2d68122c7b8a
22 486 7283087579962637 CMakeFiles/H750_CJSON.elf.dir/Core/Src/main.c.obj 3b1b3dd76e950676
3 2151 7283087596498410 CMakeFiles/H750_CJSON.elf.dir/Core/Src/SerialDataProcess.c.obj a12ea5c5679952a2
2152 2549 7283087599445051 H750_CJSON.elf 12a917912d28b371

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff