添加cjson文件解析
This commit is contained in:
86
R_PINGCHANG/Core/Inc/Communication_Protocol.h
Normal file
86
R_PINGCHANG/Core/Inc/Communication_Protocol.h
Normal file
@ -0,0 +1,86 @@
|
||||
//
|
||||
// Created by zhu on 2024/1/31.
|
||||
//
|
||||
|
||||
#ifndef H750_CJSON_COMMUNICATION_PROTOCOL_H
|
||||
#define H750_CJSON_COMMUNICATION_PROTOCOL_H
|
||||
|
||||
|
||||
#ifndef COMMUNICATION_PROTOCOL_H
|
||||
#define COMMUNICATION_PROTOCOL_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include "Communication_struct.h"
|
||||
// DEFINE The protocol Here
|
||||
//Forexample
|
||||
// #define MYCOMAN 0x02 //命令全大写
|
||||
// to_do : define your protocol here
|
||||
/*-------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------------------*/
|
||||
/*
|
||||
在此之下开始定义一些函数
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
#define ERROR_NOT_ENOUGH_DATA -200
|
||||
#define ERROR_HEADER -300
|
||||
#define ERROR_COMMAND -400
|
||||
#define ERROR_INPUT -500
|
||||
#define ERROR_CRC -600
|
||||
|
||||
|
||||
// 成功返回打包后的数据长度
|
||||
// -1: Error
|
||||
// 成功返回打包后的数据长度
|
||||
int32_t IRIS_Protocol_Pack(uint8_t Command,uint16_t LenthofIn, uint8_t *BufferIn, uint8_t *PackData);
|
||||
|
||||
// 解包函数 PackData 是接收到的数据 LenthofIn 是数据长度 Command 是命令 BufferOut 是输出
|
||||
// 下位机使用的打包函数 Command 是输出
|
||||
// 成功返回解包后的数据长度
|
||||
// 0: 该命令返回无参数
|
||||
// 错误返回ERRor
|
||||
// 成功返回解包后的数据长度
|
||||
int32_t IRIS_STM32_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t *Command, uint8_t *BufferOut);
|
||||
|
||||
// 解包函数 PackData 是接收到的数据 LenthofIn 是数据长度 Command 是命令输入 BufferOut 是输出 上位机使用
|
||||
// 成功返回解包后的数据长度
|
||||
// 0: 该命令返回无参数
|
||||
// 错误返回ERRor
|
||||
// 成功返回解包后的数据长度
|
||||
int32_t IRIS_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t Command, uint8_t *BufferOut);
|
||||
|
||||
// 定义裁切命令
|
||||
// 成功返回裁切后的数据长度
|
||||
// -1: Error
|
||||
int32_t IRIS_Cut_Befor_Header(uint8_t *PackData, uint16_t LenthofIn );
|
||||
|
||||
// 检查数据是否有效
|
||||
// 有效返回值1
|
||||
// 错误返回ERRor
|
||||
int32_t IRIS_Check_Data_Valid(uint8_t *PackData, uint16_t LenthofIn );
|
||||
|
||||
|
||||
// 返回CRC校验值
|
||||
uint16_t IRIS_calcCRC(const void *pBuffer, uint16_t bufferSize);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //H750_CJSON_COMMUNICATION_PROTOCOL_H
|
46
R_PINGCHANG/Core/Inc/Communication_struct.h
Normal file
46
R_PINGCHANG/Core/Inc/Communication_struct.h
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// Created by zhu on 2024/1/31.
|
||||
//
|
||||
|
||||
#ifndef H750_CJSON_COMMUNICATION_STRUCT_H
|
||||
#define H750_CJSON_COMMUNICATION_STRUCT_H
|
||||
|
||||
#ifndef COMMUNICATION_STRUCT_H
|
||||
#define COMMUNICATION_STRUCT_H
|
||||
|
||||
// Define your communication structures here
|
||||
// For example:
|
||||
/*
|
||||
如果发送和接受的数据结构一样,那么就定义一个结构体
|
||||
struct MyComan_struct //对应的命令结构体 小驼峰命名法+struct
|
||||
{
|
||||
uint8_t Command;
|
||||
uint16_t LenthofIn;
|
||||
};
|
||||
|
||||
|
||||
|
||||
如果发送和接受的数据结构不一样,那么就分开定义
|
||||
struct MyComan_Send_struct //对应的命令结构体 小驼峰命名法+Send_struct
|
||||
{
|
||||
uint8_t Command;
|
||||
uint16_t LenthofIn;
|
||||
|
||||
};
|
||||
|
||||
struct MyComan_Recv_struct //对应的命令结构体 小驼峰命名法+Recv_struct
|
||||
{
|
||||
uint8_t Command;
|
||||
uint16_t LenthofOut;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#endif // COMMUNICATION_STRUCT_H
|
||||
|
||||
|
||||
#endif //H750_CJSON_COMMUNICATION_STRUCT_H
|
12
R_PINGCHANG/Core/Inc/Control_Adjustment.h
Normal file
12
R_PINGCHANG/Core/Inc/Control_Adjustment.h
Normal 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
R_PINGCHANG/Core/Inc/Get_Parameters.h
Normal file
12
R_PINGCHANG/Core/Inc/Get_Parameters.h
Normal 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
|
15
R_PINGCHANG/Core/Inc/Judge.h
Normal file
15
R_PINGCHANG/Core/Inc/Judge.h
Normal file
@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by zhu on 2024/1/31.
|
||||
//
|
||||
|
||||
#ifndef H750_CJSON_JUDGE_H
|
||||
#define H750_CJSON_JUDGE_H
|
||||
#include "string.h"
|
||||
#include "Get_Parameters.h"
|
||||
#include "Control_Adjustment.h"
|
||||
#include "cJSON_Test.h"
|
||||
#include "Store_Information.h"
|
||||
void Judge();
|
||||
|
||||
|
||||
#endif //H750_CJSON_JUDGE_H
|
11
R_PINGCHANG/Core/Inc/SerialDataProcess.h
Normal file
11
R_PINGCHANG/Core/Inc/SerialDataProcess.h
Normal file
@ -0,0 +1,11 @@
|
||||
//
|
||||
// Created by zhu on 2024/1/29.
|
||||
//
|
||||
|
||||
#ifndef S15909_H750_SERIALDATAPROCESS_H
|
||||
#define S15909_H750_SERIALDATAPROCESS_H
|
||||
void SerialDataProcess();
|
||||
|
||||
|
||||
|
||||
#endif //S15909_H750_SERIALDATAPROCESS_H
|
16
R_PINGCHANG/Core/Inc/Store_Information.h
Normal file
16
R_PINGCHANG/Core/Inc/Store_Information.h
Normal 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
|
300
R_PINGCHANG/Core/Inc/cJSON.h
Normal file
300
R_PINGCHANG/Core/Inc/cJSON.h
Normal file
@ -0,0 +1,300 @@
|
||||
/*
|
||||
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef cJSON__h
|
||||
#define cJSON__h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
|
||||
|
||||
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
|
||||
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
|
||||
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
|
||||
|
||||
For *nix builds that support visibility attribute, you can define similar behavior by
|
||||
|
||||
setting default visibility to hidden by adding
|
||||
-fvisibility=hidden (for gcc)
|
||||
or
|
||||
-xldscope=hidden (for sun cc)
|
||||
to CFLAGS
|
||||
|
||||
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
|
||||
|
||||
*/
|
||||
|
||||
#define CJSON_CDECL __cdecl
|
||||
#define CJSON_STDCALL __stdcall
|
||||
|
||||
/* export symbols by default, this is necessary for copy pasting the C and header file */
|
||||
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define CJSON_EXPORT_SYMBOLS
|
||||
#endif
|
||||
|
||||
#if defined(CJSON_HIDE_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) type CJSON_STDCALL
|
||||
#elif defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
|
||||
#elif defined(CJSON_IMPORT_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
|
||||
#endif
|
||||
#else /* !__WINDOWS__ */
|
||||
#define CJSON_CDECL
|
||||
#define CJSON_STDCALL
|
||||
|
||||
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
|
||||
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
|
||||
#else
|
||||
#define CJSON_PUBLIC(type) type
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* project version */
|
||||
#define CJSON_VERSION_MAJOR 1
|
||||
#define CJSON_VERSION_MINOR 7
|
||||
#define CJSON_VERSION_PATCH 17
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* cJSON Types: */
|
||||
#define cJSON_Invalid (0)
|
||||
#define cJSON_False (1 << 0)
|
||||
#define cJSON_True (1 << 1)
|
||||
#define cJSON_NULL (1 << 2)
|
||||
#define cJSON_Number (1 << 3)
|
||||
#define cJSON_String (1 << 4)
|
||||
#define cJSON_Array (1 << 5)
|
||||
#define cJSON_Object (1 << 6)
|
||||
#define cJSON_Raw (1 << 7) /* raw json */
|
||||
|
||||
#define cJSON_IsReference 256
|
||||
#define cJSON_StringIsConst 512
|
||||
|
||||
/* The cJSON structure: */
|
||||
typedef struct cJSON
|
||||
{
|
||||
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||
struct cJSON *next;
|
||||
struct cJSON *prev;
|
||||
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
||||
struct cJSON *child;
|
||||
|
||||
/* The type of the item, as above. */
|
||||
int type;
|
||||
|
||||
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
|
||||
char *valuestring;
|
||||
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
|
||||
int valueint;
|
||||
/* The item's number, if type==cJSON_Number */
|
||||
double valuedouble;
|
||||
|
||||
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
||||
char *string;
|
||||
} cJSON;
|
||||
|
||||
typedef struct cJSON_Hooks
|
||||
{
|
||||
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
|
||||
void *(CJSON_CDECL *malloc_fn)(size_t sz);
|
||||
void (CJSON_CDECL *free_fn)(void *ptr);
|
||||
} cJSON_Hooks;
|
||||
|
||||
typedef int cJSON_bool;
|
||||
|
||||
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
|
||||
* This is to prevent stack overflows. */
|
||||
#ifndef CJSON_NESTING_LIMIT
|
||||
#define CJSON_NESTING_LIMIT 1000
|
||||
#endif
|
||||
|
||||
/* returns the version of cJSON as a string */
|
||||
CJSON_PUBLIC(const char*) cJSON_Version(void);
|
||||
|
||||
/* Supply malloc, realloc and free functions to cJSON */
|
||||
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
|
||||
|
||||
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
|
||||
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
|
||||
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
|
||||
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
|
||||
|
||||
/* Render a cJSON entity to text for transfer/storage. */
|
||||
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
|
||||
/* Render a cJSON entity to text for transfer/storage without any formatting. */
|
||||
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
|
||||
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
|
||||
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
|
||||
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
|
||||
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
|
||||
/* Delete a cJSON entity and all subentities. */
|
||||
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
|
||||
|
||||
/* Returns the number of items in an array (or object). */
|
||||
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
|
||||
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
|
||||
/* Get item "string" from object. Case insensitive. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
|
||||
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
||||
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
|
||||
|
||||
/* Check item type and return its value */
|
||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
|
||||
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
|
||||
|
||||
/* These functions check the type of an item */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
|
||||
|
||||
/* These calls create a cJSON item of the appropriate type. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
|
||||
/* raw json */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
|
||||
|
||||
/* Create a string where valuestring references a string so
|
||||
* it will not be freed by cJSON_Delete */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
|
||||
/* Create an object/array that only references it's elements so
|
||||
* they will not be freed by cJSON_Delete */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
|
||||
|
||||
/* These utilities create an Array of count items.
|
||||
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
|
||||
|
||||
/* Append item to the specified array/object. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
|
||||
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
|
||||
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
|
||||
* writing to `item->string` */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
|
||||
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
|
||||
|
||||
/* Remove/Detach items from Arrays/Objects. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
|
||||
/* Update array items. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
|
||||
|
||||
/* Duplicate a cJSON item */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
|
||||
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
|
||||
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
|
||||
* The item->next and ->prev pointers are always zero on return from Duplicate. */
|
||||
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
|
||||
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
|
||||
|
||||
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
|
||||
* The input pointer json cannot point to a read-only address area, such as a string constant,
|
||||
* but should point to a readable and writable address area. */
|
||||
CJSON_PUBLIC(void) cJSON_Minify(char *json);
|
||||
|
||||
/* Helper functions for creating and adding items to an object at the same time.
|
||||
* They return the added item or NULL on failure. */
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
|
||||
|
||||
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
|
||||
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
||||
/* helper for the cJSON_SetNumberValue macro */
|
||||
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
||||
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
|
||||
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
|
||||
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
|
||||
|
||||
/* If the object is not a boolean type this does nothing and returns cJSON_Invalid else it returns the new type*/
|
||||
#define cJSON_SetBoolValue(object, boolValue) ( \
|
||||
(object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \
|
||||
(object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \
|
||||
cJSON_Invalid\
|
||||
)
|
||||
|
||||
/* Macro for iterating over an array or object */
|
||||
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
|
||||
|
||||
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
|
||||
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
|
||||
CJSON_PUBLIC(void) cJSON_free(void *object);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
21
R_PINGCHANG/Core/Inc/cJSON_Test.h
Normal file
21
R_PINGCHANG/Core/Inc/cJSON_Test.h
Normal file
@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by zhu on 2024/1/29.
|
||||
//
|
||||
#include "cJSON.h"
|
||||
#ifndef H750_CJSON_CJSON_TEST_H
|
||||
#define H750_CJSON_CJSON_TEST_H
|
||||
struct paramstruct {
|
||||
int temperature;
|
||||
int pn;
|
||||
int sn;
|
||||
int production_date;
|
||||
int manufacturer;
|
||||
int Device_Pixel_Length;
|
||||
uint8_t Set_Integration_Time;
|
||||
|
||||
};
|
||||
|
||||
void cjson(uint8_t g_usart_json_string[]);
|
||||
void parseNestedObject(cJSON *nestedObject);
|
||||
struct paramstruct *GetParametesptr();
|
||||
#endif //H750_CJSON_CJSON_TEST_H
|
180
R_PINGCHANG/Core/Src/Communication_Protocol.c
Normal file
180
R_PINGCHANG/Core/Src/Communication_Protocol.c
Normal file
@ -0,0 +1,180 @@
|
||||
#include "Communication_Protocol.h"
|
||||
#include "string.h"
|
||||
|
||||
|
||||
int32_t IRIS_Protocol_Pack(uint8_t Command,uint16_t LenthofIn, uint8_t *BufferIn, uint8_t *PackData)
|
||||
{
|
||||
if( PackData == NULL || (LenthofIn!=0 && BufferIn == NULL))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
PackData[0] = 0x55;
|
||||
PackData[1] = 0xAA;
|
||||
PackData[2] = Command;
|
||||
PackData[3] = LenthofIn & 0xFF;
|
||||
PackData[4] = (LenthofIn >> 8) & 0xFF;
|
||||
if(LenthofIn!=0)
|
||||
{
|
||||
memcpy(&PackData[5],BufferIn,LenthofIn);
|
||||
}
|
||||
uint16_t CRC = IRIS_calcCRC(PackData, LenthofIn+5);
|
||||
PackData[LenthofIn+5] = CRC & 0xFF;
|
||||
PackData[LenthofIn+6] = (CRC >> 8) & 0xFF;
|
||||
return LenthofIn+7;
|
||||
}
|
||||
|
||||
int32_t IRIS_STM32_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t *Command, uint8_t *BufferOut)
|
||||
{
|
||||
|
||||
if( PackData == NULL || BufferOut == NULL)
|
||||
{
|
||||
return ERROR_INPUT;
|
||||
}
|
||||
if(PackData[0] != 0x55 || PackData[1] != 0xAA)
|
||||
{
|
||||
return ERROR_HEADER;
|
||||
}
|
||||
|
||||
uint16_t LenthofOut = PackData[3] + (PackData[4] << 8);
|
||||
if(LenthofOut > LenthofIn - 7)
|
||||
{
|
||||
return ERROR_NOT_ENOUGH_DATA;
|
||||
}
|
||||
uint16_t CRC = IRIS_calcCRC(PackData, LenthofOut+5);
|
||||
if(CRC != (PackData[LenthofOut+5] + (PackData[LenthofOut+6] << 8)))
|
||||
{
|
||||
return ERROR_CRC;
|
||||
}
|
||||
if(LenthofOut == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
*Command = PackData[2] ;
|
||||
|
||||
memcpy(BufferOut,&PackData[5],LenthofOut);
|
||||
return LenthofOut;
|
||||
}
|
||||
|
||||
|
||||
int32_t IRIS_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t Command, uint8_t *BufferOut)
|
||||
{
|
||||
if( PackData == NULL || BufferOut == NULL)
|
||||
{
|
||||
return ERROR_INPUT;
|
||||
}
|
||||
if(PackData[0] != 0x55 || PackData[1] != 0xAA)
|
||||
{
|
||||
return ERROR_HEADER;
|
||||
}
|
||||
if(PackData[2] != Command)
|
||||
{
|
||||
return ERROR_COMMAND;
|
||||
}
|
||||
uint16_t LenthofOut = *(uint16_t *)(PackData+3)-2;
|
||||
if(LenthofOut > LenthofIn - 7)
|
||||
{
|
||||
return ERROR_NOT_ENOUGH_DATA;
|
||||
}
|
||||
uint16_t CRC = IRIS_calcCRC(PackData, LenthofOut+5);
|
||||
uint16_t CRC2=*(uint16_t *)(PackData+LenthofOut+5);
|
||||
if(CRC != CRC2)
|
||||
{
|
||||
return ERROR_CRC;
|
||||
}
|
||||
if(LenthofOut == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
memcpy(BufferOut,&PackData[5],LenthofOut);
|
||||
return LenthofOut;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int32_t IRIS_Cut_Befor_Header(uint8_t *PackData, uint16_t LenthofIn )
|
||||
{
|
||||
if( PackData == NULL )
|
||||
{
|
||||
return ERROR_INPUT;
|
||||
}
|
||||
uint16_t i = 0;
|
||||
for(i = 0; i < LenthofIn; i++)
|
||||
{
|
||||
if(PackData[i] == 0x55 && PackData[i+1] == 0xAA)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i == LenthofIn)
|
||||
{
|
||||
//清空数据
|
||||
memset(PackData,0,LenthofIn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t LenthofOut = LenthofIn - i;
|
||||
memcpy(PackData,&PackData[i],LenthofOut);
|
||||
return LenthofOut;
|
||||
}
|
||||
|
||||
int32_t IRIS_Check_Data_Valid(uint8_t *PackData, uint16_t LenthofIn)
|
||||
{
|
||||
if( PackData == NULL)
|
||||
{
|
||||
return ERROR_INPUT;
|
||||
}
|
||||
if (LenthofIn < 7)
|
||||
{
|
||||
return ERROR_NOT_ENOUGH_DATA;
|
||||
/* code */
|
||||
}
|
||||
|
||||
if(PackData[0] != 0x55 || PackData[1] != 0xAA)
|
||||
{
|
||||
return ERROR_HEADER;
|
||||
}
|
||||
uint16_t LenthofOut = PackData[3] + (PackData[4] << 8);
|
||||
if(LenthofOut > LenthofIn - 7)
|
||||
{
|
||||
return ERROR_NOT_ENOUGH_DATA;
|
||||
}
|
||||
uint16_t CRC = IRIS_calcCRC(PackData, LenthofOut+5);
|
||||
if(CRC != (PackData[LenthofOut+5] + (PackData[LenthofOut+6] << 8)))
|
||||
{
|
||||
return ERROR_CRC;
|
||||
}
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
uint16_t IRIS_calcCRC(const void *pBuffer, uint16_t bufferSize)
|
||||
{
|
||||
const uint8_t *pBytesArray = (const uint8_t*)pBuffer;
|
||||
uint16_t poly = 0x8408;
|
||||
uint16_t crc = 0;
|
||||
uint8_t carry;
|
||||
uint8_t i_bits;
|
||||
uint16_t j;
|
||||
for (j =0; j < bufferSize; j++)
|
||||
{
|
||||
crc = crc ^ pBytesArray[j];
|
||||
for (i_bits = 0; i_bits < 8; i_bits++)
|
||||
{
|
||||
carry = crc & 1;
|
||||
crc = crc / 2;
|
||||
if (carry)
|
||||
{
|
||||
crc = crc^poly;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
11
R_PINGCHANG/Core/Src/Control_Adjustment.c
Normal file
11
R_PINGCHANG/Core/Src/Control_Adjustment.c
Normal 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);
|
||||
}
|
9
R_PINGCHANG/Core/Src/Get_Parameters.c
Normal file
9
R_PINGCHANG/Core/Src/Get_Parameters.c
Normal file
@ -0,0 +1,9 @@
|
||||
//
|
||||
// Created by zhu on 2024/1/31.
|
||||
//
|
||||
|
||||
#include "Get_Parameters.h"
|
||||
float Get_Temperature(){
|
||||
return 1.00;
|
||||
|
||||
}
|
34
R_PINGCHANG/Core/Src/Judge.c
Normal file
34
R_PINGCHANG/Core/Src/Judge.c
Normal file
@ -0,0 +1,34 @@
|
||||
//
|
||||
// Created by zhu on 2024/1/31.
|
||||
//
|
||||
|
||||
#include "Judge.h"
|
||||
|
||||
void Judge(){
|
||||
struct paramstruct *ParamStructPtr;
|
||||
ParamStructPtr = GetParametesptr();
|
||||
//IRIS_Protocol_Pack(0x10,1040, uint8_t *BufferIn, uint8_t *PackData);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
38
R_PINGCHANG/Core/Src/SerialDataProcess.c
Normal file
38
R_PINGCHANG/Core/Src/SerialDataProcess.c
Normal file
@ -0,0 +1,38 @@
|
||||
//
|
||||
// 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"
|
||||
#include "Communication_Protocol.h"
|
||||
extern bool Printf_Flag ;
|
||||
uint8_t cjson_buf[200];
|
||||
void SerialDataProcess()
|
||||
{
|
||||
uint8_t len;
|
||||
if (g_usart_rx_sta & 0x8000) /* 接收到了数据 */
|
||||
{
|
||||
len = g_usart_rx_sta & 0x3FFF; /* 获取有效数据长度 */
|
||||
g_usart_rx_buf[len] = '\0'; /* 末尾插入结束符 */
|
||||
// printf("接收到的JSON命令: ");
|
||||
// printf(" %s\r\n",g_usart_rx_buf);
|
||||
|
||||
IRIS_Cut_Befor_Header(g_usart_rx_buf,len);
|
||||
IRIS_Protocol_Unpack(g_usart_rx_buf, len, 0x00, cjson_buf);
|
||||
cjson(cjson_buf);
|
||||
//
|
||||
|
||||
g_usart_rx_sta = 0;
|
||||
memset(g_usart_rx_buf, 0, sizeof(g_usart_rx_buf));
|
||||
memset(cjson_buf, 0, sizeof(cjson_buf));
|
||||
}else
|
||||
{
|
||||
Printf_Flag = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
35
R_PINGCHANG/Core/Src/Store_Information.c
Normal file
35
R_PINGCHANG/Core/Src/Store_Information.c
Normal 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, "IRIS_ZHU_01");
|
||||
printf("%s\n", pn_number);
|
||||
}
|
||||
void Printf_Sn_Number() {
|
||||
strcpy(sn_number, "Sensor_1");
|
||||
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);
|
||||
}
|
3129
R_PINGCHANG/Core/Src/cJSON.c
Normal file
3129
R_PINGCHANG/Core/Src/cJSON.c
Normal file
File diff suppressed because it is too large
Load Diff
63
R_PINGCHANG/Core/Src/cJSON_Test.c
Normal file
63
R_PINGCHANG/Core/Src/cJSON_Test.c
Normal file
@ -0,0 +1,63 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "cJSON_Test.h"
|
||||
#include "string.h"
|
||||
#include "Store_Information.h"
|
||||
#include "stdlib.h"
|
||||
#include "stdbool.h"
|
||||
struct paramstruct Parameters; //声明结构体对象
|
||||
extern bool Printf_Flag ;
|
||||
void cjson(uint8_t g_usart_json_string[])
|
||||
{
|
||||
const char * json_string = g_usart_json_string;
|
||||
printf("JSON string: %s\r\n", json_string);
|
||||
cJSON *json = cJSON_Parse(json_string);
|
||||
if (json != NULL) {
|
||||
// 获取 JSON 对象中的值
|
||||
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("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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Printf_Flag= true;
|
||||
// 释放 cJSON 对象
|
||||
cJSON_Delete(json);
|
||||
} else {
|
||||
// 处理解析错误
|
||||
printf("JSON parsing error JSON parsing error JSON parsing error JSON parsing error.\n");
|
||||
Printf_Flag = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct paramstruct *GetParametesptr()
|
||||
{
|
||||
return &Parameters;
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
#include "dma.h"
|
||||
#include "usart.h"
|
||||
|
||||
|
||||
DMA_HandleTypeDef UART1TxDMA_Handler; //DMA<4D><41><EFBFBD><EFBFBD>
|
||||
|
||||
void MYDMA_Config(DMA_Stream_TypeDef *DMA_Streamx)
|
||||
{
|
||||
if((uint32_t)DMA_Streamx>(uint32_t)DMA2)//<2F>õ<EFBFBD><C3B5><EFBFBD>ǰstream<61><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DMA2<41><32><EFBFBD><EFBFBD>DMA1
|
||||
{
|
||||
__HAL_RCC_DMA2_CLK_ENABLE();//DMA2ʱ<32><CAB1>ʹ<EFBFBD><CAB9>
|
||||
}
|
||||
else
|
||||
{
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();//DMA1ʱ<31><CAB1>ʹ<EFBFBD><CAB9>
|
||||
}
|
||||
|
||||
__HAL_LINKDMA(&huart1,hdmatx,UART1TxDMA_Handler); //<2F><>DMA<4D><41>USART1<54><31>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>DMA)
|
||||
|
||||
//Tx DMA<4D><41><EFBFBD><EFBFBD>
|
||||
UART1TxDMA_Handler.Instance=DMA_Streamx; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
||||
UART1TxDMA_Handler.Init.Request=DMA_REQUEST_USART1_TX; //USART1<54><31><EFBFBD><EFBFBD>DMA
|
||||
UART1TxDMA_Handler.Init.Direction=DMA_MEMORY_TO_PERIPH; //<2F>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
UART1TxDMA_Handler.Init.PeriphInc=DMA_PINC_DISABLE; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
||||
UART1TxDMA_Handler.Init.MemInc=DMA_MINC_ENABLE; //<2F>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
||||
UART1TxDMA_Handler.Init.PeriphDataAlignment=DMA_PDATAALIGN_BYTE; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>:8λ
|
||||
UART1TxDMA_Handler.Init.MemDataAlignment=DMA_MDATAALIGN_BYTE; //<2F>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>:8λ
|
||||
UART1TxDMA_Handler.Init.Mode=DMA_CIRCULAR; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
||||
UART1TxDMA_Handler.Init.Priority=DMA_PRIORITY_MEDIUM; //<2F>е<EFBFBD><D0B5><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
||||
UART1TxDMA_Handler.Init.FIFOMode=DMA_FIFOMODE_DISABLE;
|
||||
UART1TxDMA_Handler.Init.FIFOThreshold=DMA_FIFO_THRESHOLD_FULL;
|
||||
UART1TxDMA_Handler.Init.MemBurst=DMA_MBURST_SINGLE; //<2F>洢<EFBFBD><E6B4A2>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>
|
||||
UART1TxDMA_Handler.Init.PeriphBurst=DMA_PBURST_SINGLE; //<2F><><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>
|
||||
|
||||
HAL_DMA_DeInit(&UART1TxDMA_Handler);
|
||||
HAL_DMA_Init(&UART1TxDMA_Handler);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -27,13 +27,13 @@
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "retarget.h"
|
||||
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
#include "SerialDataProcess.h"
|
||||
#include "stdio.h" //<2F><>printf<74><66><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD>
|
||||
#include <stdint.h>
|
||||
#include "Judge.h"
|
||||
#include "cJSON_Test.h"
|
||||
#include <stdbool.h>
|
||||
///**
|
||||
// * <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20>ض<EFBFBD><D8B6><EFBFBD>c<EFBFBD>⺯<EFBFBD><E2BAAF>printf<74><66>DEBUG_USARTx
|
||||
// * <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||||
@ -96,7 +96,7 @@ static void MPU_Config(void);
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
bool Printf_Flag = true;
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@ -143,6 +143,7 @@ int main(void)
|
||||
MX_TIM1_Init();
|
||||
MX_TIM2_Init();
|
||||
MX_USART1_UART_Init();
|
||||
RetargetInit(&huart1);
|
||||
MX_TIM12_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_TIM3_Init();
|
||||
@ -161,73 +162,61 @@ int main(void)
|
||||
int needreset1=0;
|
||||
int needreset2=1;
|
||||
int thisneedtransfor=1;
|
||||
uint8_t len;
|
||||
int value;
|
||||
|
||||
while (1)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
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> */
|
||||
char *p = strtok(g_usart_rx_buf, "#");
|
||||
if (strcmp(p, "SET") == 0) { /* SET#MUL#0 */
|
||||
// <20><>ȡ<EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
p = strtok(NULL, "#");
|
||||
if (strcmp(p, "MUL") == 0) {
|
||||
p = strtok(NULL, "#");
|
||||
value = atoi(p);
|
||||
mul_int_max = value;
|
||||
printf("mul");
|
||||
}
|
||||
}
|
||||
g_usart_rx_sta = 0;
|
||||
memset(g_usart_rx_buf, 0, sizeof(g_usart_rx_buf));
|
||||
// SerialDataProcess();
|
||||
SerialDataProcess();
|
||||
if(Printf_Flag== true){
|
||||
Judge();
|
||||
Printf_Flag = false;
|
||||
}
|
||||
if(G_Clk_Rise_Number>=2080)
|
||||
{
|
||||
needreset1=1;
|
||||
}
|
||||
if(G_Hamamatsu_Trigger_Rise_Number>=512&&thisneedtransfor)
|
||||
{
|
||||
thisneedtransfor=0;
|
||||
for(int i=0;i<512;i++)
|
||||
{
|
||||
temp16_2[i]+=adc_ans[i];
|
||||
}
|
||||
|
||||
if (index%Average_Number==0)
|
||||
{
|
||||
for(int i=0;i<512;i++)
|
||||
{
|
||||
temp16[i]=temp16_2[i]/Average_Number;
|
||||
temp16_2[i]=0;
|
||||
|
||||
}
|
||||
temp[0]=0xff;
|
||||
temp[1]=0xff;
|
||||
memcpy(temp+2,temp16,1024);
|
||||
HAL_UART_Transmit_DMA(&huart1,temp,1026);
|
||||
}
|
||||
needreset2=1;
|
||||
index++;
|
||||
}
|
||||
if(mul_int>mul_int_max)
|
||||
{
|
||||
mul_int=0;
|
||||
}
|
||||
if(needreset1==1&&needreset2==1)
|
||||
{
|
||||
__disable_irq();
|
||||
mul_int++;
|
||||
G_Clk_Rise_Number=0;
|
||||
G_Hamamatsu_Trigger_Rise_Number_U8=0;
|
||||
G_Hamamatsu_Trigger_Rise_Number=0;
|
||||
__enable_irq();
|
||||
needreset1=0;
|
||||
needreset2=0;
|
||||
thisneedtransfor=1;
|
||||
}
|
||||
// if(G_Clk_Rise_Number>=2080)
|
||||
// {
|
||||
// needreset1=1;
|
||||
// }
|
||||
// if(G_Hamamatsu_Trigger_Rise_Number>=512&&thisneedtransfor)
|
||||
// {
|
||||
// thisneedtransfor=0;
|
||||
// for(int i=0;i<512;i++)
|
||||
// {
|
||||
// temp16_2[i]+=adc_ans[i];
|
||||
// }
|
||||
//
|
||||
// if (index%Average_Number==0)
|
||||
// {
|
||||
// for(int i=0;i<512;i++)
|
||||
// {
|
||||
// temp16[i]=temp16_2[i]/Average_Number;
|
||||
// temp16_2[i]=0;
|
||||
// }
|
||||
// temp[0]=0xff;
|
||||
// temp[1]=0xff;
|
||||
// /**** void *memcpy(void *dest, const void *src, size_t n); *****/
|
||||
// memcpy(temp+2,temp16,1024);
|
||||
// HAL_UART_Transmit_DMA(&huart1,temp,1026);
|
||||
// }
|
||||
// needreset2=1;
|
||||
// index++;
|
||||
// }
|
||||
// if(mul_int>mul_int_max)
|
||||
// {
|
||||
// mul_int=0;
|
||||
// }
|
||||
// if(needreset1==1&&needreset2==1)
|
||||
// {
|
||||
// __disable_irq();
|
||||
// mul_int++;
|
||||
// G_Clk_Rise_Number=0;
|
||||
// G_Hamamatsu_Trigger_Rise_Number_U8=0;
|
||||
// G_Hamamatsu_Trigger_Rise_Number=0;
|
||||
// __enable_irq();
|
||||
// needreset1=0;
|
||||
// needreset2=0;
|
||||
// thisneedtransfor=1;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,13 +21,13 @@
|
||||
#include "usart.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
/* 接收缓冲, <20><EFBFBD>?大USART_REC_LEN个字<E4B8AA><EFBFBD>?. */
|
||||
/* 接收缓冲, <20>?大USART_REC_LEN个字<E4B8AA>?. */
|
||||
uint8_t g_usart_rx_buf[USART_REC_LEN];
|
||||
|
||||
/* 接收状<E694B6>??
|
||||
* bit15<31><EFBFBD>? 接收完成标志
|
||||
* bit14<31><EFBFBD>? 接收<E68EA5><EFBFBD>?0x0d
|
||||
* bit13~0<><EFBFBD>? 接收到的有效字节数目
|
||||
/* 接收状<E694B6>??
|
||||
* bit15<31>? 接收完成标志
|
||||
* bit14<31>? 接收<E68EA5>?0x0d
|
||||
* bit13~0<>? 接收到的有效字节数目
|
||||
*/
|
||||
uint16_t g_usart_rx_sta = 0;
|
||||
/* HAL库使用的串口接收缓冲 */
|
||||
@ -129,7 +129,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
||||
hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
hdma_usart1_tx.Init.Mode = DMA_CIRCULAR;
|
||||
hdma_usart1_tx.Init.Mode = DMA_NORMAL;
|
||||
hdma_usart1_tx.Init.Priority = DMA_PRIORITY_MEDIUM;
|
||||
hdma_usart1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
|
||||
if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK)
|
||||
@ -179,19 +179,19 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
|
||||
/* USER CODE BEGIN 1 */
|
||||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
if(huart->Instance == USART1) /* 如果是串<E698AF><EFBFBD>?1 */
|
||||
if(huart->Instance == USART1) /* 如果是串<E698AF>?1 */
|
||||
{
|
||||
if((g_usart_rx_sta & 0x8000) == 0) /* 接收未完<E69CAA><EFBFBD>? */
|
||||
if((g_usart_rx_sta & 0x8000) == 0) /* 接收未完<E69CAA>? */
|
||||
{
|
||||
if(g_usart_rx_sta & 0x4000) /* 接收到了0x0d */
|
||||
{
|
||||
if(g_rx_buffer[0] != 0x0a)
|
||||
{
|
||||
g_usart_rx_sta = 0; /* 接收错误,重新<E9878D><EFBFBD>?<3F><EFBFBD>? */
|
||||
g_usart_rx_sta = 0; /* 接收错误,重新<E9878D>?<EFBFBD>? */
|
||||
}
|
||||
else
|
||||
{
|
||||
g_usart_rx_sta |= 0x8000; /* 接收完成<E5AE8C><EFBFBD>? */
|
||||
g_usart_rx_sta |= 0x8000; /* 接收完成<E5AE8C>? */
|
||||
}
|
||||
}
|
||||
else /* 还没收到0X0D */
|
||||
@ -206,7 +206,7 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
||||
g_usart_rx_sta++;
|
||||
if(g_usart_rx_sta > (USART_REC_LEN - 1))
|
||||
{
|
||||
g_usart_rx_sta = 0; /* 接收数据错误,重新<E9878D><EFBFBD>?始接<E5A78B><EFBFBD>? */
|
||||
g_usart_rx_sta = 0; /* 接收数据错误,重新<E9878D>?始接<E5A78B>? */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user