Przeglądaj źródła

1.mini7_boot 上库

yidongFan 1 miesiąc temu
rodzic
commit
69d173d98a
40 zmienionych plików z 525 dodań i 10064 usunięć
  1. 3 12
      BoardInterface/onechip_devinf_define.h
  2. 1 9
      BoardInterface/onechip_include_header.h
  3. 3 5
      BoardInterface/onechip_load_inf.c
  4. 2 2
      BoardInterface/onechip_load_inf.h
  5. 1 1
      Core/Src/adc.c
  6. 34 56
      Core/Src/main.c
  7. 4 0
      Core/Src/usart.c
  8. 0 33
      DriverInterface/TCA9548A.h
  9. 23 13
      DriverInterface/VAN_ITCallBack.c
  10. 0 3119
      DriverInterface/cJSON.c
  11. 0 300
      DriverInterface/cJSON.h
  12. 158 449
      DriverInterface/communication.c
  13. 47 2
      DriverInterface/communication.h
  14. 93 0
      DriverInterface/onchip_flash.c
  15. 10 0
      DriverInterface/onchip_flash.h
  16. 0 149
      DriverInterface/pt1000.c
  17. 0 26
      DriverInterface/pt1000.h
  18. 0 512
      DriverInterface/state_mini.c
  19. 0 249
      DriverInterface/state_mini.h
  20. 0 648
      DriverInterface/uart_rcv.c
  21. 0 125
      DriverInterface/uart_rcv.h
  22. 0 211
      DriverInterface/user_heater.c
  23. 0 47
      DriverInterface/user_heater.h
  24. 0 21
      DriverInterface/usr_b2b_msg.h
  25. 0 883
      DriverInterface/usr_b2pc_msg.c
  26. 0 370
      DriverInterface/usr_lysis.c
  27. 0 98
      DriverInterface/usr_lysis.h
  28. 0 680
      DriverInterface/usr_motor.c
  29. 0 49
      DriverInterface/usr_motor.h
  30. 0 287
      DriverInterface/van_BSP_Com_Pwm.c
  31. 0 76
      DriverInterface/van_BSP_Com_Pwm.h
  32. 0 254
      DriverInterface/van_BSP_Scanner.c
  33. 0 34
      DriverInterface/van_BSP_Scanner.h
  34. 0 1000
      DriverInterface/van_bsp_uart_fun.c
  35. 0 51
      DriverInterface/van_bsp_uart_fun.h
  36. 8 22
      MDK-ARM/mini7_V2.uvguix.Administrator
  37. 49 151
      MDK-ARM/mini7_V2.uvoptx
  38. 22 67
      MDK-ARM/mini7_V2.uvprojx
  39. 66 30
      MDK-ARM/startup_stm32f103xe.lst
  40. 1 23
      tshell/van_bsp_debug_shell.c

+ 3 - 12
BoardInterface/onechip_devinf_define.h

@@ -3,13 +3,10 @@
 
 
 #include "oneChip_basic_define.h"
-#include "state_mini.h"
-#include "user_heater.h"
-#include "usr_lysis.h"
 #define OFFLINE_TIME 20*60  /*一分钟*/
 
 
-#define CMD_BUF_SIZE (128)	// 调试串口缓冲区长度
+#define CMD_BUF_SIZE (256)	// 调试串口缓冲区长度
 typedef enum {
 	ONECHIP_DEV_STATE_NONE,
 	ONECHIP_DEV_STATE_POWEROFF,
@@ -106,11 +103,7 @@ typedef struct {
 	uint32_t resendeQRtimer;
 	uint32_t QRBeepTimeer;
 	
-	ProcessStateMachine_t psmMaster;
-	ProcessStateMachine_t psmSlave;
-	heat_ctrl_def heaterMaster;
-	heat_ctrl_def heaterSlave;
-    lysis_ctr_def lysis;
+
 	float lysis_offset;
 	float lysis_overHeat;
 	float lysis_overHeatTime;
@@ -154,12 +147,10 @@ typedef struct {
 
 ONECHIP_GLOBAL_DEF oneChipSysdef sysinf;
 
-ONECHIP_GLOBAL_DEF uint8_t g_cmd_rx_buf[CMD_BUF_SIZE];
 ONECHIP_GLOBAL_DEF uint32_t  cmd_rx_last;
+ONECHIP_GLOBAL_DEF uint8_t g_cmd_rx_buf[CMD_BUF_SIZE];
 ONECHIP_GLOBAL_DEF uint32_t  cmd_rx_header;
 ONECHIP_GLOBAL_DEF CmdMessage  uart0_massage;
 ONECHIP_GLOBAL_DEF uint8_t  uart0_data[CMD_BUF_SIZE];
-
-ONECHIP_GLOBAL_DEF test_result_struct result;
 #endif //__ONECHIP_BASIC_DEFINE_H_
 

+ 1 - 9
BoardInterface/onechip_include_header.h

@@ -13,24 +13,16 @@
 #include "tim.h"
 #include "usart.h"
 #include "gpio.h"
+#include "communication.h"
 #include "onechip_devinf_define.h"
 #include "van_bsp_debug_shell.h"
 #include "van_bsp_debug_uart.h"
 #include "onechip_load_inf.h"
 #include "van_com_algorithm.h"
 #include "onechip_basic_define.h"
-#include "pt1000.h"
-#include "cJSON.h"
 #include "VAN_ITCallBack.h"
-#include "van_BSP_Com_Pwm.h"
-#include "user_heater.h"
-#include "state_mini.h"
-#include "usr_motor.h"
-#include "usr_lysis.h"
 #include "ws2812.h"
-#include "rgb381.h"
 #include "communication.h"
-#include "van_BSP_Scanner.h"
 #include "van_BSP_ESPUart.h"
 #include "ESP32_WROOM_32D.h"
 #include "onchip_flash.h"

+ 3 - 5
BoardInterface/onechip_load_inf.c

@@ -28,10 +28,10 @@
 #define STR1(R)  #R
 #define STR2(R)  STR1(R)
 
-const char Software_Ver[] __attribute__((at(VERINFO_ADDR_BASE + 0x00)))  = "Soft: " STR2(SOFT_VERSION_1) "." STR2(SOFT_VERSION_2) "." STR2(SOFT_VERSION_3) "." STR2(SOFT_VERSION_4);
-const char Compiler_Date[] __attribute__((at(VERINFO_ADDR_BASE + 0x10))) = "Time: " __DATE__  "-" __TIME__;
+const char Software_Ver[]   = "Soft: " STR2(SOFT_VERSION_1) "." STR2(SOFT_VERSION_2) "." STR2(SOFT_VERSION_3) "." STR2(SOFT_VERSION_4);
+const char Compiler_Date[] = "Time: " __DATE__  "-" __TIME__;
 #ifdef ONE_CHIP_GIT_SHA_SHORT
-const char git_sha[] __attribute__((at(VERINFO_ADDR_BASE + 0x30))) = "SHA: " ONE_CHIP_GIT_SHA_SHORT;
+const char git_sha[]  = "SHA: " ONE_CHIP_GIT_SHA_SHORT;
 #endif  
 
 /**********************************************************************************
@@ -150,8 +150,6 @@ void dev_load_allinf (void)
 	sysinf.beep_pin = MINI7_V2_BEEPER_Pin;	
 	sysinf.beep_port = MINI7_V2_BEEPER_GPIO_Port;
 	sysinf.ms_conter = 0;
-	sysinf.heaterMaster.pwdId = MINI7_SUB_FUN_HEATER1;
-	sysinf.lysis.pwdId = MINI7_SUB_FUN_HEATER2;
 	sysinf.pc_link_timeout = OFFLINE_TIME;
 }
 /**********************************************************************************

+ 2 - 2
BoardInterface/onechip_load_inf.h

@@ -5,8 +5,8 @@
 #define HARD_VERSION_1    (0x01)//硬件版本号
 #define HARD_VERSION_2    (0x00)//硬件版本号
 
-#define SOFT_VERSION_1  7	//软件版本号
-#define SOFT_VERSION_2  4	//软件版本号
+#define SOFT_VERSION_1  1	//软件版本号
+#define SOFT_VERSION_2  1	//软件版本号
 #define SOFT_VERSION_3  0	//软件版本号
 #define SOFT_VERSION_4  0	//软件版本号
 

+ 1 - 1
Core/Src/adc.c

@@ -80,7 +80,7 @@ void MX_ADC1_Init(void)
     Error_Handler();
   }
   /* USER CODE BEGIN ADC1_Init 2 */
-
+  HAL_ADC_Stop_DMA(&hadc1);
   /* USER CODE END ADC1_Init 2 */
 
 }

+ 34 - 56
Core/Src/main.c

@@ -84,15 +84,6 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
 							sysinf.s10_flag = 1;
 						}            
 					}
-					 Motor_mix_work();
-				 }
-				 if(sysinf.ms_conter%100 == 1){          
-            float temp = getADC_Chanel_value(0);
-            sysinf.heaterMaster.pid.realtemp = temp + sysinf.heaterMaster.offset;
-            heater_work(&sysinf.heaterMaster);
-				 }
-				 if(sysinf.ms_conter%100 == 2){
-            lysis_work();
 				 }
 				 if(sysinf.ms_conter%100 == 1){
 					 sysinf.deal_espFlag=1;
@@ -117,7 +108,9 @@ int main(void)
 {
 
   /* USER CODE BEGIN 1 */
-
+	
+	SCB->VTOR = 0x8000000;
+   unsigned int waittime = 0;
   /* USER CODE END 1 */
 
   /* MCU Configuration--------------------------------------------------------*/
@@ -159,14 +152,10 @@ int main(void)
   light_refresh(COLOR_YELLOW, COLOR_YELLOW);
 	con_sysinf_debugUart((void *)&huart1);
   Van_Debug_UART_Init((UART_HandleTypeDef *)sysinf.debugUart);
-	ADC_Inner_start();
-	load_com_pwm_Cfg(&sysinf.devdesc);
-	sysinf.scannerUart = &huart4;
-	svanner_receive_Rec_Start(sysinf.scannerUart);
+
 	sysinf.ESPUart = &huart2;
 	esp_receive_Rec_Start(sysinf.ESPUart);
 	
-	SensorInitial();
   /* USER CODE END 2 */
 
   /* Infinite loop */
@@ -174,14 +163,11 @@ int main(void)
 	
 	Van_Device_Printf(VAN_LOG_ALLPRINT, "\n-----------------------------\n\r");
 	Van_Device_Printf(VAN_LOG_ALLPRINT,"*			  build %s %s						   *\n",__DATE__,__TIME__);
-	Van_Device_Printf(VAN_LOG_ALLPRINT, "ATCG ControlBoard\n\r");
+	Van_Device_Printf(VAN_LOG_ALLPRINT, "mini7 bootlader\n\r");
 #ifdef ONE_CHIP_GIT_SHA
 	Van_Device_Printf(VAN_LOG_ALLPRINT, "git sha: %s\n\r", ONE_CHIP_GIT_SHA);
 #endif  
-	Van_Device_Printf(VAN_LOG_ALLPRINT, "desversion 0x%x \n\r",sysinf.devdesc.desversion);
-	Van_Device_Printf(VAN_LOG_ALLPRINT, "dev type:%d  ver:%d\n\r",sysinf.devdesc.deveice_type,sysinf.devdesc.deveice_ver);
-	Van_Device_Printf(VAN_LOG_ALLPRINT, "structure type:%d	structure ver:%d\n\r",sysinf.devdesc.structure_type,sysinf.devdesc.structure_ver);
-	Van_Device_Printf(VAN_LOG_ALLPRINT, "hard type:%d  hard ver :%d \n\r",sysinf.devdesc.hardware_type,sysinf.devdesc.hardware_ver);
+
 	Van_Device_Printf(VAN_LOG_ALLPRINT, "Soft Version: V%d.%d.%d.%d\n\r",SOFT_VERSION_1, SOFT_VERSION_2, SOFT_VERSION_3, SOFT_VERSION_4);
   if(sysinf.resetByIwdg){
 	Van_Device_Printf(VAN_LOG_ALLPRINT, "**************************************************************************\n\r");
@@ -191,67 +177,60 @@ int main(void)
 	Van_Device_Printf(VAN_LOG_ALLPRINT, "**************************************************************************\n\r");
   }
   cfg_param_init();
-  Motor_Init();
-  updatParm_lysis();
-  updatParm_heater_master();
-  check_heater_master_needPreheat();
+
 	if (HAL_TIM_Base_Start_IT(&htim2) != HAL_OK) {
 			/* 启动失败,可在此处添加错误处理 */
 			Error_Handler();
 	}
-	// if(	SensorSelfCheck()){
-	// 	Van_Device_Printf(VAN_LOG_ALLPRINT, "SensorSelfCheck failed\n\r");
-	// }else{
-	// 	Van_Device_Printf(VAN_LOG_ALLPRINT, "SensorSelfCheck pass\n\r");
-	// }
-	
-   sysinf.psmMaster.state = SW_Read_To_Board_Selftest;
-
   while (1)
   {
     /* USER CODE END WHILE */
 
     /* USER CODE BEGIN 3 */
-		svanner_receive_analysis();
-  	Van_Debug_UART1_test();
     if(((cmd_rx_last + CMD_BUF_SIZE - cmd_rx_header) % CMD_BUF_SIZE) >= 8){
 		    uint32_t  uart0_recOK = DecodeNew(&uart0_massage,uart0_data,g_cmd_rx_buf, &cmd_rx_header,cmd_rx_last,CMD_BUF_SIZE);
         if(uart0_recOK){
             uart0_recOK = 0;
             sysinf.pc_channel_recv  = PC_CONNECT_TYPE_UART;
             sysinf.pc_link_timeout = 0;
-            uart0_massage.data = (char *)uart0_data;            
-            deal_mUnion_cmd(&uart0_massage);
+            uart0_massage.data = (char *)uart0_data;  
             query_pc_cmd(&uart0_massage);
           }
       }
 
 		if(sysinf.deal_espFlag){
 			sysinf.deal_espFlag =0;
-			WIFI_process();
+			// WIFI_process();
 		}
 		if(	sysinf.s1_flag == 1){
 			sysinf.s1_flag = 0;
-			HAL_GPIO_TogglePin((GPIO_TypeDef *)sysinf.run_led_port, sysinf.run_led_pin); /*green*/      
-      update_work();
-      resetSampleData(&sysinf.psmMaster);
-		}
-    if(sysinf.resendFlag == 1 ){
-      sysinf.resendFlag  = 0;      
-      reSend_QR();	
-      resend_error_update();
-      re_send_state();
-    }
-		if(	sysinf.ms10_flag == 1){
-			sysinf.ms10_flag = 0;
-      if(sysinf.QRBeepTimeer){
-        sysinf.QRBeepTimeer --;
-        if(sysinf.QRBeepTimeer == 0){
-            HAL_GPIO_WritePin((GPIO_TypeDef *)sysinf.beep_port, sysinf.beep_pin,GPIO_PIN_RESET);
-        }
-      }		
+      waittime++;
+				HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_14); /*green*/ 
+				HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_13); /*green*/ 
+      if(in_update_process()==0){        
+         send_baseinf_pc(0,0);
+      }
+	    Van_Device_Printf(VAN_LOG_ALLPRINT, "wait time %d\n\r",waittime);   
+      if((in_update_process() == 0) && ((waittime > 5)) ){
+            
+            Van_Device_Printf(VAN_LOG_ALLPRINT, "go to app at:%x\n\r",FLASH_APP1_ADDR);  
+            HAL_Delay(1000);  
+            if (HAL_TIM_Base_Stop(&htim2) != HAL_OK) {
+                  /* 启动失败,可在此处添加错误处理 */
+                  Error_Handler();
+              }
+            	// // 7. 关闭SysTick(避免其产生中断)
+            SysTick->CTRL = 0;
+            SysTick->LOAD = 0;
+            SysTick->VAL  = 0;
+            for(unsigned i=0;i<10000;i++){
+              i++;i--;
+            }
+            iap_load_app(FLASH_APP1_ADDR);
+      }
 		}
 
+
 		if(	sysinf.upheart_flag == 1){
 			sysinf.upheart_flag = 0;
       if((sysinf.pc_channel_recv  == PC_CONNECT_TYPE_NULL)||(sysinf.pc_channel_recv == PC_CONNECT_TYPE_WIFI && sysinf.pc_link_timeout > (OFFLINE_TIME/3)) ){
@@ -264,7 +243,6 @@ int main(void)
 				send_Devinf_pc();
 			}
 		}
-    usr_state_machine(&sysinf.psmMaster,&sysinf.heaterMaster);
   }
   /* USER CODE END 3 */
 }

+ 4 - 0
Core/Src/usart.c

@@ -122,6 +122,10 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
 {
 
   GPIO_InitTypeDef GPIO_InitStruct = {0};
+  
+		__HAL_UART_CLEAR_IDLEFLAG(uartHandle);
+    __HAL_UART_CLEAR_FLAG(uartHandle, UART_FLAG_ORE);
+    __HAL_UART_CLEAR_FLAG(uartHandle, UART_FLAG_RXNE);
   if(uartHandle->Instance==UART4)
   {
   /* USER CODE BEGIN UART4_MspInit 0 */

+ 0 - 33
DriverInterface/TCA9548A.h

@@ -1,33 +0,0 @@
-
-
-#ifndef __TCA9548A__H
-#define __TCA9548A_H
-#define Sensor1           1
-#define Sensor2           2
-#define Sensor3           3
-#define Sensor4           4
-#define Sensor5           5
-#define Sensor6           6
-#define Sensor7           7
-#define Sensor8           8
-#define Sensor9           9
-#define Sensor10          10
-#define SenRST            11
-/**********************************/
-#define TCA9548A_SLAVE_ADDR         0x70
-#define TCA9548A_SLAVE_ADDR1        0x74
-
-#define TCA9548A_WRITE_BIT          0x00
-#define TCA9548A_READ_BIT           0x01
-
-#define TCA9548A_CHANNEL_0          0x00
-#define TCA9548A_CHANNEL_1          0x01
-#define TCA9548A_CHANNEL_2          0x02
-#define TCA9548A_CHANNEL_3          0x04
-#define TCA9548A_CHANNEL_4          0x08
-#define TCA9548A_CHANNEL_5          0x10
-#define TCA9548A_CHANNEL_6          0x20
-#define TCA9548A_CHANNEL_7          0x40
-#define TCA9548A_CHANNEL_8          0x80
-
-#endif

+ 23 - 13
DriverInterface/VAN_ITCallBack.c

@@ -33,18 +33,28 @@ void HAL_UART_Rec_IDLE(UART_HandleTypeDef *huart)
 		Van_Debug_UART_Rec_IDLE(huart);
 	  return;
 	}
-	Uart = (UART_HandleTypeDef *)sysinf.scannerUart;
-	if (huart->Instance == Uart->Instance){
-		svanner_receive_Rec_IDLE(huart);
-	  return;
-	}
 	
 	Uart = (UART_HandleTypeDef *)sysinf.ESPUart;
 	if (huart->Instance == Uart->Instance){
 		esp_receive_Rec_IDLE(huart);
 	  return;
-	}
-	
+	}else{
+		if ((__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE) != RESET))
+		{
+			__HAL_UART_CLEAR_IDLEFLAG(huart);
+
+		}
+		if ((__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET))
+		{
+			
+			__HAL_UART_CLEAR_FLAG(huart, UART_FLAG_RXNE);
+		}
+		if ((__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET))
+		{			
+			__HAL_UART_CLEAR_FLAG(huart, UART_FLAG_ORE);
+		}
+		}
+
 	return;
 }
 
@@ -138,13 +148,13 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
 {
   /* Prevent unused argument(s) compilation warning */
   UNUSED(GPIO_Pin);
-	if(GPIO_Pin == MINI7_V2_KEY_Pin){
-		KYE_IRQHandler();
-	}
+	// if(GPIO_Pin == MINI7_V2_KEY_Pin){
+	// 	KYE_IRQHandler();
+	// }
 	
-	if(GPIO_Pin == MINI7_V2_REF_SW2_Pin){
-		OPTO_IRQHandler();
-	}
+	// if(GPIO_Pin == MINI7_V2_REF_SW2_Pin){
+	// 	OPTO_IRQHandler();
+	// }
 	
   /* NOTE: This function Should not be modified, when the callback is needed,
            the HAL_GPIO_EXTI_Callback could be implemented in the user file

+ 0 - 3119
DriverInterface/cJSON.c

@@ -1,3119 +0,0 @@
-/*
-  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.
-*/
-
-/* cJSON */
-/* JSON parser in C. */
-
-/* disable warnings about old C89 functions in MSVC */
-#if !defined(_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
-#define _CRT_SECURE_NO_DEPRECATE
-#endif
-
-#ifdef __GNUC__
-#pragma GCC visibility push(default)
-#endif
-#if defined(_MSC_VER)
-#pragma warning (push)
-/* disable warning about single line comments in system headers */
-#pragma warning (disable : 4001)
-#endif
-
-#include <string.h>
-#include <stdio.h>
-#include <math.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <ctype.h>
-#include <float.h>
-
-#ifdef ENABLE_LOCALES
-#include <locale.h>
-#endif
-
-#if defined(_MSC_VER)
-#pragma warning (pop)
-#endif
-#ifdef __GNUC__
-#pragma GCC visibility pop
-#endif
-
-#include "cJSON.h"
-
-/* define our own boolean type */
-#ifdef true
-#undef true
-#endif
-#define true ((cJSON_bool)1)
-
-#ifdef false
-#undef false
-#endif
-#define false ((cJSON_bool)0)
-
-/* define isnan and isinf for ANSI C, if in C99 or above, isnan and isinf has been defined in math.h */
-#ifndef isinf
-#define isinf(d) (isnan((d - d)) && !isnan(d))
-#endif
-#ifndef isnan
-#define isnan(d) (d != d)
-#endif
-
-#ifndef NAN
-#ifdef _WIN32
-#define NAN sqrt(-1.0)
-#else
-#define NAN 0.0/0.0
-#endif
-#endif
-
-typedef struct {
-    const unsigned char *json;
-    size_t position;
-} error;
-static error global_error = { NULL, 0 };
-
-CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void)
-{
-    return (const char*) (global_error.json + global_error.position);
-}
-
-CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
-{
-    if (!cJSON_IsString(item))
-    {
-        return NULL;
-    }
-
-    return item->valuestring;
-}
-
-CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
-{
-    if (!cJSON_IsNumber(item))
-    {
-        return (double) NAN;
-    }
-
-    return item->valuedouble;
-}
-
-/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
-#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 16)
-    #error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
-#endif
-
-CJSON_PUBLIC(const char*) cJSON_Version(void)
-{
-    static char version[15];
-    sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH);
-
-    return version;
-}
-
-/* Case insensitive string comparison, doesn't consider two NULL pointers equal though */
-static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2)
-{
-    if ((string1 == NULL) || (string2 == NULL))
-    {
-        return 1;
-    }
-
-    if (string1 == string2)
-    {
-        return 0;
-    }
-
-    for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++)
-    {
-        if (*string1 == '\0')
-        {
-            return 0;
-        }
-    }
-
-    return tolower(*string1) - tolower(*string2);
-}
-
-typedef struct internal_hooks
-{
-    void *(CJSON_CDECL *allocate)(size_t size);
-    void (CJSON_CDECL *deallocate)(void *pointer);
-    void *(CJSON_CDECL *reallocate)(void *pointer, size_t size);
-} internal_hooks;
-
-#if defined(_MSC_VER)
-/* work around MSVC error C2322: '...' address of dllimport '...' is not static */
-static void * CJSON_CDECL internal_malloc(size_t size)
-{
-    return malloc(size);
-}
-static void CJSON_CDECL internal_free(void *pointer)
-{
-    free(pointer);
-}
-static void * CJSON_CDECL internal_realloc(void *pointer, size_t size)
-{
-    return realloc(pointer, size);
-}
-#else
-#define internal_malloc malloc
-#define internal_free free
-#define internal_realloc realloc
-#endif
-
-/* strlen of character literals resolved at compile time */
-#define static_strlen(string_literal) (sizeof(string_literal) - sizeof(""))
-
-static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc };
-
-static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks)
-{
-    size_t length = 0;
-    unsigned char *copy = NULL;
-
-    if (string == NULL)
-    {
-        return NULL;
-    }
-
-    length = strlen((const char*)string) + sizeof("");
-    copy = (unsigned char*)hooks->allocate(length);
-    if (copy == NULL)
-    {
-        return NULL;
-    }
-    memcpy(copy, string, length);
-
-    return copy;
-}
-
-CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks)
-{
-    if (hooks == NULL)
-    {
-        /* Reset hooks */
-        global_hooks.allocate = malloc;
-        global_hooks.deallocate = free;
-        global_hooks.reallocate = realloc;
-        return;
-    }
-
-    global_hooks.allocate = malloc;
-    if (hooks->malloc_fn != NULL)
-    {
-        global_hooks.allocate = hooks->malloc_fn;
-    }
-
-    global_hooks.deallocate = free;
-    if (hooks->free_fn != NULL)
-    {
-        global_hooks.deallocate = hooks->free_fn;
-    }
-
-    /* use realloc only if both free and malloc are used */
-    global_hooks.reallocate = NULL;
-    if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free))
-    {
-        global_hooks.reallocate = realloc;
-    }
-}
-
-/* Internal constructor. */
-static cJSON *cJSON_New_Item(const internal_hooks * const hooks)
-{
-    cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON));
-    if (node)
-    {
-        memset(node, '\0', sizeof(cJSON));
-    }
-
-    return node;
-}
-
-/* Delete a cJSON structure. */
-CJSON_PUBLIC(void) cJSON_Delete(cJSON *item)
-{
-    cJSON *next = NULL;
-    while (item != NULL)
-    {
-        next = item->next;
-        if (!(item->type & cJSON_IsReference) && (item->child != NULL))
-        {
-            cJSON_Delete(item->child);
-        }
-        if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL))
-        {
-            global_hooks.deallocate(item->valuestring);
-        }
-        if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
-        {
-            global_hooks.deallocate(item->string);
-        }
-        global_hooks.deallocate(item);
-        item = next;
-    }
-}
-
-/* get the decimal point character of the current locale */
-static unsigned char get_decimal_point(void)
-{
-#ifdef ENABLE_LOCALES
-    struct lconv *lconv = localeconv();
-    return (unsigned char) lconv->decimal_point[0];
-#else
-    return '.';
-#endif
-}
-
-typedef struct
-{
-    const unsigned char *content;
-    size_t length;
-    size_t offset;
-    size_t depth; /* How deeply nested (in arrays/objects) is the input at the current offset. */
-    internal_hooks hooks;
-} parse_buffer;
-
-/* check if the given size is left to read in a given parse buffer (starting with 1) */
-#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
-/* check if the buffer can be accessed at the given index (starting with 0) */
-#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
-#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
-/* get a pointer to the buffer at the position */
-#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
-
-/* Parse the input text to generate a number, and populate the result into item. */
-static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer)
-{
-    double number = 0;
-    unsigned char *after_end = NULL;
-    unsigned char number_c_string[64];
-    unsigned char decimal_point = get_decimal_point();
-    size_t i = 0;
-
-    if ((input_buffer == NULL) || (input_buffer->content == NULL))
-    {
-        return false;
-    }
-
-    /* copy the number into a temporary buffer and replace '.' with the decimal point
-     * of the current locale (for strtod)
-     * This also takes care of '\0' not necessarily being available for marking the end of the input */
-    for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++)
-    {
-        switch (buffer_at_offset(input_buffer)[i])
-        {
-            case '0':
-            case '1':
-            case '2':
-            case '3':
-            case '4':
-            case '5':
-            case '6':
-            case '7':
-            case '8':
-            case '9':
-            case '+':
-            case '-':
-            case 'e':
-            case 'E':
-                number_c_string[i] = buffer_at_offset(input_buffer)[i];
-                break;
-
-            case '.':
-                number_c_string[i] = decimal_point;
-                break;
-
-            default:
-                goto loop_end;
-        }
-    }
-loop_end:
-    number_c_string[i] = '\0';
-
-    number = strtod((const char*)number_c_string, (char**)&after_end);
-    if (number_c_string == after_end)
-    {
-        return false; /* parse_error */
-    }
-
-    item->valuedouble = number;
-
-    /* use saturation in case of overflow */
-    if (number >= INT_MAX)
-    {
-        item->valueint = INT_MAX;
-    }
-    else if (number <= (double)INT_MIN)
-    {
-        item->valueint = INT_MIN;
-    }
-    else
-    {
-        item->valueint = (int)number;
-    }
-
-    item->type = cJSON_Number;
-
-    input_buffer->offset += (size_t)(after_end - number_c_string);
-    return true;
-}
-
-/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */
-CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number)
-{
-    if (number >= INT_MAX)
-    {
-        object->valueint = INT_MAX;
-    }
-    else if (number <= (double)INT_MIN)
-    {
-        object->valueint = INT_MIN;
-    }
-    else
-    {
-        object->valueint = (int)number;
-    }
-
-    return object->valuedouble = number;
-}
-
-CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
-{
-    char *copy = NULL;
-    /* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */
-    if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference))
-    {
-        return NULL;
-    }
-    if (strlen(valuestring) <= strlen(object->valuestring))
-    {
-        strcpy(object->valuestring, valuestring);
-        return object->valuestring;
-    }
-    copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks);
-    if (copy == NULL)
-    {
-        return NULL;
-    }
-    if (object->valuestring != NULL)
-    {
-        cJSON_free(object->valuestring);
-    }
-    object->valuestring = copy;
-
-    return copy;
-}
-
-typedef struct
-{
-    unsigned char *buffer;
-    size_t length;
-    size_t offset;
-    size_t depth; /* current nesting depth (for formatted printing) */
-    cJSON_bool noalloc;
-    cJSON_bool format; /* is this print a formatted print */
-    internal_hooks hooks;
-} printbuffer;
-
-/* realloc printbuffer if necessary to have at least "needed" bytes more */
-static unsigned char* ensure(printbuffer * const p, size_t needed)
-{
-    unsigned char *newbuffer = NULL;
-    size_t newsize = 0;
-
-    if ((p == NULL) || (p->buffer == NULL))
-    {
-        return NULL;
-    }
-
-    if ((p->length > 0) && (p->offset >= p->length))
-    {
-        /* make sure that offset is valid */
-        return NULL;
-    }
-
-    if (needed > INT_MAX)
-    {
-        /* sizes bigger than INT_MAX are currently not supported */
-        return NULL;
-    }
-
-    needed += p->offset + 1;
-    if (needed <= p->length)
-    {
-        return p->buffer + p->offset;
-    }
-
-    if (p->noalloc) {
-        return NULL;
-    }
-
-    /* calculate new buffer size */
-    if (needed > (INT_MAX / 2))
-    {
-        /* overflow of int, use INT_MAX if possible */
-        if (needed <= INT_MAX)
-        {
-            newsize = INT_MAX;
-        }
-        else
-        {
-            return NULL;
-        }
-    }
-    else
-    {
-        newsize = needed * 2;
-    }
-
-    if (p->hooks.reallocate != NULL)
-    {
-        /* reallocate with realloc if available */
-        newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize);
-        if (newbuffer == NULL)
-        {
-            p->hooks.deallocate(p->buffer);
-            p->length = 0;
-            p->buffer = NULL;
-
-            return NULL;
-        }
-    }
-    else
-    {
-        /* otherwise reallocate manually */
-        newbuffer = (unsigned char*)p->hooks.allocate(newsize);
-        if (!newbuffer)
-        {
-            p->hooks.deallocate(p->buffer);
-            p->length = 0;
-            p->buffer = NULL;
-
-            return NULL;
-        }
-
-        memcpy(newbuffer, p->buffer, p->offset + 1);
-        p->hooks.deallocate(p->buffer);
-    }
-    p->length = newsize;
-    p->buffer = newbuffer;
-
-    return newbuffer + p->offset;
-}
-
-/* calculate the new length of the string in a printbuffer and update the offset */
-static void update_offset(printbuffer * const buffer)
-{
-    const unsigned char *buffer_pointer = NULL;
-    if ((buffer == NULL) || (buffer->buffer == NULL))
-    {
-        return;
-    }
-    buffer_pointer = buffer->buffer + buffer->offset;
-
-    buffer->offset += strlen((const char*)buffer_pointer);
-}
-
-/* securely comparison of floating-point variables */
-static cJSON_bool compare_double(double a, double b)
-{
-    double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b);
-    return (fabs(a - b) <= maxVal * DBL_EPSILON);
-}
-
-/* Render the number nicely from the given item into a string. */
-static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer)
-{
-    unsigned char *output_pointer = NULL;
-    double d = item->valuedouble;
-    int length = 0;
-    size_t i = 0;
-    unsigned char number_buffer[26] = {0}; /* temporary buffer to print the number into */
-    unsigned char decimal_point = get_decimal_point();
-    double test = 0.0;
-
-    if (output_buffer == NULL)
-    {
-        return false;
-    }
-
-    /* This checks for NaN and Infinity */
-    if (isnan(d) || isinf(d))
-    {
-        length = sprintf((char*)number_buffer, "null");
-    }
-	else if(d == (double)item->valueint)
-	{
-		length = sprintf((char*)number_buffer, "%d", item->valueint);
-	}
-    else
-    {
-        /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
-        length = sprintf((char*)number_buffer, "%1.15g", d);
-
-        /* Check whether the original double can be recovered */
-        if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d))
-        {
-            /* If not, print with 17 decimal places of precision */
-            length = sprintf((char*)number_buffer, "%1.17g", d);
-        }
-    }
-
-    /* sprintf failed or buffer overrun occurred */
-    if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1)))
-    {
-        return false;
-    }
-
-    /* reserve appropriate space in the output */
-    output_pointer = ensure(output_buffer, (size_t)length + sizeof(""));
-    if (output_pointer == NULL)
-    {
-        return false;
-    }
-
-    /* copy the printed number to the output and replace locale
-     * dependent decimal point with '.' */
-    for (i = 0; i < ((size_t)length); i++)
-    {
-        if (number_buffer[i] == decimal_point)
-        {
-            output_pointer[i] = '.';
-            continue;
-        }
-
-        output_pointer[i] = number_buffer[i];
-    }
-    output_pointer[i] = '\0';
-
-    output_buffer->offset += (size_t)length;
-
-    return true;
-}
-
-/* parse 4 digit hexadecimal number */
-static unsigned parse_hex4(const unsigned char * const input)
-{
-    unsigned int h = 0;
-    size_t i = 0;
-
-    for (i = 0; i < 4; i++)
-    {
-        /* parse digit */
-        if ((input[i] >= '0') && (input[i] <= '9'))
-        {
-            h += (unsigned int) input[i] - '0';
-        }
-        else if ((input[i] >= 'A') && (input[i] <= 'F'))
-        {
-            h += (unsigned int) 10 + input[i] - 'A';
-        }
-        else if ((input[i] >= 'a') && (input[i] <= 'f'))
-        {
-            h += (unsigned int) 10 + input[i] - 'a';
-        }
-        else /* invalid */
-        {
-            return 0;
-        }
-
-        if (i < 3)
-        {
-            /* shift left to make place for the next nibble */
-            h = h << 4;
-        }
-    }
-
-    return h;
-}
-
-/* converts a UTF-16 literal to UTF-8
- * A literal can be one or two sequences of the form \uXXXX */
-static unsigned char utf16_literal_to_utf8(const unsigned char * const input_pointer, const unsigned char * const input_end, unsigned char **output_pointer)
-{
-    long unsigned int codepoint = 0;
-    unsigned int first_code = 0;
-    const unsigned char *first_sequence = input_pointer;
-    unsigned char utf8_length = 0;
-    unsigned char utf8_position = 0;
-    unsigned char sequence_length = 0;
-    unsigned char first_byte_mark = 0;
-
-    if ((input_end - first_sequence) < 6)
-    {
-        /* input ends unexpectedly */
-        goto fail;
-    }
-
-    /* get the first utf16 sequence */
-    first_code = parse_hex4(first_sequence + 2);
-
-    /* check that the code is valid */
-    if (((first_code >= 0xDC00) && (first_code <= 0xDFFF)))
-    {
-        goto fail;
-    }
-
-    /* UTF16 surrogate pair */
-    if ((first_code >= 0xD800) && (first_code <= 0xDBFF))
-    {
-        const unsigned char *second_sequence = first_sequence + 6;
-        unsigned int second_code = 0;
-        sequence_length = 12; /* \uXXXX\uXXXX */
-
-        if ((input_end - second_sequence) < 6)
-        {
-            /* input ends unexpectedly */
-            goto fail;
-        }
-
-        if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u'))
-        {
-            /* missing second half of the surrogate pair */
-            goto fail;
-        }
-
-        /* get the second utf16 sequence */
-        second_code = parse_hex4(second_sequence + 2);
-        /* check that the code is valid */
-        if ((second_code < 0xDC00) || (second_code > 0xDFFF))
-        {
-            /* invalid second half of the surrogate pair */
-            goto fail;
-        }
-
-
-        /* calculate the unicode codepoint from the surrogate pair */
-        codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF));
-    }
-    else
-    {
-        sequence_length = 6; /* \uXXXX */
-        codepoint = first_code;
-    }
-
-    /* encode as UTF-8
-     * takes at maximum 4 bytes to encode:
-     * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
-    if (codepoint < 0x80)
-    {
-        /* normal ascii, encoding 0xxxxxxx */
-        utf8_length = 1;
-    }
-    else if (codepoint < 0x800)
-    {
-        /* two bytes, encoding 110xxxxx 10xxxxxx */
-        utf8_length = 2;
-        first_byte_mark = 0xC0; /* 11000000 */
-    }
-    else if (codepoint < 0x10000)
-    {
-        /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */
-        utf8_length = 3;
-        first_byte_mark = 0xE0; /* 11100000 */
-    }
-    else if (codepoint <= 0x10FFFF)
-    {
-        /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */
-        utf8_length = 4;
-        first_byte_mark = 0xF0; /* 11110000 */
-    }
-    else
-    {
-        /* invalid unicode codepoint */
-        goto fail;
-    }
-
-    /* encode as utf8 */
-    for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--)
-    {
-        /* 10xxxxxx */
-        (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF);
-        codepoint >>= 6;
-    }
-    /* encode first byte */
-    if (utf8_length > 1)
-    {
-        (*output_pointer)[0] = (unsigned char)((codepoint | first_byte_mark) & 0xFF);
-    }
-    else
-    {
-        (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F);
-    }
-
-    *output_pointer += utf8_length;
-
-    return sequence_length;
-
-fail:
-    return 0;
-}
-
-/* Parse the input text into an unescaped cinput, and populate item. */
-static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer)
-{
-    const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1;
-    const unsigned char *input_end = buffer_at_offset(input_buffer) + 1;
-    unsigned char *output_pointer = NULL;
-    unsigned char *output = NULL;
-
-    /* not a string */
-    if (buffer_at_offset(input_buffer)[0] != '\"')
-    {
-        goto fail;
-    }
-
-    {
-        /* calculate approximate size of the output (overestimate) */
-        size_t allocation_length = 0;
-        size_t skipped_bytes = 0;
-        while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"'))
-        {
-            /* is escape sequence */
-            if (input_end[0] == '\\')
-            {
-                if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length)
-                {
-                    /* prevent buffer overflow when last input character is a backslash */
-                    goto fail;
-                }
-                skipped_bytes++;
-                input_end++;
-            }
-            input_end++;
-        }
-        if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"'))
-        {
-            goto fail; /* string ended unexpectedly */
-        }
-
-        /* This is at most how much we need for the output */
-        allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes;
-        output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof(""));
-        if (output == NULL)
-        {
-            goto fail; /* allocation failure */
-        }
-    }
-
-    output_pointer = output;
-    /* loop through the string literal */
-    while (input_pointer < input_end)
-    {
-        if (*input_pointer != '\\')
-        {
-            *output_pointer++ = *input_pointer++;
-        }
-        /* escape sequence */
-        else
-        {
-            unsigned char sequence_length = 2;
-            if ((input_end - input_pointer) < 1)
-            {
-                goto fail;
-            }
-
-            switch (input_pointer[1])
-            {
-                case 'b':
-                    *output_pointer++ = '\b';
-                    break;
-                case 'f':
-                    *output_pointer++ = '\f';
-                    break;
-                case 'n':
-                    *output_pointer++ = '\n';
-                    break;
-                case 'r':
-                    *output_pointer++ = '\r';
-                    break;
-                case 't':
-                    *output_pointer++ = '\t';
-                    break;
-                case '\"':
-                case '\\':
-                case '/':
-                    *output_pointer++ = input_pointer[1];
-                    break;
-
-                /* UTF-16 literal */
-                case 'u':
-                    sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer);
-                    if (sequence_length == 0)
-                    {
-                        /* failed to convert UTF16-literal to UTF-8 */
-                        goto fail;
-                    }
-                    break;
-
-                default:
-                    goto fail;
-            }
-            input_pointer += sequence_length;
-        }
-    }
-
-    /* zero terminate the output */
-    *output_pointer = '\0';
-
-    item->type = cJSON_String;
-    item->valuestring = (char*)output;
-
-    input_buffer->offset = (size_t) (input_end - input_buffer->content);
-    input_buffer->offset++;
-
-    return true;
-
-fail:
-    if (output != NULL)
-    {
-        input_buffer->hooks.deallocate(output);
-    }
-
-    if (input_pointer != NULL)
-    {
-        input_buffer->offset = (size_t)(input_pointer - input_buffer->content);
-    }
-
-    return false;
-}
-
-/* Render the cstring provided to an escaped version that can be printed. */
-static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer)
-{
-    const unsigned char *input_pointer = NULL;
-    unsigned char *output = NULL;
-    unsigned char *output_pointer = NULL;
-    size_t output_length = 0;
-    /* numbers of additional characters needed for escaping */
-    size_t escape_characters = 0;
-
-    if (output_buffer == NULL)
-    {
-        return false;
-    }
-
-    /* empty string */
-    if (input == NULL)
-    {
-        output = ensure(output_buffer, sizeof("\"\""));
-        if (output == NULL)
-        {
-            return false;
-        }
-        strcpy((char*)output, "\"\"");
-
-        return true;
-    }
-
-    /* set "flag" to 1 if something needs to be escaped */
-    for (input_pointer = input; *input_pointer; input_pointer++)
-    {
-        switch (*input_pointer)
-        {
-            case '\"':
-            case '\\':
-            case '\b':
-            case '\f':
-            case '\n':
-            case '\r':
-            case '\t':
-                /* one character escape sequence */
-                escape_characters++;
-                break;
-            default:
-                if (*input_pointer < 32)
-                {
-                    /* UTF-16 escape sequence uXXXX */
-                    escape_characters += 5;
-                }
-                break;
-        }
-    }
-    output_length = (size_t)(input_pointer - input) + escape_characters;
-
-    output = ensure(output_buffer, output_length + sizeof("\"\""));
-    if (output == NULL)
-    {
-        return false;
-    }
-
-    /* no characters have to be escaped */
-    if (escape_characters == 0)
-    {
-        output[0] = '\"';
-        memcpy(output + 1, input, output_length);
-        output[output_length + 1] = '\"';
-        output[output_length + 2] = '\0';
-
-        return true;
-    }
-
-    output[0] = '\"';
-    output_pointer = output + 1;
-    /* copy the string */
-    for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++)
-    {
-        if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\'))
-        {
-            /* normal character, copy */
-            *output_pointer = *input_pointer;
-        }
-        else
-        {
-            /* character needs to be escaped */
-            *output_pointer++ = '\\';
-            switch (*input_pointer)
-            {
-                case '\\':
-                    *output_pointer = '\\';
-                    break;
-                case '\"':
-                    *output_pointer = '\"';
-                    break;
-                case '\b':
-                    *output_pointer = 'b';
-                    break;
-                case '\f':
-                    *output_pointer = 'f';
-                    break;
-                case '\n':
-                    *output_pointer = 'n';
-                    break;
-                case '\r':
-                    *output_pointer = 'r';
-                    break;
-                case '\t':
-                    *output_pointer = 't';
-                    break;
-                default:
-                    /* escape and print as unicode codepoint */
-                    sprintf((char*)output_pointer, "u%04x", *input_pointer);
-                    output_pointer += 4;
-                    break;
-            }
-        }
-    }
-    output[output_length + 1] = '\"';
-    output[output_length + 2] = '\0';
-
-    return true;
-}
-
-/* Invoke print_string_ptr (which is useful) on an item. */
-static cJSON_bool print_string(const cJSON * const item, printbuffer * const p)
-{
-    return print_string_ptr((unsigned char*)item->valuestring, p);
-}
-
-/* Predeclare these prototypes. */
-static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer);
-static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer);
-static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer);
-static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer);
-static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer);
-static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer);
-
-/* Utility to jump whitespace and cr/lf */
-static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer)
-{
-    if ((buffer == NULL) || (buffer->content == NULL))
-    {
-        return NULL;
-    }
-
-    if (cannot_access_at_index(buffer, 0))
-    {
-        return buffer;
-    }
-
-    while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32))
-    {
-       buffer->offset++;
-    }
-
-    if (buffer->offset == buffer->length)
-    {
-        buffer->offset--;
-    }
-
-    return buffer;
-}
-
-/* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */
-static parse_buffer *skip_utf8_bom(parse_buffer * const buffer)
-{
-    if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0))
-    {
-        return NULL;
-    }
-
-    if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0))
-    {
-        buffer->offset += 3;
-    }
-
-    return buffer;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated)
-{
-    size_t buffer_length;
-
-    if (NULL == value)
-    {
-        return NULL;
-    }
-
-    /* Adding null character size due to require_null_terminated. */
-    buffer_length = strlen(value) + sizeof("");
-
-    return cJSON_ParseWithLengthOpts(value, buffer_length, return_parse_end, require_null_terminated);
-}
-
-/* Parse an object - create a new root, and populate. */
-CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated)
-{
-    parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
-    cJSON *item = NULL;
-
-    /* reset error position */
-    global_error.json = NULL;
-    global_error.position = 0;
-
-    if (value == NULL || 0 == buffer_length)
-    {
-        goto fail;
-    }
-
-    buffer.content = (const unsigned char*)value;
-    buffer.length = buffer_length;
-    buffer.offset = 0;
-    buffer.hooks = global_hooks;
-
-    item = cJSON_New_Item(&global_hooks);
-    if (item == NULL) /* memory fail */
-    {
-        goto fail;
-    }
-
-    if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer))))
-    {
-        /* parse failure. ep is set. */
-        goto fail;
-    }
-
-    /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
-    if (require_null_terminated)
-    {
-        buffer_skip_whitespace(&buffer);
-        if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0')
-        {
-            goto fail;
-        }
-    }
-    if (return_parse_end)
-    {
-        *return_parse_end = (const char*)buffer_at_offset(&buffer);
-    }
-
-    return item;
-
-fail:
-    if (item != NULL)
-    {
-        cJSON_Delete(item);
-    }
-
-    if (value != NULL)
-    {
-        error local_error;
-        local_error.json = (const unsigned char*)value;
-        local_error.position = 0;
-
-        if (buffer.offset < buffer.length)
-        {
-            local_error.position = buffer.offset;
-        }
-        else if (buffer.length > 0)
-        {
-            local_error.position = buffer.length - 1;
-        }
-
-        if (return_parse_end != NULL)
-        {
-            *return_parse_end = (const char*)local_error.json + local_error.position;
-        }
-
-        global_error = local_error;
-    }
-
-    return NULL;
-}
-
-/* Default options for cJSON_Parse */
-CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value)
-{
-    return cJSON_ParseWithOpts(value, 0, 0);
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length)
-{
-    return cJSON_ParseWithLengthOpts(value, buffer_length, 0, 0);
-}
-
-#define cjson_min(a, b) (((a) < (b)) ? (a) : (b))
-
-static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks)
-{
-    static const size_t default_buffer_size = 256;
-    printbuffer buffer[1];
-    unsigned char *printed = NULL;
-
-    memset(buffer, 0, sizeof(buffer));
-
-    /* create buffer */
-    buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size);
-    buffer->length = default_buffer_size;
-    buffer->format = format;
-    buffer->hooks = *hooks;
-    if (buffer->buffer == NULL)
-    {
-        goto fail;
-    }
-
-    /* print the value */
-    if (!print_value(item, buffer))
-    {
-        goto fail;
-    }
-    update_offset(buffer);
-
-    /* check if reallocate is available */
-    if (hooks->reallocate != NULL)
-    {
-        printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1);
-        if (printed == NULL) {
-            goto fail;
-        }
-        buffer->buffer = NULL;
-    }
-    else /* otherwise copy the JSON over to a new buffer */
-    {
-        printed = (unsigned char*) hooks->allocate(buffer->offset + 1);
-        if (printed == NULL)
-        {
-            goto fail;
-        }
-        memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1));
-        printed[buffer->offset] = '\0'; /* just to be sure */
-
-        /* free the buffer */
-        hooks->deallocate(buffer->buffer);
-    }
-
-    return printed;
-
-fail:
-    if (buffer->buffer != NULL)
-    {
-        hooks->deallocate(buffer->buffer);
-    }
-
-    if (printed != NULL)
-    {
-        hooks->deallocate(printed);
-    }
-
-    return NULL;
-}
-
-/* Render a cJSON item/entity/structure to text. */
-CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item)
-{
-    return (char*)print(item, true, &global_hooks);
-}
-
-CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item)
-{
-    return (char*)print(item, false, &global_hooks);
-}
-
-CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt)
-{
-    printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
-
-    if (prebuffer < 0)
-    {
-        return NULL;
-    }
-
-    p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer);
-    if (!p.buffer)
-    {
-        return NULL;
-    }
-
-    p.length = (size_t)prebuffer;
-    p.offset = 0;
-    p.noalloc = false;
-    p.format = fmt;
-    p.hooks = global_hooks;
-
-    if (!print_value(item, &p))
-    {
-        global_hooks.deallocate(p.buffer);
-        return NULL;
-    }
-
-    return (char*)p.buffer;
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format)
-{
-    printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
-
-    if ((length < 0) || (buffer == NULL))
-    {
-        return false;
-    }
-
-    p.buffer = (unsigned char*)buffer;
-    p.length = (size_t)length;
-    p.offset = 0;
-    p.noalloc = true;
-    p.format = format;
-    p.hooks = global_hooks;
-
-    return print_value(item, &p);
-}
-
-/* Parser core - when encountering text, process appropriately. */
-static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer)
-{
-    if ((input_buffer == NULL) || (input_buffer->content == NULL))
-    {
-        return false; /* no input */
-    }
-
-    /* parse the different types of values */
-    /* null */
-    if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0))
-    {
-        item->type = cJSON_NULL;
-        input_buffer->offset += 4;
-        return true;
-    }
-    /* false */
-    if (can_read(input_buffer, 5) && (strncmp((const char*)buffer_at_offset(input_buffer), "false", 5) == 0))
-    {
-        item->type = cJSON_False;
-        input_buffer->offset += 5;
-        return true;
-    }
-    /* true */
-    if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "true", 4) == 0))
-    {
-        item->type = cJSON_True;
-        item->valueint = 1;
-        input_buffer->offset += 4;
-        return true;
-    }
-    /* string */
-    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"'))
-    {
-        return parse_string(item, input_buffer);
-    }
-    /* number */
-    if (can_access_at_index(input_buffer, 0) && ((buffer_at_offset(input_buffer)[0] == '-') || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9'))))
-    {
-        return parse_number(item, input_buffer);
-    }
-    /* array */
-    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '['))
-    {
-        return parse_array(item, input_buffer);
-    }
-    /* object */
-    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{'))
-    {
-        return parse_object(item, input_buffer);
-    }
-
-    return false;
-}
-
-/* Render a value to text. */
-static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer)
-{
-    unsigned char *output = NULL;
-
-    if ((item == NULL) || (output_buffer == NULL))
-    {
-        return false;
-    }
-
-    switch ((item->type) & 0xFF)
-    {
-        case cJSON_NULL:
-            output = ensure(output_buffer, 5);
-            if (output == NULL)
-            {
-                return false;
-            }
-            strcpy((char*)output, "null");
-            return true;
-
-        case cJSON_False:
-            output = ensure(output_buffer, 6);
-            if (output == NULL)
-            {
-                return false;
-            }
-            strcpy((char*)output, "false");
-            return true;
-
-        case cJSON_True:
-            output = ensure(output_buffer, 5);
-            if (output == NULL)
-            {
-                return false;
-            }
-            strcpy((char*)output, "true");
-            return true;
-
-        case cJSON_Number:
-            return print_number(item, output_buffer);
-
-        case cJSON_Raw:
-        {
-            size_t raw_length = 0;
-            if (item->valuestring == NULL)
-            {
-                return false;
-            }
-
-            raw_length = strlen(item->valuestring) + sizeof("");
-            output = ensure(output_buffer, raw_length);
-            if (output == NULL)
-            {
-                return false;
-            }
-            memcpy(output, item->valuestring, raw_length);
-            return true;
-        }
-
-        case cJSON_String:
-            return print_string(item, output_buffer);
-
-        case cJSON_Array:
-            return print_array(item, output_buffer);
-
-        case cJSON_Object:
-            return print_object(item, output_buffer);
-
-        default:
-            return false;
-    }
-}
-
-/* Build an array from input text. */
-static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer)
-{
-    cJSON *head = NULL; /* head of the linked list */
-    cJSON *current_item = NULL;
-
-    if (input_buffer->depth >= CJSON_NESTING_LIMIT)
-    {
-        return false; /* to deeply nested */
-    }
-    input_buffer->depth++;
-
-    if (buffer_at_offset(input_buffer)[0] != '[')
-    {
-        /* not an array */
-        goto fail;
-    }
-
-    input_buffer->offset++;
-    buffer_skip_whitespace(input_buffer);
-    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']'))
-    {
-        /* empty array */
-        goto success;
-    }
-
-    /* check if we skipped to the end of the buffer */
-    if (cannot_access_at_index(input_buffer, 0))
-    {
-        input_buffer->offset--;
-        goto fail;
-    }
-
-    /* step back to character in front of the first element */
-    input_buffer->offset--;
-    /* loop through the comma separated array elements */
-    do
-    {
-        /* allocate next item */
-        cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks));
-        if (new_item == NULL)
-        {
-            goto fail; /* allocation failure */
-        }
-
-        /* attach next item to list */
-        if (head == NULL)
-        {
-            /* start the linked list */
-            current_item = head = new_item;
-        }
-        else
-        {
-            /* add to the end and advance */
-            current_item->next = new_item;
-            new_item->prev = current_item;
-            current_item = new_item;
-        }
-
-        /* parse next value */
-        input_buffer->offset++;
-        buffer_skip_whitespace(input_buffer);
-        if (!parse_value(current_item, input_buffer))
-        {
-            goto fail; /* failed to parse value */
-        }
-        buffer_skip_whitespace(input_buffer);
-    }
-    while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ','));
-
-    if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']')
-    {
-        goto fail; /* expected end of array */
-    }
-
-success:
-    input_buffer->depth--;
-
-    if (head != NULL) {
-        head->prev = current_item;
-    }
-
-    item->type = cJSON_Array;
-    item->child = head;
-
-    input_buffer->offset++;
-
-    return true;
-
-fail:
-    if (head != NULL)
-    {
-        cJSON_Delete(head);
-    }
-
-    return false;
-}
-
-/* Render an array to text */
-static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer)
-{
-    unsigned char *output_pointer = NULL;
-    size_t length = 0;
-    cJSON *current_element = item->child;
-
-    if (output_buffer == NULL)
-    {
-        return false;
-    }
-
-    /* Compose the output array. */
-    /* opening square bracket */
-    output_pointer = ensure(output_buffer, 1);
-    if (output_pointer == NULL)
-    {
-        return false;
-    }
-
-    *output_pointer = '[';
-    output_buffer->offset++;
-    output_buffer->depth++;
-
-    while (current_element != NULL)
-    {
-        if (!print_value(current_element, output_buffer))
-        {
-            return false;
-        }
-        update_offset(output_buffer);
-        if (current_element->next)
-        {
-            length = (size_t) (output_buffer->format ? 2 : 1);
-            output_pointer = ensure(output_buffer, length + 1);
-            if (output_pointer == NULL)
-            {
-                return false;
-            }
-            *output_pointer++ = ',';
-            if(output_buffer->format)
-            {
-                *output_pointer++ = ' ';
-            }
-            *output_pointer = '\0';
-            output_buffer->offset += length;
-        }
-        current_element = current_element->next;
-    }
-
-    output_pointer = ensure(output_buffer, 2);
-    if (output_pointer == NULL)
-    {
-        return false;
-    }
-    *output_pointer++ = ']';
-    *output_pointer = '\0';
-    output_buffer->depth--;
-
-    return true;
-}
-
-/* Build an object from the text. */
-static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer)
-{
-    cJSON *head = NULL; /* linked list head */
-    cJSON *current_item = NULL;
-
-    if (input_buffer->depth >= CJSON_NESTING_LIMIT)
-    {
-        return false; /* to deeply nested */
-    }
-    input_buffer->depth++;
-
-    if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{'))
-    {
-        goto fail; /* not an object */
-    }
-
-    input_buffer->offset++;
-    buffer_skip_whitespace(input_buffer);
-    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}'))
-    {
-        goto success; /* empty object */
-    }
-
-    /* check if we skipped to the end of the buffer */
-    if (cannot_access_at_index(input_buffer, 0))
-    {
-        input_buffer->offset--;
-        goto fail;
-    }
-
-    /* step back to character in front of the first element */
-    input_buffer->offset--;
-    /* loop through the comma separated array elements */
-    do
-    {
-        /* allocate next item */
-        cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks));
-        if (new_item == NULL)
-        {
-            goto fail; /* allocation failure */
-        }
-
-        /* attach next item to list */
-        if (head == NULL)
-        {
-            /* start the linked list */
-            current_item = head = new_item;
-        }
-        else
-        {
-            /* add to the end and advance */
-            current_item->next = new_item;
-            new_item->prev = current_item;
-            current_item = new_item;
-        }
-
-        /* parse the name of the child */
-        input_buffer->offset++;
-        buffer_skip_whitespace(input_buffer);
-        if (!parse_string(current_item, input_buffer))
-        {
-            goto fail; /* failed to parse name */
-        }
-        buffer_skip_whitespace(input_buffer);
-
-        /* swap valuestring and string, because we parsed the name */
-        current_item->string = current_item->valuestring;
-        current_item->valuestring = NULL;
-
-        if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':'))
-        {
-            goto fail; /* invalid object */
-        }
-
-        /* parse the value */
-        input_buffer->offset++;
-        buffer_skip_whitespace(input_buffer);
-        if (!parse_value(current_item, input_buffer))
-        {
-            goto fail; /* failed to parse value */
-        }
-        buffer_skip_whitespace(input_buffer);
-    }
-    while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ','));
-
-    if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}'))
-    {
-        goto fail; /* expected end of object */
-    }
-
-success:
-    input_buffer->depth--;
-
-    if (head != NULL) {
-        head->prev = current_item;
-    }
-
-    item->type = cJSON_Object;
-    item->child = head;
-
-    input_buffer->offset++;
-    return true;
-
-fail:
-    if (head != NULL)
-    {
-        cJSON_Delete(head);
-    }
-
-    return false;
-}
-
-/* Render an object to text. */
-static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer)
-{
-    unsigned char *output_pointer = NULL;
-    size_t length = 0;
-    cJSON *current_item = item->child;
-
-    if (output_buffer == NULL)
-    {
-        return false;
-    }
-
-    /* Compose the output: */
-    length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */
-    output_pointer = ensure(output_buffer, length + 1);
-    if (output_pointer == NULL)
-    {
-        return false;
-    }
-
-    *output_pointer++ = '{';
-    output_buffer->depth++;
-    if (output_buffer->format)
-    {
-        *output_pointer++ = '\n';
-    }
-    output_buffer->offset += length;
-
-    while (current_item)
-    {
-        if (output_buffer->format)
-        {
-            size_t i;
-            output_pointer = ensure(output_buffer, output_buffer->depth);
-            if (output_pointer == NULL)
-            {
-                return false;
-            }
-            for (i = 0; i < output_buffer->depth; i++)
-            {
-                *output_pointer++ = '\t';
-            }
-            output_buffer->offset += output_buffer->depth;
-        }
-
-        /* print key */
-        if (!print_string_ptr((unsigned char*)current_item->string, output_buffer))
-        {
-            return false;
-        }
-        update_offset(output_buffer);
-
-        length = (size_t) (output_buffer->format ? 2 : 1);
-        output_pointer = ensure(output_buffer, length);
-        if (output_pointer == NULL)
-        {
-            return false;
-        }
-        *output_pointer++ = ':';
-        if (output_buffer->format)
-        {
-            *output_pointer++ = '\t';
-        }
-        output_buffer->offset += length;
-
-        /* print value */
-        if (!print_value(current_item, output_buffer))
-        {
-            return false;
-        }
-        update_offset(output_buffer);
-
-        /* print comma if not last */
-        length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)(current_item->next ? 1 : 0));
-        output_pointer = ensure(output_buffer, length + 1);
-        if (output_pointer == NULL)
-        {
-            return false;
-        }
-        if (current_item->next)
-        {
-            *output_pointer++ = ',';
-        }
-
-        if (output_buffer->format)
-        {
-            *output_pointer++ = '\n';
-        }
-        *output_pointer = '\0';
-        output_buffer->offset += length;
-
-        current_item = current_item->next;
-    }
-
-    output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2);
-    if (output_pointer == NULL)
-    {
-        return false;
-    }
-    if (output_buffer->format)
-    {
-        size_t i;
-        for (i = 0; i < (output_buffer->depth - 1); i++)
-        {
-            *output_pointer++ = '\t';
-        }
-    }
-    *output_pointer++ = '}';
-    *output_pointer = '\0';
-    output_buffer->depth--;
-
-    return true;
-}
-
-/* Get Array size/item / object item. */
-CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array)
-{
-    cJSON *child = NULL;
-    size_t size = 0;
-
-    if (array == NULL)
-    {
-        return 0;
-    }
-
-    child = array->child;
-
-    while(child != NULL)
-    {
-        size++;
-        child = child->next;
-    }
-
-    /* FIXME: Can overflow here. Cannot be fixed without breaking the API */
-
-    return (int)size;
-}
-
-static cJSON* get_array_item(const cJSON *array, size_t index)
-{
-    cJSON *current_child = NULL;
-
-    if (array == NULL)
-    {
-        return NULL;
-    }
-
-    current_child = array->child;
-    while ((current_child != NULL) && (index > 0))
-    {
-        index--;
-        current_child = current_child->next;
-    }
-
-    return current_child;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index)
-{
-    if (index < 0)
-    {
-        return NULL;
-    }
-
-    return get_array_item(array, (size_t)index);
-}
-
-static cJSON *get_object_item(const cJSON * const object, const char * const name, const cJSON_bool case_sensitive)
-{
-    cJSON *current_element = NULL;
-
-    if ((object == NULL) || (name == NULL))
-    {
-        return NULL;
-    }
-
-    current_element = object->child;
-    if (case_sensitive)
-    {
-        while ((current_element != NULL) && (current_element->string != NULL) && (strcmp(name, current_element->string) != 0))
-        {
-            current_element = current_element->next;
-        }
-    }
-    else
-    {
-        while ((current_element != NULL) && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0))
-        {
-            current_element = current_element->next;
-        }
-    }
-
-    if ((current_element == NULL) || (current_element->string == NULL)) {
-        return NULL;
-    }
-
-    return current_element;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string)
-{
-    return get_object_item(object, string, false);
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string)
-{
-    return get_object_item(object, string, true);
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string)
-{
-    return cJSON_GetObjectItem(object, string) ? 1 : 0;
-}
-
-/* Utility for array list handling. */
-static void suffix_object(cJSON *prev, cJSON *item)
-{
-    prev->next = item;
-    item->prev = prev;
-}
-
-/* Utility for handling references. */
-static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks)
-{
-    cJSON *reference = NULL;
-    if (item == NULL)
-    {
-        return NULL;
-    }
-
-    reference = cJSON_New_Item(hooks);
-    if (reference == NULL)
-    {
-        return NULL;
-    }
-
-    memcpy(reference, item, sizeof(cJSON));
-    reference->string = NULL;
-    reference->type |= cJSON_IsReference;
-    reference->next = reference->prev = NULL;
-    return reference;
-}
-
-static cJSON_bool add_item_to_array(cJSON *array, cJSON *item)
-{
-    cJSON *child = NULL;
-
-    if ((item == NULL) || (array == NULL) || (array == item))
-    {
-        return false;
-    }
-
-    child = array->child;
-    /*
-     * To find the last item in array quickly, we use prev in array
-     */
-    if (child == NULL)
-    {
-        /* list is empty, start new one */
-        array->child = item;
-        item->prev = item;
-        item->next = NULL;
-    }
-    else
-    {
-        /* append to the end */
-        if (child->prev)
-        {
-            suffix_object(child->prev, item);
-            array->child->prev = item;
-        }
-    }
-
-    return true;
-}
-
-/* Add item to array/object. */
-CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item)
-{
-    return add_item_to_array(array, item);
-}
-
-#if defined(__clang__) || (defined(__GNUC__)  && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
-    #pragma GCC diagnostic push
-#endif
-#ifdef __GNUC__
-#pragma GCC diagnostic ignored "-Wcast-qual"
-#endif
-/* helper function to cast away const */
-static void* cast_away_const(const void* string)
-{
-    return (void*)string;
-}
-#if defined(__clang__) || (defined(__GNUC__)  && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
-    #pragma GCC diagnostic pop
-#endif
-
-
-static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key)
-{
-    char *new_key = NULL;
-    int new_type = cJSON_Invalid;
-
-    if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item))
-    {
-        return false;
-    }
-
-    if (constant_key)
-    {
-        new_key = (char*)cast_away_const(string);
-        new_type = item->type | cJSON_StringIsConst;
-    }
-    else
-    {
-        new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks);
-        if (new_key == NULL)
-        {
-            return false;
-        }
-
-        new_type = item->type & ~cJSON_StringIsConst;
-    }
-
-    if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
-    {
-        hooks->deallocate(item->string);
-    }
-
-    item->string = new_key;
-    item->type = new_type;
-
-    return add_item_to_array(object, item);
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)
-{
-    return add_item_to_object(object, string, item, &global_hooks, false);
-}
-
-/* Add an item to an object with constant string as key */
-CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item)
-{
-    return add_item_to_object(object, string, item, &global_hooks, true);
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item)
-{
-    if (array == NULL)
-    {
-        return false;
-    }
-
-    return add_item_to_array(array, create_reference(item, &global_hooks));
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item)
-{
-    if ((object == NULL) || (string == NULL))
-    {
-        return false;
-    }
-
-    return add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false);
-}
-
-CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name)
-{
-    cJSON *null = cJSON_CreateNull();
-    if (add_item_to_object(object, name, null, &global_hooks, false))
-    {
-        return null;
-    }
-
-    cJSON_Delete(null);
-    return NULL;
-}
-
-CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name)
-{
-    cJSON *true_item = cJSON_CreateTrue();
-    if (add_item_to_object(object, name, true_item, &global_hooks, false))
-    {
-        return true_item;
-    }
-
-    cJSON_Delete(true_item);
-    return NULL;
-}
-
-CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name)
-{
-    cJSON *false_item = cJSON_CreateFalse();
-    if (add_item_to_object(object, name, false_item, &global_hooks, false))
-    {
-        return false_item;
-    }
-
-    cJSON_Delete(false_item);
-    return NULL;
-}
-
-CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean)
-{
-    cJSON *bool_item = cJSON_CreateBool(boolean);
-    if (add_item_to_object(object, name, bool_item, &global_hooks, false))
-    {
-        return bool_item;
-    }
-
-    cJSON_Delete(bool_item);
-    return NULL;
-}
-
-CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number)
-{
-    cJSON *number_item = cJSON_CreateNumber(number);
-    if (add_item_to_object(object, name, number_item, &global_hooks, false))
-    {
-        return number_item;
-    }
-
-    cJSON_Delete(number_item);
-    return NULL;
-}
-
-CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string)
-{
-    cJSON *string_item = cJSON_CreateString(string);
-    if (add_item_to_object(object, name, string_item, &global_hooks, false))
-    {
-        return string_item;
-    }
-
-    cJSON_Delete(string_item);
-    return NULL;
-}
-
-CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw)
-{
-    cJSON *raw_item = cJSON_CreateRaw(raw);
-    if (add_item_to_object(object, name, raw_item, &global_hooks, false))
-    {
-        return raw_item;
-    }
-
-    cJSON_Delete(raw_item);
-    return NULL;
-}
-
-CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name)
-{
-    cJSON *object_item = cJSON_CreateObject();
-    if (add_item_to_object(object, name, object_item, &global_hooks, false))
-    {
-        return object_item;
-    }
-
-    cJSON_Delete(object_item);
-    return NULL;
-}
-
-CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name)
-{
-    cJSON *array = cJSON_CreateArray();
-    if (add_item_to_object(object, name, array, &global_hooks, false))
-    {
-        return array;
-    }
-
-    cJSON_Delete(array);
-    return NULL;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item)
-{
-    if ((parent == NULL) || (item == NULL))
-    {
-        return NULL;
-    }
-
-    if (item != parent->child)
-    {
-        /* not the first element */
-        item->prev->next = item->next;
-    }
-    if (item->next != NULL)
-    {
-        /* not the last element */
-        item->next->prev = item->prev;
-    }
-
-    if (item == parent->child)
-    {
-        /* first element */
-        parent->child = item->next;
-    }
-    else if (item->next == NULL)
-    {
-        /* last element */
-        parent->child->prev = item->prev;
-    }
-
-    /* make sure the detached item doesn't point anywhere anymore */
-    item->prev = NULL;
-    item->next = NULL;
-
-    return item;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which)
-{
-    if (which < 0)
-    {
-        return NULL;
-    }
-
-    return cJSON_DetachItemViaPointer(array, get_array_item(array, (size_t)which));
-}
-
-CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which)
-{
-    cJSON_Delete(cJSON_DetachItemFromArray(array, which));
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string)
-{
-    cJSON *to_detach = cJSON_GetObjectItem(object, string);
-
-    return cJSON_DetachItemViaPointer(object, to_detach);
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string)
-{
-    cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string);
-
-    return cJSON_DetachItemViaPointer(object, to_detach);
-}
-
-CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string)
-{
-    cJSON_Delete(cJSON_DetachItemFromObject(object, string));
-}
-
-CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string)
-{
-    cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string));
-}
-
-/* Replace array/object items with new ones. */
-CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem)
-{
-    cJSON *after_inserted = NULL;
-
-    if (which < 0)
-    {
-        return false;
-    }
-
-    after_inserted = get_array_item(array, (size_t)which);
-    if (after_inserted == NULL)
-    {
-        return add_item_to_array(array, newitem);
-    }
-
-    newitem->next = after_inserted;
-    newitem->prev = after_inserted->prev;
-    after_inserted->prev = newitem;
-    if (after_inserted == array->child)
-    {
-        array->child = newitem;
-    }
-    else
-    {
-        newitem->prev->next = newitem;
-    }
-    return true;
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
-{
-    if ((parent == NULL) || (parent->child == NULL) || (replacement == NULL) || (item == NULL))
-    {
-        return false;
-    }
-
-    if (replacement == item)
-    {
-        return true;
-    }
-
-    replacement->next = item->next;
-    replacement->prev = item->prev;
-
-    if (replacement->next != NULL)
-    {
-        replacement->next->prev = replacement;
-    }
-    if (parent->child == item)
-    {
-        if (parent->child->prev == parent->child)
-        {
-            replacement->prev = replacement;
-        }
-        parent->child = replacement;
-    }
-    else
-    {   /*
-         * To find the last item in array quickly, we use prev in array.
-         * We can't modify the last item's next pointer where this item was the parent's child
-         */
-        if (replacement->prev != NULL)
-        {
-            replacement->prev->next = replacement;
-        }
-        if (replacement->next == NULL)
-        {
-            parent->child->prev = replacement;
-        }
-    }
-
-    item->next = NULL;
-    item->prev = NULL;
-    cJSON_Delete(item);
-
-    return true;
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem)
-{
-    if (which < 0)
-    {
-        return false;
-    }
-
-    return cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem);
-}
-
-static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive)
-{
-    if ((replacement == NULL) || (string == NULL))
-    {
-        return false;
-    }
-
-    /* replace the name in the replacement */
-    if (!(replacement->type & cJSON_StringIsConst) && (replacement->string != NULL))
-    {
-        cJSON_free(replacement->string);
-    }
-    replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks);
-    if (replacement->string == NULL)
-    {
-        return false;
-    }
-
-    replacement->type &= ~cJSON_StringIsConst;
-
-    return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement);
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem)
-{
-    return replace_item_in_object(object, string, newitem, false);
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem)
-{
-    return replace_item_in_object(object, string, newitem, true);
-}
-
-/* Create basic types: */
-CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void)
-{
-    cJSON *item = cJSON_New_Item(&global_hooks);
-    if(item)
-    {
-        item->type = cJSON_NULL;
-    }
-
-    return item;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void)
-{
-    cJSON *item = cJSON_New_Item(&global_hooks);
-    if(item)
-    {
-        item->type = cJSON_True;
-    }
-
-    return item;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void)
-{
-    cJSON *item = cJSON_New_Item(&global_hooks);
-    if(item)
-    {
-        item->type = cJSON_False;
-    }
-
-    return item;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean)
-{
-    cJSON *item = cJSON_New_Item(&global_hooks);
-    if(item)
-    {
-        item->type = boolean ? cJSON_True : cJSON_False;
-    }
-
-    return item;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num)
-{
-    cJSON *item = cJSON_New_Item(&global_hooks);
-    if(item)
-    {
-        item->type = cJSON_Number;
-        item->valuedouble = num;
-
-        /* use saturation in case of overflow */
-        if (num >= INT_MAX)
-        {
-            item->valueint = INT_MAX;
-        }
-        else if (num <= (double)INT_MIN)
-        {
-            item->valueint = INT_MIN;
-        }
-        else
-        {
-            item->valueint = (int)num;
-        }
-    }
-
-    return item;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string)
-{
-    cJSON *item = cJSON_New_Item(&global_hooks);
-    if(item)
-    {
-        item->type = cJSON_String;
-        item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks);
-        if(!item->valuestring)
-        {
-            cJSON_Delete(item);
-            return NULL;
-        }
-    }
-
-    return item;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string)
-{
-    cJSON *item = cJSON_New_Item(&global_hooks);
-    if (item != NULL)
-    {
-        item->type = cJSON_String | cJSON_IsReference;
-        item->valuestring = (char*)cast_away_const(string);
-    }
-
-    return item;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child)
-{
-    cJSON *item = cJSON_New_Item(&global_hooks);
-    if (item != NULL) {
-        item->type = cJSON_Object | cJSON_IsReference;
-        item->child = (cJSON*)cast_away_const(child);
-    }
-
-    return item;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) {
-    cJSON *item = cJSON_New_Item(&global_hooks);
-    if (item != NULL) {
-        item->type = cJSON_Array | cJSON_IsReference;
-        item->child = (cJSON*)cast_away_const(child);
-    }
-
-    return item;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw)
-{
-    cJSON *item = cJSON_New_Item(&global_hooks);
-    if(item)
-    {
-        item->type = cJSON_Raw;
-        item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks);
-        if(!item->valuestring)
-        {
-            cJSON_Delete(item);
-            return NULL;
-        }
-    }
-
-    return item;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void)
-{
-    cJSON *item = cJSON_New_Item(&global_hooks);
-    if(item)
-    {
-        item->type=cJSON_Array;
-    }
-
-    return item;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void)
-{
-    cJSON *item = cJSON_New_Item(&global_hooks);
-    if (item)
-    {
-        item->type = cJSON_Object;
-    }
-
-    return item;
-}
-
-/* Create Arrays: */
-CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count)
-{
-    size_t i = 0;
-    cJSON *n = NULL;
-    cJSON *p = NULL;
-    cJSON *a = NULL;
-
-    if ((count < 0) || (numbers == NULL))
-    {
-        return NULL;
-    }
-
-    a = cJSON_CreateArray();
-
-    for(i = 0; a && (i < (size_t)count); i++)
-    {
-        n = cJSON_CreateNumber(numbers[i]);
-        if (!n)
-        {
-            cJSON_Delete(a);
-            return NULL;
-        }
-        if(!i)
-        {
-            a->child = n;
-        }
-        else
-        {
-            suffix_object(p, n);
-        }
-        p = n;
-    }
-
-    if (a && a->child) {
-        a->child->prev = n;
-    }
-
-    return a;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count)
-{
-    size_t i = 0;
-    cJSON *n = NULL;
-    cJSON *p = NULL;
-    cJSON *a = NULL;
-
-    if ((count < 0) || (numbers == NULL))
-    {
-        return NULL;
-    }
-
-    a = cJSON_CreateArray();
-
-    for(i = 0; a && (i < (size_t)count); i++)
-    {
-        n = cJSON_CreateNumber((double)numbers[i]);
-        if(!n)
-        {
-            cJSON_Delete(a);
-            return NULL;
-        }
-        if(!i)
-        {
-            a->child = n;
-        }
-        else
-        {
-            suffix_object(p, n);
-        }
-        p = n;
-    }
-
-    if (a && a->child) {
-        a->child->prev = n;
-    }
-
-    return a;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count)
-{
-    size_t i = 0;
-    cJSON *n = NULL;
-    cJSON *p = NULL;
-    cJSON *a = NULL;
-
-    if ((count < 0) || (numbers == NULL))
-    {
-        return NULL;
-    }
-
-    a = cJSON_CreateArray();
-
-    for(i = 0; a && (i < (size_t)count); i++)
-    {
-        n = cJSON_CreateNumber(numbers[i]);
-        if(!n)
-        {
-            cJSON_Delete(a);
-            return NULL;
-        }
-        if(!i)
-        {
-            a->child = n;
-        }
-        else
-        {
-            suffix_object(p, n);
-        }
-        p = n;
-    }
-
-    if (a && a->child) {
-        a->child->prev = n;
-    }
-
-    return a;
-}
-
-CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count)
-{
-    size_t i = 0;
-    cJSON *n = NULL;
-    cJSON *p = NULL;
-    cJSON *a = NULL;
-
-    if ((count < 0) || (strings == NULL))
-    {
-        return NULL;
-    }
-
-    a = cJSON_CreateArray();
-
-    for (i = 0; a && (i < (size_t)count); i++)
-    {
-        n = cJSON_CreateString(strings[i]);
-        if(!n)
-        {
-            cJSON_Delete(a);
-            return NULL;
-        }
-        if(!i)
-        {
-            a->child = n;
-        }
-        else
-        {
-            suffix_object(p,n);
-        }
-        p = n;
-    }
-
-    if (a && a->child) {
-        a->child->prev = n;
-    }
-
-    return a;
-}
-
-/* Duplication */
-CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse)
-{
-    cJSON *newitem = NULL;
-    cJSON *child = NULL;
-    cJSON *next = NULL;
-    cJSON *newchild = NULL;
-
-    /* Bail on bad ptr */
-    if (!item)
-    {
-        goto fail;
-    }
-    /* Create new item */
-    newitem = cJSON_New_Item(&global_hooks);
-    if (!newitem)
-    {
-        goto fail;
-    }
-    /* Copy over all vars */
-    newitem->type = item->type & (~cJSON_IsReference);
-    newitem->valueint = item->valueint;
-    newitem->valuedouble = item->valuedouble;
-    if (item->valuestring)
-    {
-        newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks);
-        if (!newitem->valuestring)
-        {
-            goto fail;
-        }
-    }
-    if (item->string)
-    {
-        newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks);
-        if (!newitem->string)
-        {
-            goto fail;
-        }
-    }
-    /* If non-recursive, then we're done! */
-    if (!recurse)
-    {
-        return newitem;
-    }
-    /* Walk the ->next chain for the child. */
-    child = item->child;
-    while (child != NULL)
-    {
-        newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */
-        if (!newchild)
-        {
-            goto fail;
-        }
-        if (next != NULL)
-        {
-            /* If newitem->child already set, then crosswire ->prev and ->next and move on */
-            next->next = newchild;
-            newchild->prev = next;
-            next = newchild;
-        }
-        else
-        {
-            /* Set newitem->child and move to it */
-            newitem->child = newchild;
-            next = newchild;
-        }
-        child = child->next;
-    }
-    if (newitem && newitem->child)
-    {
-        newitem->child->prev = newchild;
-    }
-
-    return newitem;
-
-fail:
-    if (newitem != NULL)
-    {
-        cJSON_Delete(newitem);
-    }
-
-    return NULL;
-}
-
-static void skip_oneline_comment(char **input)
-{
-    *input += static_strlen("//");
-
-    for (; (*input)[0] != '\0'; ++(*input))
-    {
-        if ((*input)[0] == '\n') {
-            *input += static_strlen("\n");
-            return;
-        }
-    }
-}
-
-static void skip_multiline_comment(char **input)
-{
-    *input += static_strlen("/*");
-
-    for (; (*input)[0] != '\0'; ++(*input))
-    {
-        if (((*input)[0] == '*') && ((*input)[1] == '/'))
-        {
-            *input += static_strlen("*/");
-            return;
-        }
-    }
-}
-
-static void minify_string(char **input, char **output) {
-    (*output)[0] = (*input)[0];
-    *input += static_strlen("\"");
-    *output += static_strlen("\"");
-
-
-    for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) {
-        (*output)[0] = (*input)[0];
-
-        if ((*input)[0] == '\"') {
-            (*output)[0] = '\"';
-            *input += static_strlen("\"");
-            *output += static_strlen("\"");
-            return;
-        } else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) {
-            (*output)[1] = (*input)[1];
-            *input += static_strlen("\"");
-            *output += static_strlen("\"");
-        }
-    }
-}
-
-CJSON_PUBLIC(void) cJSON_Minify(char *json)
-{
-    char *into = json;
-
-    if (json == NULL)
-    {
-        return;
-    }
-
-    while (json[0] != '\0')
-    {
-        switch (json[0])
-        {
-            case ' ':
-            case '\t':
-            case '\r':
-            case '\n':
-                json++;
-                break;
-
-            case '/':
-                if (json[1] == '/')
-                {
-                    skip_oneline_comment(&json);
-                }
-                else if (json[1] == '*')
-                {
-                    skip_multiline_comment(&json);
-                } else {
-                    json++;
-                }
-                break;
-
-            case '\"':
-                minify_string(&json, (char**)&into);
-                break;
-
-            default:
-                into[0] = json[0];
-                json++;
-                into++;
-        }
-    }
-
-    /* and null-terminate. */
-    *into = '\0';
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item)
-{
-    if (item == NULL)
-    {
-        return false;
-    }
-
-    return (item->type & 0xFF) == cJSON_Invalid;
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item)
-{
-    if (item == NULL)
-    {
-        return false;
-    }
-
-    return (item->type & 0xFF) == cJSON_False;
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item)
-{
-    if (item == NULL)
-    {
-        return false;
-    }
-
-    return (item->type & 0xff) == cJSON_True;
-}
-
-
-CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item)
-{
-    if (item == NULL)
-    {
-        return false;
-    }
-
-    return (item->type & (cJSON_True | cJSON_False)) != 0;
-}
-CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item)
-{
-    if (item == NULL)
-    {
-        return false;
-    }
-
-    return (item->type & 0xFF) == cJSON_NULL;
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item)
-{
-    if (item == NULL)
-    {
-        return false;
-    }
-
-    return (item->type & 0xFF) == cJSON_Number;
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item)
-{
-    if (item == NULL)
-    {
-        return false;
-    }
-
-    return (item->type & 0xFF) == cJSON_String;
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item)
-{
-    if (item == NULL)
-    {
-        return false;
-    }
-
-    return (item->type & 0xFF) == cJSON_Array;
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item)
-{
-    if (item == NULL)
-    {
-        return false;
-    }
-
-    return (item->type & 0xFF) == cJSON_Object;
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item)
-{
-    if (item == NULL)
-    {
-        return false;
-    }
-
-    return (item->type & 0xFF) == cJSON_Raw;
-}
-
-CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive)
-{
-    if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)))
-    {
-        return false;
-    }
-
-    /* check if type is valid */
-    switch (a->type & 0xFF)
-    {
-        case cJSON_False:
-        case cJSON_True:
-        case cJSON_NULL:
-        case cJSON_Number:
-        case cJSON_String:
-        case cJSON_Raw:
-        case cJSON_Array:
-        case cJSON_Object:
-            break;
-
-        default:
-            return false;
-    }
-
-    /* identical objects are equal */
-    if (a == b)
-    {
-        return true;
-    }
-
-    switch (a->type & 0xFF)
-    {
-        /* in these cases and equal type is enough */
-        case cJSON_False:
-        case cJSON_True:
-        case cJSON_NULL:
-            return true;
-
-        case cJSON_Number:
-            if (compare_double(a->valuedouble, b->valuedouble))
-            {
-                return true;
-            }
-            return false;
-
-        case cJSON_String:
-        case cJSON_Raw:
-            if ((a->valuestring == NULL) || (b->valuestring == NULL))
-            {
-                return false;
-            }
-            if (strcmp(a->valuestring, b->valuestring) == 0)
-            {
-                return true;
-            }
-
-            return false;
-
-        case cJSON_Array:
-        {
-            cJSON *a_element = a->child;
-            cJSON *b_element = b->child;
-
-            for (; (a_element != NULL) && (b_element != NULL);)
-            {
-                if (!cJSON_Compare(a_element, b_element, case_sensitive))
-                {
-                    return false;
-                }
-
-                a_element = a_element->next;
-                b_element = b_element->next;
-            }
-
-            /* one of the arrays is longer than the other */
-            if (a_element != b_element) {
-                return false;
-            }
-
-            return true;
-        }
-
-        case cJSON_Object:
-        {
-            cJSON *a_element = NULL;
-            cJSON *b_element = NULL;
-            cJSON_ArrayForEach(a_element, a)
-            {
-                /* TODO This has O(n^2) runtime, which is horrible! */
-                b_element = get_object_item(b, a_element->string, case_sensitive);
-                if (b_element == NULL)
-                {
-                    return false;
-                }
-
-                if (!cJSON_Compare(a_element, b_element, case_sensitive))
-                {
-                    return false;
-                }
-            }
-
-            /* doing this twice, once on a and b to prevent true comparison if a subset of b
-             * TODO: Do this the proper way, this is just a fix for now */
-            cJSON_ArrayForEach(b_element, b)
-            {
-                a_element = get_object_item(a, b_element->string, case_sensitive);
-                if (a_element == NULL)
-                {
-                    return false;
-                }
-
-                if (!cJSON_Compare(b_element, a_element, case_sensitive))
-                {
-                    return false;
-                }
-            }
-
-            return true;
-        }
-
-        default:
-            return false;
-    }
-}
-
-CJSON_PUBLIC(void *) cJSON_malloc(size_t size)
-{
-    return global_hooks.allocate(size);
-}
-
-CJSON_PUBLIC(void) cJSON_free(void *object)
-{
-    global_hooks.deallocate(object);
-}

+ 0 - 300
DriverInterface/cJSON.h

@@ -1,300 +0,0 @@
-/*
-  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 16
-
-#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

+ 158 - 449
DriverInterface/communication.c

@@ -13,6 +13,7 @@ static unsigned char seq  =0;
 extern uint8_t wifi_tx_buf[WIFI_TX_BUF_SIZE];
 extern uint16_t wifi_tx_len;
 
+updateProcessInf updateInf;
 unsigned int check_to_pc_busy(void){
 	/*判断是否可以发送,缓冲区为空或者索引为0*/
 	CmdMessage *pMessage = (CmdMessage *)wifi_tx_buf;
@@ -48,7 +49,9 @@ int data_send_to_pc(pc_cmd_type cmd, char *data, unsigned short len)
 		 Van_Device_Printf(VAN_LOG_COMM,"send_to_pc :%x  len:%d error ", cmd, len);
 		 return  ret;
 	}
-	if(sysinf.pc_channel_recv  == PC_CONNECT_TYPE_NULL  && cmd != PC_CMD_SETIP){
+
+	
+	if(sysinf.pc_channel_recv  == PC_CONNECT_TYPE_NULL  && ((cmd != PC_CMD_SETIP) && (cmd != PC_CMD_STARTUPDATE))  ){
 				/*无链接情况,只考虑*/
 				return ret;
 	}			
@@ -94,6 +97,42 @@ int data_send_to_pc(pc_cmd_type cmd, char *data, unsigned short len)
    return 0;
 }
 
+int data_send_to_pc_withindex(pc_cmd_type cmd, char *data, unsigned short len, unsigned char index)
+{
+    uint16_t check;
+    int ret = -1;
+    msg.head = 0x55aa;
+    msg.seq = index;
+    msg.cmd = cmd;
+    msg.tail = 0x5a;
+    msg.len = len;
+    msg.data = data;
+
+
+	check = checkSum((const unsigned char *)&msg.seq, 4);
+	check += checkSum((const unsigned char *)data, len);
+	msg.checksum = check & 0xFF;
+	msg.tail = (check >> 8);	
+	if(check_to_pc_busy()){		
+		memcpy(&wifi_tx_buf[0], (uint8_t*)&msg, MSG_CMDFRAME_LEN);
+		memcpy(&wifi_tx_buf[MSG_CMDFRAME_LEN], data, len);
+		memcpy(&wifi_tx_buf[MSG_CMDFRAME_LEN+len],  (uint8_t*)&check, 2);
+		wifi_tx_len = MSG_CMDFRAME_LEN+len+2;	
+	}else{
+		return ret;
+	}	
+	if((sysinf.pc_channel_recv  == PC_CONNECT_TYPE_WIFI || cmd == PC_CMD_SETIP ) && PC_CMD_SETWIFI != cmd)
+	{			
+		return WIFI_ReSend();
+	}
+	else
+	{	
+    Van_Debug_UART_Send_DMA((unsigned char *)wifi_tx_buf, wifi_tx_len); //将收到的信息发送出		
+		memset(wifi_tx_buf, 0, sizeof(wifi_tx_buf));
+	}
+   return 0;
+}
+
 
 void PackDeviceNum(void){		
 	int len = 0;
@@ -103,12 +142,12 @@ void PackDeviceNum(void){
     uid[1] = HAL_GetUIDw1(); // 读取中间32位[reference:17]
     uid[2] = HAL_GetUIDw2(); // 读取高32位[reference:18]
 #ifdef ONECHIP_MINI_ONE
-	my_sprintf(&DeviceNum[len],sizeof(DeviceNum), "Mini7-one,V%d.%d.%d.%d",SOFT_VERSION_1,SOFT_VERSION_2,SOFT_VERSION_3,SOFT_VERSION_4);	
+	my_sprintf(&DeviceNum[len],sizeof(DeviceNum), "Mini7_boot,V%d.%d.%d.%d",SOFT_VERSION_1,SOFT_VERSION_2,SOFT_VERSION_3,SOFT_VERSION_4);	
 #else 
 #ifdef ONECHIP_MINI_PLUS
-	my_sprintf(&DeviceNum[len],sizeof(DeviceNum), "Mini7-plus,V%d.%d.%d.%d",SOFT_VERSION_1,SOFT_VERSION_2,SOFT_VERSION_3,SOFT_VERSION_4);	
+	my_sprintf(&DeviceNum[len],sizeof(DeviceNum), "Mini7_boot,V%d.%d.%d.%d",SOFT_VERSION_1,SOFT_VERSION_2,SOFT_VERSION_3,SOFT_VERSION_4);	
 #else
-	my_sprintf(&DeviceNum[len],sizeof(DeviceNum), "Mini7,V%d.%d.%d.%d",SOFT_VERSION_1,SOFT_VERSION_2,SOFT_VERSION_3,SOFT_VERSION_4);		
+	my_sprintf(&DeviceNum[len],sizeof(DeviceNum), "Mini7_boot,V%d.%d.%d.%d",SOFT_VERSION_1,SOFT_VERSION_2,SOFT_VERSION_3,SOFT_VERSION_4);		
 #endif //ONECHIP_MINI_PLUS
 #endif //ONECHIP_MINI_ONE
 	strcat(DeviceNum, ",");
@@ -140,6 +179,24 @@ void send_Devinf_pc(void)
 
 }
 
+/********************************************************************
+ *    uint16_t send_Devinf_pc(void)
+ *
+ *描述:发送设备信息到主机,便于主机下法TCP信息
+ *参数:无
+ *返回:无
+ *其他:无
+ *--------------------------------------------------------------------
+ *记录:
+ ********************************************************************/
+int  send_baseinf_pc(unsigned char cmd, unsigned char *parg)
+{
+
+    uint16_t len = 0;
+	len =  strlen(DeviceNum);
+	data_send_to_pc(PC_CMD_STARTUPDATE,DeviceNum,len);
+
+}
 /********************************************************************
  * int handshake_action(unsigned char cmd, unsigned char *parg)
  *
@@ -186,21 +243,6 @@ int wifi_action(unsigned char cmd, unsigned char *parg)
     WIFI_set_ssid();
     return 1;
 }
-int setState_action(unsigned char cmd, unsigned char *parg)
-{
-	unsigned char block = *parg++;
-	unsigned char nextState = *parg;
-    if(SYS_STATE_WORKEND == nextState){
-        if(block==0){
-                sysinf.psmMaster.state = SW_move_card;
-        }else{
-            /*下发命令,改变从模块状态*/
-            sysinf.psmSlave.state = SW_move_card;
-        }
-    }
-    return 1;
-}
-
 
 
 /********************************************************************
@@ -223,41 +265,6 @@ int SN_action(unsigned char cmd, unsigned char *parg)
 }
 
 
-/********************************************************************
- * int seq_selftest_action(unsigned char cmd, unsigned char *parg)
- *
- *描述:设备自检处理
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-int seq_selftest_action(unsigned char cmd, unsigned char *parg)
-{
-    return 0;
-}
-
-/********************************************************************
- * int confirm_result_action(unsigned char cmd, unsigned char *parg)
- *
- *描述:设备收到pc的结果响应
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-int confirm_result_action(unsigned char cmd, unsigned char *parg)
-{
-    // if(0 == memcmp(parg,sysinf.psmMaster.card_param_info.pid, 10 )){
-    //      sysinf.psmMaster.state  = SW_move_card;
-    // }else if (0 == memcmp(parg,sysinf.psmSlave.card_param_info.pid, 10 ))
-    // {
-    //      sysinf.psmSlave.state  = SW_move_card;
-    // }
-    return 0;
-}
 
 
 /********************************************************************
@@ -290,125 +297,18 @@ int handshake_response(CmdMessage *pMsg, unsigned char result)
 	unsigned short len = 0;
 	PackDeviceNum();
 	len = strlen(DeviceNum);
-	return data_send_to_pc((pc_cmd_type)pMsg->cmd, (char*)DeviceNum, len);
+	return data_send_to_pc_withindex((pc_cmd_type)pMsg->cmd, (char*)DeviceNum, len,pMsg->seq);
 }
 
-	
-int AskState_response(CmdMessage *pMsg, unsigned char result)
-{
-        stateinfDef st;
-        st.amplifState =sysinf.amplifState;
-        st.lysisState =sysinf.lysisState;
-        memcpy(st.SN, &sysinf.SN, 7);
-
-   	data_send_to_pc(PC_CMD_ASKSTATE, (char *)&st, sizeof(stateinfDef));  
-    return 0;  
-}
 
 int set_response(CmdMessage *pMsg, unsigned char result)
 {
-//    char wifi_result = 1;
-//    data_send_to_pc(PC_CMD_SETWIFI, &wifi_result, 1);
+	return data_send_to_pc((pc_cmd_type)pMsg->cmd, (char*)&result, 1);
     return 0;
 }
 
-int setState_response(CmdMessage *pMsg, unsigned char result)
-{
-//    char result = 1;
-    data_send_to_pc(PC_CMD_SETSTATE, (char *)&result, 1);
-    return 0;
-}
 
 
-int ans_response(CmdMessage *pMsg, unsigned char result)
-{	
-	/*清空需要上位机应答的消息*/
-	switch(pMsg->cmd){
-		case PC_CMD_REPORT_REEOR:
-			sysinf.updateError = 0;  
-			break;
-		case PC_CMD_UPDATESTATE:
-			sysinf.updateSt = 0;
-			break;
-		case PC_CMD_QRCODE:
-			sysinf.updateQR = false;                
-			break;
-		case PC_CMD_DATA_UPLOAD:{
-			unsigned char *data = (unsigned char *)pMsg->data;			
-			unsigned int recdex = 0xfffffff;
-//			unsigned char result = *data;
-//			unsigned char part = *(data+1);
-			if( pMsg->len == 6){
-				recdex = *(data+5);
-			    recdex = recdex<<8;
-				recdex += *(data+4);
-			    recdex = recdex<<8;
-				recdex += *(data+3);
-			    recdex = recdex<<8;
-				recdex += *(data+2);
-			}else{
-				if(seq == pMsg->seq){
-					recdex = 0;
-				}
-			}
-			updateData_next(recdex,data);
-	    	
-		}
-			break;	
-		case PC_CMD_REPORT_RESULT:{
-
-//			unsigned char result = *data;
-//			unsigned char part = *(data+1);	
-			clean_reult_next((unsigned char *)pMsg->data);
-//			if(result){		
-//				/*消息成功,进行跟新*/		
-//				clean_reult_next(part);
-//			}
-		}
-			break;		
-	}
-    return 0;
-}
-
-int confirm_qrcode_action(unsigned char cmd, unsigned char *parg)
-{
-    //先判断主模块,优先给主模块,扫描上报上报也是相同处理    
-    svanner_receive_Rec_Start(sysinf.scannerUart);
-    if(*parg == 1)
-    {
-        if((sysinf.psmMaster.state == SW_Scan_Qrcode || sysinf.psmMaster.state == SW_Chip_Id  ))   //主机空闲,给自己
-        {
-            sysinf.psmMaster.controlword = Scan_Qrcode_cmd;            
-		    Van_Device_Printf(VAN_LOG_INFO,"Master rec start\n\r:");
-    	    return 0;
-        }else {   
-#ifdef ONECHIP_MINI_PLUSE         
-            if((sysinf.psmSlave.state == SW_Scan_Qrcode || sysinf.psmSlave.state == SW_Chip_Id  )){
-                sysinf.psmSlave.controlword = Scan_Qrcode_cmd;                
-                Van_Device_Printf(VAN_LOG_INFO,"Slave rec start\n\r:");
-                return 0;
-            }
-#endif
-        }
-        Van_Device_Printf(VAN_LOG_INFO, "master:%d slave:%d Not in startState\n\r:",sysinf.psmMaster.state,sysinf.psmSlave.state );
-        return -1;
-    }
-	Van_Device_Printf(VAN_LOG_INFO, "rec no macth\n\r:");
-    return -1;
-}
-
-
-int confirm_error_action(unsigned char cmd, unsigned char *parg)
-{
-    return 0;
-}
-
-
-int confirm_data_action(unsigned char cmd, unsigned char *parg)
-{
-    return 0;
-}
-
 /********************************************************************
  * int set_IP_action(uint8_t cmd, uint8_t *parg)
  *
@@ -455,27 +355,101 @@ int set_IP_action(uint8_t cmd, uint8_t *parg)
 		
 		WIFI_set_CloseConnect();
 	}
+	return 0;
+}
 
 
-	return 0;
+/********************************************************************
+ * int handshake_response(struct CmdMessage *pMsg, unsigned char result)
+ *
+ *描述:握手回应
+ *参数:无
+ *返回:无
+ *其他:无
+ *--------------------------------------------------------------------
+ *记录:
+ ********************************************************************/
 
+int updateInfo_action(uint8_t cmd, uint8_t *parg)
+{
+	updateHeader *upHead = (updateHeader *)parg;
+	updateInf.allchecksum = upHead->allchecksum;
+	updateInf.appLen = upHead->appLen;
+	updateInf.allpackage = upHead->allpackage;
+	updateInf.packageSize = upHead->packageSize;
+	if(FLASH_PAGE_SIZE%upHead->packageSize){
+		/*包大小演出*/
+		return 0;
+	}
+	updateInf.packageInPage = FLASH_PAGE_SIZE/upHead->packageSize;
+	updateInf.writeAddr = FLASH_APP1_ADDR;
+	updateInf.lenInPage = 0;
+	updateInf.updateState = FLASH_UPDATE_ST_REC;
+	updateInf.nextpackageOrder = 0;
+	return 1;
 }
-int send_temp_parm(uint8_t cmd, uint8_t *parg)
+int updateDate_action(uint8_t cmd, uint8_t *parg)
 {
-	/*设置温度*/
-    sysinf.lysis.idletemp =  *(float *)(parg+4);
-    sysinf.lysis.pid.goal =  *(float *)(parg+8);
-    sysinf.lysis.worktime =  *(float *)(parg+12);
-    sysinf.lysis.worktime *= 10;
-    sysinf.lysis.recGoalFlag = 1;
+	updateData *upHead = (updateData *)parg;
+	unsigned int posInPage;
+	if(upHead->packageOrder !=updateInf.nextpackageOrder){
+		/*序号不对,返回错误*/
+		return 0;
+	}
+
+	posInPage = upHead->packageOrder%(updateInf.packageInPage);
+	memcpy(&updateInf.data[posInPage*updateInf.packageSize], (uint8_t*)upHead->data, upHead->packageSize);
+	updateInf.nextpackageOrder++;
+	updateInf.lenInPage += upHead->packageSize;
+	if((updateInf.nextpackageOrder%updateInf.packageInPage==0) || (updateInf.nextpackageOrder==updateInf.allpackage)){
+		/*当前页收完,或包收完*/
+		iap_write_apppage(updateInf.writeAddr,updateInf.data,updateInf.lenInPage);
+		updateInf.writeAddr = updateInf.writeAddr+updateInf.lenInPage;
+		updateInf.lenInPage = 0;
+	}
+	
+	if(updateInf.nextpackageOrder==updateInf.allpackage){
+		/*稍后添加check sum */
+		updateInf.updateState = FLASH_UPDATE_ST_PROG;
+	}
 	return 1;
 }
-int setTemp_response(CmdMessage *pMsg, uint8_t result)
+
+int updatestart_respone(CmdMessage *pMsg, unsigned char result)
 {
-//    char result = 1;
-    data_send_to_pc(PC_CMD_SETRUNTEMP, (char *)&result, 1);
+	unsigned short len = 0;
+	PackDeviceNum();
+	len = strlen(DeviceNum);
+	return data_send_to_pc_withindex((pc_cmd_type)pMsg->cmd, (char*)DeviceNum, len,pMsg->seq);
+}
+int updateInfo_response(CmdMessage *pMsg, unsigned char result)
+{
+	return data_send_to_pc_withindex((pc_cmd_type)pMsg->cmd, (char*)&result, 1,pMsg->seq);
+}
+int updateDate_response(CmdMessage *pMsg, unsigned char result)
+{
+
+	unsigned char *data  = (unsigned char *)pMsg->data;
+    *(unsigned int *)(data+4) = updateInf.nextpackageOrder;	
+    *(unsigned int *)(data+8) =  result;
+	return data_send_to_pc_withindex((pc_cmd_type)pMsg->cmd, pMsg->data, 12,pMsg->seq);
+
+}
+
+
+int in_update_process(void)
+{
+	if(updateInf.updateState == FLASH_UPDATE_ST_REC) return 1;	
+    return 0;
+}
+
+int no_update_process(void)
+{	
+    if(updateInf.updateState == FLASH_UPDATE_ST_PROG) return 1;	
     return 0;
 }
+
+
 const struct PCActionPack mPCActionPack[] =
     {
         {
@@ -497,68 +471,27 @@ const struct PCActionPack mPCActionPack[] =
             .datalen = 7,
         },
         {
-            .cmd = PC_CMD_QRCODE,
-            .action = confirm_qrcode_action,
-            .response = ans_response,
-            .datalen = 0xff,
-        },
-        {
-            .cmd = PC_CMD_SNANDCARD,
-            .action = confirm_error_action,
-            .datalen = 1,
-        },
-        {
-            .cmd = PC_CMD_REPORT_RESULT,
-            .action = confirm_result_action,
-            .response = ans_response,
-            .datalen = 0xff,
-        },
-        {
-            .cmd = PC_CMD_REPORT_REEOR,
-            .action = confirm_error_action,
-            .response = ans_response,
-            .datalen = 0xff,
-        },
-        {
-            .cmd = PC_CMD_DATA_UPLOAD,
-            .action = confirm_data_action,
-            .response = ans_response,
-            .datalen = 0xff,
-        },
-        {
-            .cmd = PC_CMD_SETIP,
-            .action = set_IP_action,
-            .response = NULL,
-            .datalen = 0xff,
-        },
-        {
-            .cmd = PC_CMD_UPDATESTATE,
-            .action = confirm_data_action,
-            .response = ans_response,
+            .cmd = PC_CMD_STARTUPDATE,
+            .action = handshake_action, 
+            .response = updatestart_respone,
             .datalen = 0xff,
         },
         {
-            .cmd = PC_CMD_ASKSTATE,
-            .action = confirm_data_action,
-            .response = AskState_response,
+            .cmd = PC_CMD_UPDATEINFO,
+            .action = updateInfo_action,
+            .response = updateInfo_response,
             .datalen = 0xff,
         },
         {
-            .cmd = PC_CMD_SETSTATE,
-            .action = setState_action,
-            .response = setState_response,
-            .datalen = 0xff,
-        },
-
-        {
-            .cmd = PC_CMD_SETRUNTEMP,
-            .action = send_temp_parm,
-            .response = setTemp_response,
+            .cmd = PC_CMD_UPDATEDATA,
+            .action = updateDate_action,
+            .response = updateDate_response,
             .datalen = 0xff,
         },
 
 };
 
+
 void pc_resend_del(uint8_t seq){
 	// struct CmdMessage *pMessage = (struct CmdMessage *)wifi_tx_buf;
 	// if(pMessage->seq == seq){
@@ -604,227 +537,3 @@ void query_pc_cmd(CmdMessage *pMsg)
 
 
 
-
-
-
-
-/********************************************************************
- * int handshake_action(uint8_t cmd, uint8_t *parg)
- *
- *描述:握手命令处理
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-int con_heat_action(uint8_t cmd, uint8_t *parg )
-{
-//    CmdMessage *pMsg = (CmdMessageDef *)parg;
-    CmdMessage *pMsg = (CmdMessage *)parg;;
-    miniConfigPram *pram = (miniConfigPram *)pMsg->data;
-    uint8_t * pdata = (uint8_t *)pMsg->data;
-    switch(pMsg->cmd){
-        case UINON_CMD_MOTORMOVE:{	
-            
-			sysinf.timeinner =  *(float *)(pMsg->data+4) * 100;
-			sysinf.swingspeed =  *(float *)(pMsg->data+8);
-			sysinf.swingtime =  *(float *)(pMsg->data+12) * 100;
-			sysinf.swingtimeRight =  *(float *)(pMsg->data+16) * 100;
-			sysinf.swingtimePause =  *(float *)(pMsg->data+20) * 100;	
-			if((1 == *(int *)(pMsg->data+pMsg->len - 4))){
-				cfg_save_cfg_param();	
-				Motor_Init();
-			}else{				
-				Motor_mix(sysinf.timeinner,sysinf.swingspeed,sysinf.swingtime,sysinf.swingtimeRight,sysinf.swingtimePause);
-			}		
-		    data_send_to_pc((pc_cmd_type)pMsg->cmd, pMsg->data,  pMsg->len);
-        }break;			
-        case UINON_CMD_MOTORTRETURN:{		
-            Motor_reset();
-            data_send_to_pc( (pc_cmd_type)pMsg->cmd, pMsg->data,	pMsg->len);
-        }break;			
-        case UINON_CMD_THEROM_GET:{		
-            char data[40];
-            *(float *)(data+0) = 0;
-            *(float *)(data+4) = sysinf.lysis_offset;	
-            *(float *)(data+8) = sysinf.lysis_overHeat;	
-            *(float *)(data+12) = sysinf.lysis_overHeatTime;	
-            *(float *)(data+16) = sysinf.lysis_Kp;	
-            *(float *)(data+20) = sysinf.lysis_Ki;	
-            *(float *)(data+24) = sysinf.lysis_Kd;		
-            *(float *)(data+28) = sysinf.lysis.pid.goal;	
-            *(float *)(data+32) = sysinf.lysis.idletemp;	
-            *(float *)(data+36) = sysinf.lysis.worktime/10;	
-            pMsg->data = data;
-            pMsg->len = sizeof(data);
-            data_send_to_pc( (pc_cmd_type)pMsg->cmd, pMsg->data,	pMsg->len);
-        }break;			
-        case UINON_CMD_THEROM_OFFSET:{		
-					
-            sysinf.lysis_Kp  = *(float *)(pdata+4);
-            sysinf.lysis_Ki = *(float *)(pdata+8);
-            sysinf.lysis_Kd     = *(float *)(pdata+12);
-            sysinf.lysis_overHeat  = *(float *)(pdata+16);
-            sysinf.lysis_overHeatTime = *(float *)(pdata+20);
-            sysinf.lysis_offset  = *(float *)(pdata+24);
-					
-            data_send_to_pc((pc_cmd_type)pMsg->cmd, pMsg->data,	pMsg->len);
-            updatParm_lysis();
-            cfg_save_cfg_param();
-        }break;		
-        case UINON_CMD_AMPLIF_GET:{		
-            char data[44];
-            *(float *)(data+0) = 0;
-            *(float *)(data+4) = sysinf.amplif_Kp;	
-            *(float *)(data+8) = sysinf.amplif_Ki;	
-            *(float *)(data+12) = sysinf.amplif_Kd;	
-            *(float *)(data+16) = sysinf.PreHeatTime;	
-            *(float *)(data+20) = sysinf.holdTemp;	
-            *(float *)(data+24) = sysinf.readyTemp;		
-            *(float *)(data+28) = sysinf.PresetTempVal;	
-            *(float *)(data+32) = sysinf.PresetTempTime;	
-            *(float *)(data+36) = sysinf.adJTarget;	
-            *(float *)(data+40) = sysinf.SetTempVal;	
-            pMsg->data = data;
-            pMsg->len = sizeof(data);
-            data_send_to_pc( (pc_cmd_type)pMsg->cmd, pMsg->data,	pMsg->len);
-        }break;			
-        case UINON_CMD_AMPLIF_SET:{		
-					
-            sysinf.amplif_Kp  = *(float *)(pdata+4);
-            sysinf.amplif_Ki = *(float *)(pdata+8);
-            sysinf.amplif_Kd     = *(float *)(pdata+12);
-            sysinf.PreHeatTime  = *(float *)(pdata+16);
-            sysinf.holdTemp = *(float *)(pdata+20);
-            sysinf.readyTemp  = *(float *)(pdata+24);
-            sysinf.PresetTempVal  = *(float *)(pdata+28);
-            sysinf.PresetTempTime  = *(float *)(pdata+32);
-            sysinf.adJTarget  = *(float *)(pdata+36);
-            sysinf.SetTempVal  = *(float *)(pdata+40);
-					
-            data_send_to_pc((pc_cmd_type)pMsg->cmd, pMsg->data,	pMsg->len);
-            updatParm_heater_master();
-            cfg_save_cfg_param();
-        }break;
-        case UINON_CMD_THEROM_GOAL:{					
-            float goal =  *(float *)(pMsg->data+4) ;
-            set_lysis(goal);
-            data_send_to_pc((pc_cmd_type)pMsg->cmd, pMsg->data,	pMsg->len);
-        }break;
-        // case UINON_CMD_THEROM_CHECK:{
-        //         pMsg->data[0] =Therm_Check();
-        //     data_send_to_pc((pc_cmd_type)pMsg->cmd, pMsg->data,  pMsg->len);
-        // }break;
-    }
-    return 0;
-}
-const struct PCActionPack mUnionActionPack[] =
-    {   {
-            .cmd = UINON_CMD_MOTORMOVE,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_MOTORTRETURN,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_TEMP_ADJ,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_TEMP_PID,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_TEMP_ADJ_GET,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_TEMP_PID_GET,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_TEMP_START,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_TEMP_STOP,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_THEROM_GOAL,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_THEROM_OFFSET,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_THEROM_GET,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_AMPLIF_SET,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_AMPLIF_GET,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_THEROM_PID,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_THEROM_OVERHEAT,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_THEROM_OVERCOOL,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_TEMP_DEBUG,
-            .response = handshake_response,
-        },
-
-};
-
-
-
-
-
-
-void deal_mUnion_cmd(CmdMessage *pMsg)
-{
-	for (uint8_t i = 0; i < sizeof(mUnionActionPack)/sizeof(mUnionActionPack[0]); i++)
-	{
-		if (mUnionActionPack[i].cmd == pMsg->cmd ) 
-		{			
-			uint8_t ret = mUnionActionPack[i].action( pMsg->cmd,(uint8_t *)pMsg);
-			if (mUnionActionPack[i].response)
-			{
-				mUnionActionPack[i].response(pMsg, ret);
-			}
-			break;
-		}
-	}
-}
-
-
-void update_work(void) {
-   float temp;
-   unsigned int st;
-
-	char data[20];
-    get_master_st(&temp,&st); 
-	*(unsigned int *)(data+0) = st;
-	*(float *)(data+4) =temp;
-    get_lysis_st(&temp,&st);
-	*(unsigned int *)(data+8) = st; 
-	*(float *)(data+12) = temp;
-	// data_send_to_pc(PC_CMD_UPDATETEMP, data,sizeof(data));
-    Van_Device_Printf(VAN_LOG_TEMP,"st:%d %f %d %f\n\r",sysinf.psmMaster.state,sysinf.heaterMaster.pid.realtemp,sysinf.lysis.thermostat_st,sysinf.lysis.pid.realtemp);
-	return ;
-}

+ 47 - 2
DriverInterface/communication.h

@@ -3,7 +3,7 @@
 #define __COMMUNITION_MINI_H
 
 
-
+#define WRITE_FLASH_PAGE_SIZE 0x800
 
 typedef  enum 
 {
@@ -35,6 +35,12 @@ typedef  enum
 	PC_CMD_ASKSTATE = 0x12,
 	PC_CMD_SETSTATE = 0x13,/*设置强制改变模块状态*/
 	PC_CMD_UPDATETEMP = 0x14,/*设置强制改变模块状态*/
+	
+	PC_CMD_STARTUPDATE = 0x20,/*开始升级*/
+	PC_CMD_UPDATEINFO = 0x21,/*升级包信息*/	
+	PC_CMD_UPDATEDATA = 0x22,/*升级数据*/
+	
+
 	UINON_CMD_TEMP_ADJ = 0x40, /*校准参数*/
 	UINON_CMD_TEMP_PID = 0x41, /*PID参数*/
 	UINON_CMD_TEMP_ADJ_GET = 0x42, /*校准参数*/
@@ -115,10 +121,49 @@ typedef struct _miniConfigPram {
     }Pram;
 } miniConfigPram;
 
+
+enum FLASH_UPDATE_ST
+{
+	FLASH_UPDATE_ST_NUILL,
+	FLASH_UPDATE_ST_REC,
+	FLASH_UPDATE_ST_PROG,
+};
+
+typedef struct _updateHeader
+{
+	unsigned char UPFLAG[8];
+	unsigned int appLen;
+	unsigned int packageSize;
+	unsigned int allpackage;
+ 	unsigned int allchecksum;
+}updateHeader;
+
+typedef struct _updateData
+{ 
+	unsigned int packageOrder;
+	unsigned int packageSize;
+	unsigned char data[256];
+}updateData;
+
+
+typedef struct _updateProcessInf
+{
+	unsigned int appLen;
+	unsigned int packageSize;
+ 	unsigned int allchecksum;
+	unsigned int allpackage;
+	unsigned int updateState;
+	unsigned int writeAddr;
+	unsigned int lenInPage;
+	unsigned int packageInPage;
+	unsigned int nextpackageOrder;
+	unsigned char data[WRITE_FLASH_PAGE_SIZE];
+}updateProcessInf;
 void deal_mUnion_cmd(CmdMessage *pMsg);
 void query_pc_cmd(CmdMessage *pMsg);
 unsigned int check_to_pc_busy(void);
 int data_send_to_pc(pc_cmd_type cmd, char *data, unsigned short len);
 void update_work(void) ;
-void send_Devinf_pc(void);
+int  send_baseinf_pc(unsigned char cmd, unsigned char *parg);
+int no_update_process(void);
 #endif

+ 93 - 0
DriverInterface/onchip_flash.c

@@ -293,3 +293,96 @@ uint8_t cfg_param_init(void)
 
 	return rlt;
 }
+
+
+/**
+ * @brief       跳转到应用程序段(执行APP)
+ * @param       appxaddr : 应用程序的起始地址
+
+ * @retval      无
+ */
+void iap_load_app(uint32_t appxaddr)
+{
+    if (((*(volatile  uint32_t *)appxaddr) & 0x2FFE0000) == 0x20000000)     /* 检查栈顶地址是否合法.可以放在内部SRAM共64KB(0x20000000) */
+    {
+	    // uint32_t msp_value = *(volatile uint32_t*)appxaddr;
+		// uint32_t reset_vector = *(volatile uint32_t*)(appxaddr + 4);
+
+		// // 1. 检查栈顶地址是否在合法SRAM范围(STM32F103 64KB)
+		// if ((msp_value < 0x20000000) || (msp_value > 0x2000FFFF))
+		// 	return;
+
+		// // 2. 检查复位向量是否为有效的Thumb地址(最低位为1)
+		// if ((reset_vector & 0x1) == 0)
+		// 	return;
+
+		// // 3. 关闭全局中断
+		// __disable_irq();
+
+		// // 4. 关闭所有外设时钟(可选,但推荐)
+		// HAL_RCC_DeInit();
+
+		// // 5. 复位HAL库
+		// HAL_DeInit();
+
+		// // 6. 清除所有挂起的中断(清除NVIC挂起状态)
+		// for (int i = 0; i < 8; i++) {
+		// 	NVIC->ICPR[i] = 0xFFFFFFFF;   // 清挂起
+		// 	NVIC->ICER[i] = 0xFFFFFFFF;   // 禁用所有中断
+		// }
+
+		// // 7. 关闭SysTick(避免其产生中断)
+		// SysTick->CTRL = 0;
+		// SysTick->LOAD = 0;
+		// SysTick->VAL  = 0;
+
+		// // 8. 数据与指令同步屏障
+		// __DSB();
+		// __ISB();
+
+		// // 9. 设置主堆栈指针
+		// __set_MSP(msp_value);
+		// __DSB();
+		// __ISB();
+
+		// //10. 跳转到复位地址(强制Thumb模式)
+		// volatile iapfun jump2app = (iapfun)(reset_vector );
+		// jump2app();
+
+        /* 用户代码区第二个字为程序开始地址(复位地址) */
+        volatile iapfun jump2app = (iapfun) * (volatile uint32_t *)(appxaddr + 4);
+		// __disable_irq();
+        // HAL_DeInit();
+        /* 初始化APP堆栈指针(用户代码区的第一个字用于存放栈顶地址) */
+        __set_MSP(*(volatile uint32_t *)appxaddr);
+        
+        /* 跳转到APP */
+        jump2app();
+    }
+}
+
+
+/**
+ * @brief       IAP写入一页
+ * @param       appxaddr : 应用程序的起始地址
+ * @param       appbuf   : 应用程序CODE
+ * @param       appsize  : 应用程序大小(字节)
+ * @retval      无
+ */
+void iap_write_apppage(uint32_t start_addr, uint8_t *pBuffer, uint32_t appsize)
+{
+   
+	   // 1. 擦除目标页
+    uint32_t page_start = start_addr - (start_addr % FLASH_PAGE_SIZE);
+	if(start_addr % FLASH_PAGE_SIZE){
+		return ;
+	}
+    Flash_ErasePage(start_addr);
+    
+    // 2. 依次写入每个半字
+    for (uint32_t i = 0; i < appsize; i=i+4) {
+        Flash_WriteWord(start_addr + i, *(uint32_t *)(pBuffer+i));
+    }
+
+
+}

+ 10 - 0
DriverInterface/onchip_flash.h

@@ -2,6 +2,16 @@
 #ifndef USR_ONCHIP_FLASH_H_
 #define USR_ONCHIP_FLASH_H_
 
+typedef void (*iapfun)(void);                   /* 定义一个函数类型的参数 */
+
+#define FLASH_APP1_ADDR         0x08010000      /* 第一个应用程序起始地址(存放在内部FLASH)
+                                                 * 保留 0X08000000~0X08010000(64KB) 的空间为 Bootloader 使用
+                                                 */
+
+void iap_load_app(uint32_t appxaddr);   /* 跳转到APP程序执行 */
+void iap_write_apppage(uint32_t start_addr, uint8_t *appbuf, uint32_t appsize);   /* 在指定地址开始,写入bin */
+
+
 void cfg_load_default_param(void);
 uint8_t cfg_param_verify(void);
 uint8_t cfg_save_cfg_param(void);

+ 0 - 149
DriverInterface/pt1000.c

@@ -1,149 +0,0 @@
-#include "math.h"
-// PT1000温度阻值对照表-50  单位:欧姆
-#define PT1000_table_len(array) (sizeof(array) / sizeof(array[0]))
-
-#define TEMP_ERR_NEGATIVE  (float)-50
-#define TEMP_ERR_POSITIVE  (float)1000
-
-
-
-const float PT1000_TempList[] = {
-    803.063,  807.033,  811.003,  814.970,  818.937,  822.902,  826.865,  830.828,  834.789,  838.748,  842.707,  846.663,  850.619,  854.573,  858.526,
-    862.478,  866.428,  870.377,  874.325,  878.271,  882.217,  886.160,  890.103,  894.044,  897.985,  901.923,  905.861,  909.797,  913.732,  917.666,
-    921.599,  925.530,  929.461,  933.390,  937.317,  941.244,  945.169,  949.093,  953.016,  956.938,  960.859,  964.778,  968.696,  972.613,  976.529,
-    980.444,  984.358,  988.270,  992.181,  996.091,  1000.000, 1003.908, 1007.814, 1011.720, 1015.624, 1019.527, 1023.429, 1027.330, 1031.229, 1035.128,
-    1039.025, 1042.921, 1046.816, 1050.710, 1054.603, 1058.495, 1062.385, 1066.274, 1070.162, 1074.049, 1077.935, 1081.820, 1085.703, 1089.585, 1093.467,
-    1097.347, 1101.225, 1105.103, 1108.980, 1112.855, 1116.729, 1120.602, 1124.474, 1128.345, 1132.215, 1136.083, 1139.950, 1143.817, 1147.681, 1151.545,
-    1155.408, 1159.270, 1163.130, 1166.989, 1170.847, 1174.704, 1178.560, 1182.414, 1186.268, 1190.120, 1193.971, 1197.821, 1201.670, 1205.518, 1209.364,
-    1213.210, 1217.054, 1220.897, 1224.739, 1228.579, 1232.419, 1236.257, 1240.095, 1243.931, 1247.766, 1251.600, 1255.432, 1259.264, 1263.094, 1266.923,
-    1270.751, 1274.578, 1278.404, 1282.228, 1286.052, 1289.874, 1293.695, 1297.515, 1301.334, 1305.152, 1308.968, 1312.783, 1316.597, 1320.411, 1324.222,
-    1328.033, 1331.843, 1335.651, 1339.458, 1343.264, 1347.069, 1350.873, 1354.676, 1358.477, 1362.277, 1366.077, 1369.875, 1373.671, 1377.467, 1381.262,
-    1385.055, 1388.847, 1392.638, 1396.428, 1400.217, 1404.005, 1407.791, 1411.576, 1415.360, 1419.143, 1422.925, 1426.706, 1430.485, 1434.264, 1438.041,
-    1441.817, 1445.592, 1449.366, 1453.138, 1456.910, 1460.680, 1464.449, 1468.217, 1471.984, 1475.750, 1479.514, 1483.277, 1487.040, 1490.801, 1494.561,
-    1498.319, 1502.077, 1505.833, 1509.589, 1513.343, 1517.096, 1520.847, 1524.598, 1528.347, 1532.096, 1535.843, 1539.589, 1543.334, 1547.078, 1550.820,
-    1554.562, 1558.302, 1562.041, 1565.779, 1569.516, 1573.251, 1576.986, 1580.719, 1584.451, 1588.182, 1591.912, 1595.641, 1599.368, 1603.095, 1606.820,
-    1610.544, 1614.267, 1617.989, 1621.709, 1625.429, 1629.147, 1632.864, 1636.580, 1640.295, 1644.009, 1647.721, 1651.433, 1655.143, 1658.852, 1662.560,
-    1666.267, 1669.972, 1673.677, 1677.380, 1681.082, 1684.783, 1688.483, 1692.181, 1695.879, 1699.575, 1703.271, 1706.965, 1710.658, 1714.349, 1718.040,
-    1721.729, 1725.418, 1729.105, 1732.791, 1736.475, 1740.159, 1743.842, 1747.523, 1751.203, 1754.882, 1758.560};
-unsigned int table_len = PT1000_table_len(PT1000_TempList);
-
-const float PB7_TempList[] = {37.56, 35.89, 34.30, 32.80, 31.36, 30,    28.71, 27.48, 26.31, 25.19, 24.13, 23.12, 22.16, 21.24, 20.37, 19.53, 18.74, 17.98,
-                              17.26, 16.57, 15.91, 15.28, 14.68, 14.11, 13.56, 13.03, 12.53, 12.06, 11.60, 11.16, 10.74, 10.34, 9.955, 9.587, 9.235, 8.898,
-                              8.574, 8.264, 7.967, 7.683, 7.410, 7.148, 6.896, 6.655, 6.424, 6.201, 5.988, 5.783, 5.586, 5.397, 5.215, 5.041, 4.873, 4.711,
-                              4.556, 4.406, 4.262, 4.124, 3.991, 3.863, 3.739, 3.620, 3.506, 3.396, 3.289, 3.187, 3.088, 2.993, 2.901, 2.813, 2.727, 2.645,
-                              2.565, 2.489, 2.415, 2.343, 2.274, 2.208, 2.143, 2.081, 2.021, 1.963, 1.907, 1.853, 1.800, 1.749, 1.700, 1.653, 1.607, 1.563,
-                              1.520, 1.478, 1.438, 1.399, 1.361, 1.325, 1.289, 1.255, 1.222, 1.190, 1.159, 1.128, 1.099, 1.071, 1.043, 1.017, 0.9908
-
-};
-unsigned int PB7_table_len = PT1000_table_len(PB7_TempList);
-
-const float K_Thermocouple_Reference_Tables[] = {
-    0.000, 0.039, 0.079, 0.119, 0.158, 0.198, 0.238, 0.277, 0.317, 0.357, 0.397, 0.437, 0.477, 0.517, 0.557, 0.597, 0.637, 0.677, 0.718, 0.758,
-    0.798, 0.838, 0.879, 0.919, 0.960, 1.000, 1.041, 1.081, 1.122, 1.163, 1.203, 1.244, 1.285, 1.326, 1.366, 1.407, 1.448, 1.489, 1.530, 1.571,
-    1.612, 1.653, 1.694, 1.735, 1.776, 1.817, 1.858, 1.899, 1.941, 1.982, 2.023, 2.064, 2.106, 2.147, 2.188, 2.230, 2.271, 2.312, 2.354, 2.395,
-    2.436, 2.478, 2.519, 2.561, 2.602, 2.644, 2.685, 2.727, 2.768, 2.810, 2.851, 2.893, 2.934, 2.976, 3.017, 3.059, 3.100, 3.142, 3.184, 3.225,
-    3.267, 3.308, 3.350, 3.391, 3.433, 3.474, 3.516, 3.557, 3.599, 3.640, 3.682, 3.723, 3.765, 3.806, 3.848, 3.889, 3.931, 3.972, 4.013, 4.055,
-    4.096, 4.138, 4.179, 4.220, 4.262, 4.303, 4.344, 4.385, 4.427, 4.468, 4.509, 4.550, 4.591, 4.633, 4.674, 4.715, 4.756, 4.797, 4.838, 4.879,
-    4.920, 4.961, 5.002, 5.043, 5.084, 5.124, 5.165, 5.206, 5.247, 5.288, 5.328, 5.369, 5.410, 5.450, 5.491, 5.532, 5.572, 5.613, 5.653, 5.694,
-    5.735, 5.775, 5.815, 5.856, 5.896, 5.937, 5.977, 6.017, 6.058, 6.098, 6.138, 6.179, 6.219, 6.259, 6.299, 6.339, 6.380, 6.420, 6.460, 6.500,
-    6.540, 6.580, 6.620, 6.660, 6.701, 6.741, 6.781, 6.821, 6.861, 6.901, 6.941, 6.981, 7.021, 7.060, 7.100, 7.140, 7.180, 7.220, 7.260, 7.300,
-    7.340, 7.380, 7.420, 7.460, 7.500, 7.540, 7.579, 7.619, 7.659, 7.699, 7.739, 7.779, 7.819, 7.859, 7.899, 7.939, 7.979, 8.019, 8.059, 8.099};
-unsigned int K_Thermocouple_Reference_Tables_len = PT1000_table_len(K_Thermocouple_Reference_Tables);
-
-float getTemp(float R) {
-  float temp;
-
-  if (R < PT1000_TempList[0]) {
-    return TEMP_ERR_NEGATIVE;
-  } else if (R >= PT1000_TempList[table_len - 1]) {
-    return (PT1000_table_len(PT1000_TempList) - 50);
-  }
-  for (int i = 0; i < (table_len - 1); i++) {
-    if (R >= PT1000_TempList[i] && R < PT1000_TempList[i + 1]) {
-      temp = (R - PT1000_TempList[i]) / (PT1000_TempList[i + 1] - PT1000_TempList[i]);
-      temp = temp + i - 50;
-      return temp;
-    }
-  }
-  return TEMP_ERR_POSITIVE;
-}
-float getPB7_Temp(float R) {
-  float temp;
-  R = R / 1000;
-  if (R > PB7_TempList[0]) {
-    return TEMP_ERR_NEGATIVE;
-  } else if (R < PB7_TempList[PB7_table_len - 1]) {
-    return (101);
-  }
-  for (int i = 0; i < (PB7_table_len - 1); i++) {
-    if (R <= PB7_TempList[i] && R > PB7_TempList[i + 1]) {
-      temp = (R - PB7_TempList[i]) / (PB7_TempList[i + 1] - PB7_TempList[i]);
-      temp = temp + i - 5;
-      return temp;
-    }
-  }
-  return TEMP_ERR_POSITIVE;
-}
-
-float Get_Temp_K_Thermocouple(float Vt) {
-  float temp;
-
-  if (Vt < K_Thermocouple_Reference_Tables[0]) {
-    return TEMP_ERR_NEGATIVE;
-  } else if (Vt >= K_Thermocouple_Reference_Tables[K_Thermocouple_Reference_Tables_len - 1]) {
-    return (PT1000_table_len(K_Thermocouple_Reference_Tables));
-  }
-  for (int i = 0; i < (K_Thermocouple_Reference_Tables_len - 1); i++) {
-    if (Vt >= K_Thermocouple_Reference_Tables[i] && Vt < K_Thermocouple_Reference_Tables[i + 1]) {
-      temp = (Vt - K_Thermocouple_Reference_Tables[i]) / (K_Thermocouple_Reference_Tables[i + 1] - K_Thermocouple_Reference_Tables[i]);
-      temp = temp + i;
-      return temp;
-    }
-  }
-  return TEMP_ERR_POSITIVE;
-}
-
-const float Rp = 10000.0;  // 10K
-const float T2 = (273.15 + 25.0);
-;                         // T2
-const float Bx = 3380.0;  // B
-const float Ka = 273.15;
-float Get_Temp_NCP18XH103(float Rt) {
-  float temp;
-  // Rt = Get_TempResistor();
-  // like this R=5000, T2=273.15+25,B=3470, RT=5000*EXP(3470*(1/T1-1/(273.15+25)),
-  temp = Rt / Rp;
-  temp = log(temp);  // ln(Rt/Rp)
-  temp /= Bx;        // ln(Rt/Rp)/B
-  temp += (1 / T2);
-  temp = 1 / (temp);
-  temp -= Ka;
-  if(temp < 0){temp = TEMP_ERR_NEGATIVE;}
-  if(temp > 150){temp = TEMP_ERR_POSITIVE;}
-  return temp;
-}
-
-static const unsigned char crc8_table[256] = {
-    0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d, 0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, 0x48, 0x4f,
-    0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d, 0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5, 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd, 0x90, 0x97, 0x9e, 0x99,
-    0x8c, 0x8b, 0x82, 0x85, 0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd, 0xc7, 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2, 0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4,
-    0xed, 0xea, 0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2, 0x8f, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9d, 0x9a, 0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32,
-    0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a, 0x57, 0x50, 0x59, 0x5e, 0x4b, 0x4c, 0x45, 0x42, 0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a, 0x89, 0x8e,
-    0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c, 0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3, 0xa4, 0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec, 0xc1, 0xc6, 0xcf, 0xc8,
-    0xdd, 0xda, 0xd3, 0xd4, 0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c, 0x51, 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44, 0x19, 0x1e, 0x17, 0x10, 0x05, 0x02,
-    0x0b, 0x0c, 0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34, 0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b, 0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63,
-    0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b, 0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13, 0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, 0x96, 0x91,
-    0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83, 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3};
-
-unsigned char crc8_check(unsigned char* data, unsigned char len) {
-  unsigned int i = 0;
-  unsigned char fcs = 0x0;
-  // 计算数据校验
-  for (i = 0; i < (len); i++) {
-    fcs = crc8_table[(unsigned char)fcs ^ *data];
-    data++;
-  }
-  // 计算的 CRC 校验与数据最后一个字节对比
-
-  return fcs;
-}

+ 0 - 26
DriverInterface/pt1000.h

@@ -1,26 +0,0 @@
-#ifndef __PT1000_H__
-#define __PT1000_H__
-
-/*
-采样值转电压:0.000050354004 16bit 满篇3.3V
-分压偏置 0.436170213  分压电阻为20k,8.2k  偏置电压为
-电流值:0.0005 限流电阻1500
-(V*0.000050354004/10 + 0.436170213)/0.0005
-简化为:
-=V*3.3/65536/10/0.0005 + 0.436170213/0.0005
-=V*0.01007080078125+872.34
-*/
-
-#define ADCTORESISTANCE   0.01007080078125
-#define BASERESISTANCE   872.34
-
-
-
-float getTemp(float R);
-float getPB7_Temp(float R);
-float Get_Temp_NCP18XH103(float Rt);
-float Get_Temp_K_Thermocouple(float Vt);
-unsigned char crc8_check(unsigned char* data, unsigned char len);
-
-
-#endif

+ 0 - 512
DriverInterface/state_mini.c

@@ -1,512 +0,0 @@
-
-
-
-#include "onechip_include_header.h"
-
-
-#define CardON 1
-#define CardOFF 0
-
-uint32_t g_card_tick_s = 0;	//插卡计时S
-uint8_t cardonsta = 0;
-int samp_time = 0;
-int samp_num = 0;
-uint8_t datasope_flag = 0;
-
-str_error_info_t error_info = {0};    //错误信息
-uint32_t error_delay = 0;    //错误持续时长
-// test_result_struct result = {0};
-heat_ctrl_struct g_heat_ctrl = {0};
-
-int TrigStateCheck(void)
-{
-	 return (HAL_GPIO_ReadPin(MINI7_V2_DEC_S1_GPIO_Port,MINI7_V2_DEC_S1_Pin)) ? 1 : 0; // 
-}
-uint32_t get_master_st(float *temp,unsigned int *st) {
-	*temp = sysinf.heaterMaster.pid.realtemp;
-	*st = sysinf.psmMaster.state;
-	return 0;
-}
-
-
-uint32_t get_slave_st(float *temp,unsigned int *st) {
-	*temp = sysinf.heaterSlave.pid.realtemp;
-	*st = sysinf.psmSlave.state;
-	return 0;
-}
-
-uint8_t is_command(uint16_t controlword, Controlword_t command_to_check)
-{
-    return (controlword) == command_to_check;
-}
-void updateData(ProcessStateMachine_t *psm)
-{ 
-
-	if(psm->cursendok == 0){
-		return;
-	}
-	if (check_to_pc_busy()){		
-		psm->cursendok = 0;
-		psm->sendTime = 3;
-		if(psm->DataSendHeader != psm->DataSendLast){ 			
-				/*1.5s 无应答,或者当前发送完成*/
-				char data[55] = {0};
-				memcpy(&data[1], psm->card_param_info.pid, 10);
-				memcpy(&data[11],&psm->DataBufRDR[psm->DataSendHeader], 40);
-				memcpy(&data[51],&psm->sendconter, 4);
-				if(0 == data_send_to_pc(PC_CMD_DATA_UPLOAD, data, sizeof(data))){
-					Van_Device_Printf(VAN_LOG_WIFI, "send Header:%d last:%d  sendconter:0x%x \n",psm->DataSendHeader, psm->DataSendLast,psm->sendconter);
-				}
-		}else{
-			/*无数据,有结果*/
-			if(psm->updateresult){
-				data_send_to_pc(PC_CMD_REPORT_RESULT, (char *)&result, sizeof(test_result_struct));              				
-			}			
-		}
-	}
-}
-ProcessStateMachine_t * matchPid(unsigned char * part){
-    if( 0 == memcmp(sysinf.psmMaster.card_param_info.pid, part, sizeof(sysinf.psmMaster.card_param_info.pid))){
-        return &sysinf.psmMaster;        
-    }
-    
-    if( 0 == memcmp(sysinf.psmSlave.card_param_info.pid, part, sizeof(sysinf.psmSlave.card_param_info.pid))){
-        return &sysinf.psmSlave;        
-    }
-	return 0;
-}
-
-void updateData_next(unsigned int recdex,unsigned char * part)
-{ 
-    ProcessStateMachine_t *psm = matchPid(part);
-	if(psm){				
-		psm->cursendok = 1;
-		if(psm->DataSendHeader != psm->DataSendLast){ 
-			psm->sendconter++;		
-			Van_Device_Printf(VAN_LOG_WIFI,"send ok Header:%d sendconter:0x%x \n",psm->DataSendHeader, psm->sendconter);
-			/*主模块又消息,更新头,发下一条*/
-			psm->DataSendHeader++;
-			if(psm->DataSendHeader == MAX_DATA_BUF_SIZE){
-				psm->DataSendHeader = 0;
-			}
-		}
-	}
-}
-void resetSampleData(ProcessStateMachine_t *psm){
-	if(psm->sendTime){
-		psm->sendTime--;
-		if(psm->sendTime==0){						
-			psm->cursendok = 1;
-		}
-	}
-}
-
-void clean_reult_next(unsigned char * part)
-{ 
-	ProcessStateMachine_t *psm = matchPid(part);
-	if(psm){			
-		psm->updateresult = 0;			
-		psm->cursendok = 1;
-        psm->controlword = result_move_card;  
-	}
-}
-
-
-
-/********************************************************************
- *      uint8_t error_set(uint8_t error)
- *
- *描述:设置错误位,并上报主机,灯带显示
- *参数:error: 错误位
- *返回:错误码
- *其他:无
- ********************************************************************/
-uint8_t error_set(uint8_t error)
-{
-       
-    if(error_info.error_code == error)
-        return error;
-
-    if(error == ERROR_SAMP_MOVE_CARD)   //检测中拔卡,需等待60S才能消除
-    {
-       error_delay = 60; 
-    }    
-    error_info.error_code = error;
-    error_info.id = 0;
-    sysinf.updateError = 1;
-
-    Van_Device_Printf(VAN_LOG_ERROR, "error_set: %d %d %d\n", 0, error,sysinf.psmMaster.state);
-    memcpy(error_info.SN, &sysinf.SN, 7);
-	error_info.SN[7] = 0;
-    error_info.error_report = 1;
-    data_send_to_pc(PC_CMD_REPORT_REEOR, (char*)&error_info, sizeof(str_error_info_t));
-    
-   if(error != ERROR_MOTOR_FIALED){
-	   sysinf.psmMaster.state = SW_Fault;
-	//    mcu_ack_ctrl.re_send_card = ACK_TIMEOUT;
-	//    Card_State_Send(HEAT_OFF);			  //降温至40°C,不开风扇
-   }  
-
-    return 0;
-}
-/********************************************************************
- *       void error_clear()
- *
- *描述:清除错误
- *参数:error: 错误
- *返回:错误码
- *其他:无
- ********************************************************************/
-void error_clear(void)
-{
-    error_info.error_code = 0;
-	error_info.error_report = 0;
-}
-
-
-void resend_error_update(void){
-	 if(sysinf.updateError == 1){
-		data_send_to_pc(PC_CMD_REPORT_REEOR, (char*)&error_info, sizeof(str_error_info_t));
-	 }
-}
-void re_send_state(void){
-	 if(sysinf.updateSt == 1){
-        stateinfDef st;
-        st.amplifState =sysinf.amplifState;
-        st.lysisState =sysinf.lysisState;
-        memcpy(st.SN, &sysinf.SN, 7);
-        data_send_to_pc(PC_CMD_UPDATESTATE, (char *)&st, sizeof(stateinfDef));  
-	 }
-}
-  
-
-
-void updateAmplifState(uint8_t newset){
-    if(sysinf.amplifState != newset){
-        sysinf.amplifState = newset;
-        sysinf.updateSt = 1;
-    }
-}
-void updateLysisState(uint8_t newset){
-    if(sysinf.lysisState != newset){
-        sysinf.lysisState = newset;
-        sysinf.updateSt = 1;
-    }
-
-}
-
-void usr_state_machine(ProcessStateMachine_t *sts, heat_ctrl_def *heater)
-{
-    sts->statusword = 0x0000;
-    static uint8_t state = 0;
-    static uint32_t delay = 0;
-    //采样前,3秒发一次加热指令
-    if((sts->state < SW_Chip_Id) && (sts->state != SW_Fault)){
-        if (TrigStateCheck() == CardON){            
-            error_set(ERROR_NO_QRCODE);
-            updateAmplifState(SYS_STATE_ERROR_HM);
-        }
-    }
-    switch (sts->state)
-    {
-    // 所有板卡准备自检,包含通道预加热
-    case SW_Read_To_Board_Selftest:
-    {
-        if (is_command(sts->controlword, Board_Selftest_cmd))
-        {    
-            sts->state = SW_Target_reached;
-            sts->statusword |= SW_Target_reached;
-            
-        }
-
-        break;
-    }
-    case SW_Fault:
-    {
-        // 没有预热完成前插卡检测
-        // 采样没有完成,拔卡检测
-        
-        sts->sampleStart = 0;
-
-        if(error_info.error_code < ERROR_SENSOR_SELF_CHECK && error_delay == 0)
-        {
-            //拔卡消除故障
-            if (TrigStateCheck() == CardOFF)
-            {
-                sts->statusword |= SW_move_card;
-                sts->state = SW_move_card;
-                error_clear();
-				memset(&sts->card_param_info, 0 , sizeof(str_card_param_info_t));
-            }
-        }
-		if(error_info.error_code == ERROR_SENSOR_SELF_CHECK){
-			if(check_first_zero() == 0){ 
-				sts->statusword |= SW_Chip_Id;
-            	sts->state = SW_Chip_Id;
-                error_clear();
-				}
-		}
-        break;
-    }
-    // 快速停止
-    case SW_Quick_stop:
-    {
-        break;
-    }
-    // 获取温度,两通道加热
-    // 等温度稳定后
-    case SW_Target_reached:
-    {
-        if (heater->temp_stable_sta == 1)
-        {
-            sts->controlword = Target_reached_cmd;
-             updateAmplifState(SYS_STATE_READY); 
-        	/*************lxx-add-20232.11.30****************/
-            if (SensorSelfCheck() == SystemError)
-        	{
-                error_set(ERROR_SENSOR_SELF_CHECK);
-        	}
-        }
-		if ((sysinf.skip_CheckOrRun & SKIP_HEATONCHECK_OK))
-        {
-           /*跳过温度判断*/
-            sts->controlword = Target_reached_cmd;
-            if (SensorSelfCheck() == SystemError)
-        	{
-                error_set(ERROR_SENSOR_SELF_CHECK);
-        	}
-			// Card_State_Send(HEAT_STOP);
-        }
-
-        if (is_command(sts->controlword, Target_reached_cmd))
-        {
-            sts->statusword |= SW_Scan_Qrcode;
-            sts->state = SW_Scan_Qrcode;
-            sts->heat_timeout = 0;
-        }
-        break;
-    }
-    
-    // 扫码
-    case SW_Scan_Qrcode:
-    {
-        // if (scan_qrcode_done)
-        // {
-        //     // calc_balance();
-        //     controlword = Scan_Qrcode_cmd;
-        // }
-        if (is_command(sts->controlword, Scan_Qrcode_cmd))
-        {
-            calc_balance();
-            sts->statusword |= SW_Chip_Id;
-            sts->state = SW_Chip_Id;
-             updateAmplifState(SYS_STATE_CHECK); 
-        }
-		if((sysinf.skip_CheckOrRun & SKIP_SCANQRCODE)){
-	            sts->statusword |= SW_Chip_Id;
-	            sts->state = SW_Chip_Id;
-		}
-        break;
-    }
-    // 插卡,通道检测
-    case SW_Chip_Id:
-    {
-        if (TrigStateCheck() == CardON)
-        {
-			HAL_Delay(1000);/*插卡后延时1s检测*/
-			if(!(sysinf.skip_CheckOrRun & SKIP_CHECK_CARDINSERT)){
-				if(check_first_zero() == 1)break;
-			}
-			{				
-	            sts->controlword = Qrcode_publish_cmd;
-	            // mcu_ack_ctrl.re_send_card = ACK_TIMEOUT;
-	            // Card_State_Send(HEAT_ON);
-                
-        	    sysinf.heaterMaster.HeatState = SysPreHeatUP;
-                sysinf.heaterMaster.timenum=0;
-	            g_heat_ctrl.temp_stable_sta=0;
-	            g_card_tick_s = 0;
-				if (is_command(sts->controlword, Qrcode_publish_cmd))
-				{
-					sts->statusword |= SW_Sample_timeout;
-					sts->state = SW_Sample_timeout;
-                     updateAmplifState(SYS_STATE_RUNING); 
-				}
-				};
-        }
-        break;
-    }
-    // 采样,30min定时
-    case SW_Sample_timeout:
-    {
-         if (TrigStateCheck() == CardOFF){            
-            error_set(ERROR_SAMP_MOVE_CARD);
-            updateAmplifState(SYS_STATE_ERROR_HM);
-        }
-    	if(((heater->temp_stable_sta==2)||(sysinf.skip_CheckOrRun & SKIP_HEATONCHECK_OK))&& sts->sampleStart == 0)
-    	{
-			// 启动定时器计时
-			sts->sampleTimes = 0;
-			sts->sampleStart = 1;
-    	}
-     	if(sysinf.samp_flag == 1 && sts->sampleStart)
-    	{
-			sysinf.samp_flag = 0;
-		
-			if (sts->sampleTimes == 0)
-			{
-				sample_first_zero();    //计算校零值	
-				// sts->samp_num = 0;
-				sts->cursendok = 1;
-			}
-			else
-			{
-				sample_calibrate_calc(sts->sampleTimes);     //采样,前18组计算均值
-                //输出原始数据
-                // DatascopeSend(CS[0].RDR,CS[1].RDR,CS[2].RDR,CS[3].RDR,CS[4].RDR,CS[5].RDR,CS[6].RDR,CS[7].RDR,CS[8].RDR,CS[9].RDR, g_card_tick_s/60.0f);
-			}
-
-
-            //上报采样数据
-//            sample_send_rt_data();
-			if(((sts->DataSendLast+ 1)%MAX_DATA_BUF_SIZE) != sts->DataSendHeader){
-				for (int i = 0; i < CS_MAX; i++)
-				{
-					memcpy(&sts->DataBufRDR[sts->DataSendLast][i], &CS[i].RtR, 4);
-				}
-				sts->DataSendLast++;
-				if(sts->DataSendLast == MAX_DATA_BUF_SIZE){
-					sts->DataSendLast = 0;
-				}
-			}
-
-			if (sts->sampleTimes == 19)
-			{
-				// sample_calc_avg_std();      //计算均值标准差
-			}
-			if (sts->sampleTimes > 19)
-			{
-				// sample_calc_tt();      //计算Tt
-			}
-//			if ((!(g_cfg.skip_CheckOrRun & SKIP_HEATONCHECK_OK) || g_cfg.skip_CheckOrRun & SKIP_FARSTRUN)){		
-//			}		
-			if (!(sysinf.skip_CheckOrRun & SKIP_FARSTRUN)){
-				sts->sampleTimes++;
-			}
-			
-			Van_Device_Printf(VAN_LOG_INFO,"SendLast:%d Times:%d \n",sts->DataSendLast,sts->sampleTimes);
-			if (sts->sampleTimes >= sampleTotalTimes)
-			{
-//				sampleTimes = 0;
-				if(0==(sysinf.skip_CheckOrRun & SKIP_FARSTRUN)){
-					sts->sampleStart = 0;
-					sts->controlword = result_report_cmd;
-				}
-
-			}
-
-			
-    	}
-        if (is_command(sts->controlword, result_report_cmd))
-        {
-            sts->statusword |= SW_result_report;
-            sts->state = SW_result_report;
-             sample_calc_result();
-            delay = 0;
-            // datasope_flag = 0;
-            
-            // mcu_ack_ctrl.re_send_card = ACK_TIMEOUT;
-        	// Card_State_Send(HEAT_OFF);              //降温至40°C,不开风扇
-        	sts->updateresult = 1;
-			
-        }
-
-        break;
-    }
-    // 计算,阈值范围,所有孔的结果(阴阳性、无效)
-    // 结果上传&数据上传
-    case SW_result_report:
-    {
-        if(0 == datasope_flag)
-        {
-            datasope_flag = 1;
-            // DatascopeSend(CS[0].Tt,CS[1].Tt,CS[2].Tt,CS[3].Tt,CS[4].Tt,CS[5].Tt,CS[6].Tt,CS[7].Tt,CS[8].Tt,CS[9].Tt, 101);                                                     //Tt值
-            // DatascopeSend(CS[0].average,CS[1].average,CS[2].average,CS[3].average,CS[4].average,CS[5].average,CS[6].average,CS[7].average,CS[8].average,CS[9].average, 102);   //均值
-            // DatascopeSend(CS[0].STD,CS[1].STD,CS[2].STD,CS[3].STD,CS[4].STD,CS[5].STD,CS[6].STD,CS[7].STD,CS[8].STD,CS[9].STD, 103);                                           //方差
-            // DatascopeSend(CS[0].CDR, CS[1].CDR, CS[2].CDR, CS[3].CDR, CS[4].CDR, CS[5].CDR, CS[6].CDR, CS[7].CDR, CS[8].CDR, CS[9].CDR, 104);                                  //校零值
-            // DatascopeSend(CS[0].Result,CS[1].Result,CS[2].Result,CS[3].Result,CS[4].Result,CS[5].Result,CS[6].Result,CS[7].Result,CS[8].Result,CS[9].Result, 105);             //结果
-            // DatascopeSend(CS[0].gain, CS[1].gain, CS[2].gain, CS[3].gain, CS[4].gain, CS[5].gain, CS[6].gain, CS[7].gain, CS[8].gain, CS[9].gain, 106);                        //gain值
-            // DatascopeSend(CS[0].RDC, CS[1].RDC, CS[2].RDC, CS[3].RDC, CS[4].RDC, CS[5].RDC, CS[6].RDC, CS[7].RDC, CS[8].RDC, CS[9].RDC, 107);                                  //gain基值
-            // DatascopeSend(CS[0].TtMax, CS[1].TtMax, CS[2].TtMax, CS[3].TtMax, CS[4].TtMax, CS[5].TtMax, CS[6].TtMax, CS[7].TtMax, CS[8].TtMax, CS[9].TtMax, 108);              //TtMax
-            // DatascopeSend(CS[0].TtMin, CS[1].TtMin, CS[2].TtMin, CS[3].TtMin, CS[4].TtMin, CS[5].TtMin, CS[6].TtMin, CS[7].TtMin, CS[8].TtMin, CS[9].TtMin, 109);              //TtMin
-        }
-
-//        if(g_sys_tick > delay)
-//        {
-//            if (Devicenum == 0)
-//            {
-//                data_send_to_pc(PC_CMD_REPORT_RESULT, (char *)&result, sizeof(test_result_struct));
-//            }
-//            else
-//            {
-//                b2b_send_device(B2B_CMD_REQ_RESULT, (char *)&result, sizeof(test_result_struct),0);
-//            }
-//            delay = g_sys_tick + 10;
-//        }
-
-        if (is_command(sts->controlword, result_move_card))
-        {
-            sts->statusword |= SW_move_card;
-            sts->state = SW_move_card;
-             updateAmplifState(SYS_STATE_WORKEND);
-        }
-        break;
-    }
-
-    case SW_move_card:
-    {
-        //等待拔卡进入下一次循环
-        if (TrigStateCheck() != CardON)
-        {
-            //跳转到等待扫码状态
-            sts->statusword = SW_Target_reached;
-            sts->state = SW_Target_reached;            
-		
-			sts->sampleTimes = 0;
-			sts->sampleStart = 0;
-            g_heat_ctrl.temp_stable_sta = 0;
-            datasope_flag = 0;
-            sts->heat_timeout = 0;
-            memset(&sts->card_param_info, 0 ,sizeof(sts->card_param_info));
-        	sysinf.heaterMaster.HeatState = SystemPreHeat;
-            sysinf.heaterMaster.temp_stable_sta = 0;
-            sts->controlword = Board_Selftest_cmd; 
-             updateAmplifState(SYS_STATE_PREPARE); 
-        }
-        break;
-    }
-    default:
-        break;
-    }
-    switch (sts->state)
-    {
-    case SW_Read_To_Board_Selftest:
-        sts->flags.selftest_allowed = 1;
-        sts->flags.scan_qrcode_allowed = 0;
-        sts->flags.pre_heat_enabled = 0;
-        sts->flags.target_reached = 0;
-        sts->flags.check_chipid_enabled = 0;
-        sts->flags.qrcode_info_applied = 0;
-        break;
-
-    default:
-        break;
-    }
-
-    if(state != sts->state)
-    {
-        state = sts->state;
-        Van_Device_Printf(VAN_LOG_NOTICE,"\nstate:%d \n", state);
-    }
-    updateData(sts);
-}

+ 0 - 249
DriverInterface/state_mini.h

@@ -1,249 +0,0 @@
-/*
- * state_mini.h
- *
- *  Created on: 2026年6月29日
- *      Author: dell
- */
-
-#ifndef __STATE_MINI_H
-#define __STATE_MINI_H
-
-#include "user_heater.h"
-#define MAX_DATA_BUF_SIZE  36
-#define SystemChecking    0
-#define SystemOK          1
-#define SystemError       2
-
-#define SKIP_CHECK_CARDINSERT (1 << 0)  //开始检测插卡正确
-#define SKIP_CHECK_CARDREMOVE (1 << 1) //运行过程中检测插卡拔卡
-#define SKIP_HEATONCHECK_OK   (1 << 2) //跳过加热,不管加热状态
-#define SKIP_SAMPLIGHT_ACC   (1 << 3)  //上报加速
-#define SKIP_SCANQRCODE    (1 << 4)  //上报加速
-#define SKIP_FARSTRUN    (1 << 5)  //上报加速
-#define SKIP_SLAVEDATASCOP    (1 << 6)  //从模块datascop上报
-
-
-#define HEAT_OFF 0x00    //关加热
-#define HEAT_ON 0x01     //开加热
-#define HEAT_STOP 0x02     //停止加热
-#define FAN_ON 0x02     //启用风扇
-
-
-#define sampleTotalTimes  181
-typedef enum StatusWord
-{
-    // 所有板卡准备自检,包含通道预加热
-    SW_Read_To_Board_Selftest = 0,
-    // 准备和PC握手
-    // SW_Ready_To_Shake_On = 0,
-    // 故障
-    SW_Fault = 1,
-    // 获取温度,两通道通道加热
-    SW_Switch_On_Pre_Heat = 8,
-    // 快速停止
-    SW_Quick_stop = 30,
-    // 等温度稳定后
-    SW_Target_reached = 10,
-    // 等待扫码
-    SW_Scan_Qrcode = 12,
-    // 插卡,通道检测
-    SW_Chip_Id = 14,
-    // 条码信息匹配,下发
-    SW_Qrcode_publish = 16,
-    // 采样,30min定时
-    SW_Sample_timeout = 18,
-    // 计算,阈值范围,所有孔的结果(阴阳性、无效)
-    // 结果上传&数据上传
-    SW_result_report = 25,
-    SW_move_card = 26,      //拔卡,进入下一次流程循环
-    SW_SystemError
-} StatusWord_t;
-// pc Controlword commands
-typedef enum Controlword
-{
-    Board_Selftest_cmd,
-    Hand_Shake_cmd,
-    Scan_ready_Qrcode_cmd,
-    Scan_Qrcode_cmd,
-    Pre_Heat_cmd,
-    Target_reached_cmd,
-    Chip_Id_cmd,
-    Qrcode_publish_cmd,
-    Sample_timeout_cmd,
-    result_report_cmd,
-    result_move_card
-}  Controlword_t;
-
-//故障码
-enum ERROR_CODE
-{
-    ERROR_HEAT_INSERT_CARD = 101,      //温度稳定前插卡
-    ERROR_NO_QRCODE = 102,             //未扫码就插卡
-    ERROR_SAMP_MOVE_CARD = 103,        //检测中拔卡
-    ERROR_SENSOR_SELF_CHECK= 104,      //光电自检失败
-    ERROR_HEAT_SELF_CHECK= 105,        //加热自检失败
-    ERROR_MCU_LINK_TIMEOUT = 106,             //mcut通讯超时
-    ERROR_PRE_HEAT_TIMEOUT = 107,             //预热超时
-    ERROR_HEAT_TIMEOUT = 108,                 //加热超时
-    ERROR_MOTOR_FIALED = 109,                 //电机
-    ERROR_TUPE_MOVE = 110,                 //检测过程中拔试管
-    ERROR_TUPE_EXIST = 111,                 //检测过程中拔试管
-    ERROR_HEATFUC_EER = 112,               //加热模块无反应
-    ERROR_TEMPSENSOR_EER = 113,            //温度传感器异常
-};
-
-typedef struct inner_action_flags_t
-{
-    uint8_t selftest_allowed : 1;
-    uint8_t scan_qrcode_allowed : 1;
-    uint8_t pre_heat_enabled : 1;
-    uint8_t target_reached : 1;
-    uint8_t check_chipid_enabled : 1;
-    uint8_t qrcode_info_applied : 1;
-}  inner_action_flags_t;
-
-
-typedef struct
-{
-	uint8_t    Devicenum;               //设备编号
-	char   	   card_num[10];            //卡盒编号
-
-	uint8_t    hole1_item;              //孔1检测项目
-	uint8_t    hole1_item_result;       //孔1检测项目结果
-	uint8_t    hole1_result;            //孔1检测结果
-	uint8_t      hole1_Tt[2];                //孔1 Tt
-
-	uint8_t    hole2_item;              //孔2检测项目
-	uint8_t    hole2_item_result;       //孔2检测项目结果
-	uint8_t    hole2_result;            //孔2检测结果
-	uint8_t     hole2_Tt[2] ;                //孔2 Tt
-
-	uint8_t    hole3_item;              //孔3检测项目
-	uint8_t    hole3_item_result;       //孔3检测项目结果
-	uint8_t    hole3_result;            //孔3检测结果
-	uint8_t      hole3_Tt[2];                //孔3 Tt
-
-	uint8_t    hole4_item;              //孔4检测项目
-	uint8_t    hole4_item_result;       //孔4检测项目结果
-	uint8_t    hole4_result;            //孔4检测结果
-	uint8_t      hole4_Tt[2];                //孔4 Tt
-
-	uint8_t    hole5_item;              //孔5检测项目
-	uint8_t    hole5_item_result;       //孔5检测项目结果
-	uint8_t    hole5_result;            //孔5检测结果
-	uint8_t      hole5_Tt[2];                //孔5 Tt
-
-	uint8_t    hole6_item;              //孔6检测项目
-	uint8_t    hole6_item_result;       //孔6检测项目结果
-	uint8_t    hole6_result;            //孔6检测结果
-	uint8_t      hole6_Tt[2];                //孔6 Tt
-
-	uint8_t    hole7_item;              //孔7检测项目
-	uint8_t    hole7_item_result;       //孔7检测项目结果
-	uint8_t    hole7_result;            //孔7检测结果
-	uint8_t      hole7_Tt[2];                //孔7 Tt
-
-	uint8_t    hole8_item;              //孔8检测项目
-	uint8_t    hole8_item_result;       //孔8检测项目结果
-	uint8_t    hole8_result;            //孔8检测结果
-	uint8_t      hole8_Tt[2];                //孔8 Tt
-
-	uint8_t    hole9_item;              //孔9检测项目
-	uint8_t    hole9_item_result;       //孔9检测项目结果
-	uint8_t    hole9_result;            //孔9检测结果
-	uint8_t      hole9_Tt[2];                //孔9 Tt
-
-	uint8_t    hole10_item;             //孔10检测项目
-	uint8_t    hole10_item_result;      //孔10检测项目结果
-	uint8_t    hole10_result;           //孔10检测结果
-	uint8_t      hole10_Tt[2];               //孔10 Tt
-
-}test_result_struct;
-
-
-
-
-
-
-typedef struct str_error_info
-{
-    uint8_t id; //板卡id
-    uint8_t error_code; //错误码 
-    char   	SN[10];
-    uint8_t error_report; //错误码 
-} str_error_info_t;
-
-
-typedef struct str_hole_info
-{
-    uint8_t    item;
-    uint8_t TtMax[2];
-    uint8_t TtMin[2];
-} str_hole_info_t;
-//str_hole_info_t hole1,hole2,hole3,hole4,hole5,hole6,hole7,hole8,hole9,hole10;
-typedef struct str_card_param_info
-{
-    char   pid[10];
-    uint8_t temp[2];
-    struct str_hole_info hole_info[10];
-} str_card_param_info_t;
-
-typedef struct
-{
-	uint8_t   id;            		//设备编号
-	uint8_t   heat_state;            		//串口控制加热状态
-	uint8_t   temp_stable_sta;            	//串口控制加热状态
-	float     heater_temp;                  //加热体温度
-	uint8_t   fan_state;   					//风扇状态
-	float heater_independent_temp;
-
-}heat_ctrl_struct;
-typedef struct  //由于flash_write是按4字节写入,所以本结构体内部都按4字节定义和对齐
-{
-	float    presetTempVal;   //拉升温度
-	uint32_t presetTempTime;   //拉升保持时间
-	float    setTempVal;      //设定温度
-	float    holdTemp;       //稳定温度
-	float	tempOffset;		//温度补偿
-	uint32_t preHeatTime;	//上电预热时间,min
-	float readyTemp;		//就绪温度
-	uint32_t log_level;		//日志等级
-	uint32_t skip_CheckOrRun;		//插入光变化检测
-	float adjtemp;		//调整温度
-
-}CFG_PARAM_STRUCT;
-
-
-typedef struct ProcessStateMachine
-{
-    StatusWord_t state;
-    inner_action_flags_t flags; 
-    float DataBufRDR[MAX_DATA_BUF_SIZE][10];
-    uint32_t DataSendHeader;    //串口超时
-    uint32_t DataSendLast;    //串口超时   
-    unsigned int sendconter;
-    unsigned int updateresult;
-    unsigned int cursendok;
-    unsigned int sendTime ;
-    unsigned int  sampleStart;
-    unsigned int  sampleTimes;
-    unsigned int  heat_timeout; //加热超时
-    unsigned int  scan_qrcode_done;
-    unsigned int  statusword; 
-    unsigned int  controlword;     
-	str_card_param_info_t card_param_info; 
-} ProcessStateMachine_t;
-
-void resend_error_update(void);
-void re_send_state(void);
-uint32_t get_master_st(float *temp,unsigned int *st);
-uint32_t get_slave_st(float *temp,unsigned int *st);
-void updateAmplifState(uint8_t newset);
-void updateLysisState(uint8_t newset);
-void updateData_next(unsigned int recdex,unsigned char * part);
-void clean_reult_next(unsigned char * part);
-uint8_t error_set(uint8_t error);
-void error_clear(void);
-void usr_state_machine(ProcessStateMachine_t *sts, heat_ctrl_def *heater);
-void resetSampleData(ProcessStateMachine_t *psm);
-#endif

+ 0 - 648
DriverInterface/uart_rcv.c

@@ -1,648 +0,0 @@
-/*
- * uart_rcv.c
- *
- *  Created on: 2022年4月20日
- *      Author: dell
- */
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include "NuMicro.h"
-#include "cfg_param_record.h"
-#include "uart_rcv.h"
-#include "usr_pid.h"
-#include "cJSON.h"
-#include "ws2812.h"
-
-
-
-
-#define ENV_ADJ_THRESHOLD 27.0
-
-
-enum SLAVE_MCU_Ctr_cmd_type
-{
-    SLAVE_MCU_CMD_PARAM = 0x01,
-    SLAVE_MCU_CMD_HEAT = 0x02,
-    SLAVE_MCU_CMD_LIGHT_CTR= 0X03,
-    SLAVE_MCU_CMD_QRSCANNER_CTR= 0X04,    
-    SLAVE_MCU_CMD_FAN= 0X05,
-    SLAVE_MCU_CMD_CARD_ST= 0X06,
-	SLAVE_MCU_CMD_PID = 0x20,
-};
-enum SLAVE_MCU_Ctr_UP_type
-{
-	SLAVE_MCU_UP_HEAT = 0x10,
-	SLAVE_MCU_UP_QR_PARAM= 0X11,
-	SLAVE_MCU_UP_QR = 0x12,
-	SLAVE_MCU_INFO,					//异常信息
-};
-
-
-
-#define combine_cmdMessage(msg,header,seqer,cmder,tailer) { \
-	msg.head = header; \
-	msg.seq = seqer; \
-	msg.cmd = cmder; \
-	msg.tail = tailer; \
-}
-
-uint8_t g_uart2_rcv_start = 0;
-uint8_t g_uart2_rcv_complete_flg = 0;
-uint16_t g_uart2_rx_len = 0;
-uint8_t g_uart2_frame_overtime_cnt = 0;
-uint16_t g_uart2_rcv_cmd = 0;
-uint16_t g_uart2_cmd_overtime_secs = 0;
-uint32_t g_uart2_cmd_overtime_cnt = 0;
-uint8_t g_param_set_mode = 0; // 参数设置模式
-
-uint8_t g_uart1_rcv_start = 0;
-uint8_t g_uart1_rcv_complete_flg = 0;
-uint8_t g_uart1_tx_buf[BUF_SIZE] = {0};
-uint8_t g_uart1_rx_buf[BUF_SIZE] = {0};
-uint8_t g_uart1_rx_len = 0;
-uint8_t g_uart1_frame_overtime_cnt = 0;
-
-uint8_t g_uart0_rcv_start = 0;
-uint8_t g_uart0_rcv_complete_flg = 0;
-uint8_t g_uart0_tx_buf[DEBUG_BUF_SIZE] = {0};
-uint8_t g_uart0_rx_buf[BUF_SIZE] = {0};
-uint8_t g_uart0_rx_len = 0;
-uint8_t g_uart0_frame_overtime_cnt = 0;
-
-uint32_t  uart0_header = 0;
-uint32_t  uart0_last = 0;
-
-unsigned int haveheaderflag = 0;
-
-heat_ctrl_struct g_heat_ctrl = {0};
-// card_param_struct card = {0};
-str_hole_info_t hole1 = {0};
-str_hole_info_t hole2 = {0};
-str_hole_info_t hole3 = {0};
-str_hole_info_t hole4 = {0};
-str_hole_info_t hole5 = {0};
-str_hole_info_t hole6 = {0};
-str_hole_info_t hole7 = {0};
-str_hole_info_t hole8 = {0};
-str_hole_info_t hole9 = {0};
-str_hole_info_t hole10 = {0};
-str_card_param_info_t m_str_card_param_info = {0};
-
-uint32_t qr_check_delay = QR_CHECH_STATE_FIRST;  /*1s定时器里面,大于0,每s减1*/
-extern void QRparam_upload(str_card_param_info_t *p_str_card_param_info);
-extern uint8_t sys_info[40];
-/********************************************************************
- *                         bcd_to_hex()
- *
- *描述:BCD转HEX
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-uint8_t bcd_to_hex(uint8_t val)
-{
-	return ((val / 10) << 4) + val % 10;
-}
-
-/********************************************************************
- *                         debug_receive_int_handle()
- *
- *描述:调试串口接收中断数据处理
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-void debug_receive_int_handle0(void)
-{
-
-	if (UART_GET_INT_FLAG(UART0, UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk))
-	{
-		/* UART receive data available flag */
-
-		/* Move the data from Rx FIFO to sw buffer (RAM). */
-		/* Every time leave 1 byte data in FIFO for Rx timeout */
-		while (UART_GET_RX_EMPTY(UART0) == 0)
-		{
-			if (uart0_last == BUF_SIZE)uart0_last = 0;
-			g_uart0_rx_buf[uart0_last] = UART_READ(UART0);
-			uart0_last++;
-		}  
-	}
-
-}
-
-
-void debug_receive_int_handle1(void)
-{
-	while (UART_GET_RX_EMPTY(UART1) == 0)
-	{
-		if (g_uart1_rx_len >= BUF_SIZE)
-			g_uart1_rx_len = 0;
-		g_uart1_rx_buf[g_uart1_rx_len] = UART_READ(UART1);
-		g_uart1_rx_len++;
-	}
-}
-
-
-
-/********************************************************************
- *                         UART02_IRQHandler()
- *
- *描述:串口接收中断
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-void UART02_IRQHandler(void)
-{
-	if (UART_GET_INT_FLAG(UART0, UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk | UART_INTSTS_RXTOIF_Msk) )
-	{
-		debug_receive_int_handle0();
-	}
-	else if (UART_GET_INT_FLAG(UART0,UART_INTSTS_BUFERRIF_Msk) )
-	{
-		debug_receive_int_handle0();
-		UART_ClearIntFlag(UART0,UART_INTSTS_BUFERRINT_Msk);
-	}
-	else if (UART_GET_INT_FLAG(UART0,UART_INTSTS_RLSINT_Msk) )
-	{
-		UART_ClearIntFlag(UART0,UART_INTSTS_RLSINT_Msk);
-	}
-	
-	if (UART_GET_INT_FLAG(UART2, UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk | UART_INTSTS_RXTOIF_Msk) )
-	{
-		debug_receive_int_handle2();
-	}
-	else if (UART_GET_INT_FLAG(UART2,UART_INTSTS_BUFERRIF_Msk) )
-	{
-		debug_receive_int_handle2();
-		UART_ClearIntFlag(UART2,UART_INTSTS_BUFERRINT_Msk);
-	}
-	else if (UART_GET_INT_FLAG(UART2,UART_INTSTS_RLSINT_Msk) )
-	{
-		UART_ClearIntFlag(UART2,UART_INTSTS_RLSINT_Msk);
-	}
-}
-
-/********************************************************************
- *                         UART13_IRQHandler()
- *
- *描述:串口接收中断
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-void UART13_IRQHandler(void)
-{
-	if (UART_GET_INT_FLAG(UART1, UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk | UART_INTSTS_RXTOIF_Msk) )
-	{
-		debug_receive_int_handle1();
-	}
-	else if (UART_GET_INT_FLAG(UART1,UART_INTSTS_BUFERRIF_Msk) )
-	{
-		debug_receive_int_handle1();
-		UART_ClearIntFlag(UART1,UART_INTSTS_BUFERRINT_Msk);
-	}
-	else if (UART_GET_INT_FLAG(UART1,UART_INTSTS_RLSINT_Msk) )
-	{
-		UART_ClearIntFlag(UART1,UART_INTSTS_RLSINT_Msk);
-	}
-}
-
-
-
-
-void sendMsgtoMasterMcu(struct CmdMessage *pmsg)
-{
-	static uint8_t sedbuf[DEBUG_BUF_SIZE];
-	uint16_t checksum = 0;
-	*(unsigned short *)sedbuf = pmsg->head;
-	sedbuf[2] = pmsg->seq;
-	sedbuf[3] = pmsg->cmd;
-	*(unsigned short *)(sedbuf+4) = pmsg->len;
-	for(int i=0; i < pmsg->len; i++){
-		sedbuf[6+i] = pmsg->data[i];
-	}
-
-	for(int i=2; i < (pmsg->len + 6); i++){
-		checksum += sedbuf[i];
-	}
-	sedbuf[6+pmsg->len] = checksum&0xff;/*结尾标记高位*/
-	sedbuf[7+pmsg->len ] = checksum>>8 ;/*结尾标记低位*/
-	UART_Write(UART0, sedbuf, (8+pmsg->len));
-}
-
-
-
-uint16_t checkSum(const uint8_t *pInBuffer, int uLen)
-{
-    uint32_t sum = 0;
-
-    for(int i = 0; i < uLen; i++)
-    {
-        sum += pInBuffer[i];
-    }
-
-    return (sum);
-}
-
-/********************************************************************
- *                         int Decode(const char *pInBuffer, int uLen)
- *
- *描述:对串口数据进行解码成结构体
- *参数:pInBuffer    接收缓冲区
-        *uheader 当前头位置
-        ulast 当前头尾位置
-        maxlen 缓冲区长度
-        pMessage  命令结构体
-        pdata 命令数据
- *返回:1解码成功,0解码失败
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-int DecodeNew(struct CmdMessage *pMessage, uint8_t *pdata, const uint8_t *pInBuffer, uint32_t* pheader,uint32_t  ulast,uint32_t maxlen)
-{
-	uint32_t  bufRealLen;
-	uint32_t  sizeofMessage = MINI7_MASSAGE_SIZE;
-	uint32_t  header = *pheader;
-	uint32_t i = 0;
-    if (NULL == pInBuffer || NULL == pMessage || NULL == pdata || NULL == pheader)
-    {
-		/*空指针判断*/
-		return 0;
-    }
-	/*缓冲区有效数据长度,缓冲区循环处理,会出现头大于未情况*/
-	bufRealLen = (ulast > header)?(ulast - header):(ulast + maxlen - header);
-	if(bufRealLen < sizeofMessage){
-		/*长度过段,跳过*/
-		return 0;
-	}
-	bufRealLen -= sizeofMessage; /*最大有效数据长度*/
-	for(; i<=bufRealLen;){
-		uint32_t headerflag = pInBuffer[(header + i)%maxlen];
-		headerflag += pInBuffer[(header + i + 1)%maxlen] <<8;
-		if(headerflag != MINI7_HEADER_FALG){
-			i += 1;
-//			header = (header + 1)%maxlen;
-			continue;
-		}
-		uint32_t messagelen =  pInBuffer[(header + i + 4)%maxlen];
-		messagelen += pInBuffer[(header + i + 5)%maxlen] <<8;
-		if(messagelen > (maxlen- sizeofMessage)){
-			/*长度超长 跳过2个字节*/
-			i += 1;
-//			header = (header + 1)%maxlen;
-			continue;
-		}
-		if(messagelen >bufRealLen){
-			/*当前起始点可能存在数据,跳出循环,*/
-			i++; /*for采样小于等于判断,循环次数多1,此处加1便于后续处理*/
-			break;
-		}
-		uint16_t checkesum = 0;
-		uint16_t recsum = 0;
-		if((header + i + 6 + messagelen) < maxlen){
-			checkesum = checkSum(pInBuffer + header + i + 2, messagelen+4);
-		}else{
-			checkesum = checkSum(pInBuffer + header + i + 2, (maxlen - (header + i + 2)));
-			checkesum += checkSum(pInBuffer, (header + i + 6 + messagelen)%maxlen);
-		}
-		recsum = *(pInBuffer + (header + i + 6 + messagelen)%maxlen ) ;
-		recsum += *(pInBuffer + (header + i + 7 + messagelen)%maxlen) << 8;
-		/*固定结尾预留做调试用*/
-		if(checkesum != recsum && recsum>>8 != MINI7_TAIL_FALG){
-			 i += 1;
-		// ? ? ? ? ?header = (header + 1)%maxlen;
-		}else{
-		/*解析成功,拷贝消息结构体*/
-		 uint8_t * pCharMessage = (uint8_t *)pMessage;
-		for(unsigned copyi=0;copyi<(sizeofMessage-2);copyi++){
-			*pCharMessage++ = pInBuffer[(header + i+ copyi)%maxlen];
-		}
-		 (*pMessage).tail = MINI7_TAIL_FALG;
-
-		/*解析成功,拷贝数据结构体*/
-		for(unsigned copyi=0;copyi<messagelen;copyi++){
-			*pdata++ = pInBuffer[(header + i + 6 + copyi)%maxlen];
-		}
-		*pheader = (header + messagelen + i + sizeofMessage - 2)%maxlen;
-			return 1;
-		}
-	}
-   *pheader = (header + i - 1)%maxlen;
-   return 0;
-}
-
-
-
-/********************************************************************
- *                         heater_state_upload()
- *
- *描述:上传加热、风扇状态及加热体温度
- *参数:无
- *返回:0/1:设置失败/成功
- *其他:无
- *--------------------------------------------------------------------
- *记录:包含上报和应答处理
- ********************************************************************/
-void heater_state_upload(uint32_t upenv)
-{
-	struct CmdMessage msg;
-	uint8_t databuf[7]={0};
-	combine_cmdMessage(msg,MINI7_HEADER_FALG,MINI7_MASSAGE_TYPE_MCUTOMCU,SLAVE_MCU_UP_HEAT,MINI7_TAIL_FALG)
-	if(upenv){		
-		msg.len = sizeof(databuf);
-	}else{
-		msg.len = sizeof(databuf)-2;
-	}
-	msg.data = databuf;	
-	databuf[0] = g_heat_ctrl.heat_state;
-	databuf[1] = g_heat_ctrl.temp_stable_sta;
-	databuf[2] = (uint8_t)pid1.ActualTemp;
-	databuf[3] = (uint8_t)((pid1.ActualTemp - (uint8_t)pid1.ActualTemp) * 100);
-	databuf[4] = g_heat_ctrl.fan_state;
-	databuf[5] = (uint8_t)pid1.cabinTem;
-	databuf[6] = (uint8_t)((pid1.cabinTem - (uint8_t)pid1.cabinTem) * 100);
-	sendMsgtoMasterMcu(&msg);
-	
-}
-
-void sendInfoMasterMcu(uint8_t *data, uint16_t len)
-{
-	struct CmdMessage msg;
-	combine_cmdMessage(msg,MINI7_HEADER_FALG,MINI7_MASSAGE_TYPE_MCUTOMCU,SLAVE_MCU_INFO,MINI7_TAIL_FALG)
-	msg.len = len;
-	msg.data = data;
-
-	sendMsgtoMasterMcu(&msg);
-}
-
-/********************************************************************
- *                         uart2_rcv_frame_analysis()
- *
- *描述:接收帧解析
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-
-void send_param(void){	
-	struct CmdMessage msg;
-	combine_cmdMessage(msg,MINI7_HEADER_FALG,MINI7_MASSAGE_TYPE_MCUTOMCU,SLAVE_MCU_UP_QR_PARAM,MINI7_TAIL_FALG)
-	msg.len = sizeof(m_str_card_param_info);
-	msg.data = (char*)&m_str_card_param_info;
-	sendMsgtoMasterMcu(&msg);
-}
-
-
-
-/********************************************************************
- *                         trigmode_select_sensor()
- *
- *描述:切换为感应触发模式
- *参数:无
- *返回:0/1:设置失败/成功
- *其他:无
- *--------------------------------------------------------------------
- *记录:包含上报和应答处理
- ********************************************************************/
-void trigmode_select_sensor(void)
-{
-	memset(g_uart2_tx_buf, 0, sizeof(g_uart2_tx_buf));
-	//	memset(g_uart2_rx_buf, 0, sizeof(g_uart2_rx_buf));
-	g_uart2_tx_buf[0] = 0x7E; // 帧头
-	g_uart2_tx_buf[1] = 0x00; // 帧头
-	g_uart2_tx_buf[2] = 0x08; // 命令标识
-	g_uart2_tx_buf[3] = 0x01; // 命令标识
-	g_uart2_tx_buf[4] = 0x00;
-	g_uart2_tx_buf[5] = 0x00;
-	g_uart2_tx_buf[6] = 0xD7;
-	//	g_uart2_tx_buf[6]  = 0xEF;
-	g_uart2_tx_buf[7] = 0xAB;
-	g_uart2_tx_buf[8] = 0xCD;
-	UART_Write(UART2, g_uart2_tx_buf, 9);
-}
-
-/********************************************************************
- *                         data_out_oragin()
- *
- *描述:切换为原始数据输出
- *参数:无
- *返回:0/1:设置失败/成功
- *其他:无
- *--------------------------------------------------------------------
- *记录:包含上报和应答处理
- ********************************************************************/
-void data_out_original(void)
-{
-	memset(g_uart2_tx_buf, 0, sizeof(g_uart2_tx_buf));
-
-	g_uart2_tx_buf[0] = 0x7E; // 帧头
-	g_uart2_tx_buf[1] = 0x00; // 帧头
-	g_uart2_tx_buf[2] = 0x08; // 命令标识
-	g_uart2_tx_buf[3] = 0x01; // 命令标识
-	g_uart2_tx_buf[4] = 0x00;
-	g_uart2_tx_buf[5] = 0x0D;
-	//	g_uart0_tx_buf[6]  = 0xD7;
-	g_uart2_tx_buf[6] = 0xCA;
-	g_uart2_tx_buf[7] = 0xAB;
-	g_uart2_tx_buf[8] = 0xCD;
-	UART_Write(UART2, g_uart2_tx_buf, 9);
-	HAL_Delay(100);
-
-}
-
-int parse_qrcode_info(str_card_param_info_t *info, char *qrcode_str)
-{
-	int id = 0;
-	double Tt = 0;
-	double Tt1 = 0;
-	
-	if (info == 0)
-	{
-		return -1;
-	}
-
-	cJSON *root = cJSON_Parse(qrcode_str);
-	if (root == NULL)
-	{   /*消息不合格*/
-		return -1;
-	}
-	cJSON *item = cJSON_GetObjectItem(root, "p");
-	if (item == NULL)
-	{   /*消息不合格*/
-		cJSON_Delete(root);
-		return -1;
-	}
-	char *pid = cJSON_GetStringValue(item);
-	//    printf("pid=%s \r\n", pid);
-	memcpy(info->pid, pid, 10);
-
-	item = cJSON_GetObjectItem(root, "t");
-	if (item == NULL)
-	{   /*消息不合格*/
-		cJSON_Delete(root);
-		return -1;
-	}
-	double t = item->valuedouble;
-	//    printf("t=%f \r\n", t);
-	info->temp[0] = (uint8_t)t;
-	info->temp[1] = (uint8_t)((t -(uint8_t)t)* 100);
-
-	// 获取数组item
-	item = cJSON_GetObjectItem(root, "e");
-	if (item == NULL)
-	{   /*消息不合格*/
-		cJSON_Delete(root);
-		return -1;
-	}
-	int test_arry_size = cJSON_GetArraySize(item);
-
-	for (int i = 0; i < test_arry_size; i++)
-	{
-		// 打印数组里的所有item
-		cJSON *sub_array = cJSON_GetArrayItem(item, i);
-
-		cJSON *sub = cJSON_GetObjectItem(sub_array, "i");
-		id = sub->valueint;
-		//        printf("id=%d \r\n", id);
-
-		if(id > 0)
-		{
-			sub = cJSON_GetObjectItemCaseSensitive(sub_array, "T");
-			Tt = sub->valuedouble;
-			//        printf("Tt=%f \r\n", Tt);
-
-			sub = cJSON_GetObjectItemCaseSensitive(sub_array, "t");
-			Tt1 = sub->valuedouble;
-			//        printf("Tt1=%f \r\n", Tt1);
-		}
-		else
-		{
-			Tt = 0;
-			Tt1 = 0;
-		}
-
-		info->hole_info[i].item = id;
-		info->hole_info[i].TtMax[0] = (uint8_t)Tt;
-		info->hole_info[i].TtMax[1] = (uint8_t)((Tt -(uint8_t)Tt)* 100);
-		info->hole_info[i].TtMin[0] = (uint8_t)Tt1;
-		info->hole_info[i].TtMin[1] = (uint8_t)((Tt1 -(uint8_t)Tt1)* 100);
-	}
-	// 记得删除json
-	cJSON_Delete(root);
-	return 0;
-}
-
-/********************************************************************
- *                         QRparam_upload()
- *
- *描述:上传二维码扫码参数
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:包含上报和应答处理
- ********************************************************************/
-void QRparam_upload(str_card_param_info_t *p_str_card_param_info)
-{
-	memset(g_uart0_tx_buf, 0, sizeof(g_uart0_tx_buf));
-	//	int QR_param_pid = 0;
-	//	QR_param_pid = atoi(&m_str_card_param_info.pid[0]);
-
-	g_uart0_tx_buf[0] = 0xAA; // 帧头
-	g_uart0_tx_buf[1] = 0x55; // 帧头
-	g_uart0_tx_buf[2] = 0x0A; // 命令标识
-	g_uart0_tx_buf[3] = 0x11; // 命令标识
-#if 0
-	/*卡盒编号*/
-	g_uart0_tx_buf[4]  = (uint8_t)m_str_card_param_info.pid[0] - 48;
-	g_uart0_tx_buf[5]  = (uint8_t)m_str_card_param_info.pid[1] - 48;
-	g_uart0_tx_buf[6]  = (uint8_t)m_str_card_param_info.pid[2] - 48;
-	g_uart0_tx_buf[7]  = (uint8_t)m_str_card_param_info.pid[3] - 48;
-	g_uart0_tx_buf[8]  = (uint8_t)m_str_card_param_info.pid[4] - 48;
-	g_uart0_tx_buf[9]  = (uint8_t)m_str_card_param_info.pid[5] - 48;
-	/*卡槽工作温度(整数+小数)*/
-	g_uart0_tx_buf[10] = (uint8_t)(m_str_card_param_info.temp);
-	g_uart0_tx_buf[11] = (uint8_t)((m_str_card_param_info.temp-(uint8_t)(m_str_card_param_info.temp))*100);
-	/*孔1检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
-	g_uart0_tx_buf[12] = (uint8_t)(m_str_card_param_info.hole_info[0].item);
-	g_uart0_tx_buf[13] = (uint8_t)(m_str_card_param_info.hole_info[0].TtMax);
-	g_uart0_tx_buf[14] = (uint8_t)((m_str_card_param_info.hole_info[0].TtMax-(uint8_t)(m_str_card_param_info.hole_info[0].TtMax))*100);
-	g_uart0_tx_buf[15] = (uint8_t)(m_str_card_param_info.hole_info[0].TtMin);
-	g_uart0_tx_buf[16] = (uint8_t)((m_str_card_param_info.hole_info[0].TtMin-(uint8_t)(m_str_card_param_info.hole_info[0].TtMin))*100);
-	/*孔2检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
-	g_uart0_tx_buf[17] = (uint8_t)(m_str_card_param_info.hole_info[1].item);
-	g_uart0_tx_buf[18] = (uint8_t)(m_str_card_param_info.hole_info[1].TtMax);
-	g_uart0_tx_buf[19] = (uint8_t)((m_str_card_param_info.hole_info[1].TtMax-(uint8_t)(m_str_card_param_info.hole_info[1].TtMax))*100);
-	g_uart0_tx_buf[20] = (uint8_t)(m_str_card_param_info.hole_info[1].TtMin);
-	g_uart0_tx_buf[21] = (uint8_t)((m_str_card_param_info.hole_info[1].TtMin-(uint8_t)(m_str_card_param_info.hole_info[1].TtMin))*100);
-	/*孔3检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
-	g_uart0_tx_buf[22] = (uint8_t)(m_str_card_param_info.hole_info[2].item);
-	g_uart0_tx_buf[23] = (uint8_t)(m_str_card_param_info.hole_info[2].TtMax);
-	g_uart0_tx_buf[24] = (uint8_t)((m_str_card_param_info.hole_info[2].TtMax-(uint8_t)(m_str_card_param_info.hole_info[2].TtMax))*100);
-	g_uart0_tx_buf[25] = (uint8_t)(m_str_card_param_info.hole_info[2].TtMin);
-	g_uart0_tx_buf[26] = (uint8_t)((m_str_card_param_info.hole_info[2].TtMin-(uint8_t)(m_str_card_param_info.hole_info[2].TtMin))*100);
-	/*孔4检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
-	g_uart0_tx_buf[27] = (uint8_t)(m_str_card_param_info.hole_info[3].item);
-	g_uart0_tx_buf[28] = (uint8_t)(m_str_card_param_info.hole_info[3].TtMax);
-	g_uart0_tx_buf[29] = (uint8_t)((m_str_card_param_info.hole_info[3].TtMax-(uint8_t)(m_str_card_param_info.hole_info[3].TtMax))*100);
-	g_uart0_tx_buf[30] = (uint8_t)(m_str_card_param_info.hole_info[3].TtMin);
-	g_uart0_tx_buf[31] = (uint8_t)((m_str_card_param_info.hole_info[3].TtMin-(uint8_t)(m_str_card_param_info.hole_info[3].TtMin))*100);
-	/*孔5检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
-	g_uart0_tx_buf[32] = (uint8_t)(m_str_card_param_info.hole_info[4].item);
-	g_uart0_tx_buf[33] = (uint8_t)(m_str_card_param_info.hole_info[4].TtMax);
-	g_uart0_tx_buf[34] = (uint8_t)((m_str_card_param_info.hole_info[4].TtMax-(uint8_t)(m_str_card_param_info.hole_info[4].TtMax))*100);
-	g_uart0_tx_buf[35] = (uint8_t)(m_str_card_param_info.hole_info[4].TtMin);
-	g_uart0_tx_buf[36] = (uint8_t)((m_str_card_param_info.hole_info[4].TtMin-(uint8_t)(m_str_card_param_info.hole_info[4].TtMin))*100);
-	/*孔6检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
-	g_uart0_tx_buf[37] = (uint8_t)(m_str_card_param_info.hole_info[5].item);
-	g_uart0_tx_buf[38] = (uint8_t)(m_str_card_param_info.hole_info[5].TtMax);
-	g_uart0_tx_buf[39] = (uint8_t)((m_str_card_param_info.hole_info[5].TtMax-(uint8_t)(m_str_card_param_info.hole_info[5].TtMax))*100);
-	g_uart0_tx_buf[40] = (uint8_t)(m_str_card_param_info.hole_info[5].TtMin);
-	g_uart0_tx_buf[41] = (uint8_t)((m_str_card_param_info.hole_info[5].TtMin-(uint8_t)(m_str_card_param_info.hole_info[5].TtMin))*100);
-	/*孔7检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
-	g_uart0_tx_buf[42] = (uint8_t)(m_str_card_param_info.hole_info[6].item);
-	g_uart0_tx_buf[43] = (uint8_t)(m_str_card_param_info.hole_info[6].TtMax);
-	g_uart0_tx_buf[44] = (uint8_t)((m_str_card_param_info.hole_info[6].TtMax-(uint8_t)(m_str_card_param_info.hole_info[6].TtMax))*100);
-	g_uart0_tx_buf[45] = (uint8_t)(m_str_card_param_info.hole_info[6].TtMin);
-	g_uart0_tx_buf[46] = (uint8_t)((m_str_card_param_info.hole_info[6].TtMin-(uint8_t)(m_str_card_param_info.hole_info[6].TtMin))*100);
-	/*孔8检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
-	g_uart0_tx_buf[47] = (uint8_t)(m_str_card_param_info.hole_info[7].item);
-	g_uart0_tx_buf[48] = (uint8_t)(m_str_card_param_info.hole_info[7].TtMax);
-	g_uart0_tx_buf[49] = (uint8_t)((m_str_card_param_info.hole_info[7].TtMax-(uint8_t)(m_str_card_param_info.hole_info[7].TtMax))*100);
-	g_uart0_tx_buf[50] = (uint8_t)(m_str_card_param_info.hole_info[7].TtMin);
-	g_uart0_tx_buf[51] = (uint8_t)((m_str_card_param_info.hole_info[7].TtMin-(uint8_t)(m_str_card_param_info.hole_info[7].TtMin))*100);
-	/*孔9检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
-	g_uart0_tx_buf[52] = (uint8_t)(m_str_card_param_info.hole_info[8].item);
-	g_uart0_tx_buf[53] = (uint8_t)(m_str_card_param_info.hole_info[8].TtMax);
-	g_uart0_tx_buf[54] = (uint8_t)((m_str_card_param_info.hole_info[8].TtMax-(uint8_t)(m_str_card_param_info.hole_info[8].TtMax))*100);
-	g_uart0_tx_buf[55] = (uint8_t)(m_str_card_param_info.hole_info[8].TtMin);
-	g_uart0_tx_buf[56] = (uint8_t)((m_str_card_param_info.hole_info[8].TtMin-(uint8_t)(m_str_card_param_info.hole_info[8].TtMin))*100);
-	/*孔10检测项目ID、TtMax(整数+小数)、TtMin(整数+小数)*/
-	g_uart0_tx_buf[57] = (uint8_t)(m_str_card_param_info.hole_info[9].item);
-	g_uart0_tx_buf[58] = (uint8_t)(m_str_card_param_info.hole_info[9].TtMax);
-	g_uart0_tx_buf[59] = (uint8_t)((m_str_card_param_info.hole_info[9].TtMax-(uint8_t)(m_str_card_param_info.hole_info[9].TtMax))*100);
-	g_uart0_tx_buf[60] = (uint8_t)(m_str_card_param_info.hole_info[9].TtMin);
-	g_uart0_tx_buf[61] = (uint8_t)((m_str_card_param_info.hole_info[9].TtMin-(uint8_t)(m_str_card_param_info.hole_info[9].TtMin))*100);
-#endif
-	memcpy(g_uart0_tx_buf + 4, (uint8_t*)p_str_card_param_info, sizeof(str_card_param_info_t));
-
-	g_uart0_tx_buf[62] = 0x55; // 帧尾
-	g_uart0_tx_buf[63] = 0xBB; // 帧尾
-
-	UART_Write(UART0, g_uart0_tx_buf, 64);
-}

+ 0 - 125
DriverInterface/uart_rcv.h

@@ -1,125 +0,0 @@
-/*
- * uart_rcv.h
- *
- *  Created on: 2022年4月20日
- *      Author: dell
- */
-
-#ifndef UART_RCV_H_
-#define UART_RCV_H_
-
-
-
-#define DEBUG_BUF_SIZE (512)	// 调试串口缓冲区长度
-#define FRAME_RCV_OVERTIME (10) // 帧接收超时时间,单位:ms
-#define OVERTIME_SEC (10)		// 接收清除命令超时时间:10秒
-
-
-#define BUF_SIZE (64)			// 调试串口缓冲区长度
-#define FRAME_RCV_OVERTIME (10) // 帧接收超时时间,单位:ms
-#define OVERTIME_SEC (10)
-#define MINI7_HEADER_FALG 0x55AA
-#define MINI7_TAIL_FALG 0x5A
-#define MINI7_MASSAGE_SIZE 8
-#define MINI7_MASSAGE_TYPE_MCUTOMCU 0x10
-
-#define DEBUG_UART           UART0         //调试串口号
-#define DEBUG_UART_RST       UART0_RST     //调试串口复位标志
-#define DEBUG_UART_IRQ       UART02_IRQn   //中断向量
-
-//#define hole1 	1
-//#define hole2 	2
-//#define hole3 	3
-//#define hole4 	4
-//#define hole5 	5
-//#define hole6	6
-//#define hole7 	7
-//#define hole8 	8
-//#define hole9 	9
-//#define hole10 	10
-//#define hole1 1
-
-enum QR_CHECH_STATE
-{
-	QR_CHECH_STATE_FIRST = 0,
-	QR_CHECH_STATE_TRYAGAIN = 1,
-	QR_CHECH_STATE_WAITING= 3,
-	QR_CHECH_STATE_SEND= 4,
-};
-enum QR_REC_STATE
-{
-	QR_REC_STATE_EMPTY = 0,
-	QR_REC_STATE_HEADER ,
-	QR_REC_STATE_SENDPRAM,
-	QR_REC_STATE_SENDQR,
-	QR_REC_STATE_END,
-};
-
-/* 串口命令码  */
-enum
-{
-	UART0_PARAM_DOWNLOAD  = 0x01,           //参数下载
-	UART0_HEAT_CTRL       = 0x02,           //加热控制
-	UART0_lIGHTBAND_CTRL  = 0x03,           //灯带控制
-	UART0_QRSCANNER_CTRL  = 0x04,           //二维码扫码模块控制
-	UART0_FAN_CTRL        = 0x05,           //风扇控制
-	UART0_CARD_STA        = 0x06,           //风扇控制
-	UART0_CMD_REPLY       = 0x10,           //回复命令
-};
-/* 串口2命令码  */
-enum
-{
-	UART2_CMD_RCV         = 0x00,           //命令回复
-
-};
-typedef struct
-{
-	uint8_t   heat_state;            		//串口控制加热状态
-	uint8_t   temp_stable_sta;            	//加热稳定状态
-	uint8_t   fan_state;   					//风扇状态
-	uint8_t   card_state;   				//插卡状态
-	float     SetTempVal;
-	uint32_t  PresetTempTime;
-	float     PresetTempVal;
-	
-	float    HoldTemp;       //稳定温度
-	float	TempOffset;		//温度补偿
-	uint32_t  PreHeatTime;					//上电预热时间,min
-	float     ReadyTempVal;					//就绪温度55℃
-	float     adJTarget;					//根据环境温度,修正目标温度
-}heat_ctrl_struct;
-
-extern heat_ctrl_struct g_heat_ctrl;
-
-
-
-
-//灯带控制参数
-struct light_band_para_t
-{
-	uint8_t		channel;
-	uint8_t		mode;
-	uint16_t	speed;
-	uint32_t	color;
-};
-
-struct str_card_param_info m_str_card_param_info;
-
-void UART02_IRQHandler(void);
-extern void debug_receive_int_handle0(void);
-extern void debug_receive_int_handle1(void);
-extern void debug_receive_int_handle2(void);
-void uart0_rcv_data_analysis(void);
-void uart1_rcv_data_analysis(void);
-void uart2_rcv_frame_analysis(void);
-void debug_receive_start0(void);
-void debug_receive_start2(void);
-void heater_state_upload(uint32_t upenv);
-void trigmode_select_sensor(void);
-void data_out_original(void);
-int parse_qrcode_info(struct str_card_param_info *info, char *qrcode_str);
-void QRparam_upload(str_card_param_info_t *p_str_card_param_info);
-int DecodeNew(struct CmdMessage *pMessage, uint8_t *pdata, const uint8_t *pInBuffer, uint32_t* pheader,uint32_t  ulast,uint32_t maxlen);
-void sendQR_inf(void);
-
-#endif /* UART_RCV_H_ */

+ 0 - 211
DriverInterface/user_heater.c

@@ -1,211 +0,0 @@
-
-#include "onechip_include_header.h"
-
-#define HEATER_NEED_PREHEAT    37.0
-
-#define HEATER_MIN_TEMP  15.0
-#define  HEATER_MAX_TEMP 95.0
-#define HEATER_MIN_ERROR_TEMP  5.0
-#define  HEATER_MAX_ERROR_TEMP 115.0
-uint32_t get_heater_master_st(float *temp,unsigned int *st) {
-	*temp = sysinf.heaterMaster.pid.realtemp + sysinf.heaterMaster.offset;
-	*st = sysinf.heaterMaster.HeatState;
-	return 0;
-}
-
-
-uint32_t get_heater_slave_st(float *temp,unsigned int *st) {
-	*temp = sysinf.heaterSlave.pid.realtemp + sysinf.heaterSlave.offset;
-	*st = sysinf.heaterSlave.HeatState;
-	return 0;
-}
-
-uint32_t check_heater_master_needPreheat(void) {
-        
-    float temp = getADC_Chanel_value(0);
-    sysinf.heaterMaster.pid.realtemp = temp + sysinf.heaterMaster.offset;
-    if(sysinf.heaterMaster.pid.realtemp < HEATER_NEED_PREHEAT){
-        sysinf.heaterMaster.needpreheat = 1;
-        sysinf.heaterMaster.HeatState = SysPreHeatUP;
-        sysinf.heaterMaster.stabletime = 0;
-    }else{
-        sysinf.heaterMaster.needpreheat = 0;
-        sysinf.heaterMaster.HeatState = SystemPreHeat;
-    }
-	return 0;
-}
-
-void updatParm_heater_master(void) {
-	sysinf.heaterMaster.PreHeatTime = sysinf.PreHeatTime;
-	sysinf.heaterMaster.HoldTemp = sysinf.holdTemp;
-	sysinf.heaterMaster.readyTemp =  sysinf.readyTemp;
-	sysinf.heaterMaster.PresetTempVal = sysinf.PresetTempVal;
-	sysinf.heaterMaster.PresetTempTime = sysinf.PresetTempTime*10;
-	sysinf.heaterMaster.adJTarget =  sysinf.adJTarget;
-	sysinf.heaterMaster.SetTempVal =  sysinf.SetTempVal;
-	sysinf.heaterMaster.pid.Kp = sysinf.amplif_Kp;
-	sysinf.heaterMaster.pid.Ki = sysinf.amplif_Ki ;
-	sysinf.heaterMaster.pid.Kd = sysinf.amplif_Kd;
-
-
-
-
-}
-
-void heater_work(heat_ctrl_def *heater)
-{
-    if(heater->needpreheat){
-        heater->stabletime ++;
-        if(heater->stabletime > heater->PreHeatTime * 600){
-            /*提前预热阶段完成,进入正式控温流程*/
-            sysinf.heaterMaster.needpreheat = 0;
-            sysinf.heaterMaster.HeatState = SystemPreHeat;
-            sysinf.heaterMaster.stabletime = 0;  
-        }
-    }
-    
-    if((heater->pid.realtemp < HEATER_MIN_TEMP) || (heater->pid.realtemp > HEATER_MAX_TEMP)){
-        /*稍后添加*/
-         com_pwm_Set(heater->pwdId,0);  
-         heater->HeatState = SystemPreHeat;
-         return;
-
-    }
-    if((heater->pid.realtemp < HEATER_MIN_ERROR_TEMP) || (heater->pid.realtemp > HEATER_MAX_ERROR_TEMP)){
-        /*稍后添加*/
-         com_pwm_Set(heater->pwdId,0);  
-         heater->HeatState = SysERRORHeat;
-         error_set(ERROR_HEAT_SELF_CHECK);
-         return;
-
-    }
-    heater->timenum ++;
-    switch (heater->HeatState)
-    {
-        case SystemPreHeat:{
-            heater->pid.goal = heater->HoldTemp;  
-            if(heater->pid.realtemp -  heater->HoldTemp  > 0.6){
-                com_pwm_Set(heater->pwdId,0);                   
-                heater->pid.integral = 0;	  
-                heater->timenum = 0;       
-            }else{
-                PIDRealize(&heater->pid);
-                com_pwm_Set(heater->pwdId,heater->pid.variate);                
-                if(heater->timenum>=60*10)//system led turn red while the temperature could not heat up to PresetTemp over 10min
-                {
-                    if((heater->pid.realtemp<heater->HoldTemp))
-                    {
-                        com_pwm_Set(heater->pwdId,0);
-                        /*TODO 加热模块故障*/
-                        error_set(ERROR_HEAT_TIMEOUT);
-                        heater->HeatState = SysERRORHeat;
-                        return;
-                    }
-                }
-            }
-            
-                //稳定条件,大于待机温度-0.5度,并且小于就绪温度
-            if(heater->pid.realtemp > ( heater->HoldTemp  - 0.5) && heater->pid.realtemp < heater->readyTemp)
-            {
-                if(heater->stabletime++ > 10)
-                {
-                    heater->temp_stable_sta = 1;
-                    heater->HeatState = SystemIdle;
-                }
-            }
-            else
-            {
-                heater->temp_stable_sta = 0;
-                heater->stabletime = 0;
-            }
-        }break;
-        case SystemIdle:{                
-            PIDRealize(&heater->pid);
-            com_pwm_Set(heater->pwdId,heater->pid.variate);
-        }break;
-        case SysPreHeatUP: {
-            com_pwm_Set(heater->pwdId,100);
-            if((heater->pid.realtemp>=(heater->PresetTempVal-1)))
-            {
-                heater->timenum=0;
-                heater->HeatState=SysPreKepTemp;
-                heater->pid.integral = 0;
-                heater->pid.goal = heater->PresetTempVal;
-            }
-            if(heater->timenum>=60*10)//system led turn red while the temperature could not heat up to PresetTemp over 10min
-            {
-                if((heater->pid.realtemp<heater->PresetTempVal))
-                {
-                    /*TODO 加热模块故障*/
-                    com_pwm_Set(heater->pwdId,0);                    
-                    error_set(ERROR_HEAT_TIMEOUT);
-                    heater->HeatState = SysERRORHeat;
-                    return;
-                }
-            }
-        }
-        break;
-        case SysPreKepTemp:{            
-            PIDRealize(&heater->pid);
-            com_pwm_Set(heater->pwdId,heater->pid.variate);
-            if(heater->timenum>=heater->PresetTempTime)//time of duration while initial segment constant temperature stage,timenum*1S
-            {
-                heater->timenum=0;
-                heater->HeatState=SysPreCoolDown;
-                com_pwm_Set(heater->pwdId,0);
-            }
-        }
-        break;
-        case SysPreCoolDown: {
-            if(heater->pid.realtemp<=(heater->SetTempVal-1))
-            {
-                heater->HeatState=SysPreConTemp;
-                heater->overtempnum = 0;
-                heater->timenum=0;
-                heater->targetAfterAdj = heater->adJTarget + heater->SetTempVal;
-                heater->pid.integral = 0;
-                heater->pid.goal = heater->targetAfterAdj ;
-
-            }
-            heater->stabletime = 0;
-        }
-        break;
-        
-        case SysPreConTemp:{        
-            PIDRealize(&heater->pid);
-            com_pwm_Set(heater->pwdId,heater->pid.variate);
-            if(heater->timenum>=20)
-            {
-                /*system report error while the difference of the temperature over 5℃  3times*/
-                if(fabs(heater->pid.realtemp-heater->SetTempVal)>5)
-                {
-                    heater->overtempnum++;
-                    if(heater->overtempnum>=3)
-                    {
-                        com_pwm_Set(heater->pwdId,0);
-                        error_set(ERROR_HEAT_TIMEOUT);
-                        heater->HeatState = SysERRORHeat;
-                        return;
-                    }
-                    else
-                    {
-                        heater->overtempnum = 0;
-                    }
-                }
-                else if(fabs(heater->pid.realtemp- (heater->targetAfterAdj))<=0.5)
-                {
-                    if(heater->stabletime++ >10)
-                    {
-                        heater->temp_stable_sta = 2;    //二次加热稳定
-                    }
-                }
-                else{
-                    heater->stabletime = 0;
-                }
-            }
-        }
-        break;
-        default:
-            break;
-    }    
-}

+ 0 - 47
DriverInterface/user_heater.h

@@ -1,47 +0,0 @@
-#ifndef  __USER_TEATER_H
-#define  __USER_TEATER_H
-
-#include "van_com_algorithm.h"
-
-#define SystemPreHeat     1
-#define SystemIdle        2
-#define SysPreHeatUP      3
-#define SysPreKepTemp     4
-#define SysPreCoolDown    5
-#define SysPreConTemp     6
-#define SysNorHeatUP      7
-#define SysNorHeatHold     8
-#define SysERRORHeat     10
-
-
-typedef struct
-{
-	unsigned char   heat_state;            		//串口控制加热状态
-	unsigned char   temp_stable_sta;            	//加热稳定状态
-	unsigned char   fan_state;   					//风扇状态
-	unsigned char   card_state;   				//插卡状态
-    unsigned int  stabletime;
-	float     SetTempVal;
-	unsigned int  PresetTempTime;
-	float     PresetTempVal;
-    float readyTemp;	  //就绪温度
-	float    HoldTemp;       //稳定温度
-	float	offset;		//温度补偿
-	unsigned int   PreHeatTime;					//上电预热时间,min
-	float     adJTarget;					//根据环境温度,修正目标温度
-    unsigned int timenum;
-    unsigned int HeatState;	  
-    unsigned int overtempnum;
-    float     targetAfterAdj;	       
-    pid_def  pid;	
-    unsigned int pwdId; 
-    unsigned int needpreheat;  
-}heat_ctrl_def;
-
-
-uint32_t get_heater_master_st(float *temp,unsigned int *st);
-uint32_t get_heater_slave_st(float *temp,unsigned int *st);
-uint32_t check_heater_master_needPreheat(void);
-void updatParm_heater_master(void);
-void heater_work(heat_ctrl_def *heater);
-#endif

+ 0 - 21
DriverInterface/usr_b2b_msg.h

@@ -1,21 +0,0 @@
-#ifndef _USR_B2B_MSG_
-#define _USR_B2B_MSG_
-
-
-#include "usr_protocol_type.h"
-
-
-#define combine_cmdMessage(msg,header,seqer,cmder,tailer)  {\
-	msg.head = header; \
-	msg.seq = seqer; \
-	msg.cmd = cmder; \
-	msg.tail = tailer; \
-}
-
-int DecodeNew(struct CmdMessage* pMessage, uint8_t *pdata, const uint8_t *pInBuffer, uint32_t *pheader,uint32_t  ulast,uint32_t maxlen);
-uint32_t PackDeviceNum(void);
-void send_Devinf_pc(void);
-
-
-
-#endif

+ 0 - 883
DriverInterface/usr_b2pc_msg.c

@@ -1,883 +0,0 @@
-/*
- *  usr_b2pc_msg.c
- *  pc同主机通信
- *  Created on: 2023年9月18日
- *      Author: longtengjun
- */
-
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
-#include "onechip_include_header.h"
-
-
-char DeviceNum[64] = "mini7 2312230001 v1.1, ";
-extern uint16_t WriteComm0(uint8_t *data, uint16_t len);
-
-uint8_t pc_channel_recv = 0;      //接收pc的通道,0:未连接; 1:wifi; 2:串口
-uint8_t pc_channel_send = 0;      //发给pc的通道,0:未连接; 1:wifi; 2:串口
-static uint8_t pc_channel_send_backup = 0;      //发给pc的通道备份
-
-// extern float slave_temp;
-// extern uint8_t other_run_state;
-// str_error_info_t error_info = {0};    //错误信息
-
-uint8_t pc_send_wait = 0;     //数据发送等待,0可以立即发送;>0正在发送请等待
-uint8_t pc_send_cmd = 0;     //当前发送cmd
-
-// extern str_mcu_ack mcu_ack_ctrl;
-// extern uint32_t timeout_com;
-// extern uint32_t pc_link_timeout;
-// extern struct light_band_para_t light_band_para[2];
-// extern ProcessStateMachine_t psm;
-
-// extern CFG_PARAM_STRUCT g_cfg;
-// #ifdef ONECHIP_MINI_PLUS
-// extern CFG_PARAM_STRUCT g_cfg_slave;
-// #endif
-// extern float evnTemp;
-// extern  uint32_t connectTcpFlag;
-// extern uint32_t broadDevFlag;
-// extern uint16_t scan_qrcode_ropprt;
-// extern uint8_t wifi_tx_buf[WIFI_TX_BUF_SIZE];
-// extern uint16_t wifi_tx_len;
-static unsigned char seq  =0;
-
-//字节流转整数,大端模式
-uint32_t byte_to_u32(uint8_t *p, int len)
-{
-	uint32_t temp = 0;
-
-	for(int i = len-1; i >= 0; i--)
-	{
-		temp <<= 8;
-		temp |= p[i];
-	}
-
-	return temp;
-}
-uint32_t PackDeviceNum(void){		
-	int len = 0;
-	memset((uint8_t *)&DeviceNum, 0 ,sizeof(DeviceNum));
-#ifdef ONECHIP_MINI_ONE
-	my_sprintf(&DeviceNum[len],sizeof(DeviceNum), "Mini7-one,V%d.%d.%d.%d",VERSION_1,VERSION_2,VERSION_3,VERSION_4);	
-#else 
-#ifdef ONECHIP_MINI_PLUS
-	my_sprintf(&DeviceNum[len],sizeof(DeviceNum), "Mini7-plus,V%d.%d.%d.%d",VERSION_1,VERSION_2,VERSION_3,VERSION_4);	
-#else
-	my_sprintf(&DeviceNum[len],sizeof(DeviceNum), "Mini7,V%d.%d.%d.%d",VERSION_1,VERSION_2,VERSION_3,VERSION_4);		
-#endif //ONECHIP_MINI_PLUS
-#endif //ONECHIP_MINI_ONE
-	strcat(DeviceNum, ",");
-	len = strlen(DeviceNum);
-	hex_to_ascii(get_uid(), &DeviceNum[len], 12);	//uid
-	strcat(DeviceNum, ",");
-	strcat(DeviceNum, g_cfg.SN);
-	strcat(DeviceNum, " ");
-	LOG("DeviceNum:%s\n", DeviceNum);
-}
-
-
-/********************************************************************
- *    uint16_t b2b_send_to_pc(enum pc_cmd_type cmd, char *data, uint16_t len)
- *
- *描述:串口发送
- *参数:Devicenum 0-发至主机,1发至从机
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-uint16_t b2b_send_to_pc(enum pc_cmd_type cmd, char *data, uint16_t len)
-{
-    uint16_t check;
-    CmdMessage msg;
-
-    msg.head = 0x55aa;
-    msg.seq = cmd_frame_type_req;
-    msg.cmd = cmd;
-    msg.tail = 0x5a;
-    msg.len = len;
-
-    check = checkSum(&msg.seq, 4);
-    check += checkSum(data, len);
-    msg.checksum = check & 0xFF;
-    msg.tail = check >> 8;
-
-    WriteComm0((uint8_t*)&msg, g_uMsgCmdFrameLen);
-
-    msg.data = data;
-
-    WriteComm0(data, len);
-
-    return WriteComm0(&msg.checksum, 2);
-
-}
-
-/********************************************************************
- *    uint16_t data_send_to_pc(enum pc_cmd_type cmd, char *data, uint16_t len)
- *
- *描述:发生数据到PC
- *参数:Devicenum 0-发至主机,1发至从机
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-uint16_t union_data_send_to_pc(struct CmdMessage *pMsg)
-{
-    uint16_t check;
-    uint16_t try = 0;
-    struct CmdMessage msg;
-    int ret = 0;
-
-    msg.head = 0x55aa;
-    msg.seq = pMsg->seq;
-    msg.cmd = pMsg->cmd;
-    msg.tail = 0x5a;
-    msg.len = pMsg->len;
-
-    msg.data = pMsg->data;
-   
-     check = checkSum(&msg.seq, 4);
-     *(unsigned int*)msg.data = Devicenum;/*打包模块编号*/
-     check += checkSum(msg.data, msg.len);
-     msg.checksum = check & 0xFF;
-     msg.tail = (check >> 8);
-     if(Devicenum)
-     {
-         /*从模块 通过IIC上报,稍后跟新*/
-     }
-     else
-     {
-         WriteComm0((uint8_t*)&msg, g_uMsgCmdFrameLen);		 
-         WriteComm0(msg.data, msg.len);
-         return WriteComm0(&msg.checksum, 2);
-     }   
-}
-
-
-/********************************************************************
- *    uint16_t data_send_to_pc(enum pc_cmd_type cmd, char *data, uint16_t len)
- *
- *描述:发生数据到PC
- *参数:Devicenum 0-发至主机,1发至从机
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-uint16_t data_send_to_pc(enum pc_cmd_type cmd, char *data, uint16_t len)
-{
-    uint16_t check;
-    struct CmdMessage msg;	
-    int ret = 0;
-
-    msg.head = 0x55aa;
-    msg.seq = cmd_frame_type_req;
-    msg.cmd = cmd;
-    msg.tail = 0x5a;
-    msg.len = len;
-    msg.data = data;
-	if((len+8) > WIFI_TX_BUF_SIZE){
-		 LOG_E("send_to_pc :%x  len:%d error ", cmd, len);
-		 return  -1;
-
-	}
-	if(pc_channel_send == 1 && !connectTcpFlag && cmd != PC_CMD_SETIP){
-				/*UDP 模式,不响应设置IP以为指令*/
-				return -1;
-	}			
-	if((pc_channel_send == 1 && PC_CMD_DATASCOPE == cmd)|| /*网口不上报数据*/
-		(pc_channel_send != 1 && PC_CMD_SETIP == cmd))     /*串口不广播UDP*/{
-		return  -1;
-	}	
-    switch(cmd)
-    {
-        case PC_CMD_QRCODE:
-        case PC_CMD_DATA_UPLOAD:
-        case PC_CMD_REPORT_RESULT:
-			seq++;
-			if(0xff == seq){
-				seq =1;
-			}
-            msg.seq = seq;
-            break;
-        default:    //应答
-            break;
-    }
-	check = checkSum(&msg.seq, 4);
-	check += checkSum(data, len);
-	msg.checksum = check & 0xFF;
-	msg.tail = (check >> 8);	
-	if(check_to_pc_busy()){		
-		memcpy(&wifi_tx_buf[0], (uint8_t*)&msg, g_uMsgCmdFrameLen);
-		memcpy(&wifi_tx_buf[g_uMsgCmdFrameLen], data, len);
-		memcpy(&wifi_tx_buf[g_uMsgCmdFrameLen+len],  (uint8_t*)&check, 2);
-		wifi_tx_len = g_uMsgCmdFrameLen+len+2;	
-	}else{
-		return -1;
-	}	
-	if((pc_channel_send == 1 || cmd == PC_CMD_SETIP ) && PC_CMD_SETWIFI != cmd)
-	{			
-		return WIFI_ReSend();
-	}
-	else
-	{	
-		WriteComm0(wifi_tx_buf, wifi_tx_len);			
-		memset(wifi_tx_buf, 0, sizeof(wifi_tx_buf));
-	}
-}
-
-unsigned int check_to_pc_busy(void){
-	/*判断是否可以发送,缓冲区为空或者索引为0*/
-	struct CmdMessage *pMessage = (struct CmdMessage *)wifi_tx_buf;
-	if(pMessage->seq == 0 || pMessage->len == 0){
-		return 1;
-	}
-	return 0;
-	
-}
-
-///********************************************************************
-// *    void data_resend_to_pc(void)
-// *
-// *描述:判断缓冲区内容,是否需要重发
-// *参数:无
-// *返回:无
-// *其他:无
-// *--------------------------------------------------------------------
-// *记录:
-// ********************************************************************/
-void pc_resend_del(uint8_t seq){
-	struct CmdMessage *pMessage = (struct CmdMessage *)wifi_tx_buf;
-	if(pMessage->seq == seq){
-		wifi_tx_len = 0;
-		memset(wifi_tx_buf, 0, sizeof(wifi_tx_buf));
-	}
-}
-
-/********************************************************************
- *    uint16_t send_Devinf_pc(void)
- *
- *描述:发送设备信息到主机,便于主机下法TCP信息
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-void send_Devinf_pc(void)
-{
-
-    uint16_t len = 0;
-	len =  strlen(DeviceNum);
-	data_send_to_pc(PC_CMD_SETIP,DeviceNum,len);
-
-}
-
-#ifdef ONECHIP_MINI_ONE
-int send_temp_parm(uint8_t cmd, uint8_t *parg)
-{
-	b2b_send_device(B2B_CMD_THEROM_GOAL_ONCE, parg,  16, !Devicenum);
-	return 1;
-		
-	
-}
-int setTemp_response(struct CmdMessage *pMsg, uint8_t result)
-{
-//    char result = 1;
-    data_send_to_pc(PC_CMD_SETRUNTEMP, &result, 1);
-}
-#endif
-
-
-
-
-void set_pc_chanel_recv(uint8_t channel)
-{
-    pc_channel_recv = channel;
-}
-
-void set_pc_chanel_temp()
-{
-    if(pc_channel_recv == 2)
-        timeout_com = 0;
-    
-    pc_channel_send_backup = pc_channel_send;
-    pc_channel_send = pc_channel_recv;
-}
-
-void reload_pc_chanel()
-{
-    if(pc_channel_recv > pc_channel_send_backup)   //串口优先
-    {
-        pc_channel_send_backup = pc_channel_recv;
-    }
-
-    pc_channel_send = pc_channel_send_backup;
-}
-
-void set_pc_chanel(uint8_t channel)
-{
-    pc_channel_send_backup = channel;
-    pc_channel_send = channel;
-}
-
-
-/********************************************************************
- * int handshake_action(uint8_t cmd, uint8_t *parg)
- *
- *描述:握手命令处理
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-int handshake_action(uint8_t cmd, uint8_t *parg)
-{
-    if(state_controlword < Hand_Shake_cmd)      //上位机会间隔发送握手,保活
-    {
-        state_controlword = Hand_Shake_cmd;
-    }
-
-    return 0;
-}
-
-void char_replace(uint8_t *str, int size, uint8_t ch, uint8_t replace)
-{
-    for(int i = 0; i < size; i++)
-    {
-        if(str[i] == ch)
-            str[i] = replace;
-    }
-}
-
-
-/********************************************************************
- * int wifi_action(uint8_t cmd, uint8_t *parg)
- *
- *描述:设置wifi命令处理
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-int wifi_action(uint8_t cmd, uint8_t *parg)
-{
-//    char_replace(parg, 64, 0xAA, 0);
-//    char_replace(parg, 64, 0xAD, ' ');
-    wifiCfg_set_new_wifi_param(parg, parg + WIFI_AP_NAME_MAX_LEN);
-
-    // wifi用户名和密码设置
-    WIFI_set_ssid();
-
-    return 1;
-}
-int setState_action(uint8_t cmd, uint8_t *parg)
-{
-	uint8_t block = *parg++;
-	uint8_t nextState = *parg;
-	if(block==0){
-		if(SYS_STATE_WORKEND == nextState){
-			psm.state = SW_move_card;
-		}
-	}else{
-		/*下发命令,改变从模块状态*/
-		b2b_send_device(B2B_CMD_STATE_SET, &nextState, sizeof(nextState), 1);
-	}
-	
-
-
-    return 1;
-}
-
-
-
-/********************************************************************
- * int wifi_action(uint8_t cmd, uint8_t *parg)
- *
- *描述:设置wifi命令处理
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-int SN_action(uint8_t cmd, uint8_t *parg)
-{
-    
-	parg[15] = 0;
-	strcpy(g_cfg.SN, parg);	
-	PackDeviceNum();
-	return cfg_save_cfg_param();
-}
-
-
-/********************************************************************
- * int seq_selftest_action(uint8_t cmd, uint8_t *parg)
- *
- *描述:设备自检处理
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-int seq_selftest_action(uint8_t cmd, uint8_t *parg)
-{
-    return 0;
-}
-
-/********************************************************************
- * int confirm_result_action(uint8_t cmd, uint8_t *parg)
- *
- *描述:设备收到pc的结果响应
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-int confirm_result_action(uint8_t cmd, uint8_t *parg)
-{
-    if(Devicenum)
-    {
-        return 0;
-    }
-
-    if(0 == memcmp(parg,card_param_info.pid, 10 ))
-        state_controlword = result_move_card;
-
-    return 0;
-}
-
-/********************************************************************
- * int default_pc_response(struct CmdMessage *pMsg, uint8_t result)
- *
- *描述:默认回应PC
- *参数:无
- *返回:成功->0 失败->-1
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-int default_pc_response(struct CmdMessage *pMsg, uint8_t result)
-{
-    if(Devicenum)
-    {
-        return 0;
-    }
-
-	return data_send_to_pc(pMsg->cmd, &result, 1);
-}
-
-/********************************************************************
- * int handshake_response(struct CmdMessage *pMsg, uint8_t result)
- *
- *描述:握手回应
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-int handshake_response(struct CmdMessage *pMsg, uint8_t result)
-{
-	int len = 0;
-//	PackDeviceNum();
-	len = strlen(DeviceNum);
-	return data_send_to_pc(pMsg->cmd, (uint8_t*)DeviceNum, len);
-}
-
-	
-int AskState_response(struct CmdMessage *pMsg, uint8_t result)
-{
-	ANS_State();
-}
-
-int set_response(struct CmdMessage *pMsg, uint8_t result)
-{
-//    char wifi_result = 1;
-//    data_send_to_pc(PC_CMD_SETWIFI, &wifi_result, 1);
-}
-
-int setState_response(struct CmdMessage *pMsg, uint8_t result)
-{
-//    char result = 1;
-    data_send_to_pc(PC_CMD_SETSTATE, &result, 1);
-}
-
-
-int ans_response(struct CmdMessage *pMsg, uint8_t result)
-{	
-	/*清空需要上位机应答的消息*/
-	switch(pMsg->cmd){
-		case PC_CMD_REPORT_REEOR:
-//			unsigned char *data = pMsg->data;
-//			if(*data == Devicenum){
-//			}
-			
-			clean_error_update();
-
-			break;
-		case PC_CMD_UPDATESTATE:
-    		clean_state_update();
-			break;
-		case PC_CMD_QRCODE:
-    		clean_QR_update();
-			break;
-		case PC_CMD_DATA_UPLOAD:{
-			unsigned char *data = pMsg->data;			
-			unsigned int recdex = 0xfffffff;
-//			unsigned char result = *data;
-//			unsigned char part = *(data+1);
-			if( pMsg->len == 6){
-				recdex = *(data+5);
-			    recdex = recdex<<8;
-				recdex += *(data+4);
-			    recdex = recdex<<8;
-				recdex += *(data+3);
-			    recdex = recdex<<8;
-				recdex += *(data+2);
-			}else{
-				if(seq == pMsg->seq){
-					recdex = 0;
-				}
-			}
-			updateData_next(recdex,data);
-	    	
-		}
-			break;	
-		case PC_CMD_REPORT_RESULT:{
-			
-			unsigned char *data = pMsg->data;	
-//			unsigned char result = *data;
-//			unsigned char part = *(data+1);	
-			clean_reult_next(data);
-//			if(result){		
-//				/*消息成功,进行跟新*/		
-//				clean_reult_next(part);
-//			}
-		}
-			break;		
-	}
-}
-
-int confirm_qrcode_action(uint8_t cmd, uint8_t *parg)
-{
-    //PC返回成功,才认为扫码成功
-	scan_qrcode_ropprt = 1;
-    if(*parg == 1)
-    {
-        if(0 == mem_value(&card_param_info_temp, 0 , sizeof(str_card_param_info_t)))
-        {
-//			scan_qrcode_ropprt = 1;
-			LOG_D("rec no card \n\r:");
-            return -1;
-        }
-        if((psm.state == SW_Scan_Qrcode || psm.state == SW_Chip_Id  ))   //主机空闲,给自己
-        {
-            scan_qrcode_done = 1;
-            memcpy(&card_param_info, &card_param_info_temp, sizeof(str_card_param_info_t));
-        }
-        else
-        {
-            //比较是否跟主模块相同
-            if(0 == memcmp(&card_param_info, &card_param_info_temp, sizeof(str_card_param_info_t)))
-            {
-                return 0;
-            }
-            //主机不空,下发给从机
-            card_param_info_temp.envtemp = evnTemp;
-            b2b_send_device(B2B_CMD_REQ_QRCODE, (char *)&card_param_info_temp, sizeof(str_card_param_info_t), 1);
-        }
-		LOG_D("rec start\n\r:");
-    	return 0;
-		
-    }	
-	LOG_D("rec no macth\n\r:");
-    return -1;
-}
-
-
-int confirm_error_action(uint8_t cmd, uint8_t *parg)
-{
-    return 0;
-}
-
-
-int confirm_data_action(uint8_t cmd, uint8_t *parg)
-{
-    return 0;
-}
-
-const struct PCActionPack mPCActionPack[] =
-    {
-        {
-            .cmd = PC_CMD_HANDSHAKE,
-            .action = handshake_action,
-            .response = handshake_response,
-            .datalen = 0,
-        },
-        {
-            .cmd = PC_CMD_SETWIFI,
-            .action = wifi_action,
-            .response = set_response,
-            .datalen = 0xff,
-        },
-        {
-            .cmd = PC_CMD_SETSN,
-            .action = SN_action,
-            .response = handshake_response,
-            .datalen = 7,
-        },
-        {
-            .cmd = PC_CMD_QRCODE,
-            .action = confirm_qrcode_action,
-            .response = ans_response,
-            .datalen = 0xff,
-        },
-        {
-            .cmd = PC_CMD_SNANDCARD,
-            .action = confirm_error_action,
-            .datalen = 1,
-        },
-        {
-            .cmd = PC_CMD_REPORT_RESULT,
-            .action = confirm_result_action,
-            .response = ans_response,
-            .datalen = 0xff,
-        },
-        {
-            .cmd = PC_CMD_REPORT_REEOR,
-            .action = confirm_error_action,
-            .response = ans_response,
-            .datalen = 0xff,
-        },
-        {
-            .cmd = PC_CMD_DATA_UPLOAD,
-            .action = confirm_data_action,
-            .response = ans_response,
-            .datalen = 0xff,
-        },
-        {
-            .cmd = PC_CMD_SETIP,
-            .action = set_IP_action,
-            .response = NULL,
-            .datalen = 0xff,
-        },
-        {
-            .cmd = PC_CMD_UPDATESTATE,
-            .action = confirm_data_action,
-            .response = ans_response,
-            .datalen = 0xff,
-        },
-        {
-            .cmd = PC_CMD_ASKSTATE,
-            .action = confirm_data_action,
-            .response = AskState_response,
-            .datalen = 0xff,
-        },
-        {
-            .cmd = PC_CMD_SETSTATE,
-            .action = setState_action,
-            .response = setState_response,
-            .datalen = 0xff,
-        },
-#ifdef ONECHIP_MINI_ONE
-        {
-            .cmd = PC_CMD_SETRUNTEMP,
-            .action = send_temp_parm,
-            .response = setTemp_response,
-            .datalen = 0xff,
-        },
-#endif
-};
-			
-
-
-/********************************************************************
- * int handshake_action(uint8_t cmd, uint8_t *parg)
- *
- *描述:握手命令处理
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-int con_heat_action(uint8_t cmd, uint8_t *parg )
-{
-//    CmdMessage *pMsg = (CmdMessageDef *)parg;
-    struct CmdMessage *pMsg = (struct CmdMessage *)parg;;
-    miniConfigPram *pram = (miniConfigPram *)pMsg->data;
-	if(pram->partID == Devicenum){
-		if( pMsg->cmd == UINON_CMD_MOTORMOVE ){
-			/*直接透传给从muc处理*/
-			g_cfg.timeinner =  *(float *)(pMsg->data+4) * 100;
-			g_cfg.swingspeed =  *(float *)(pMsg->data+8);
-			g_cfg.swingtime =  *(float *)(pMsg->data+12) * 100;
-			g_cfg.swingtimeRight =  *(float *)(pMsg->data+16) * 100;
-			g_cfg.swingtimePause =  *(float *)(pMsg->data+20) * 100;	
-			if((1 == *(int *)(pMsg->data+pMsg->len - 4))){
-				cfg_save_cfg_param();	
-				Motor_Init();
-			}else{				
-				Motor_mix(g_cfg.timeinner,g_cfg.swingspeed,g_cfg.swingtime,g_cfg.swingtimeRight,g_cfg.swingtimePause);
-			}		
-		    data_send_to_pc(pMsg->cmd, pMsg->data,  pMsg->len);
-		}
-		if( pMsg->cmd == UINON_CMD_MOTORTRETURN ){
-			/*直接透传给从muc处理*/
-			uint32_t time = *(float *)(pMsg->data+4) * 10;
-			uint32_t speed =  *(float *)(pMsg->data+8) ;
-		    data_send_to_pc(pMsg->cmd, pMsg->data,  pMsg->len);
-//			sw_st = FIND_GAPNUM;
-//			stateFistin = 1;
-		}
-#ifdef ONECHIP_MINI_ONE
-		if( pMsg->cmd == UINON_CMD_TEMP_ADJ || 
-			pMsg->cmd == UINON_CMD_TEMP_PID ||
-			pMsg->cmd == UINON_CMD_TEMP_ADJ_GET	|| 
-			pMsg->cmd == UINON_CMD_TEMP_PID_GET	|| 
-			pMsg->cmd == UINON_CMD_TEMP_START	|| 
-			pMsg->cmd == UINON_CMD_TEMP_STOP){
-			/*直接透传给从muc处理*/
-			sendMsgtoSlaveMcu(pMsg);
-		}
-#endif
-	}else{
-#ifdef ONECHIP_MINI_ONE
-		switch(pMsg->cmd){
-			case UINON_CMD_THEROM_GOAL:{
-				b2b_send_device(B2B_CMD_THEROM_GOAL, pMsg->data,  pMsg->len, !Devicenum);
-			}break;
-			
-			case UINON_CMD_THEROM_OFFSET:{
-				b2b_send_device(B2B_CMD_THEROM_OFFSET, pMsg->data,  pMsg->len, !Devicenum);
-			}break;
-			
-			case UINON_CMD_THEROM_GET:{
-				b2b_send_device(B2B_CMD_GETTHEROMPRAM_ACK, pMsg->data,  pMsg->len, !Devicenum);
-			}break;
-		}		
-		/*发送给从模块 稍后实现*/
-#endif
-	}
-    return 0;
-}
-const struct PCActionPack mUnionActionPack[] =
-    {
-        {
-            .cmd = UINON_CMD_MOTORMOVE,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_MOTORTRETURN,
-            .action = con_heat_action,
-        },
-#ifdef ONECHIP_MINI_ONE
-        {
-            .cmd = UINON_CMD_TEMP_ADJ,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_TEMP_PID,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_TEMP_ADJ_GET,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_TEMP_PID_GET,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_TEMP_START,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_TEMP_STOP,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_THEROM_GOAL,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_THEROM_OFFSET,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_THEROM_GET,
-            .action = con_heat_action,
-        },
-        {
-            .cmd = UINON_CMD_TEMP_DEBUG,
-            .response = handshake_response,
-        },
-				
-#endif
-
-};
-
- 
-
-void deal_mUnion_cmd(struct CmdMessage *pMsg)
-{
-	for (uint8_t i = 0; i < sizeof(mUnionActionPack)/sizeof(mUnionActionPack[0]); i++)
-	{
-		if (mUnionActionPack[i].cmd == pMsg->cmd ) 
-		{			
-			uint8_t ret = mUnionActionPack[i].action( pMsg->cmd,(uint8_t *)pMsg);
-			if (mUnionActionPack[i].response)
-			{
-				mUnionActionPack[i].response(pMsg, ret);
-			}
-			break;
-		}
-	}
-}
-
-
-/********************************************************************
- * void query_pc_cmd(struct CmdMessage *pMsg)
- *
- *描述:处理PC命令
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-void query_pc_cmd(struct CmdMessage *pMsg)
-{
-    for (uint8_t i = 0; i < sizeof(mPCActionPack)/sizeof(mPCActionPack[0]); i++)
-    {
-        if (mPCActionPack[i].cmd == pMsg->cmd && (mPCActionPack[i].datalen == pMsg->len || mPCActionPack[i].datalen == 0xff)) //防止接收到其他设备的数据帧
-        {
-            if(pc_send_cmd == mPCActionPack[i].cmd)
-                pc_send_wait = 0;
-            if(mPCActionPack[i].cmd != 1)
-            {
-            	pc_resend_del(pMsg->seq);
-                LOG_I("\n<-- pc cmd %x %d \n", pMsg->cmd, pMsg->seq);
-            }
-			pMsg->data[pMsg->len] = 0;
-            uint8_t ret = mPCActionPack[i].action(mPCActionPack[i].cmd, pMsg->data);
-            if (mPCActionPack[i].response)
-            {
-                mPCActionPack[i].response(pMsg, ret);
-            }
-			if(!(pc_channel_recv == 1 && !connectTcpFlag)){				
-    			pc_link_timeout = 0;    //确保TCP通信上在变灯
-			}
-            break;
-        }
-    }
-}
-

+ 0 - 370
DriverInterface/usr_lysis.c

@@ -1,370 +0,0 @@
-
-
-/*
- * usr_gpio.c
- *
- *	Created on: 2022年4月11日
- *		Author: amos
- */ 
-
-#include "onechip_include_header.h"
-
-
-
-extern uint32_t conter100ms;
-extern uint32_t conter10ms;
-
-
-
-
-
-#define MIN_TEMPERATUARE 5
-#define MAX_TEMPERATUARE 120 
-#define COOL_WORK_THD 5 
-#define HEAT_WORK_THD 2.5
-#define COOL_TEST_TIME 30 
-#define HEAT_TEST_TIME 6000
-#define COOL_TEST_PWR -50
-#define HEAT_TEST_PWR 50 
-#define THERM_ADC_CHN 5 
-#define OVER_HEAT_EDGE 0.5 
-#define HEAT_STABLE_TIME 300
-#define MAX_REMOVE_GAP  100 
-#define EER_NOEXIST_TIME_GAP  500 
-#define HEAT_ARRIVE_EDGE 0.5 
-#define GOTO_IDLE_GAP  3000 
-
-
-
-int32_t tupeExist = 0;
-
-
-
-extern void light_band_set(uint8_t mode_select, uint16_t speed_ms, uint32_t rgb_color);
-
-volatile uint32_t g_u32AdcIntFlag;   //adc simple finish flag
-
-
-uint32_t Read_Tupe(void) {
-  return (HAL_GPIO_ReadPin(MINI7_V2_TUBE_SW_GPIO_Port,MINI7_V2_TUBE_SW_Pin)) ? 0 : 1; // 检查PF5引脚值
-}
-
-
-
-
-void updatParm_lysis(void) {
-	sysinf.lysis.offset = sysinf.lysis_offset;
-	sysinf.lysis.overHeat = sysinf.lysis_overHeat;
-	sysinf.lysis.overHeatTime =  sysinf.lysis_overHeatTime;
-	sysinf.lysis.pid.Kp = sysinf.lysis_Kp;
-	sysinf.lysis.pid.Ki = sysinf.lysis_Ki ;
-	sysinf.lysis.pid.Kd = sysinf.lysis_Kd;
-}
-
-
-
-/**
- * @brief	   Motor_Init
- *
- * @param		init key and optic input
- *
- * @return		0正常,1不能加热,2,不能制冷,3 传感器异常
- *
- * @details    上电,通过设置加热制冷,判断温度变化。
- */
-uint32_t Therm_Check(void) {
-  float firstTemp,heattemp;
-  firstTemp = getADC_Chanel_value(1);
-  if(firstTemp < MIN_TEMPERATUARE || firstTemp > MAX_TEMPERATUARE){
-  		com_pwm_Set(sysinf.lysis.pwdId,100);
-		return  THERMOSTAT_SENSER_EER;		
-  }  
-  com_pwm_Set(sysinf.lysis.pwdId,HEAT_TEST_PWR);
-  HAL_Delay(HEAT_TEST_TIME);
-  heattemp = getADC_Chanel_value(1);
-  com_pwm_Set(sysinf.lysis.pwdId,0);
-  if((heattemp - firstTemp) < HEAT_WORK_THD){
-		return  THERMOSTAT_HEAT_EER;	
-  }
-  return THERMOSTAT_NOR;
-}
-/**
- * @brief	   set_lysis
- *
- * @param		goal 目标温度
- *
- * @return		无
- *
- * @details   设置目标温度。
- */
-void set_lysis(float goal) {
-   sysinf.lysis.pid.goal = goal;
-   if(goal > (sysinf.lysis.overHeat + sysinf.lysis.pid.realtemp )){
-		sysinf.lysis.pid_st = PID_OVERHEAT;
-		sysinf.lysis.pid.goal += sysinf.lysis.overHeat;
-   }else{
-		sysinf.lysis.pid_st = PID_ADJ;
-   }
-   sysinf.lysis.pid.integral = 0;
-   sysinf.lysis.pid_stable = 0;
-}
-void Close_therm(float goal) {  
-   sysinf.lysis.pid_st = PID_IDLE;
-   sysinf.lysis.pid.integral = 0;
-   sysinf.lysis.pid_stable = 0;
-  com_pwm_Set(sysinf.lysis.pwdId,0);
-}
-
-/**
- * @brief	   Therm_work
- *
- * @param		adjflag 调节标记
- *
- * 
- *
- * @details    温控器调节。
- */
-uint32_t Pid_work(void) {
-  static uint32_t chrConter = 0;
-  lysis_ctr_def *ptherm = &sysinf.lysis;
-  float temp = getADC_Chanel_value(1);  
-  
-  ptherm->pid.realtemp = temp + ptherm->offset;
-  switch(ptherm->pid_st){
-	case PID_OVERHEAT:{
-		PIDRealize(&ptherm->pid);
-		
-        com_pwm_Set(ptherm->pwdId,ptherm->pid.variate);
-		if (ptherm->pid.realtemp  > (ptherm->pid.goal - OVER_HEAT_EDGE)){
-			ptherm->pid_st = PID_OVERHEATLAST;
-			chrConter = 0;		   
-		}
-	}break;
-	case PID_OVERHEATLAST:{
-  		chrConter ++;
-		if (chrConter  > ptherm->overHeatTime){
-			ptherm->pid_st = PID_ADJ;
-			/*PID功率值维持不变*/
-			ptherm->pid.integral = (ptherm->overHeat*ptherm->pid.Kp)/ptherm->pid.Ki;	
-			ptherm->pid.integral += (ptherm->pid.variate)/ptherm->pid.Ki;	
-			ptherm->pid.goal -= ptherm->overHeat;
-			chrConter = 0;
-		}
-	}break;
-	case PID_ADJ:{
-		PIDRealize(&ptherm->pid);
-		if ((ptherm->pid.realtemp  > (ptherm->pid.goal - OVER_HEAT_EDGE)) && (ptherm->pid.realtemp  < (ptherm->pid.goal + OVER_HEAT_EDGE))){
-			if(chrConter < HEAT_STABLE_TIME){
-				chrConter ++;
-			}
-			else{
-				/*上报加热稳定*/
-				ptherm->pid_stable = 1;
-			}
-		}else{
-			if(chrConter){chrConter--;}
-			else{ptherm->pid_stable = 0;}
-		}
-	}break;
-	default:
-		ptherm->pid_st = PID_IDLE;
-		ptherm->pid.variate = 0;
-		break;
-  }  
-  com_pwm_Set(sysinf.lysis.pwdId,ptherm->pid.variate);
-//   com_pwm_Set(sysinf.lysis.pwdId,80);
-  return 0;
-}
-
-uint32_t get_lysis_st(float *temp,unsigned int *st) {
-
-	*temp = sysinf.lysis.pid.realtemp;
-	*st = sysinf.lysis.thermostat_st;
-	return 0;
-}
-uint32_t lysis_work(void) {
-  float temp;
-  static uint32_t last10ms;
-  lysis_ctr_def *ptherm = &sysinf.lysis;
-
-  temp = getADC_Chanel_value(1);
-  ptherm->pid.realtemp = temp + ptherm->offset;
-  switch(ptherm->thermostat_st){
-	case THERMOSTAT_PWRON:{
-		
-  		static float firstTemp;
-		if(ptherm->firstin){
-			ptherm->firstin = false;
-			updateLysisState(SYS_STATE_PREPARE);sysinf.lysisState = SYS_STATE_PREPARE; 
-			firstTemp = getADC_Chanel_value(1);
-			if(firstTemp < MIN_TEMPERATUARE || firstTemp > MAX_TEMPERATUARE){
-			 	error_set(ERROR_TEMPSENSOR_EER);
-				ptherm->thermostat_st = THERMOSTAT_ERROR;
-				ptherm->firstin = true;	
-			 }else{
-				 set_lysis(firstTemp+30);
-				 last10ms = conter10ms;
-			 }  
-			
-		}else{
-			float heattemp = getADC_Chanel_value(1); 
-			if((heattemp - firstTemp) > HEAT_WORK_THD){
-					ptherm->thermostat_st = THERMOSTAT_WARM;
-					ptherm->firstin = true;
-					ptherm->pid_st = PID_IDLE;
-			  }
-
-			if((conter10ms-last10ms)> HEAT_TEST_TIME){
-				/*超时判断*/
-				ptherm->thermostat_st = THERMOSTAT_ERROR;
-				updateLysisState(SYS_STATE_ERROR_HW);
-				error_set(ERROR_HEATFUC_EER);
-				ptherm->firstin = true;
-			}
-		}	
-	}break;
-	case THERMOSTAT_NOTICE:{
-		if(ptherm->firstin){
-			/*上电或者预热状态存在管管,停止加热*/			
-			updateLysisState(SYS_STATE_ERROR_HM);
-			set_lysis( 0);
-			ptherm->firstin = false;
-		}else{			
-		    if(Read_Tupe() == 0){
-			/*管管移除,进入到预热状态*/
-				ptherm->thermostat_st = THERMOSTAT_WARM;
-				error_clear();
-				ptherm->firstin = true;
-			}
-		}	    	
-	}break;
-		
-	case THERMOSTAT_WARM:{
-		if(ptherm->firstin){
-			
-			updateLysisState(SYS_STATE_PREPARE);
-			ptherm->firstin = false;
-			if(ptherm->idletemp < 0.1){
-				/*预热参数配置为0,无需要预热*/
-				ptherm->thermostat_st = THERMOSTAT_IDLE;
-				ptherm->firstin = true;
-			}else{				
-				set_lysis(ptherm->idletemp);
-			}
-		}else{
-			/*预热到位,进入空闲状态*/
-			if(ptherm->pid.realtemp > (ptherm->idletemp - HEAT_ARRIVE_EDGE)){
-				ptherm->thermostat_st = THERMOSTAT_IDLE;
-				ptherm->firstin = true;
-			}
-//		    if(Read_Tupe()){
-//				/*预热插管管,进入提示状态*/
-//				ptherm->thermostat_st = THERMOSTAT_NOTICE;
-//				ptherm->firstin = TRUE;
-//			}
-		}
-	}break;
-	case THERMOSTAT_IDLE:{
-		if(ptherm->firstin){			
-			updateLysisState(SYS_STATE_READY);
-			ptherm->firstin = false;
-			Close_therm(0);
-			ptherm->recGoalFlag = 0;
-			
-		}else{	
-		    if(ptherm->recGoalFlag){
-				set_lysis(ptherm->pid.goal);	
-				ptherm->recGoalFlag = 0;
-			}
-			if(ptherm->pid_stable){
-				ptherm->thermostat_st = THERMOSTAT_INSERT;
-				ptherm->firstin = true;	
-			}
-//		    if(Read_Tupe()){
-//				/*预热插管管,进入提示状态*/
-//				ptherm->thermostat_st = THERMOSTAT_NOTICE;
-//				ptherm->firstin = TRUE;
-//			}
-		}
-	}break;
-	case THERMOSTAT_INSERT:{
-		if(ptherm->firstin){			
-			updateLysisState(SYS_STATE_CHECK);
-			ptherm->firstin = false;
-		}else{	
-		    if(Read_Tupe()){
-				ptherm->thermostat_st = THERMOSTAT_WORK;
-				ptherm->firstin = true;		
-				}
-		}
-	}break;
-	case THERMOSTAT_WORK:{
-		if(ptherm->firstin){	
-			updateLysisState(SYS_STATE_RUNING);
-			ptherm->firstin = false;
-			ptherm->pid_stable_time = 0;
-		}else{
-//		    if(Read_Tupe()){
-//				last10ms = conter10ms;
-//			}else{
-//				if((conter10ms-last10ms)> MAX_REMOVE_GAP){
-//					Close_therm(0);
-//					ptherm->eerst = THERMOSTAT_TUBENOEXIST_EER;
-//					ptherm->thermostat_st = THERMOSTAT_ERROR;
-//					error_set(ERROR_TUPE_MOVE); 
-//					last10ms = conter10ms;	
-//					ptherm->firstin = TRUE;			
-//				}
-//			}
-//			if(ptherm->pid_stable)
-			{
-				ptherm->pid_stable_time ++;
-				if(ptherm->pid_stable_time > ptherm->worktime){
-					ptherm->thermostat_st = THERMOSTAT_END;
-					ptherm->firstin = true;		
-				}
-			}
-		}
-	}break;
-	case THERMOSTAT_END:{
-		if(ptherm->firstin){
-			updateLysisState(SYS_STATE_WORKEND);
-			ptherm->firstin = false;
-			Close_therm(0);
-			last10ms = conter10ms;
-		}else{			
-			if((conter10ms-last10ms)> GOTO_IDLE_GAP){
-//			if(Read_Tupe() == 0){
-			/*管管移除,进入到预热状态*/
-				ptherm->thermostat_st = THERMOSTAT_WARM;
-				ptherm->firstin = true;
-			}
-		}
-	}break;
-	case THERMOSTAT_ERROR:{
-		if(ptherm->firstin){
-			ptherm->firstin = false;
-			Close_therm(0);
-		}else{	
-			if(ptherm->eerst == THERMOSTAT_TUBENOEXIST_EER){
-				if((conter10ms-last10ms)> EER_NOEXIST_TIME_GAP){			
-					ptherm->thermostat_st = THERMOSTAT_IDLE;
-					error_clear();
-					ptherm->firstin = true;		
-				}
-			}	
-		}
-	}break;
-		
-  }
-  Pid_work();
-  return 0;
-}
-
-uint32_t Close_Therm_work(void) {
-  lysis_ctr_def *ptherm = &sysinf.lysis;
-  ptherm->thermostat_st = THERMOSTAT_END;
-  ptherm->firstin = true;
-  return 0;
-}
-

+ 0 - 98
DriverInterface/usr_lysis.h

@@ -1,98 +0,0 @@
-/*
- * usr_gpio.h
- *
- *  Created on: 2022��4��11��
- *      Author: amos
- */
-
-#ifndef USR_LYSIS_H_
-#define USR_LYSIS_H_
-
-#include "van_com_algorithm.h"
-/*************************************/
-
-#define TUPE_OPTIC_PORT PF//光开
-#define TUPE_OPTIC_PIN  BIT5//光开
-#define TUPE_OPTIC_INT_CH  5//光开
-#define TUPE_OPTIC()  (PF5)  //按键
-
-#define HEAT_UP_CH_MASK PWM_CH_4_MASK 
-#define HEAT_UP_CH	4
-#define COOL_DOWN_CH_MASK PWM_CH_5_MASK 
-#define COOL_DOWN_CH	5 
-
-#define MOTOR_CHECK_SPEED	60
-#define MOTOR_MOVEFORM_OPTIC_TIM	10
-#define MOTOR_LOOP_TIM	100
-
-#define MOTOR_SWING_TIM	100
-
-typedef enum {
-	HEAT_UP = 0,
-	COOL_DOWN = 1,
-}HEAT_DIR;
-
-
-typedef enum Heat_state {
-  PID_IDLE,
-  PID_OVERHEAT,
-  PID_OVERHEATLAST,
-  PID_OVERCOOL,
-  PID_OVERCOOLLAST,
-  PID_ADJ,
-  PID_STAB,
-  PID_ERROR,
-} pid_state_def;
-
-typedef enum {
-  THERMOSTAT_NOR,     // 正常
-  THERMOSTAT_COOL_EER,    //制冷坏
-  THERMOSTAT_HEAT_EER, // 加热坏
-  THERMOSTAT_SENSER_EER,     // 传感器坏
-  THERMOSTAT_TUBEEXIST_EER,     //存在试管
-  THERMOSTAT_TUBENOEXIST_EER,     //不存在试管
-} THERMOSTAT_ERR_State;
-
-
-
-typedef enum THERMO_state {
-  THERMOSTAT_PWRON,
-  THERMOSTAT_CHECK,
-  THERMOSTAT_WARM,
-  THERMOSTAT_IDLE,
-  THERMOSTAT_INSERT,
-  THERMOSTAT_NOTICE,
-  THERMOSTAT_WORK,
-  THERMOSTAT_END,
-  THERMOSTAT_ERROR,
-} thermostat_state_def;
-
-
-typedef struct
-{
-	float offset;               
-    float overHeat;       
-    float overHeatTime;          
-    float overCool;       
-    float overCoolTime;       
-    float idletemp;  	      
-    float worktime;  		     
-    pid_def  pid;	
-	unsigned int pwdId;
-    float cabinTem;    
-	pid_state_def pid_st; 
-	unsigned int pid_stable;   
-	unsigned int pid_stable_time;   
-	thermostat_state_def thermostat_st;
-	THERMOSTAT_ERR_State eerst;
-  unsigned int recGoalFlag;
-  unsigned int firstin;
-}lysis_ctr_def;
-
-void updatParm_lysis(void);
-void set_lysis(float goal) ;
-uint32_t lysis_work(void);
-uint32_t Close_lysis_work(void);
-uint32_t get_lysis_st(float *temp,unsigned int *st);
-/***********************************/
-#endif /* USR_HEATER_H_ */

+ 0 - 680
DriverInterface/usr_motor.c

@@ -1,680 +0,0 @@
-
-
-/*
- * usr_gpio.c
- *
- *	Created on: 2022年4月11日
- *		Author: amos
- */
-#include "usr_motor.h"
-
-#define BOUNCE_THRESHOLD 2 // 800ms长按阈值
-#define LONG_PRESS_THRESHOLD 80 // 800ms长按阈值
-#define CONTINUOUS_INTERVAL 40 // 300ms内算连续按键
-#define USER_STOP_TIMER 200 // 长按2s不放,停止混匀
-
-#define FIND_OPTIC_SPEED 50 // 找光开速度
-#define FIND_OPTIC_BACK_SPEED 43 // 过光开回退速度
-#define FIND_OPTIC_BACK_GAP 2 // 过光开回退速度
-
-#define MAX_RUNCNT 4 // 找光开速度
-
-typedef enum swing_state {
-  SWING_IDLE,
-  SWING_START,
-  SWING_LOOP,
-  SWING_END,
-  LOOP_START,
-  LOOP_END,
-  EMERGENCY_END,
-  FIND_GAPNUM,
-  FIND_HOMEGAP,
-  SWING_ERR,
-} swing_state_def;
-
-typedef enum {
-  KEY_IDLE,     // 空闲状态
-  KEY_SHORT,    // 短按
-  KEY_CONTINUE, // 连续按
-  KEY_LONG,     // 空闲状态,长按抬起,复位设备
-  KEY_END       //混匀状态,长按不释放,停止混匀
-} KeyState;
-
-volatile
-
-    struct {
-  KeyState state;
-  uint32_t press_tick;        // 按下时刻(10ms单位)
-  uint32_t release_tick;      // 当前释放时刻
-  uint32_t last_release_tick; // 新增:上一次释放时刻
-  uint32_t click_count;       // 连续按键计数
-  uint32_t last_level;
-  uint32_t key_valid_flag; // 连续按键标志
-} key_ctrl;
-
-swing_state_def sw_st, last_st;
-unsigned int keyState = 0;
-unsigned int MotorOptState = 0;
-
-extern uint32_t conter100ms;
-uint32_t conter10ms;
-
-int32_t runLoopTime = 600;
-int32_t runLoopSpeed = 80;
-
-uint32_t curtimeinner;
-uint32_t timeinner = 6000;
-uint32_t swingtime = 100;
-uint32_t swingtimeRight = 40;
-uint32_t swingtimePause = 100;
-int32_t backOptFlag = 0;
-int32_t startLoopConter = 0;
-int32_t swingspeed = 60;
-int32_t stateFistin;
-int32_t REVORFWD;
-//extern uint8_t error_set(uint8_t error);
-uint32_t timerBuf[16];
-uint32_t timerconter;
-uint32_t intoGap;
-uint32_t OutGap;
-uint32_t lastGap;
-uint32_t judgeGap;
-uint32_t curGap;
-uint32_t checkPWM;
-MOTOR_DIR findhomedir;
-uint32_t intoGapFlag;
-uint32_t resetFromSwingFlag;
-
-uint32_t swingLoopHigtTime = 0;
-uint32_t swingHigStopflage = 0;
-uint32_t swingStoptime = 0;
-uint32_t startFindHometime = 0;
-uint32_t findHome = 0;
-
-
-
-extern void DelayMS(uint32_t ms);
-
-
-//冒泡法排序,排序结果有小到大
-void Bubble_Sort(unsigned int *Array,unsigned int n)
-{ 
-	unsigned char i, j;
-	unsigned int temp;
-	for(i=0;i<n-1;i++)
-	{
-		for(j=i+1;j<n;j++)
-		{
-			if(Array[i] > Array[j])
-			{
-				temp     = Array[i];
-				Array[i] = Array[j];
-				Array[j] = temp;
-			}
-		}
-	}
- }
-
-
-uint32_t Read_Motor(void) {
-  return (HAL_GPIO_ReadPin(MINI7_V2_REF_SW2_GPIO_Port,MINI7_V2_REF_SW2_Pin)) ? 1 : 0; // 检查PF5引脚值
-}
-
-
-uint32_t Read_key(void) {
-  return (HAL_GPIO_ReadPin(MINI7_V2_KEY_GPIO_Port,MINI7_V2_KEY_Pin)) ? 1 : 0; // 检查PF5引脚值
-}
-
-
-uint32_t TIMER_GetCounter(void) {
-  return htim3.Instance->CNT;
-}
-
-/**
- * @brief	   SetMotorPwm
- *
- * @param		value between 0-100
- *
- * @return		None
- *
- * @details
- */
-void SetMotorPwm(int dir, int32_t value) {
-  /* Start PWM counter */
-  unsigned int DutyCycle;
-  if (value > 100) {
-    value = 100;
-  } else if (value < 0) {
-    value = 0;
-    DutyCycle = 0;
-  } 
-	DutyCycle = value*10;
-
-  if (dir) {    
-		__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 0);
-		__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_3, DutyCycle);
-  } else {
-		__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, DutyCycle);
-		__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_3, 0);
-  }
-}
-
-/**
- * @brief		GPIO PA/PB/PG/PH IRQ
- *
- * @param		None
- *
- * @return		None
- *
- * @details 	The PA/PB/PG/PH default IRQ, declared in startup_M031Series.s.
- */
-void KYE_IRQHandler(void) {
-  volatile uint32_t temp;
-	conter10ms = sysinf.conter10ms;
-
-  /* To check if PB.2 interrupt occurred */
-   {
-    uint8_t curr_level = Read_key();
-
-    if (curr_level != key_ctrl.last_level) {
-      key_ctrl.last_level = curr_level;
-
-      if (curr_level == 0) { // 下降沿(按下)
-        key_ctrl.press_tick = conter10ms;
-        if (key_ctrl.state == KEY_SHORT) {
-          key_ctrl.last_release_tick =
-              key_ctrl.release_tick; // 更新上次释放时间
-        } else {
-          key_ctrl.last_release_tick = 0;
-        }
-
-      } else { // 上升沿(释放)
-        key_ctrl.release_tick = conter10ms;
-        uint32_t press_duration = 0;
-				if(key_ctrl.press_tick){
-					press_duration = key_ctrl.release_tick - key_ctrl.press_tick;
-				}
-		
-        key_ctrl.press_tick = 0;
-        // 长按判定
-        if (press_duration <= BOUNCE_THRESHOLD) {
-          key_ctrl.state = KEY_IDLE;
-          key_ctrl.last_release_tick = 0;
-        } else if (press_duration >= LONG_PRESS_THRESHOLD) {
-          key_ctrl.state = KEY_LONG;
-          key_ctrl.last_release_tick = 0; // 更新上次释放时间
-          key_ctrl.key_valid_flag = 1;
-        }
-
-        // 短按判定
-        else {
-          key_ctrl.click_count = 1;
-          key_ctrl.state = KEY_SHORT;
-          if ((key_ctrl.release_tick - key_ctrl.last_release_tick) <=
-              CONTINUOUS_INTERVAL) {
-            key_ctrl.key_valid_flag = 1;
-            key_ctrl.click_count++;
-            key_ctrl.state = KEY_CONTINUE;
-          }
-        }
-      }
-    }
-  }
-}
-
-void check_keyShortValid(void) {
-  volatile uint32_t temp;
-
-  /* To check if PB.2 interrupt occurred */
-  if (key_ctrl.state == KEY_SHORT) {
-    if ((conter10ms - key_ctrl.release_tick) > CONTINUOUS_INTERVAL * 2) {
-      key_ctrl.key_valid_flag = 1;
-    }
-  }
-  if (sw_st != SWING_IDLE && key_ctrl.press_tick) {
-    if ((conter10ms - key_ctrl.press_tick) > USER_STOP_TIMER) {
-      key_ctrl.state = KEY_END;
-      key_ctrl.key_valid_flag = 1;
-	  key_ctrl.press_tick = 0;
-    }
-  }
-}
-
-/**
- * @brief		GPIO PC/PD/PE/PF IRQ
- *
- * @param		None
- *
- * @return		None
- *
- * @details 	The PC/PD/PE/PF default IRQ, declared in startup_M031Series.s.
- */
-void OPTO_IRQHandler(void) {
-  //
-  // volatile unsigned int temp;
-
-  /* To check if PB.2 interrupt occurred */
-  {
-	conter10ms = sysinf.conter10ms;
-	switch(sw_st){
-		case FIND_GAPNUM:{
-			if (Read_Motor()){
-					intoGap = TIMER_GetCounter();		
-				}else{
-					OutGap = TIMER_GetCounter();
-					if((conter10ms - startFindHometime) > MOTOR_LOOP_TIM){
-						if(MAX_RUNCNT > timerconter){			
-							if(OutGap > intoGap){
-								timerBuf[timerconter++] = OutGap - intoGap;
-							}else{
-								timerBuf[timerconter++] = OutGap + 0x10000 - intoGap;
-							}
-							if(MAX_RUNCNT == timerconter){
-								Bubble_Sort(timerBuf,MAX_RUNCNT);
-								judgeGap = 0;
-								if(timerBuf[0]*1.25<timerBuf[1]){
-									judgeGap = timerBuf[0]+timerBuf[0];
-								}else{
-									judgeGap = timerBuf[1]+timerBuf[0];
-								}
-	//							for(unsigned int i =0;i<(MAX_RUNCNT/2);i++){
-	//								judgeGap += timerBuf[i];
-	//							}
-								judgeGap =judgeGap*0.625;
-								timerBuf[timerconter++] = judgeGap ;
-								/*判决门限为最低两个值均值的1.5倍*/
-							}
-						}else{
-							if(OutGap > intoGap){
-								curGap = OutGap - intoGap;
-							}else{
-								curGap = OutGap + 0x10000 - intoGap;
-							}
-							timerBuf[timerconter++] = curGap ;							
-							if(curGap > judgeGap){						
-							   sw_st = FIND_HOMEGAP;	
-							   SetMotorPwm(MOTOR_REV, 0);
-							   SetMotorPwm(MOTOR_FWD, 0);	
-							   stateFistin = 1;
-							   checkPWM = checkPWM*0.8; /*降速便于复位*/		
-							   findhomedir = (MOTOR_DIR)!findhomedir;
-							}
-							if(timerconter==sizeof(timerBuf)){
-							   SetMotorPwm(MOTOR_REV, 0);
-							   SetMotorPwm(MOTOR_FWD, 0);	
-							   timerconter = 0;
-							}
-						}
-
-					}
-					
-				}
-		}
-		break;
-		case FIND_HOMEGAP:{
-		/*找远点阶段,光开亮停止*/
-		if (Read_Motor()){			
-			SetMotorPwm(MOTOR_REV, 0);
-			SetMotorPwm(MOTOR_FWD, 0);	
-		    intoGapFlag = 1;
-			intoGap = TIMER_GetCounter();
-			}
-		}
-		break;
-		case SWING_LOOP:{
-		/*找远点阶段,光开亮停止*/		
-		if(startLoopConter > 0){
-			startLoopConter --;
-		}else{
-			if (Read_Motor()){			
-				SetMotorPwm(MOTOR_REV, 0);
-				SetMotorPwm(MOTOR_FWD, 0);	
-				intoGapFlag = 1;
-				intoGap = TIMER_GetCounter();
-			}
-		}
-		}break;
-		default:{	
-				SetMotorPwm(MOTOR_REV, 0);
-				SetMotorPwm(MOTOR_FWD, 0);	
-//			  sw_st = FIND_GAPNUM;
-//		      stateFistin = 1;	  
-		}break;	
-		
-	}
-	  
-  }
-}
-
-
-
-/**
- * @brief	   Motor_Init
- *
- * @param		init key and optic input
- *
- * @return		None
- *
- * @details
- */
-void Motor_Init()
-{
-  key_ctrl.last_level = 1;
-  timeinner = sysinf.timeinner;
-  swingspeed = sysinf.swingspeed;
-	swingtime =sysinf.swingtime;
-	swingtimeRight =sysinf.swingtimeRight;
-	swingtimePause =sysinf.swingtimePause;
-	runLoopTime = sysinf.runLoopTime;
-	runLoopSpeed =sysinf.runLoopSpeed;
-}
-
-/**
- * @brief	   Motor_mix
- *
- * @param		init key and optic input
- *
- * @return		0正常,1没离开光开,2,没回到光开
- *
- * @details    设置夹爪转动参数。
- */
-uint32_t Motor_mix(uint32_t time, uint32_t speed, uint32_t swing,
-                   uint32_t timeRight, uint32_t timePause) {
-
-  timeinner = time;
-  swingtime = swing;
-  swingspeed = speed;
-  swingtimeRight = timeRight;
-  swingtimePause = timePause;
-//  timeinner = time - time % (swing + timeRight);
-//  curtimeinner = timeinner;
-  if (speed == 0) {    
-	return 0;
-  }
-  
-      curtimeinner = conter10ms;
-      sw_st = SWING_LOOP;
-	  startLoopConter = 2;
-      stateFistin = 1;	  		
-	  backOptFlag = 1;
-	  findhomedir = MOTOR_REV;
-	return 0;
-}
-
-/**
- * @brief	  Motor_deal_key
- *
- * @param	   按键处理,短按,左右摇;连续点击,转圈摇;长按,复位;
- *
- * @return	   0正常,1没离开光开,2,没回到光开
- *
- * @details	  夹爪根据。
- */
-uint32_t Motor_deal_key(swing_state_def st, KeyState key) {
-  if (st == SWING_IDLE) {
-    switch (key) {
-    case KEY_SHORT:
-      curtimeinner = conter10ms;
-      sw_st = SWING_LOOP;
-	  startLoopConter = 2;
-      stateFistin = 1;	  		
-	  backOptFlag = 1;
-	  findhomedir = MOTOR_REV;
-      break;
-//    case KEY_CONTINUE:
-//      curtimeinner = conter10ms;
-//      sw_st = LOOP_START;
-//      stateFistin = 1;
-//      break;
-    case KEY_LONG:
-      curtimeinner = conter10ms;
-	  sw_st = FIND_GAPNUM;
-	  stateFistin = 1;
-      break;
-    default:
-      break;
-    }
-
-  } 
-if (key == KEY_LONG || key == KEY_END ) {
-	  sw_st = FIND_GAPNUM;
-      stateFistin = 1;	  
-	  resetFromSwingFlag = 0;
-   }
-	return 0;
-}
-
-void Motor_reset(void) {
-      curtimeinner = conter10ms;
-	  sw_st = FIND_GAPNUM;
-	  stateFistin = 1;
-	  resetFromSwingFlag = 0;
-}
-
-
-/**
- * @brief	   Motor_mix_work
- *
- * @param		init key and optic input
- *
- * @return		0正常,1没离开光开,2,没回到光开
- *
- * @details    夹爪根据。
- */
-uint32_t Motor_mix_work(void) {
-  static uint32_t last10ms;
-  static uint32_t firstINGap;
-  static uint32_t powerOnFlag = 1;
-  check_keyShortValid();
-  if(powerOnFlag){
-	powerOnFlag = 0;
-//	Motor_Check(0);  
-	resetFromSwingFlag = 0;
-	sw_st = FIND_GAPNUM;
-	stateFistin = 1;
-  }
-	conter10ms = sysinf.conter10ms;
-  if (key_ctrl.key_valid_flag) {
-    key_ctrl.key_valid_flag = 0;
-    Motor_deal_key(sw_st, key_ctrl.state);
-    key_ctrl.state = KEY_IDLE;
-  }
-  if(sw_st == SWING_ERR){
-  		/*电机故障,不执行操作*/
-		return 0;
-  }
-  switch (sw_st) {
-  case SWING_IDLE: {
-    SetMotorPwm(MOTOR_REV, 0);
-    SetMotorPwm(MOTOR_FWD, 0);
-  } break;
-  case FIND_GAPNUM: {
-    if (stateFistin) {
-      timerconter = 0;
-	  intoGap = 0;
-	  OutGap = 0;
-	  lastGap = 0;
-	  judgeGap = 0;
-	  HAL_TIM_Base_Stop(&htim4);
-	  HAL_TIM_Base_Start(&htim4);
-      last10ms = conter10ms;
-      stateFistin = 0;    
-	  startFindHometime = conter10ms;  
-	  findhomedir = MOTOR_REV;
-    checkPWM = swingspeed;
-	  SetMotorPwm(findhomedir, checkPWM);
-    } else  {
-  	  if (((conter10ms - last10ms) > MOTOR_LOOP_TIM*4 )&&(timerconter < MAX_RUNCNT)) {
-  		/*电机不动,返回报错*/
-  		SetMotorPwm(MOTOR_REV, 0);
-  		sw_st = SWING_ERR;
-		error_set(ERROR_MOTOR_FIALED);
-  		return 1;
-  	  }
-    } 
-  } break;
-  case FIND_HOMEGAP: {
-    if (stateFistin) {
-      last10ms = conter10ms;
-      stateFistin = 0;
-	  intoGapFlag = 0;
-	  firstINGap = 0;
-	  SetMotorPwm(findhomedir, checkPWM);
-    } else  {
-  	  if (!intoGapFlag && (conter10ms - last10ms) > MOTOR_LOOP_TIM) {
-  		  /*电机来回不动,返回报错*/
-		  stateFistin = 1;
-		  checkPWM = checkPWM/0.85; /*降速便于复位*/
-  	  }
-	   if(intoGapFlag){
-	   		if(!firstINGap){
-				/*进入缝隙,置位,延时判读*/
-				firstINGap = 1;
-				last10ms = conter10ms;
-			}else{
-				if((conter10ms - last10ms) > MOTOR_MOVEFORM_OPTIC_TIM){
-					if(Read_Motor()){							
-					   sw_st = SWING_IDLE;
-					   stateFistin = 1;
-					   findHome = 1;
-					  
-					}
-					else{
-						sw_st = FIND_HOMEGAP;
-					   stateFistin = 1;
-				   	   findhomedir = (MOTOR_DIR)!findhomedir;
-					   checkPWM = checkPWM*0.9; /*降速便于复位*/		  
-					}
-				}
-			}   	    
-	   }
-    } 
-  } break;
-  
-
-  case LOOP_START: {
-    if (stateFistin) {
-      SetMotorPwm(MOTOR_REV, runLoopSpeed);
-      last10ms = conter10ms;
-      stateFistin = 0;
-    } else {
-      if ((conter10ms - last10ms) == (runLoopTime)) {
-        SetMotorPwm(MOTOR_REV, 0);
-        SetMotorPwm(MOTOR_FWD, 0);
-      }
-      if ((conter10ms - last10ms) >= (runLoopTime + swingtimePause)) {
-        sw_st = LOOP_END;
-        stateFistin = 1;
-        REVORFWD = 0;
-      }
-    }
-  } break;
-
-  case LOOP_END: {
-	sw_st = FIND_GAPNUM;
-	stateFistin = 1;
-    REVORFWD = 1;
-  } break;
-
-
-  case SWING_LOOP: { 
-    if (stateFistin ) {
-	  	/**/
-	 	if(backOptFlag){
-			if(swingtime< (conter10ms - swingStoptime)){
-			 checkPWM = swingspeed;		
-			 backOptFlag = 0;
-			 SetMotorPwm(findhomedir, checkPWM);
-			 stateFistin = 0;
-			 last10ms = conter10ms;
-			 swingHigStopflage = 0;
-			}			
-		}else{
-			 SetMotorPwm(findhomedir, checkPWM);
-			 stateFistin = 0;
-			 last10ms = conter10ms;
-			 swingHigStopflage = 0;
-		}   
-		intoGapFlag = 0;
-		firstINGap = 0;
-    } else{
-  	  if (!intoGapFlag && (conter10ms - last10ms) > MOTOR_LOOP_TIM) {
-  		/*速度过底,电机回不来*/	  
-		  backOptFlag = 1;		  
-		  swingStoptime = conter10ms;
-		  findhomedir = MOTOR_REV;
-		  stateFistin = 1;
-
-  	  }
-	   if(intoGapFlag){
-	   		if(!firstINGap){
-				/*进入缝隙,置位,延时判读*/
-				firstINGap = 1;
-				last10ms = conter10ms;
-			}else{
-			if((conter10ms - last10ms) > MOTOR_MOVEFORM_OPTIC_TIM){
-				 stateFistin = 1;
-				if(Read_Motor()){		
-					backOptFlag = 1;		
-					swingStoptime = conter10ms;
-	  				findhomedir = MOTOR_REV;
-				}
-				else{
-			   	   findhomedir = (MOTOR_DIR)!findhomedir;
-				   checkPWM = checkPWM*0.9; /*降速便于复位*/		  
-				}
-			}	
-			}   
-	   }
-	   if ((conter10ms - curtimeinner) > (timeinner)){
-		  resetFromSwingFlag = 0;  		  
-			__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 0);		 
-			__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 0);
-			timerconter = 0;
-		  memset(timerBuf,0,sizeof(timerBuf));
-	      stateFistin = 1;	
-		  sw_st = FIND_GAPNUM;  
-	  }
-    } 
-  } break;
-
-  default:
-  	sw_st = SWING_ERR;
-    break;
-  }
-	return 0;
-}
-
-
-/**
- * @brief	   Motor_mix
- *
- * @param		init key and optic input
- *
- * @return		空闲返回1 其他返回0
- *
- * @details    设置夹爪转动参数。
- */
-uint32_t Motor_idle() {
-	return(sw_st == SWING_IDLE);
- 
-}
-uint32_t print_home_time() {
-	if(findHome){
-		findHome = 0;
-		Van_Device_Printf(VAN_LOG_NOTICE,"gap:%d  ",timerconter);
-	    if(timerconter > sizeof(timerBuf)){
-			timerconter = sizeof(timerBuf);
-		}
-		for(unsigned int i=0;i<timerconter;i++){
-			Van_Device_Printf(VAN_LOG_NOTICE," %d  ",timerBuf[i]);
-		}
-		Van_Device_Printf(VAN_LOG_NOTICE,"\n");
-	}
-	
-	return 0;
-}
-
-
-
-

+ 0 - 49
DriverInterface/usr_motor.h

@@ -1,49 +0,0 @@
-/*
- * usr_gpio.h
- *
- *  Created on: 2022��4��11��
- *      Author: amos
- */
-
-#ifndef USR_MOTMOR_H_
-#define USR_MOTMOR_H_
-
-#include "onechip_include_header.h"
-/*************************************/
-#define MOTOR_OPTIC_PORT PF//光开
-#define MOTOR_OPTIC_PIN  BIT5//光开
-#define MOTOR_OPTIC_INT_CH  5//光开
-#define MOTOR_OPTIC()  (PF5)  //按键
-#define KYE_PORT  PA //按键
-#define KYE_PIN  BIT15 //按键
-#define KYE_INT_CH  15//光开
-#define KYE()  PA15 //按键
-#define MOTOR_CH_REV_MASK PWM_CH_4_MASK 
-#define MOTOR_CH_REV	4
-#define MOTOR_CH_FWD_MASK PWM_CH_5_MASK 
-#define MOTOR_CH_FWD	5 
-
-#define MOTOR_CHECK_SPEED	60
-#define MOTOR_MOVEFORM_OPTIC_TIM	10
-#define MOTOR_LOOP_TIM	100
-
-#define MOTOR_SWING_TIM	100
-
-typedef enum {
-	MOTOR_REV = 0,
-	MOTOR_FWD = 1,
-}MOTOR_DIR;
-void KYE_IRQHandler(void);
-void OPTO_IRQHandler(void);
-void Motor_Init(void);
-uint32_t Motor_Check(uint32_t swing);
-uint32_t Motor_mix(uint32_t time,uint32_t speed,uint32_t swing,uint32_t swingtimeRight, uint32_t swingtimePause);
-uint32_t Read_Motor(void);
-uint32_t Motor_mix_work(void);
-uint32_t Motor_Run_Continue(uint32_t speed);
-uint32_t Motor_idle(void);
-uint32_t print_home_time(void);
-void Motor_reset(void);
-
-/***********************************/
-#endif /* USR_MOTMOR_H_ */

+ 0 - 287
DriverInterface/van_BSP_Com_Pwm.c

@@ -1,287 +0,0 @@
-/******************************************************************************
-*Copyright(C),2024-2024,万众一芯生
-*van_BSP_Com_Pwm.c
-*stm32 pwm控制的
-*修改历史
-author				范义东			新建				2024/01/27
-******************************************************************************/
-
-#include "onechip_include_header.h"
-#include "van_BSP_Com_Pwm.h"
-
-	
-VAN_COM_PWM_Def gcom_pwm_MINI_V2_V1[] = {
-    {MINI7_SUB_FUN_MOTOR, NAME(MOTOR), PWM_BUMP_ST_IDLE, COM_PWM_8870, (void *)&htim3, TIM_CHANNEL_2}, 
-    {MINI7_SUB_FUN_HEATER1, NAME(HEATER1), PWM_BUMP_ST_IDLE, COM_PWM_8870, (void *)&htim3, TIM_CHANNEL_1},			 
-    {MINI7_SUB_FUN_HEATER2, NAME(HEATER2), PWM_BUMP_ST_IDLE, COM_PWM_8870, (void *)&htim1, TIM_CHANNEL_3}
-};
-
-unsigned int gcom_pwm_MINI_V2_Num = ARR_LEN(gcom_pwm_MINI_V2_V1);
-
-
-P_VAN_COM_PWM_Def gcom_pwm_V1;
-unsigned int gcom_pwm_V1_Num;
-
-/****************************************************************
- 函数名:    loadPidCfg
- 创建时间:  2024/01/08
- 创建人:    范义东
- 函数说明:加载配置文件
- 参数:
-
- 返回值 :  加载成功
-****************************************************************/
-unsigned int load_com_pwm_Cfg(pDeviceBasicInfdef pDevice) {
-
-	gcom_pwm_V1 = gcom_pwm_MINI_V2_V1;
-  gcom_pwm_V1_Num = gcom_pwm_MINI_V2_Num;
-  P_VAN_COM_PWM_Def pdev = gcom_pwm_V1;
-  for (int i = 0; i < gcom_pwm_V1_Num; i++) {
-    pdev++;
-  }
-  return true;
-}
-/****************************************************************
- * 函数名:    com_pwm_FindChanle
- * 创建时间:    2024/01/08
- * 创建人:    范义东
- * 函数说明:通过ID,查找PWM模块
- * 输入参数: devId
- * 输出参数: pdev 比例阀配置
- * 返回值 :   有配置文件返回true,返回失败
- ****************************************************************/
-bool com_pwm_FindChanle(unsigned int devId, P_VAN_COM_PWM_Def *pdev) {
-  unsigned char id;
-  /*寻找配置文件*/
-  for (id = 0; id < gcom_pwm_V1_Num; id++) {
-    if (devId == gcom_pwm_V1[id].ID) {
-      *pdev = &gcom_pwm_V1[id];
-      return true;
-    }
-  }
-  Van_Device_Printf(VAN_LOG_NOTICE, "pwm devId:%d no exit\r\n", devId);
-  *pdev = NULL;
-  return false;
-}
-
-
-/****************************************************************
- 函数名:   com_pwm_Getconter
- 创建时间:  2024/01/08
- 创建人:    范义东
- 函数说明:获取当前脉冲计算器
- 参数: devId 通道
-       value pwm值,负值为反向
- 返回值 :  加载成功
-****************************************************************/
-unsigned int com_pwm_Getconter(unsigned int devId) {
-  P_VAN_COM_PWM_Def pdev;
-  if (com_pwm_FindChanle(devId, &pdev)) {
-    Van_Device_Printf(VAN_LOG_DEBUG, "time:%d  conter:%d\n", devId, pdev->feedbackconter);
-    return pdev->feedbackconter;
-  } else {
-    Van_Device_Printf(VAN_LOG_ERROR, "pwn %d not support:%d\n", devId);
-  }
-  return 0;
-}
-
-/****************************************************************
- * 函数名:    com_pwm_test
- * 创建时间:    2024/01/08
- * 创建人:    范义东
- * 函数说明:设置PWM输出
- * 输入参数:     runMtsId 通道
- * 输出参数: pTemp 当前温度
- * 返回值 :   成功rue,失败返回false
- ****************************************************************/
-bool com_pwm_test(unsigned int Id, int value) {
-  P_VAN_COM_PWM_Def pdev;
-  float fvalue = value;
-  if (com_pwm_FindChanle(Id, &pdev)) {
-    com_pwm_Set(Id, fvalue);
-    Van_Device_Printf(VAN_LOG_NOTICE, "%s: ID:%d set out:%f\r\n", pdev->Name, Id, fvalue);
-  } else {
-    Van_Device_Printf(VAN_LOG_NOTICE, "no support  ID:%d\r\n", Id);
-  }
-  return False;
-}
-
-/****************************************************************
- 函数名:   com_pwm_Set
- 创建时间:  2024/01/08
- 创建人:    范义东
- 函数说明:设置pwm
- 参数: devId 通道
-       value pwm值,负值为反向
- 返回值 :  加载成功
-****************************************************************/
-void com_pwm_Set(unsigned int devId, float value) {
-  P_VAN_COM_PWM_Def pdev;
-  float temp = value;
-  int DutyCycle = (int)temp;
-  DutyCycle *= 10; 
-  if (DutyCycle > MAX_PWM_VALUE) {
-      DutyCycle = MAX_PWM_VALUE;
-  }else if(DutyCycle < -MAX_PWM_VALUE) {
-      DutyCycle = -MAX_PWM_VALUE;
-  }
-  if (com_pwm_FindChanle(devId, &pdev)) {
-    // //    Van_Device_Printf(VAN_LOG_NOTICE, "before pwn %s pluse:%d\n", pdev->Name, DutyCycle);
-    // if (pdev->dirPort && (pdev->type == COM_PWM_8870 || pdev->type == COM_PWM_8873)) {
-		// 	GPIO_PinState PinState =   ((DutyCycle < 0) ^ (pdev->dirState == GPIO_PIN_SET))?GPIO_PIN_SET:GPIO_PIN_RESET;
-		// 	HAL_GPIO_WritePin(pdev->dirPort, pdev->dirPin, PinState);
-		// 	if (DutyCycle < 0 && pdev->type == COM_PWM_8870) {
-		// 		DutyCycle = MAX_PWM_VALUE+DutyCycle;	
-		// 	}		
-		// 	if (DutyCycle < 0 && pdev->type == COM_PWM_8873) {
-		// 		DutyCycle = -DutyCycle;	
-		// 	}
-    // }
-    if (DutyCycle < 0) {
-      DutyCycle = 0;
-    } else if (DutyCycle > MAX_PWM_VALUE) {
-      DutyCycle = MAX_PWM_VALUE;
-    }
-    TIM_HandleTypeDef *ptimer = pdev->timerHandle;
-    __HAL_TIM_SET_COMPARE(ptimer, pdev->pwmChanle, DutyCycle);
-    pdev->state = PWM_BUMP_ST_RUN;
-  } else {
-    Van_Device_Printf(VAN_LOG_ERROR, "pwn %d not support:%d\n", devId);
-  }
-}
-/****************************************************************
- * 函数名:    showIVT
- * 创建时间:    2024/01/08
- * 创建人:    范义东
- * 函数说明:IVT模块查看
- * 输入参数: 无
- * 输出参数: 无
- * 返回值 :   无
- ****************************************************************/
-void show_com_pwm(void) {
-  P_VAN_COM_PWM_Def pdev;
-  char TimeName[16] = {0};
-  char FeedTimeCName[16] = {0};
-  char DirPortName[16] = {0};
-  Van_Device_Printf(VAN_LOG_NOTICE, "devtype:%d strtype:%d hdtype:%d PWM Num:%d\r\n", sysinf.devdesc.deveice_type, sysinf.devdesc.structure_type,
-                    sysinf.devdesc.hardware_type, gcom_pwm_V1_Num);
-  if (gcom_pwm_V1_Num == 0) {
-    Van_Device_Printf(VAN_LOG_NOTICE, "***************no Pwm***************\r\n");
-  }
-
-  Van_Device_Printf(VAN_LOG_NOTICE, "%2s %16s %2s %2s %6s %2s %6s %2s %4s %6s %2s %4s\r\n ", " ID ", " name ", "St", "Type", "tim ", "ch ", "ftim", "fch",
-                    "con ", "Dport", "pin", "value");
-  HAL_Delay(10); 
-  pdev = gcom_pwm_V1;
-  for (int i = 0; i < gcom_pwm_V1_Num; i++) {
-    find_stm32_Peripherals(pdev->timerHandle, TimeName);
-    find_stm32_Peripherals(pdev->feedbackTimer, FeedTimeCName);
-    find_stm32_Peripherals(pdev->dirPort, DirPortName);
-
-    Van_Device_Printf(VAN_LOG_NOTICE, "%2d %16s %2d  %2x %6s  %2x %6s %2d %4d %6s %2x %4d\r\n", pdev->ID, pdev->Name, pdev->state, pdev->type, TimeName,
-                      pdev->pwmChanle, FeedTimeCName, pdev->feedbackChanlen, pdev->feedbackconter, DirPortName, pdev->dirPin, pdev->setValue);
-    HAL_Delay(10);
-    pdev++;
-  }
-  return;
-}
-
-
-/****************************************************************
- * 函数名:    PWM_Find_By_CHl
- * 创建时间:    2024/01/08
- * 创建人:    范义东
- * 函数说明:通过ID,查找反馈模块
- * 输入参数: devId
- * 输出参数: pdev 比例阀配置
- * 返回值 :   有配置文件返回true,返回失败
- ****************************************************************/
-bool PWM_Find_feed_By_ch(unsigned int devId, P_VAN_COM_PWM_Def *pdev) {
-  unsigned char id;
-  /*寻找配置文件*/
-  for (id = 0; id < gcom_pwm_V1_Num; id++) {
-    if (devId == gcom_pwm_V1[id].ID || gcom_pwm_V1[id].feedbackChanlen) {
-      *pdev = &gcom_pwm_V1[id];
-      return true;
-    }
-  }
-  Van_Device_Printf(VAN_LOG_NOTICE, "pwm feed devId:%d no exit\r\n", devId);
-  *pdev = NULL;
-  return false;
-}
-
-/****************************************************************
- * 函数名:    com_feed_Add_Pulse
- * 创建时间:    2024/01/08
- * 创建人:    范义东
- * 函数说明:通过GPIO_Pin,跟新转到脉冲计数
- * 输入参数: devId
- * 输出参数: pdev 比例阀配置
- * 返回值 :   有配置文件返回true,返回失败
- ****************************************************************/
-void com_feed_Add_Pulse(uint16_t GPIO_Pin) {
-  P_VAN_COM_PWM_Def pdev = gcom_pwm_V1;
-  for (int i = 0; i < gcom_pwm_V1_Num; i++) {
-    if (pdev->state == PWM_BUMP_ST_RUN && pdev->feedbackChanlen == GPIO_Pin) {
-      pdev->plusconter++;
-      //	   		Van_Device_Printf(VAN_LOG_NOTICE, "ID:%d plus:%d\n",pdev->ID,pdev->plusconter);
-    }
-    pdev++;
-  }
-}
-
-/****************************************************************
- * 函数名:    check_Pwm_Plus_feedOK
- * 创建时间:    2024/01/08
- * 创建人:    范义东
- * 函数说明:通过plusconter,检查是否转到
- * 输入参数: 无
- * 输出参数: 无
- * 返回值 :   有配置文件返回true,返回失败
- ****************************************************************/
-void check_Pwm_Plus_feedOK(void) {
-  P_VAN_COM_PWM_Def pdev = gcom_pwm_V1;
-  for (int i = 0; i < gcom_pwm_V1_Num; i++) {
-    if (pdev->state == PWM_BUMP_ST_RUN && pdev->feedbackChanlen != VAN_CONFIG_NOCARE) {
-     
-      pdev->plusconter = 0;
-    }
-    pdev++;
-  }
-}
-
-
-/**********************************************************************************
-Func    Name: Paltform_Set_PWM_Pause
-Descriptions: 平台设置暂停PWM
-Input   para: 无
-In&Out  Para: 无
-Output  para: 无
-Return value: 无
-***********************************************************************************/
-void Paltform_Set_PWM_Pause(unsigned int id) {
-  P_VAN_COM_PWM_Def dev;
-  // float goal = 0; /*安1000配置占空比*/
-
-  if (com_pwm_FindChanle(id, &dev) == True) {
-    com_pwm_Set(id, 0);
-    dev->state = PWM_BUMP_ST_IDLE;
-  }
-}
-
-/**********************************************************************************
-Func    Name: Paltform_Set_PWM_Resume
-Descriptions: 平台设置恢复PWM
-Input   para: 无
-In&Out  Para: 无
-Output  para: 无
-Return value: 无
-***********************************************************************************/
-void Paltform_Set_PWM_Resume(unsigned int id) {
-  P_VAN_COM_PWM_Def dev;
-
-  if (com_pwm_FindChanle(id, &dev) == True) {
-    com_pwm_Set(id, dev->setValue);
-    dev->state = PWM_BUMP_ST_RUN;
-  }
-}

+ 0 - 76
DriverInterface/van_BSP_Com_Pwm.h

@@ -1,76 +0,0 @@
-/******************************************************************************
-*Copyright(C),2024-2024,万众一芯生
-*van_BSP_Pwm_pump.h
-* pwm 控制泵阀驱动
-*修改历史
-author				范义东			新建				2024/01/27
-******************************************************************************/
-
-#ifndef __VAN_BSP_COM_PWM_H
-#define __VAN_BSP_COM_PWM_H
-
-#include "van_com_define.h"
-#define MAX_PWM_VALUE  999
-
-typedef enum
-{
-	PWM_CHIPKK5 = 30000,
-	PWM_PIPE = 30001,
-	PWM_TOPCON = 30002,
-	PWM_BOTCON = 30003,
-	PWM_PERIS1 = 30020,
-	PWM_PERIS2 = 30021,
-	PWM_DIAPHR = 30022,
-} enPWM_004_V1;
-	
-typedef enum {
-  PWM_BUMP_ST_IDLE,
-  PWM_BUMP_ST_RUN,
-  PWM_BUMP_ST_FEEDERR, /*转速反馈异常*/
-} COM_PWM_State;
-
-typedef enum {
-  COM_PWM_BASE,
-  COM_PWM_8870, 		/*带方向*/
-  COM_PWM_8873, /*带转速反馈*/
-  COM_PWM_DIR_FEED_CNT, /*带方向转速反馈*/
-} COM_PWM_Type;
-
-
-typedef struct {
-  unsigned int ID;              //泵编号
-  unsigned char Name[16];       //泵名
-  COM_PWM_State state;         //状态
-  COM_PWM_Type type;			//类型
-  void* timerHandle;            /*定时器端口*/
-  unsigned int pwmChanle;       /*定时器通道*/
-  void* feedbackTimer;          /*反馈定时器*/
-  unsigned int feedbackChanlen; /*反馈通道*/
-  void* dirPort;                /*方向端口*/
-  unsigned int dirPin;          /*方向管脚*/
-  unsigned int 	dirState;	  // 正向电平
-  unsigned int feedbackconter;  /*反馈脉冲数*/
-  float setValue;               /*设定值*/ 
-  float getValue;               /*反馈值*/
-  float range_Max;               /*范围*/  
-  float range_Min;               /*范围*/  
-  unsigned int plusconter;		/*转动脉冲计数*/
-} VAN_COM_PWM_Def, *P_VAN_COM_PWM_Def;
-
-
-void com_pwm_Set(unsigned int devId, float value);
-unsigned int com_pwm_Getconter(unsigned int devId);
-bool com_pwm_test(unsigned int Id, int value);
-void show_com_pwm(void);
-bool com_pwm_FindChanle(unsigned int devId, P_VAN_COM_PWM_Def *pdev);
-bool PWM_Find_feed_By_ch(unsigned int devId, P_VAN_COM_PWM_Def *pdev);
-void Paltform_Set_PWM_Pause(unsigned int id);
-void Paltform_Set_PWM_Resume(unsigned int id);
-void thread_Proportiona_ctrl(void* );
-void com_feed_Add_Pulse(uint16_t GPIO_Pin);
-void check_Pwm_Plus_feedOK(void);
-void Paltform_Get_PWM_Current(void *param);
-void Paltform_Set_PWM_Goal(void *param) ;
-void Paltform_Set_PWM_Stop(void *param);
-unsigned int load_com_pwm_Cfg(pDeviceBasicInfdef pDevice);
-#endif

+ 0 - 254
DriverInterface/van_BSP_Scanner.c

@@ -1,254 +0,0 @@
-/*
- * uart_rcv.c
- *
- *  Created on: 2022年4月20日
- *      Author: dell
- */
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include "onechip_include_header.h"
-
-
-
-
-#define ENV_ADJ_THRESHOLD 27.0
-
-#define QR_RESEND_3s   300
-
-
-#define DEBUG_BUF_SIZE (512)	// 调试串口缓冲区长度
-#define BUF_SIZE (512)	// 调试串口缓冲区长度
-
-enum SLAVE_MCU_Ctr_cmd_type
-{
-    SLAVE_MCU_CMD_PARAM = 0x01,
-    SLAVE_MCU_CMD_HEAT = 0x02,
-    SLAVE_MCU_CMD_LIGHT_CTR= 0X03,
-    SLAVE_MCU_CMD_QRSCANNER_CTR= 0X04,    
-    SLAVE_MCU_CMD_FAN= 0X05,
-    SLAVE_MCU_CMD_CARD_ST= 0X06,
-	SLAVE_MCU_CMD_PID = 0x20,
-};
-enum SLAVE_MCU_Ctr_UP_type
-{
-	SLAVE_MCU_UP_HEAT = 0x10,
-	SLAVE_MCU_UP_QR_PARAM= 0X11,
-	SLAVE_MCU_UP_QR = 0x12,
-	SLAVE_MCU_INFO,					//异常信息
-};
-
-
-
-
-uint8_t g_uart2_rcv_start = 0;
-uint8_t g_uart2_rcv_complete_flg = 0;
-uint8_t g_uart2_rx_buf[DEBUG_BUF_SIZE] = {0};
-// uint8_t g_uart2_tx_buf[BUF_SIZE] = {0};
-uint32_t g_uart2_rx_len = 0;
-
-str_hole_info_t hole1 = {0};
-str_hole_info_t hole2 = {0};
-str_hole_info_t hole3 = {0};
-str_hole_info_t hole4 = {0};
-str_hole_info_t hole5 = {0};
-str_hole_info_t hole6 = {0};
-str_hole_info_t hole7 = {0};
-str_hole_info_t hole8 = {0};
-str_hole_info_t hole9 = {0};
-str_hole_info_t hole10 = {0};
-str_card_param_info_t m_str_card_param_info = {0};
-unsigned int haveheaderflag = 0;
-uint32_t qr_check_delay = QR_CHECH_STATE_FIRST;  /*1s定时器里面,大于0,每s减1*/
-extern void QRparam_upload(str_card_param_info_t *p_str_card_param_info);
-extern uint8_t sys_info[40];
-
-uint32_t received_len;
-
-
-void svanner_receive_Rec_Start(UART_HandleTypeDef *huart){
-		__HAL_UART_CLEAR_IDLEFLAG(huart);
-	  memset((char *)g_uart2_rx_buf,0,DEBUG_BUF_SIZE);
-	  received_len = 0;
-		HAL_UART_Receive_DMA(huart, g_uart2_rx_buf, DEBUG_BUF_SIZE);	
-	__HAL_UART_ENABLE_IT(huart, UART_IT_IDLE);
-	sysinf.updateQR = false;
-}
-
-
-void svanner_receive_Rec_Stop(UART_HandleTypeDef *huart){
-	HAL_UART_DMAStop(huart);
-}
-
-/********************************************************************
- *                         bcd_to_hex()
- *
- *描述:BCD转HEX
- *参数:无
- *返回:无
- *其他:无
- *--------------------------------------------------------------------
- *记录:
- ********************************************************************/
-uint8_t bcd_to_hex(uint8_t val)
-{
-	return ((val / 10) << 4) + val % 10;
-}
-
-
-void svanner_receive_Rec_IDLE(UART_HandleTypeDef *huart)
-{
-	if ((__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE) != RESET))
-	{
-		__HAL_UART_CLEAR_IDLEFLAG(huart);
-		received_len		= DEBUG_BUF_SIZE - __HAL_DMA_GET_COUNTER(huart->hdmarx);
-		HAL_UART_DMAStop(huart); 
-		HAL_UART_Receive_DMA(huart, g_uart2_rx_buf, DEBUG_BUF_SIZE);
-	}
-}
-
-
-void svanner_receive_analysis(void)
-{
-	if(received_len){	
-		// Van_Device_Printf(VAN_LOG_INFO, "rec QR inif %d \n\r",received_len);
-		if (('{' == g_uart2_rx_buf[0]) && (sysinf.updateQR == false)){
-			if(0 == parse_qrcode_info(&m_str_card_param_info,  (char *)&g_uart2_rx_buf[0])){
-				haveheaderflag = QR_REC_STATE_SENDPRAM; 	
-				memcpy(&g_uart2_rx_buf[received_len],  sysinf.SN, 7);
-				received_len += 7;
-				qr_check_delay = 0;				
-				if((sysinf.psmMaster.state == SW_Scan_Qrcode || sysinf.psmMaster.state == SW_Chip_Id  )){
-					svanner_receive_Rec_Stop(sysinf.scannerUart);
-					sysinf.updateQR = true;
-					data_send_to_pc(PC_CMD_QRCODE,(char *)g_uart2_rx_buf, received_len);	
-					memcpy(&sysinf.psmMaster.card_param_info, &m_str_card_param_info, sizeof(str_card_param_info_t));
-				}
-				else{
-#ifdef ONECHIP_MINI_PLUSE
-				if((sysinf.psmSlave.state == SW_Scan_Qrcode || sysinf.psmSlave.state == SW_Chip_Id  )){
-
-					}
-#endif
-				}
-				sysinf.QRBeepTimeer = 100;
-				sysinf.resendeQRtimer = 1;
-				HAL_GPIO_WritePin((GPIO_TypeDef *)sysinf.beep_port, sysinf.beep_pin,GPIO_PIN_SET); 
-			}
-			else{
-				Van_Device_Printf(VAN_LOG_WARN, "unpack json error \n\r %s",g_uart2_rx_buf);
-			}
-		}
-		else{
-				if(sysinf.updateQR == false){
-					Van_Device_Printf(VAN_LOG_WARN, "header error \n\r %s",g_uart2_rx_buf);		
-					svanner_receive_Rec_Start(sysinf.scannerUart);
-				}				
-			}
-
-	}
-	return;
-}
-/*****************************************************************************
-*
-*二维码未收到应答,重新上报
-*
-************************************************************************************/
-void reSend_QR(void)
-{
-	if(sysinf.updateQR ){
-		sysinf.resendeQRtimer++;
-		if((sysinf.resendeQRtimer % QR_RESEND_3s)==0){
-			data_send_to_pc(PC_CMD_QRCODE,(char *)g_uart2_rx_buf, received_len);			
-			if(sysinf.resendeQRtimer  > 5*QR_RESEND_3s){
-				/*最多重发5次*/				
-				svanner_receive_Rec_Start(sysinf.scannerUart);
-			}	
-		}
-	}
-}
-
-
-int parse_qrcode_info(str_card_param_info_t *info, char *qrcode_str)
-{
-	int id = 0;
-	double Tt = 0;
-	double Tt1 = 0;
-	
-	if (info == 0)
-	{
-		return -1;
-	}
-
-	cJSON *root = cJSON_Parse(qrcode_str);
-	if (root == NULL)
-	{   /*消息不合格*/
-		return -1;
-	}
-	cJSON *item = cJSON_GetObjectItem(root, "p");
-	if (item == NULL)
-	{   /*消息不合格*/
-		cJSON_Delete(root);
-		return -1;
-	}
-	char *pid = cJSON_GetStringValue(item);
-	//    printf("pid=%s \r\n", pid);
-	memcpy(info->pid, pid, 10);
-
-	item = cJSON_GetObjectItem(root, "t");
-	if (item == NULL)
-	{   /*消息不合格*/
-		cJSON_Delete(root);
-		return -1;
-	}
-	double t = item->valuedouble;
-	//    printf("t=%f \r\n", t);
-	info->temp[0] = (uint8_t)t;
-	info->temp[1] = (uint8_t)((t -(uint8_t)t)* 100);
-
-	// 获取数组item
-	item = cJSON_GetObjectItem(root, "e");
-	if (item == NULL)
-	{   /*消息不合格*/
-		cJSON_Delete(root);
-		return -1;
-	}
-	int test_arry_size = cJSON_GetArraySize(item);
-
-	for (int i = 0; i < test_arry_size; i++)
-	{
-		// 打印数组里的所有item
-		cJSON *sub_array = cJSON_GetArrayItem(item, i);
-
-		cJSON *sub = cJSON_GetObjectItem(sub_array, "i");
-		id = sub->valueint;
-		//        printf("id=%d \r\n", id);
-
-		if(id > 0)
-		{
-			sub = cJSON_GetObjectItemCaseSensitive(sub_array, "T");
-			Tt = sub->valuedouble;
-			//        printf("Tt=%f \r\n", Tt);
-
-			sub = cJSON_GetObjectItemCaseSensitive(sub_array, "t");
-			Tt1 = sub->valuedouble;
-			//        printf("Tt1=%f \r\n", Tt1);
-		}
-		else
-		{
-			Tt = 0;
-			Tt1 = 0;
-		}
-
-		info->hole_info[i].item = id;
-		info->hole_info[i].TtMax[0] = (uint8_t)Tt;
-		info->hole_info[i].TtMax[1] = (uint8_t)((Tt -(uint8_t)Tt)* 100);
-		info->hole_info[i].TtMin[0] = (uint8_t)Tt1;
-		info->hole_info[i].TtMin[1] = (uint8_t)((Tt1 -(uint8_t)Tt1)* 100);
-	}
-	// 记得删除json
-	cJSON_Delete(root);
-	return 0;
-}
-

+ 0 - 34
DriverInterface/van_BSP_Scanner.h

@@ -1,34 +0,0 @@
-/*
- * uart_rcv.h
- *
- *  Created on: 2022年4月20日
- *      Author: dell
- */
-
-#ifndef VAN_BAP_SCANNER_H_
-#define VAN_BAP_SCANNER_H_
-
-enum QR_CHECH_STATE
-{
-	QR_CHECH_STATE_FIRST = 0,
-	QR_CHECH_STATE_TRYAGAIN = 1,
-	QR_CHECH_STATE_WAITING= 3,
-	QR_CHECH_STATE_SEND= 4,
-};
-enum QR_REC_STATE
-{
-	QR_REC_STATE_EMPTY = 0,
-	QR_REC_STATE_HEADER ,
-	QR_REC_STATE_SENDPRAM,
-	QR_REC_STATE_SENDQR,
-	QR_REC_STATE_END,
-};
-
-
-int parse_qrcode_info(struct str_card_param_info *info, char *qrcode_str);
-void QRparam_upload(str_card_param_info_t *p_str_card_param_info);
-void svanner_receive_Rec_IDLE(UART_HandleTypeDef *huart);
-void svanner_receive_Rec_Start(UART_HandleTypeDef *huart);
-void svanner_receive_analysis(void);
-void reSend_QR(void);
-#endif /* UART_RCV_H_ */

+ 0 - 1000
DriverInterface/van_bsp_uart_fun.c

@@ -1,1000 +0,0 @@
-
-/******************************************************************
-*  Copyright (C) 2023 - 2023 OneChip, Inc. All rights reserved.
-* File name: van_bsp_uart_fun.c
-* Author: fanyidong 	 Date:2020.11.21
-* Description:		STM32串口接收函数
-* Others:
-* History:
-        1. Date:
-                 Author:
-                 Modification:
-
-*****************************************************************/
-
-#include "van_bsp_debug_uart.h"
-#include <string.h>
-
-/* USER CODE BEGIN Private defines */
-
-#define RECEIVELEN 1024
-#define USART_DMA_SENDING 1   //发送未完成
-#define USART_DMA_SENDOVER 0  //发送完成
-#define USART_DMA_COPY 1      //拷贝中
-#define USART_DMA_COPYOVER 0  //拷贝完成
-typedef struct {
-  unsigned int receive_flag;      //空闲接收标记
-  unsigned int dmaSend_flag;      //发送完成标记
-  unsigned int dmaCopy_flag;      //发送拷贝标记
-  osMutexId_t mutex_dmaCopy;  
-  unsigned int rx_head;           //接收头
-  unsigned int tx_head;           //发送头
-  unsigned int rx_last;           //接收尾
-  unsigned int tx_last;           //发送尾
-  unsigned int rx_max_len;        //接收缓冲区长度
-  unsigned int tx_max_len;        //发送缓冲区长度
-  unsigned int rx_DMA_len;        //接收长度
-  unsigned int tx_DMA_len;        //接收长度
-  unsigned char *usartDMA_RxBuf;  // DMA接收缓存
-  unsigned char *usart_RxBuf;     // 接收缓冲区
-  unsigned char *usartDMA_TxBuf;  // DMA发送缓存
-  unsigned char *usart_TxBuf;     // 发送缓冲区
-  UART_HandleTypeDef *huart;
-  
-  unsigned int uartError;      //串口错误
-} USART_COM_RECEIVETYPE, *pUSART_COM_RECEIVETYPE;
-
-#define SYS_CTR_DMA_LEN 256
-#define SYS_CTR_BUF_LEN 1024
-USART_COM_RECEIVETYPE sys_ctr_uart;
-unsigned char sys_ctr_tDMA_RxBuf[SYS_CTR_DMA_LEN + 4] = {0};
-unsigned char sys_ctr_tDMA_TxBuf[SYS_CTR_DMA_LEN + 4] = {0};
-unsigned char sys_ctr_RxBuf[SYS_CTR_BUF_LEN];
-unsigned char sys_ctr_TxBuf[SYS_CTR_BUF_LEN];
-CmdMessage sys_ctr_Message;
-unsigned char sys_ctr_data[SYS_CTR_BUF_LEN];
-
-
-#define THD_NTCSAMP_DMA_LEN 32
-#define THD_NTCSAMP_BUF_LEN 64
-USART_COM_RECEIVETYPE THD_NTCSAMP_uart;
-unsigned char THD_NTCSAMP_tDMA_RxBuf[THD_NTCSAMP_DMA_LEN + 4] = {0};
-unsigned char THD_NTCSAMP_tDMA_TxBuf[THD_NTCSAMP_DMA_LEN + 4] = {0};
-unsigned char THD_NTCSAMP_RxBuf[THD_NTCSAMP_BUF_LEN];
-unsigned char THD_NTCSAMP_TxBuf[THD_NTCSAMP_BUF_LEN];
-unsigned char THD_NTCSAMP_Message[32];
-unsigned char THD_NTCSAMP_data[SYS_CTR_BUF_LEN];
-
-unsigned int p_rec_flag = 0;
-unsigned int p_rec_data_flag = 0;
-unsigned int p_DecodeNew = 0;
-unsigned int p_Rep_flag = 0;
-unsigned int p_Rep_data_flag = 0;
-unsigned int p_Ans_flag = 0;
-unsigned int p_Ans_data_flag = 0;
-unsigned int p_Ans_flag_1 = 0;
-unsigned int p_Ans_data_flag_1 = 0;
-unsigned char sedbuf[SYS_CTR_BUF_LEN];
-unsigned int sedbuf_len;
-
-
-extern DMA_HandleTypeDef hdma_uart7_rx;
-
-extern UART_HandleTypeDef huart7;
-unsigned int resetSysUart ;
-typedef struct
-{
-  __IO uint32_t ISR;   /*!< DMA interrupt status register */
-  __IO uint32_t Reserved0;
-  __IO uint32_t IFCR;  /*!< DMA interrupt flag clear register */
-} DMA_Base_Registers;
-
- #define osMutexPrioInherit    0x00000002U    // 继承锁  继承等待线程中更高的优先级
-const osMutexAttr_t Mutex_attr1 = {
-  "myThreadMutex",     // human readable mutex name
-  osMutexPrioInherit,  // attr_bits
-  NULL,                // memory for control block   
-  0U                   // size for control block
-};
-
-/****************************************************************
-* 函数名:    Van_UART_Fun_TxCpltCallback
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明: DMA 发送中断
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_UART_Fun_TxCpltCallback_Base(pUSART_COM_RECEIVETYPE uartinf) {
-  UART_HandleTypeDef *huart = uartinf->huart;
-  __HAL_DMA_DISABLE(huart->hdmatx);
-  unsigned int dataleninTxbuf = (uartinf->tx_last + uartinf->tx_max_len - uartinf->tx_head) % uartinf->tx_max_len;
-  if (dataleninTxbuf) {
-    memset((void *)uartinf->usartDMA_TxBuf, 0, uartinf->tx_DMA_len);
-    if (dataleninTxbuf >= uartinf->tx_DMA_len) {
-      if (uartinf->tx_max_len >= (uartinf->tx_head + uartinf->tx_DMA_len)) {
-        memcpy((void *)uartinf->usartDMA_TxBuf, (const void *)(uartinf->usart_TxBuf + uartinf->tx_head), uartinf->tx_DMA_len);
-        uartinf->tx_head += uartinf->tx_DMA_len;
-        Van_Device_Printf(VAN_LOG_DEBUG, "line:%d head:%d last:%d \n\r", __LINE__, uartinf->tx_head, uartinf->tx_last);
-      } else {
-        memcpy((void *)uartinf->usartDMA_TxBuf, (const void *)(uartinf->usart_TxBuf + uartinf->tx_head), (uartinf->tx_max_len - uartinf->tx_head));
-        unsigned int secondcopelen = uartinf->tx_DMA_len - (uartinf->tx_max_len - uartinf->tx_head);
-        memcpy((void *)(uartinf->usartDMA_TxBuf + uartinf->tx_max_len - uartinf->tx_head), (const void *)uartinf->usart_TxBuf, secondcopelen);
-        uartinf->tx_head = secondcopelen;
-        Van_Device_Printf(VAN_LOG_DEBUG, "line:%d head:%d last:%d \n\r", __LINE__, uartinf->tx_head, uartinf->tx_last);
-      }
-      Van_Device_Printf(VAN_LOG_DEBUG, "len:%d %s\n\r***", uartinf->tx_DMA_len, uartinf->usartDMA_TxBuf);
-      HAL_UART_Transmit_DMA(huart, uartinf->usartDMA_TxBuf, uartinf->tx_DMA_len);
-    } else {
-      if (uartinf->tx_max_len >= (uartinf->tx_head + dataleninTxbuf)) {
-        memcpy((void *)uartinf->usartDMA_TxBuf, (const void *)(uartinf->usart_TxBuf + uartinf->tx_head), dataleninTxbuf);
-        uartinf->tx_head += dataleninTxbuf;
-        Van_Device_Printf(VAN_LOG_DEBUG, "line:%d head:%d last:%d \n\r", __LINE__, uartinf->tx_head, uartinf->tx_last);
-      } else {
-        memcpy((void *)uartinf->usartDMA_TxBuf, (const void *)(uartinf->usart_TxBuf + uartinf->tx_head), (uartinf->tx_max_len - uartinf->tx_head));
-        unsigned int secondcopelen = dataleninTxbuf - (uartinf->tx_max_len - uartinf->tx_head);
-        memcpy((void *)(uartinf->usartDMA_TxBuf + uartinf->tx_max_len - uartinf->tx_head), (const void *)uartinf->usart_TxBuf, secondcopelen);
-        uartinf->tx_head = secondcopelen;
-        Van_Device_Printf(VAN_LOG_DEBUG, "line:%d head:%d last:%d \n\r", __LINE__, uartinf->tx_head, uartinf->tx_last);
-      }
-      Van_Device_Printf(VAN_LOG_DEBUG, "len:%d %s\n\r***", dataleninTxbuf, uartinf->usartDMA_TxBuf);
-      HAL_UART_Transmit_DMA(huart, uartinf->usartDMA_TxBuf, dataleninTxbuf);
-    }
-    uartinf->dmaSend_flag = USART_DMA_SENDING;
-  } else {
-    uartinf->dmaSend_flag = USART_DMA_SENDOVER;
-  }
-}
-/****************************************************************
-* 函数名:    Van_UART_Fun_Send_DMA
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明: DMA 发送
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_UART_Fun_Send_DMA_Base(unsigned char *pdata, unsigned int Length, pUSART_COM_RECEIVETYPE uartinf) {
-  UART_HandleTypeDef *huart = uartinf->huart;
-  /*超长不拷贝*/
-
-//  Van_Device_Printf(VAN_LOG_NOTICE, "head:%d last:%d Length:%d %s\n\r", uartinf->tx_head, uartinf->tx_last, Length, pdata);
-  if (Length > uartinf->tx_max_len) {
-    Length = uartinf->tx_max_len;
-  }
-//  while (uartinf->dmaCopy_flag == USART_DMA_COPY);
-//  uartinf->dmaCopy_flag = USART_DMA_COPY;
-  __disable_irq(); 
-  osMutexAcquire(uartinf->mutex_dmaCopy,0xffffffff);
-  if ((Length + uartinf->tx_last) < uartinf->tx_max_len) {
-    memcpy((void *)(uartinf->usart_TxBuf + uartinf->tx_last), (const void *)pdata, Length);
-    uartinf->tx_last += Length;
-//    Van_Device_Printf(VAN_LOG_NOTICE, "head:%d last:%d \n\r", uartinf->tx_head, uartinf->tx_last);
-  } else {
-    memcpy((void *)(uartinf->usart_TxBuf + uartinf->tx_last), (const void *)pdata, (uartinf->tx_max_len - uartinf->tx_last));
-
-    unsigned int secondcopelen = Length - (uartinf->tx_max_len - uartinf->tx_last);
-    memcpy((void *)uartinf->usart_TxBuf, (const void *)(pdata + (uartinf->tx_max_len - uartinf->tx_last)), secondcopelen);
-    uartinf->tx_last = secondcopelen;
-//    Van_Device_Printf(VAN_LOG_NOTICE, "head:%d last:%d \n\r", uartinf->tx_head, uartinf->tx_last);
-  }  
-//  osMutexRelease(uartinf->mutex_dmaCopy);
-//  uartinf->dmaCopy_flag = USART_DMA_COPYOVER;
-  if (uartinf->dmaSend_flag == USART_DMA_SENDOVER) {
-    unsigned int dataleninTxbuf = (uartinf->tx_last + uartinf->tx_max_len - uartinf->tx_head) % uartinf->tx_max_len;
-    if (dataleninTxbuf) 
-    {
-      memset((void *)uartinf->usartDMA_TxBuf, 0, uartinf->tx_DMA_len);
-      if (dataleninTxbuf >= uartinf->tx_DMA_len) 
-      {
-        if (uartinf->tx_max_len >= (uartinf->tx_head + uartinf->tx_DMA_len)) 
-        {
-          memcpy((void *)uartinf->usartDMA_TxBuf, (const void *)(uartinf->usart_TxBuf + uartinf->tx_head), uartinf->tx_DMA_len);
-          uartinf->tx_head += uartinf->tx_DMA_len;
-//          Van_Device_Printf(VAN_LOG_NOTICE, "line:%d head:%d last:%d \n\r", __LINE__, uartinf->tx_head, uartinf->tx_last);
-        } 
-        else 
-        {
-          memcpy((void *)uartinf->usartDMA_TxBuf, (const void *)(uartinf->usart_TxBuf + uartinf->tx_head), (uartinf->tx_max_len - uartinf->tx_head));
-          unsigned int secondcopelen = uartinf->tx_DMA_len - (uartinf->tx_max_len - uartinf->tx_head);
-          memcpy((void *)(uartinf->usartDMA_TxBuf + uartinf->tx_max_len - uartinf->tx_head), (const void *)uartinf->usart_TxBuf, secondcopelen);
-          uartinf->tx_head = secondcopelen;
-//          Van_Device_Printf(VAN_LOG_NOTICE, "line:%d head:%d last:%d \n\r", __LINE__, uartinf->tx_head, uartinf->tx_last);
-        } 
-
-//        Van_Device_Printf(VAN_LOG_NOTICE, "len:%d %s\n\r***", uartinf->tx_DMA_len, uartinf->usartDMA_TxBuf);
-        HAL_UART_Transmit_DMA(huart, uartinf->usartDMA_TxBuf, uartinf->tx_DMA_len);
-      } 
-      else 
-      {
-        if (uartinf->tx_max_len >= (uartinf->tx_head + dataleninTxbuf)) 
-        {
-          memcpy((void *)uartinf->usartDMA_TxBuf, (const void *)(uartinf->usart_TxBuf + uartinf->tx_head), dataleninTxbuf);
-          uartinf->tx_head += dataleninTxbuf;
-//          Van_Device_Printf(VAN_LOG_NOTICE, "line:%d head:%d last:%d \n\r", __LINE__, uartinf->tx_head, uartinf->tx_last);
-        } 
-        else 
-        {
-          memcpy((void *)uartinf->usartDMA_TxBuf, (const void *)(uartinf->usart_TxBuf + uartinf->tx_head), (uartinf->tx_max_len - uartinf->tx_head));
-          unsigned int secondcopelen = dataleninTxbuf - (uartinf->tx_max_len - uartinf->tx_head);
-          memcpy((void *)(uartinf->usartDMA_TxBuf + uartinf->tx_max_len - uartinf->tx_head), (const void *)uartinf->usart_TxBuf, secondcopelen);
-          uartinf->tx_head = secondcopelen;
-//          Van_Device_Printf(VAN_LOG_NOTICE, "line:%d head:%d last:%d \n\r", __LINE__, uartinf->tx_head, uartinf->tx_last);
-        }
-//        Van_Device_Printf(VAN_LOG_NOTICE, "len:%d %s\n\r***", dataleninTxbuf, uartinf->usartDMA_TxBuf);
-        HAL_UART_Transmit_DMA(huart, uartinf->usartDMA_TxBuf, dataleninTxbuf);
-      }
-      uartinf->dmaSend_flag = USART_DMA_SENDING;
-    }
-//    else
-//      Van_Device_Printf(VAN_LOG_INFO, "HAL_UART_Transmit_DMA dataleninTxbuf == 0\n");
-  }
-  osMutexRelease(uartinf->mutex_dmaCopy);
-__enable_irq();
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Fun_RxCpltCallback
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明: DMA接收处理
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_UART_Fun_RxCplt_Base(pUSART_COM_RECEIVETYPE uartinf) {
-  UART_HandleTypeDef *huart = uartinf->huart;
-  uint32_t temp;
-
-  HAL_UART_DMA_RX_Stop(huart);
-  // 停止DMA接收
-  DMA_Stream_TypeDef *dma = huart->hdmarx->Instance;
-  temp = dma->NDTR;
-  unsigned int dataleninRxDMAbuf = uartinf->rx_DMA_len - temp;
-  uint32_t isrst = huart->Instance->ISR;
-  uint32_t dmacr = dma->CR;
-//  Van_Device_Printf(VAN_LOG_NOTICE, "%s %d addr:%x %d-%d=%d\n\r", __func__, __LINE__, (unsigned int)uartinf->usartDMA_RxBuf, uartinf->rx_DMA_len, temp,
-//                    dataleninRxDMAbuf);
-//  Van_Device_Printf(VAN_LOG_NOTICE, "%x %x\n\r", isrst, dmacr);
-  if (dataleninRxDMAbuf) {
-		if(dataleninRxDMAbuf > uartinf->rx_max_len){
-		   Van_Device_Printf(VAN_LOG_NOTICE, "*******************rec %d  clean*******************\n\r", dataleninRxDMAbuf);
-		}else{
-    //		 Van_Device_Printf(VAN_LOG_NOTICE, "Cplt len:%d %s\n\r***",dataleninRxDMAbuf,uartinf->usartDMA_RxBuf);
-    if ((dataleninRxDMAbuf + uartinf->rx_last) <= uartinf->rx_max_len) {
-      memcpy((void *)(uartinf->usart_RxBuf + uartinf->rx_last), (const void *)uartinf->usartDMA_RxBuf, dataleninRxDMAbuf);
-      uartinf->rx_last += dataleninRxDMAbuf;
-      //Van_Device_Printf(VAN_LOG_NOTICE, "rx_last 1:%d  %d  \n\r", uartinf->rx_last, uartinf->rx_head);
-    } else {
-      memcpy((void *)(uartinf->usart_RxBuf + uartinf->rx_last), (const void *)uartinf->usartDMA_RxBuf, (uartinf->rx_max_len - uartinf->rx_last));
-      unsigned int secondcopelen = dataleninRxDMAbuf - (uartinf->rx_max_len - uartinf->rx_last);
-      memcpy((void *)uartinf->usart_RxBuf, (const void *)(uartinf->usartDMA_RxBuf + (uartinf->rx_max_len - uartinf->rx_last)), secondcopelen);
-      uartinf->rx_last = secondcopelen;
-     // Van_Device_Printf(VAN_LOG_NOTICE, "rx_last 2 :%d  %d \n\r", uartinf->rx_last, uartinf->rx_head,dataleninRxDMAbuf,uartinf->rx_max_len );
-    }
-    uartinf->receive_flag = 1;
-	  sysinf.reccmd_conter = sysinf.ms_conter;		
-		}
-
-    memset((void *)uartinf->usartDMA_RxBuf, 0, uartinf->rx_DMA_len);
-    // 重启DMA接收
-
-    HAL_UART_Receive_DMA((UART_HandleTypeDef *)huart, uartinf->usartDMA_RxBuf, uartinf->rx_DMA_len);
-    dmacr = dma->CR;
-//   Van_Device_Printf(VAN_LOG_NOTICE, "rx len %d\n\r", uartinf->rx_DMA_len);
-  }
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Fun_Rec_IDLE
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明: 接收处理
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_UART_Fun_Rec_IDLE_Base(pUSART_COM_RECEIVETYPE uartinf) {
-  UART_HandleTypeDef *huart = uartinf->huart;
-  if ((__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE) != RESET)) {
-    __HAL_UART_CLEAR_IDLEFLAG(huart);
-    Van_UART_Fun_RxCplt_Base(uartinf);
-//    Van_Device_Printf(VAN_LOG_NOTICE, "%s %d\n\r", __func__, __LINE__);
-  }
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Fun_ErrorCallback
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:异常后处理
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_UART_Fun_ErrorCallback_Base(pUSART_COM_RECEIVETYPE uartinf) {
-  UART_HandleTypeDef *huart = uartinf->huart;
-
-  DMA_HandleTypeDef *pdma;
-  
-  Van_Device_Printf(VAN_LOG_ERROR, "Van_UART_Fun_ErrorCallback_Base %8x  dmaTX%8x  dmaRX%8x\n\r",huart->ErrorCode, huart->hdmatx->ErrorCode, huart->hdmarx->ErrorCode);
-  
-  //if (huart->ErrorCode == (HAL_UART_ERROR_NE | HAL_UART_ERROR_ORE)) 
-//{
-	  uartinf->uartError = True;
-    __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_OREF | UART_CLEAR_NEF | UART_CLEAR_PEF | UART_CLEAR_FEF);
-//  }
-  
-  pdma = huart->hdmatx;
-  if (pdma->ErrorCode) {
-    __HAL_DMA_DISABLE(huart->hdmatx);
-    uartinf->dmaSend_flag = USART_DMA_SENDOVER;
-  }
-  pdma = huart->hdmarx;
-  if ( pdma->ErrorCode) {
-    __HAL_DMA_DISABLE(huart->hdmarx);
-    HAL_UART_Receive_DMA((UART_HandleTypeDef *)huart, uartinf->usartDMA_RxBuf, RECEIVELEN);
-    __HAL_UART_ENABLE_IT((UART_HandleTypeDef *)huart, UART_IT_IDLE);
-//	Van_Device_Printf(VAN_LOG_ERROR, "huart rx dma reset\n\r");
-  }
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Fun_Rec_IDLE
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:空闲中断回调处理
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-
-void Van_UART_Fun_TxCpltCallback(UART_HandleTypeDef *huart) {
-  UART_HandleTypeDef *pUart = sys_ctr_uart.huart;
-  UART_HandleTypeDef *pTHD_NTCSAMPUart = THD_NTCSAMP_uart.huart;
-  if (huart->Instance == pUart->Instance) {
-    Van_UART_Fun_TxCpltCallback_Base(&sys_ctr_uart);
-  }else if (huart->Instance == pTHD_NTCSAMPUart->Instance) {    
-     Van_UART_Fun_TxCpltCallback_Base(&THD_NTCSAMP_uart);
-  }
-  return;
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Fun_Rec_IDLE
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:空闲中断回调处理
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-
-void Van_UART_Fun_RxCpltCallback(UART_HandleTypeDef *huart) {
-  UART_HandleTypeDef *pUart = sys_ctr_uart.huart;
-  UART_HandleTypeDef *pTHD_NTCSAMPUart = THD_NTCSAMP_uart.huart;
-  if (huart->Instance == pUart->Instance) {
-    Van_UART_Fun_RxCplt_Base(&sys_ctr_uart);
-//    Van_Device_Printf(VAN_LOG_NOTICE, "%s %d\n\r", __func__, __LINE__);
-  }else if (huart->Instance == pTHD_NTCSAMPUart->Instance) {    
-    Van_UART_Fun_RxCplt_Base(&THD_NTCSAMP_uart);
-  }
-  return;
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Fun_Rec_IDLE
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:空闲中断回调处理
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-
-void Van_UART_Fun_ErrorCallback(UART_HandleTypeDef *huart) {
-  UART_HandleTypeDef *pUart = sys_ctr_uart.huart;
-  UART_HandleTypeDef *pTHD_NTCSAMPUart = THD_NTCSAMP_uart.huart;
-  if (huart->Instance == pUart->Instance) {
-    Van_UART_Fun_ErrorCallback_Base(&sys_ctr_uart);
-  }else if (huart->Instance == pTHD_NTCSAMPUart->Instance) {    
-    Van_UART_Fun_ErrorCallback_Base(&THD_NTCSAMP_uart);
-  } 
-  return;
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Fun_Rec_IDLE
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:空闲中断回调处理
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-
-void Van_UART_Fun_Rec_IDLE(UART_HandleTypeDef *huart) {
-  UART_HandleTypeDef *pUart = sys_ctr_uart.huart;
-  UART_HandleTypeDef *pTHD_NTCSAMPUart = THD_NTCSAMP_uart.huart;
-  if (huart->Instance == pUart->Instance) {
-    Van_UART_Fun_Rec_IDLE_Base(&sys_ctr_uart);
-//    Van_Device_Printf(VAN_LOG_NOTICE, "%s %d\n\r", __func__, __LINE__);
-  }else if (huart->Instance == pTHD_NTCSAMPUart->Instance) {
-    Van_UART_Fun_Rec_IDLE_Base(&THD_NTCSAMP_uart);
-//    Van_Device_Printf(VAN_LOG_NOTICE, "%s %d\n\r", __func__, __LINE__);
-  }else{
-	if ((__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE) != RESET)) {
-	  char	Name[16] = {0};
-	  __HAL_UART_CLEAR_IDLEFLAG(huart);
-	  find_stm32_Peripherals(huart,Name);
-	   Van_Device_Printf(VAN_LOG_NOTICE, "%s %s %d\n\r", Name,__func__);
-	}
-  }
-  return;
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Fun_Send_DMA
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明: DMA 发送
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_UART_Fun_Send_DMA(unsigned char *pdata, unsigned int Length, UART_HandleTypeDef *huart) {
-  UART_HandleTypeDef *pUart = sys_ctr_uart.huart;
-  UART_HandleTypeDef *pTHD_NTCSAMPUart = THD_NTCSAMP_uart.huart;
-  if (huart->Instance == pUart->Instance) {
-    
-    Van_UART_Fun_Send_DMA_Base(pdata, Length, &sys_ctr_uart);
-  }else if (huart->Instance == pTHD_NTCSAMPUart->Instance) {    
-    Van_UART_Fun_Send_DMA_Base(pdata, Length, &THD_NTCSAMP_uart);
-  } 
-  return;
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Sys_Ctr_Send_type
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:系统命令发送
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_UART_Sys_Ctr_Send_type(unsigned char type, unsigned char *pdata, unsigned int Length) {
-  struct CmdMessage msg = {0};
-  unsigned char sedbuf[SYS_CTR_BUF_LEN];
-  unsigned int checksum = 0;
-  combine_cmdMessage(msg, VAN_COM_HEADER_FALG, type, VAN_CFG_NONE, VAN_COM_TAIL_FALG);
-  msg.len = Length;
-  *(unsigned short *)sedbuf = msg.head;
-  sedbuf[2] = msg.type;
-  sedbuf[3] = msg.cmd;
-  *(unsigned short *)(sedbuf + 4) = msg.len;
-  for (unsigned int i = 0; i < msg.len; i++) {
-    sedbuf[6 + i] = pdata[i];
-  }
-  checksum = checkSum(&sedbuf[2], msg.len + 4);
-  sedbuf[6 + msg.len] = checksum & 0xff; /*结尾标记高位*/
-  sedbuf[7 + msg.len] = checksum >> 8;   /*结尾标记低位*/
-  if(p_Rep_flag){
-  	  unsigned int alllen = msg.len + 8;
-	  Van_Device_Printf(VAN_LOG_NOTICE, "ans: len%:d \n\r",alllen);
-	  if(p_Rep_data_flag){
-		  for(int i=0; i <alllen; i++){
-			  Van_Device_Printf(VAN_LOG_NOTICE, "%2x ", sedbuf[i]);
-			  if(i%32==31){
-				 Van_Device_Printf(VAN_LOG_NOTICE, "\n\r"); 
-			  }
-		  }
-		  Van_Device_Printf(VAN_LOG_NOTICE, "\n\r");
-	  }
-  }
-  Van_UART_Fun_Send_DMA(sedbuf, Length + 8, sys_ctr_uart.huart);
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Sys_Ctr_Send
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:系统命令发送
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_UART_Sys_Ctr_Send(unsigned char *pdata, unsigned int Length) {
-  struct CmdMessage msg = {0};
-  unsigned int checksum = 0;
-  combine_cmdMessage(msg, VAN_COM_HEADER_FALG, MSG_SYS_CTR, VAN_CFG_NONE, VAN_COM_TAIL_FALG);
-  sedbuf_len = Length + 8;
-  msg.len = Length;
-  *(unsigned short *)sedbuf = msg.head;
-  sedbuf[2] = msg.type;
-  sedbuf[3] = msg.cmd;
-  *(unsigned short *)(sedbuf + 4) = msg.len;
-  for (unsigned int i = 0; i < msg.len; i++) {
-    sedbuf[6 + i] = pdata[i];
-  }
-  checksum = checkSum(&sedbuf[2], msg.len + 4);
-  sedbuf[6 + msg.len] = checksum & 0xff; /*结尾标记高位*/
-  sedbuf[7 + msg.len] = checksum >> 8;   /*结尾标记低位*/
-  if(p_Ans_flag){
-  	  unsigned int alllen = msg.len + 8;
-	  Van_Device_Printf(VAN_LOG_NOTICE, "ans len: %d \n\r",alllen);
-	  if(p_Ans_data_flag){
-		  for(int i=0; i <alllen; i++){
-			  Van_Device_Printf(VAN_LOG_NOTICE, "%2x ", sedbuf[i]);
-			  if(i%32==31){
-				 Van_Device_Printf(VAN_LOG_NOTICE, "\n\r"); 
-			  }
-		  }
-		  Van_Device_Printf(VAN_LOG_NOTICE, "\n\r");
-	  }
-  }
-  Van_UART_Fun_Send_DMA(sedbuf, sedbuf_len, sys_ctr_uart.huart);
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Sys_Ctr_SendNoBuf
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:主动上报,不缓存
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_UART_Sys_Ctr_SendNoBuf(unsigned char *pdata, unsigned int Length) {
-  struct CmdMessage msg = {0};
-  unsigned int checksum = 0;
-  combine_cmdMessage(msg, VAN_COM_HEADER_FALG, MSG_SYS_CTR, VAN_CFG_NONE, VAN_COM_TAIL_FALG);  
-  unsigned char sedbuf[SYS_CTR_BUF_LEN];
-  unsigned int sedbuf_len;
-  sedbuf_len = Length + 8;
-  msg.len = Length;
-  *(unsigned short *)sedbuf = msg.head;
-  sedbuf[2] = msg.type;
-  sedbuf[3] = msg.cmd;
-  *(unsigned short *)(sedbuf + 4) = msg.len;
-  for (unsigned int i = 0; i < msg.len; i++) {
-    sedbuf[6 + i] = pdata[i];
-  }
-  checksum = checkSum(&sedbuf[2], msg.len + 4);
-  sedbuf[6 + msg.len] = checksum & 0xff; /*结尾标记高位*/
-  sedbuf[7 + msg.len] = checksum >> 8;   /*结尾标记低位*/
-  if(p_Ans_flag_1){
-  	  unsigned int alllen = msg.len + 8;
-	  Van_Device_Printf(VAN_LOG_NOTICE, "ans len: %d \n\r",alllen);
-	  if(p_Ans_data_flag_1){
-		  for(int i=0; i <alllen; i++){
-			  Van_Device_Printf(VAN_LOG_NOTICE, "%2x ", sedbuf[i]);
-			  if(i%32==31){
-				 Van_Device_Printf(VAN_LOG_NOTICE, "\n\r"); 
-			  }
-		  }
-		  Van_Device_Printf(VAN_LOG_NOTICE, "\n\r");
-	  }
-  }
-  Van_UART_Fun_Send_DMA(sedbuf, sedbuf_len, sys_ctr_uart.huart);
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Sys_Ctr_Send_Again
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:应答消息重新发送
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_UART_Sys_Ctr_Send_Again(void) {
-  Van_UART_Fun_Send_DMA(sedbuf, sedbuf_len, sys_ctr_uart.huart);
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Sys_Ttr_Init
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:系统命令串口挂载
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_UART_Sys_Ctr_Init(UART_HandleTypeDef *puart) {
-  sys_ctr_uart.huart = puart;
-  sys_ctr_uart.usartDMA_RxBuf = sys_ctr_tDMA_RxBuf;
-  sys_ctr_uart.usartDMA_TxBuf = sys_ctr_tDMA_TxBuf;
-  sys_ctr_uart.usart_RxBuf = sys_ctr_RxBuf;
-  sys_ctr_uart.usart_TxBuf = sys_ctr_TxBuf;
-  sys_ctr_uart.tx_DMA_len = SYS_CTR_DMA_LEN;
-  sys_ctr_uart.rx_DMA_len = SYS_CTR_DMA_LEN;
-  sys_ctr_uart.rx_max_len = SYS_CTR_BUF_LEN;
-  sys_ctr_uart.tx_max_len = SYS_CTR_BUF_LEN;
-  sys_ctr_uart.rx_last = 0;
-  sys_ctr_uart.rx_head = 0;
-  sys_ctr_uart.tx_last = 0;
-  sys_ctr_uart.tx_head = 0;
-  sys_ctr_uart.uartError = False;
-  memset((void *)sys_ctr_uart.usartDMA_RxBuf, 0, sys_ctr_uart.rx_DMA_len + 4);
-  HAL_UART_Receive_DMA(puart, sys_ctr_uart.usartDMA_RxBuf, SYS_CTR_DMA_LEN);
-  __HAL_UART_CLEAR_IDLEFLAG(puart);
-  __HAL_UART_CLEAR_FLAG(puart, UART_CLEAR_OREF | UART_CLEAR_NEF | UART_CLEAR_PEF | UART_CLEAR_FEF);
-  //	__HAL_UART_CLEAR_OREFLAG(puart);
-  __HAL_UART_ENABLE_IT(puart, UART_IT_IDLE);
-  __HAL_UART_ENABLE_IT(puart, UART_IT_ERR);
-  
-  sys_ctr_uart.mutex_dmaCopy = osMutexNew(&Mutex_attr1);
-}
-
-
-
-/****************************************************************
-* 函数名:    Van_UART_Fun_RawdataDeal
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:串口接收元数据处理
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_RawdataDeal_dispatch(void* pram)
-{
-	unsigned int anslen = 0;
-	P_RawdataMessage pcmd = (P_RawdataMessage)pram;
-	RawdataMessage Ans ;
-	Ans.fuid = pcmd->fuid;
-	Ans.cmd = 0;
-	anslen = sizeof(Ans) - sizeof(Ans.data);
-	switch(pcmd->cmd){
-		case RAW_V1_SET_PID_SEC_OFFSET:
-			Ans.cmd = PidSetSectionOffsetDirect((void*)pcmd->data,(void*)Ans.data);
-			anslen = 8+sizeof(pidSectionOffset_ST_Def);
-			break;
-		case RAW_V1_GET_PID_SEC_OFFSET:
-			Ans.cmd = PidGetSectionOffsetDirect((void*)pcmd->data,(void*)Ans.data);
-			if(Ans.cmd){
-				P_pidSectionOffset_ST_Def poffset = (P_pidSectionOffset_ST_Def)Ans.data;
-				anslen = 8+sizeof(pidSectionOffset_ST_Def);
-			    Van_Device_Printf(VAN_LOG_NOTICE, "mPidNum:%d sectionNum:%d\n\r***", poffset->mPidNum ,poffset->sectionNum );
-			}
-			break;	
-		case RAW_V1_SET_PID_SINGEPIDOFFSET:
-			Ans.cmd = PidSetSinglPIDDirect((void*)pcmd->data,(void*)Ans.data);
-			break;
-		case RAW_V1_GET_PID_SINGEPIDOFFSET:
-			Ans.cmd = PidGetSinglPIDDirect((void*)pcmd->data,(void*)Ans.data);
-			if(Ans.cmd){
-				P_pidSectionOffset_ST_Def poffset = (P_pidSectionOffset_ST_Def)Ans.data;
-				anslen += sizeof(P_pidSignlePidPram_ST_Def);
-			    Van_Device_Printf(VAN_LOG_NOTICE, "mPidNum:%d sectionNum:%d\n\r***", poffset->mPidNum ,poffset->sectionNum );
-			}
-			break;	
-		case RAW_V1_SET_QUADRATICFIT:
-			Ans.cmd = PidSetQuadraticfitDirect((void*)pcmd->data,(void*)Ans.data);
-			break;
-		case RAW_V1_GET_QUADRATICFIT:
-			Ans.cmd = PidGetQuadraticfitDirect((void*)pcmd->data,(void*)Ans.data);
-			if(Ans.cmd){
-				P_quadraticfit_ST_Def poffset = (P_quadraticfit_ST_Def)Ans.data;
-				anslen += sizeof(quadraticfit_ST_Def);
-			}
-			break;	
-
-			
-		case RAW_V1_GET_PID_MULT_PRAM:{
-			Ans.cmd = PidMultSectionPramGetDirect((void*)pcmd->data,(void*)Ans.data);
-			if(Ans.cmd){
-				anslen += 64;
-			}
-			
-		}
-			break;
-		case RAW_V1_SET_PID_MULT_PRAM:{
-			Ans.cmd = PidMultSectionPramSetDirect((void*)pcmd->data,(void*)Ans.data);
-			if(Ans.cmd){
-				anslen += 64;
-			}
-			
-		}
-			break;
-	}
-	Van_UART_Sys_Ctr_Send_type(MSG_RAW_DATA_1,(void *)&Ans,anslen);
-}
-
-
-/****************************************************************
-* 函数名:    Van_UART_Fun_RawdataDeal
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:串口接收元数据处理
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_UART_Fun_RawdataDeal(void) {
-static int conter10ms = 0;
-  if (sys_ctr_uart.receive_flag)  //如果产生了空闲中断
-  {
-    sys_ctr_uart.receive_flag = 0;  //清零标记
-    unsigned int dataleninRxbuf = (sys_ctr_uart.rx_last + sys_ctr_uart.rx_max_len - sys_ctr_uart.rx_head) % sys_ctr_uart.rx_max_len;
-	if(dataleninRxbuf > 64){
-		Van_Device_Printf(VAN_LOG_NOTICE, "buffer have:%d\n\r***", dataleninRxbuf);
-	}
-    if(p_rec_flag){
-		Van_Device_Printf(VAN_LOG_NOTICE, "last:%d head:%d buflen:%d  have:%d\n\r***", sys_ctr_uart.rx_last,sys_ctr_uart.rx_head,sys_ctr_uart.rx_max_len,dataleninRxbuf);
-		if(p_rec_data_flag){
-			for(int i=0; i <dataleninRxbuf; i++){
-				Van_Device_Printf(VAN_LOG_NOTICE, "%2x ", sys_ctr_uart.usart_RxBuf[(i+sys_ctr_uart.rx_head)%sys_ctr_uart.rx_max_len]);
-				if(i%32==31){
-					Van_Device_Printf(VAN_LOG_NOTICE, "\n\r");
-				}
-			}
-			Van_Device_Printf(VAN_LOG_NOTICE, "\n\r");
-		}
-
-	}
-    if (dataleninRxbuf > (sizeof(CmdMessage)-4)) {
-      pbRawdef raw = {0};
-      if (DecodeNew(&sys_ctr_Message, raw.data, sys_ctr_uart.usart_RxBuf, &sys_ctr_uart.rx_head, sys_ctr_uart.rx_last, sys_ctr_uart.rx_max_len)) {
-        raw.datalen = sys_ctr_Message.len;     
-		if(p_DecodeNew){
-			Van_Device_Printf(VAN_LOG_NOTICE, "DecodeNew is ok\n\r");
-		}
-		if(sys_ctr_Message.type == MSG_RAW_DATA_1){		
-			Van_RawdataDeal_dispatch(raw.data);
-			
-		}else{	
-	    	pb_CtrlProto_v1_decode(raw.data, raw.datalen);
-		}
-      }
-    }
-	dataleninRxbuf = (sys_ctr_uart.rx_last + sys_ctr_uart.rx_max_len - sys_ctr_uart.rx_head) % sys_ctr_uart.rx_max_len;
-	if(dataleninRxbuf > (sizeof(CmdMessage)-4)) {
-		sys_ctr_uart.receive_flag = 1;  //缓冲区存在数据,接续解析
-	}
-    
-  }
-  if(resetSysUart){
-	resetSysUart = 0;
-	sys_ctr_uart.uartError = True;
-  }
-  if( sys_ctr_uart.uartError){
-	Van_Device_Printf(VAN_LOG_NOTICE, "reinit sysUart\n\r");
-  	HAL_UART_DMAStop(sys_ctr_uart.huart);
-	sys_ctr_uart.uartError = False;		
-    osDelay(100U);
-    if(sysinf.devdesc.deveice_type == deviceType_deviceETA_004){	
-		MX_UART4_Init();
-	}else{	
- 		MX_UART7_Init();
-	}	
-	memset((void *)sys_ctr_uart.usartDMA_RxBuf, 0, sys_ctr_uart.rx_DMA_len + 4);
-	HAL_UART_Receive_DMA(sys_ctr_uart.huart, sys_ctr_uart.usartDMA_RxBuf, SYS_CTR_DMA_LEN);
-	__HAL_UART_CLEAR_IDLEFLAG(sys_ctr_uart.huart);
-	__HAL_UART_ENABLE_IT(sys_ctr_uart.huart, UART_IT_IDLE);
-	__HAL_UART_ENABLE_IT(sys_ctr_uart.huart, UART_IT_ERR);
-  }
-  conter10ms++;
-  if(conter10ms==200){
-	  if ((__HAL_UART_GET_FLAG(sys_ctr_uart.huart, UART_FLAG_ORE) != RESET)||
-		(__HAL_UART_GET_FLAG(sys_ctr_uart.huart, UART_FLAG_NE) != RESET)||
-		(__HAL_UART_GET_FLAG(sys_ctr_uart.huart, UART_FLAG_FE) != RESET)||
-		(__HAL_UART_GET_FLAG(sys_ctr_uart.huart, UART_FLAG_PE) != RESET)){
-				Van_Device_Printf(VAN_LOG_NOTICE, "sysUart error\n\r");
-				Van_Device_Printf(VAN_LOG_NOTICE, "ISR:%8x \n\r",sys_ctr_uart.huart->Instance->ISR); 
-			    if(sysinf.devdesc.deveice_type == deviceType_deviceETA_004){	
-					MX_UART4_Init();
-				}else{	
-			 		MX_UART7_Init();
-				}	 
-  				HAL_UART_DMAStop(sys_ctr_uart.huart);
-				memset((void *)sys_ctr_uart.usartDMA_RxBuf, 0, sys_ctr_uart.rx_DMA_len + 4);
-				HAL_UART_Receive_DMA(sys_ctr_uart.huart, sys_ctr_uart.usartDMA_RxBuf, SYS_CTR_DMA_LEN);
-				__HAL_UART_CLEAR_IDLEFLAG(sys_ctr_uart.huart);
-				__HAL_UART_ENABLE_IT(sys_ctr_uart.huart, UART_IT_IDLE);
-				__HAL_UART_ENABLE_IT(sys_ctr_uart.huart, UART_IT_ERR);				  
-		}
-
-  }
-
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Fun_RawdataDeal
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:串口接收元数据处理
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_UART_Sys_Ctr_SendTest(void) {
-  unsigned char sendtestbuf[128] = {0};
-  for (int i = 0; i < 100; i++) {
-    sendtestbuf[i] = '0' + i % 10;
-  }
-
-  Van_UART_Sys_Ctr_Send(sendtestbuf, 100);
-  Van_UART_Sys_Ctr_Send((unsigned char*)"\n\r", 2);
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Sys_Get_Debuging  
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:获取调试信息
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-
-void Van_UART_Sys_Get_Debuging(void) {
-  DMA_Base_Registers  *regs_dma  = (DMA_Base_Registers *)hdma_uart7_rx.StreamBaseAddress;
-  BDMA_Channel_TypeDef *dma_instance =     (BDMA_Channel_TypeDef *)hdma_uart7_rx.Instance;
-  Van_Device_Printf(VAN_LOG_NOTICE, "ISR:%8x  IFCR:%8x \n\r",regs_dma->ISR,regs_dma->IFCR);
-  Van_Device_Printf(VAN_LOG_NOTICE, "CCR:%8x  CNDTR:%8x  CPAR:%8x  CM0AR:%8x  CM1AR:%8x \n\r",
-  		dma_instance->CCR,dma_instance->CNDTR,dma_instance->CPAR,dma_instance->CM0AR,dma_instance->CM1AR);  
-  Van_Device_Printf(VAN_LOG_NOTICE, "huart7 ISR:%8x \n\r",huart7.Instance->ISR);   
-}
-
-#if defined(DEVICETYPE_IS_ATCG)
-
-/****************************************************************
-* 函数名:    Van_THD_NTCSAMP_Fun_RawdataDeal
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:串口接收元数据处理
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_THD_NTCSAMP_Fun_RawdataDeal(void) {
-  if (THD_NTCSAMP_uart.receive_flag)  //如果产生了空闲中断
-  {
-    THD_NTCSAMP_uart.receive_flag = 0;  //清零标记
-    unsigned int dataleninRxbuf = (THD_NTCSAMP_uart.rx_last + THD_NTCSAMP_uart.rx_max_len - THD_NTCSAMP_uart.rx_head) % THD_NTCSAMP_uart.rx_max_len;
-    if(p_rec_flag){
-		Van_Device_Printf(VAN_LOG_NOTICE, "last:%d head:%d buflen:%d  have:%d\n\r***", THD_NTCSAMP_uart.rx_last,THD_NTCSAMP_uart.rx_head,THD_NTCSAMP_uart.rx_max_len,dataleninRxbuf);
-		if(p_rec_data_flag){
-			for(int i=0; i <dataleninRxbuf; i++){
-				Van_Device_Printf(VAN_LOG_NOTICE, "%2x ", THD_NTCSAMP_uart.usart_RxBuf[(i+THD_NTCSAMP_uart.rx_head)%THD_NTCSAMP_uart.rx_max_len]);
-				if(i%32==31){
-					Van_Device_Printf(VAN_LOG_NOTICE, "\n\r");
-				}
-			}
-			Van_Device_Printf(VAN_LOG_NOTICE, "\n\r");
-		}
-
-	}
-    if (dataleninRxbuf >= (sizeof(RTUMessage))) {
-			
-		unsigned int msgLen = DecodeModbud_RTU(THD_NTCSAMP_Message, THD_NTCSAMP_uart.usart_RxBuf, &THD_NTCSAMP_uart.rx_head, THD_NTCSAMP_uart.rx_last, THD_NTCSAMP_uart.rx_max_len);
-      if (msgLen) {	  	
-//	  		for(int i=0;i<msgLen;i++){
-//				Van_Device_Printf(VAN_LOG_NOTICE, "%2x ",THD_NTCSAMP_Message[i]);
-//				if( i%32 == 31){
-//					Van_Device_Printf(VAN_LOG_NOTICE, "\n\r");
-//				}	
-//			}
-//			Van_Device_Printf(VAN_LOG_NOTICE, "\n\r");
-		
-      }
-    }
-	dataleninRxbuf = (THD_NTCSAMP_uart.rx_last + THD_NTCSAMP_uart.rx_max_len - THD_NTCSAMP_uart.rx_head) % THD_NTCSAMP_uart.rx_max_len;
-	if(dataleninRxbuf >= (sizeof(RTUMessage))) {
-		THD_NTCSAMP_uart.receive_flag = 1;  //缓冲区存在数据,接续解析
-	}
-    
-  }
-  if( THD_NTCSAMP_uart.uartError){
-	THD_NTCSAMP_uart.uartError = False;		
-    osDelay(100U);
-  	MX_UART5_Init();
-   Van_THD_NTCSAMP_Init(THD_NTCSAMP_uart.huart);
-	 Van_Device_Printf(VAN_LOG_ERROR, "sys_ctr_uart reset\n\r");	
-    __HAL_DMA_DISABLE(THD_NTCSAMP_uart.huart->hdmarx);
-    HAL_UART_Receive_DMA((UART_HandleTypeDef *)&huart5, THD_NTCSAMP_uart.usartDMA_RxBuf, RECEIVELEN);
-    __HAL_UART_CLEAR_IDLEFLAG((UART_HandleTypeDef *)&huart5);
-  	__HAL_UART_CLEAR_OREFLAG((UART_HandleTypeDef *)&huart5);
-		__HAL_UART_ENABLE_IT((UART_HandleTypeDef *)&huart5, UART_IT_IDLE);
-		__HAL_UART_ENABLE_IT((UART_HandleTypeDef *)&huart5, UART_IT_ERR);
-  }
-}
-
-
-/****************************************************************
-* 函数名:    Van_THD_NTCSAMP_Ctr_Init
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:系统命令串口挂载
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_THD_NTCSAMP_Init(UART_HandleTypeDef *puart) {
-  THD_NTCSAMP_uart.huart = puart;
-  THD_NTCSAMP_uart.usartDMA_RxBuf = THD_NTCSAMP_tDMA_RxBuf;
-  THD_NTCSAMP_uart.usartDMA_TxBuf = THD_NTCSAMP_tDMA_TxBuf;
-  THD_NTCSAMP_uart.usart_RxBuf = THD_NTCSAMP_RxBuf;
-  THD_NTCSAMP_uart.usart_TxBuf = THD_NTCSAMP_TxBuf;
-  THD_NTCSAMP_uart.tx_DMA_len = THD_NTCSAMP_DMA_LEN;
-  THD_NTCSAMP_uart.rx_DMA_len = THD_NTCSAMP_DMA_LEN;
-  THD_NTCSAMP_uart.rx_max_len = THD_NTCSAMP_BUF_LEN;
-  THD_NTCSAMP_uart.tx_max_len = THD_NTCSAMP_BUF_LEN;
-  THD_NTCSAMP_uart.rx_last = 0;
-  THD_NTCSAMP_uart.rx_head = 0;
-  THD_NTCSAMP_uart.tx_last = 0;
-  THD_NTCSAMP_uart.tx_head = 0;
-  THD_NTCSAMP_uart.uartError = False;
-  memset((void *)THD_NTCSAMP_uart.usartDMA_RxBuf, 0, THD_NTCSAMP_uart.rx_DMA_len + 4);
-  HAL_UART_Receive_DMA(puart, THD_NTCSAMP_uart.usartDMA_RxBuf, THD_NTCSAMP_DMA_LEN);
-  __HAL_UART_CLEAR_IDLEFLAG(puart);
-  //	__HAL_UART_CLEAR_OREFLAG(puart);
-  __HAL_UART_ENABLE_IT(puart, UART_IT_IDLE);
-  __HAL_UART_ENABLE_IT(puart, UART_IT_ERR);
-  
-  THD_NTCSAMP_uart.mutex_dmaCopy = osMutexNew(&Mutex_attr1);
-}
-
-/****************************************************************
-* 函数名:    Van_UART_Sys_Ctr_Send
-* 创建时间:  2022/02/18
-* 创建人:    范义东
-* 函数说明:系统命令发送
-* 输入参数: 无
-
-* 输出参数:
-* 返回值 :   void
-****************************************************************/
-void Van_THD_NTCSAMP_Send(const unsigned char *pdata, unsigned int Length) {
-	unsigned char sedbuf[SYS_CTR_BUF_LEN];
-	unsigned int i = 0;
-	for (; i < Length; i++) {
-	  sedbuf[i] = pdata[i];
-	}
-	if( THD_NTCSAMP_uart.uartError) return;
-//	sedbuf[i++] = checksum & 0xff; /*结尾标记高位*/
-//	sedbuf[i++] = checksum >> 8;   /*结尾标记低位*/
-//	if(1){
-//		unsigned int alllen = msg.len + 8;
-//		Van_Device_Printf(VAN_LOG_NOTICE, "NTC: len%:d \n\r",alllen);
-//		if(1){
-//			for(int i=0; i <alllen; i++){
-//				Van_Device_Printf(VAN_LOG_NOTICE, "%2x ", sedbuf[i]);
-//				if(i%32==31){
-//				   Van_Device_Printf(VAN_LOG_NOTICE, "\n\r"); 
-//				}
-//			}
-//			Van_Device_Printf(VAN_LOG_NOTICE, "\n\r");
-//		}
-//	}
-	Van_UART_Fun_Send_DMA(sedbuf, Length, THD_NTCSAMP_uart.huart);
-
-} 
-#endif
-
-
-/* USER CODE END Private defines */

+ 0 - 51
DriverInterface/van_bsp_uart_fun.h

@@ -1,51 +0,0 @@
-
-/******************************************************************
-*  Copyright (C) 2023 - 2023 OneChip, Inc. All rights reserved.
-* File name: van_bsp_uart_fun.h
-* Author: fanyidong 	 Date:2020.11.21
-* Description:		STM32串口接收函数
-* Others:
-* History:
-        1. Date:
-                 Author:
-                 Modification:
-
-*****************************************************************/
-#ifndef VAN_BSP_UART_FUN_H
-#define VAN_BSP_UART_FUN_H
-
-typedef enum
-{
-	MSG_SYS_CTR = 0x03,/*工作指令*/
-	MSG_DEV_RPT = 0x04,/*设备上报*/
-	MSG_DEV_RECFLAG = 0x06,/*收到消息*/
-	MSG_RAW_DATA_1 = 0x10,/*原始数据控制*/
-} enMessagetype;
-
-
-
-typedef enum
-{
-	RAW_V1_SET_PID_SEC_OFFSET = 10,/*设置分段校准参数*/
-	RAW_V1_GET_PID_SEC_OFFSET = 11,/*获取分段校准参数*/
-	RAW_V1_SET_PID_MULT_PRAM = 12,/*设置分段pid参数*/
-	RAW_V1_GET_PID_MULT_PRAM = 13,/*获取分段pid参数*/
-	RAW_V1_SET_PID_SINGEPIDOFFSET = 14,/*单独pid,偏移*/
-	RAW_V1_GET_PID_SINGEPIDOFFSET = 15,/*获取分段pid参数*/
-	RAW_V1_SET_QUADRATICFIT = 16,/*单独pid,偏移*/
-	RAW_V1_GET_QUADRATICFIT = 17,/*获取分段pid参数*/
-} enRawdataCmdtype;
-
-
-/*通用消息结构体定义*/
-typedef struct 
-{
-    unsigned int fuid;
-    unsigned int cmd;
-    char data[128];
-} RawdataMessage,*P_RawdataMessage;
-
-
-
-#endif
-/* USER CODE END Private defines */

Plik diff jest za duży
+ 8 - 22
MDK-ARM/mini7_V2.uvguix.Administrator


+ 49 - 151
MDK-ARM/mini7_V2.uvoptx

@@ -152,18 +152,34 @@
         <Bp>
           <Number>0</Number>
           <Type>0</Type>
-          <LineNumber>515</LineNumber>
+          <LineNumber>274</LineNumber>
           <EnabledFlag>1</EnabledFlag>
-          <Address>134251616</Address>
+          <Address>134237408</Address>
           <ByteObject>0</ByteObject>
           <HtxType>0</HtxType>
           <ManyObjects>0</ManyObjects>
           <SizeOfObject>0</SizeOfObject>
           <BreakByAccess>0</BreakByAccess>
           <BreakIfRCount>1</BreakIfRCount>
-          <Filename>..\DriverInterface\ESP32_WROOM_32D.c</Filename>
+          <Filename>../Core/Src/stm32f1xx_it.c</Filename>
           <ExecCommand></ExecCommand>
-          <Expression>\\mini7_V2\../DriverInterface/ESP32_WROOM_32D.c\515</Expression>
+          <Expression>\\mini7_V2\../Core/Src/stm32f1xx_it.c\274</Expression>
+        </Bp>
+        <Bp>
+          <Number>1</Number>
+          <Type>0</Type>
+          <LineNumber>196</LineNumber>
+          <EnabledFlag>1</EnabledFlag>
+          <Address>134237290</Address>
+          <ByteObject>0</ByteObject>
+          <HtxType>0</HtxType>
+          <ManyObjects>0</ManyObjects>
+          <SizeOfObject>0</SizeOfObject>
+          <BreakByAccess>0</BreakByAccess>
+          <BreakIfRCount>1</BreakIfRCount>
+          <Filename>../Core/Src/stm32f1xx_it.c</Filename>
+          <ExecCommand></ExecCommand>
+          <Expression>\\mini7_V2\../Core/Src/stm32f1xx_it.c\196</Expression>
         </Bp>
       </Breakpoint>
       <WatchWindow1>
@@ -195,7 +211,7 @@
         <Ww>
           <count>5</count>
           <WinNumber>1</WinNumber>
-          <ItemText>g_wifi_rx_buf</ItemText>
+          <ItemText>updateInf</ItemText>
         </Ww>
         <Ww>
           <count>6</count>
@@ -212,7 +228,7 @@
         <Mm>
           <WinNumber>1</WinNumber>
           <SubType>0</SubType>
-          <ItemText>0x0807f800</ItemText>
+          <ItemText>0x8011000</ItemText>
           <AccSizeX>0</AccSizeX>
         </Mm>
       </MemoryWindow1>
@@ -258,16 +274,6 @@
       <pszMrulep></pszMrulep>
       <pSingCmdsp></pSingCmdsp>
       <pMultCmdsp></pMultCmdsp>
-      <SystemViewers>
-        <Entry>
-          <Name>System Viewer\GPIOA</Name>
-          <WinId>35904</WinId>
-        </Entry>
-        <Entry>
-          <Name>System Viewer\GPIOC</Name>
-          <WinId>35905</WinId>
-        </Entry>
-      </SystemViewers>
       <DebugDescription>
         <Enable>1</Enable>
         <EnableFlashSeq>1</EnableFlashSeq>
@@ -335,8 +341,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>../Core/Src/adc.c</PathWithFileName>
-      <FilenameWithoutPath>adc.c</FilenameWithoutPath>
+      <PathWithFileName>../Core/Src/dma.c</PathWithFileName>
+      <FilenameWithoutPath>dma.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
@@ -347,8 +353,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>../Core/Src/dma.c</PathWithFileName>
-      <FilenameWithoutPath>dma.c</FilenameWithoutPath>
+      <PathWithFileName>../Core/Src/tim.c</PathWithFileName>
+      <FilenameWithoutPath>tim.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
@@ -359,8 +365,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>../Core/Src/i2c.c</PathWithFileName>
-      <FilenameWithoutPath>i2c.c</FilenameWithoutPath>
+      <PathWithFileName>../Core/Src/usart.c</PathWithFileName>
+      <FilenameWithoutPath>usart.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
@@ -371,8 +377,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>../Core/Src/tim.c</PathWithFileName>
-      <FilenameWithoutPath>tim.c</FilenameWithoutPath>
+      <PathWithFileName>../Core/Src/stm32f1xx_it.c</PathWithFileName>
+      <FilenameWithoutPath>stm32f1xx_it.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
@@ -383,8 +389,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>../Core/Src/usart.c</PathWithFileName>
-      <FilenameWithoutPath>usart.c</FilenameWithoutPath>
+      <PathWithFileName>../Core/Src/stm32f1xx_hal_msp.c</PathWithFileName>
+      <FilenameWithoutPath>stm32f1xx_hal_msp.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
@@ -395,8 +401,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>../Core/Src/stm32f1xx_it.c</PathWithFileName>
-      <FilenameWithoutPath>stm32f1xx_it.c</FilenameWithoutPath>
+      <PathWithFileName>..\Core\Src\i2c.c</PathWithFileName>
+      <FilenameWithoutPath>i2c.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
@@ -407,8 +413,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>../Core/Src/stm32f1xx_hal_msp.c</PathWithFileName>
-      <FilenameWithoutPath>stm32f1xx_hal_msp.c</FilenameWithoutPath>
+      <PathWithFileName>..\Core\Src\adc.c</PathWithFileName>
+      <FilenameWithoutPath>adc.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
@@ -679,8 +685,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\tshell\van_bsp_debug_shell.c</PathWithFileName>
-      <FilenameWithoutPath>van_bsp_debug_shell.c</FilenameWithoutPath>
+      <PathWithFileName>..\tshell\van_bsp_debug_uart.c</PathWithFileName>
+      <FilenameWithoutPath>van_bsp_debug_uart.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
@@ -691,8 +697,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\tshell\van_bsp_debug_uart.c</PathWithFileName>
-      <FilenameWithoutPath>van_bsp_debug_uart.c</FilenameWithoutPath>
+      <PathWithFileName>..\tshell\van_com_algorithm.c</PathWithFileName>
+      <FilenameWithoutPath>van_com_algorithm.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
@@ -703,8 +709,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\tshell\van_com_algorithm.c</PathWithFileName>
-      <FilenameWithoutPath>van_com_algorithm.c</FilenameWithoutPath>
+      <PathWithFileName>..\tshell\van_bsp_debug_shell.c</PathWithFileName>
+      <FilenameWithoutPath>van_bsp_debug_shell.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
@@ -735,8 +741,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\DriverInterface\pt1000.c</PathWithFileName>
-      <FilenameWithoutPath>pt1000.c</FilenameWithoutPath>
+      <PathWithFileName>..\DriverInterface\ws2812.c</PathWithFileName>
+      <FilenameWithoutPath>ws2812.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
@@ -747,8 +753,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\DriverInterface\van_BSP_Com_Pwm.c</PathWithFileName>
-      <FilenameWithoutPath>van_BSP_Com_Pwm.c</FilenameWithoutPath>
+      <PathWithFileName>..\DriverInterface\communication.c</PathWithFileName>
+      <FilenameWithoutPath>communication.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
@@ -759,8 +765,8 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\DriverInterface\van_BSP_Scanner.c</PathWithFileName>
-      <FilenameWithoutPath>van_BSP_Scanner.c</FilenameWithoutPath>
+      <PathWithFileName>..\DriverInterface\onchip_flash.c</PathWithFileName>
+      <FilenameWithoutPath>onchip_flash.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
@@ -771,42 +777,6 @@
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\DriverInterface\cJSON.c</PathWithFileName>
-      <FilenameWithoutPath>cJSON.c</FilenameWithoutPath>
-      <RteFlg>0</RteFlg>
-      <bShared>0</bShared>
-    </File>
-    <File>
-      <GroupNumber>7</GroupNumber>
-      <FileNumber>38</FileNumber>
-      <FileType>1</FileType>
-      <tvExp>0</tvExp>
-      <tvExpOptDlg>0</tvExpOptDlg>
-      <bDave2>0</bDave2>
-      <PathWithFileName>..\DriverInterface\ws2812.c</PathWithFileName>
-      <FilenameWithoutPath>ws2812.c</FilenameWithoutPath>
-      <RteFlg>0</RteFlg>
-      <bShared>0</bShared>
-    </File>
-    <File>
-      <GroupNumber>7</GroupNumber>
-      <FileNumber>39</FileNumber>
-      <FileType>1</FileType>
-      <tvExp>0</tvExp>
-      <tvExpOptDlg>0</tvExpOptDlg>
-      <bDave2>0</bDave2>
-      <PathWithFileName>..\DriverInterface\rgb381.c</PathWithFileName>
-      <FilenameWithoutPath>rgb381.c</FilenameWithoutPath>
-      <RteFlg>0</RteFlg>
-      <bShared>0</bShared>
-    </File>
-    <File>
-      <GroupNumber>7</GroupNumber>
-      <FileNumber>40</FileNumber>
-      <FileType>1</FileType>
-      <tvExp>0</tvExp>
-      <tvExpOptDlg>0</tvExpOptDlg>
-      <bDave2>0</bDave2>
       <PathWithFileName>..\DriverInterface\ESP32_WROOM_32D.c</PathWithFileName>
       <FilenameWithoutPath>ESP32_WROOM_32D.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
@@ -814,7 +784,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>41</FileNumber>
+      <FileNumber>38</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -824,78 +794,6 @@
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
-    <File>
-      <GroupNumber>7</GroupNumber>
-      <FileNumber>42</FileNumber>
-      <FileType>1</FileType>
-      <tvExp>0</tvExp>
-      <tvExpOptDlg>0</tvExpOptDlg>
-      <bDave2>0</bDave2>
-      <PathWithFileName>..\DriverInterface\usr_motor.c</PathWithFileName>
-      <FilenameWithoutPath>usr_motor.c</FilenameWithoutPath>
-      <RteFlg>0</RteFlg>
-      <bShared>0</bShared>
-    </File>
-    <File>
-      <GroupNumber>7</GroupNumber>
-      <FileNumber>43</FileNumber>
-      <FileType>1</FileType>
-      <tvExp>0</tvExp>
-      <tvExpOptDlg>0</tvExpOptDlg>
-      <bDave2>0</bDave2>
-      <PathWithFileName>..\DriverInterface\communication.c</PathWithFileName>
-      <FilenameWithoutPath>communication.c</FilenameWithoutPath>
-      <RteFlg>0</RteFlg>
-      <bShared>0</bShared>
-    </File>
-    <File>
-      <GroupNumber>7</GroupNumber>
-      <FileNumber>44</FileNumber>
-      <FileType>1</FileType>
-      <tvExp>0</tvExp>
-      <tvExpOptDlg>0</tvExpOptDlg>
-      <bDave2>0</bDave2>
-      <PathWithFileName>..\DriverInterface\onchip_flash.c</PathWithFileName>
-      <FilenameWithoutPath>onchip_flash.c</FilenameWithoutPath>
-      <RteFlg>0</RteFlg>
-      <bShared>0</bShared>
-    </File>
-    <File>
-      <GroupNumber>7</GroupNumber>
-      <FileNumber>45</FileNumber>
-      <FileType>1</FileType>
-      <tvExp>0</tvExp>
-      <tvExpOptDlg>0</tvExpOptDlg>
-      <bDave2>0</bDave2>
-      <PathWithFileName>..\DriverInterface\usr_lysis.c</PathWithFileName>
-      <FilenameWithoutPath>usr_lysis.c</FilenameWithoutPath>
-      <RteFlg>0</RteFlg>
-      <bShared>0</bShared>
-    </File>
-    <File>
-      <GroupNumber>7</GroupNumber>
-      <FileNumber>46</FileNumber>
-      <FileType>1</FileType>
-      <tvExp>0</tvExp>
-      <tvExpOptDlg>0</tvExpOptDlg>
-      <bDave2>0</bDave2>
-      <PathWithFileName>..\DriverInterface\state_mini.c</PathWithFileName>
-      <FilenameWithoutPath>state_mini.c</FilenameWithoutPath>
-      <RteFlg>0</RteFlg>
-      <bShared>0</bShared>
-    </File>
-    <File>
-      <GroupNumber>7</GroupNumber>
-      <FileNumber>47</FileNumber>
-      <FileType>1</FileType>
-      <tvExp>0</tvExp>
-      <tvExpOptDlg>0</tvExpOptDlg>
-      <bDave2>0</bDave2>
-      <PathWithFileName>..\DriverInterface\user_heater.c</PathWithFileName>
-      <FilenameWithoutPath>user_heater.c</FilenameWithoutPath>
-      <RteFlg>0</RteFlg>
-      <bShared>0</bShared>
-    </File>
   </Group>
 
   <Group>

+ 22 - 67
MDK-ARM/mini7_V2.uvprojx

@@ -188,7 +188,7 @@
             <hadIRAM2>0</hadIRAM2>
             <hadIROM2>0</hadIROM2>
             <StupSel>8</StupSel>
-            <useUlib>1</useUlib>
+            <useUlib>0</useUlib>
             <EndSel>0</EndSel>
             <uLtcg>0</uLtcg>
             <nSecure>0</nSecure>
@@ -275,7 +275,7 @@
               <OCR_RVCT4>
                 <Type>1</Type>
                 <StartAddress>0x8000000</StartAddress>
-                <Size>0x80000</Size>
+                <Size>0x10000</Size>
               </OCR_RVCT4>
               <OCR_RVCT5>
                 <Type>1</Type>
@@ -312,7 +312,7 @@
           </ArmAdsMisc>
           <Cads>
             <interw>1</interw>
-            <Optim>1</Optim>
+            <Optim>3</Optim>
             <oTime>0</oTime>
             <SplitLS>0</SplitLS>
             <OneElfS>1</OneElfS>
@@ -402,21 +402,11 @@
               <FileType>1</FileType>
               <FilePath>../Core/Src/gpio.c</FilePath>
             </File>
-            <File>
-              <FileName>adc.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>../Core/Src/adc.c</FilePath>
-            </File>
             <File>
               <FileName>dma.c</FileName>
               <FileType>1</FileType>
               <FilePath>../Core/Src/dma.c</FilePath>
             </File>
-            <File>
-              <FileName>i2c.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>../Core/Src/i2c.c</FilePath>
-            </File>
             <File>
               <FileName>tim.c</FileName>
               <FileType>1</FileType>
@@ -437,6 +427,16 @@
               <FileType>1</FileType>
               <FilePath>../Core/Src/stm32f1xx_hal_msp.c</FilePath>
             </File>
+            <File>
+              <FileName>i2c.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Core\Src\i2c.c</FilePath>
+            </File>
+            <File>
+              <FileName>adc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Core\Src\adc.c</FilePath>
+            </File>
           </Files>
         </Group>
         <Group>
@@ -552,11 +552,6 @@
         <Group>
           <GroupName>tshell</GroupName>
           <Files>
-            <File>
-              <FileName>van_bsp_debug_shell.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\tshell\van_bsp_debug_shell.c</FilePath>
-            </File>
             <File>
               <FileName>van_bsp_debug_uart.c</FileName>
               <FileType>1</FileType>
@@ -567,6 +562,11 @@
               <FileType>1</FileType>
               <FilePath>..\tshell\van_com_algorithm.c</FilePath>
             </File>
+            <File>
+              <FileName>van_bsp_debug_shell.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\tshell\van_bsp_debug_shell.c</FilePath>
+            </File>
           </Files>
         </Group>
         <Group>
@@ -577,51 +577,11 @@
               <FileType>1</FileType>
               <FilePath>..\DriverInterface\VAN_ITCallBack.c</FilePath>
             </File>
-            <File>
-              <FileName>pt1000.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\DriverInterface\pt1000.c</FilePath>
-            </File>
-            <File>
-              <FileName>van_BSP_Com_Pwm.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\DriverInterface\van_BSP_Com_Pwm.c</FilePath>
-            </File>
-            <File>
-              <FileName>van_BSP_Scanner.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\DriverInterface\van_BSP_Scanner.c</FilePath>
-            </File>
-            <File>
-              <FileName>cJSON.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\DriverInterface\cJSON.c</FilePath>
-            </File>
             <File>
               <FileName>ws2812.c</FileName>
               <FileType>1</FileType>
               <FilePath>..\DriverInterface\ws2812.c</FilePath>
             </File>
-            <File>
-              <FileName>rgb381.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\DriverInterface\rgb381.c</FilePath>
-            </File>
-            <File>
-              <FileName>ESP32_WROOM_32D.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\DriverInterface\ESP32_WROOM_32D.c</FilePath>
-            </File>
-            <File>
-              <FileName>van_BSP_ESPUart.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\DriverInterface\van_BSP_ESPUart.c</FilePath>
-            </File>
-            <File>
-              <FileName>usr_motor.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\DriverInterface\usr_motor.c</FilePath>
-            </File>
             <File>
               <FileName>communication.c</FileName>
               <FileType>1</FileType>
@@ -633,19 +593,14 @@
               <FilePath>..\DriverInterface\onchip_flash.c</FilePath>
             </File>
             <File>
-              <FileName>usr_lysis.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\DriverInterface\usr_lysis.c</FilePath>
-            </File>
-            <File>
-              <FileName>state_mini.c</FileName>
+              <FileName>ESP32_WROOM_32D.c</FileName>
               <FileType>1</FileType>
-              <FilePath>..\DriverInterface\state_mini.c</FilePath>
+              <FilePath>..\DriverInterface\ESP32_WROOM_32D.c</FilePath>
             </File>
             <File>
-              <FileName>user_heater.c</FileName>
+              <FileName>van_BSP_ESPUart.c</FileName>
               <FileType>1</FileType>
-              <FilePath>..\DriverInterface\user_heater.c</FilePath>
+              <FilePath>..\DriverInterface\van_BSP_ESPUart.c</FilePath>
             </File>
           </Files>
         </Group>

+ 66 - 30
MDK-ARM/startup_stm32f103xe.lst

@@ -241,9 +241,9 @@ ARM Macro Assembler    Page 4
 ]
   146 00000000                 IMPORT           __main
   147 00000000                 IMPORT           SystemInit
-  148 00000000 4806            LDR              R0, =SystemInit
+  148 00000000 4809            LDR              R0, =SystemInit
   149 00000002 4780            BLX              R0
-  150 00000004 4806            LDR              R0, =__main
+  150 00000004 4809            LDR              R0, =__main
   151 00000006 4700            BX               R0
   152 00000008                 ENDP
   153 00000008         
@@ -531,24 +531,35 @@ ARM Macro Assembler    Page 9
   329 0000001C         ;*******************************************************
                        ************************
   330 0000001C                 IF               :DEF:__MICROLIB
-  331 0000001C         
-  332 0000001C                 EXPORT           __initial_sp
-  333 0000001C                 EXPORT           __heap_base
-  334 0000001C                 EXPORT           __heap_limit
-  335 0000001C         
-  336 0000001C                 ELSE
-  351                          ENDIF
-  352 0000001C         
-  353 0000001C                 END
+  337 0000001C         
+  338 0000001C                 IMPORT           __use_two_region_memory
+  339 0000001C                 EXPORT           __user_initial_stackheap
+  340 0000001C         
+  341 0000001C         __user_initial_stackheap
+  342 0000001C         
+  343 0000001C 4804            LDR              R0, =  Heap_Mem
+  344 0000001E 4905            LDR              R1, =(Stack_Mem + Stack_Size)
+  345 00000020 4A05            LDR              R2, = (Heap_Mem +  Heap_Size)
+  346 00000022 4B06            LDR              R3, = Stack_Mem
+  347 00000024 4770            BX               LR
+  348 00000026         
+  349 00000026 00 00           ALIGN
+  350 00000028         
+  351 00000028                 ENDIF
+  352 00000028         
+  353 00000028                 END
               00000000 
               00000000 
+              00000000 
+              00000400 
+              00000F00 
+              00000000 
 Command Line: --debug --xref --diag_suppress=9931 --cpu=Cortex-M3 --apcs=interw
 ork --depend=mini7_v2\startup_stm32f103xe.d -omini7_v2\startup_stm32f103xe.o -I
 .\RTE\_mini7_V2 -IC:\Keil_v5\ARM\PACK\ARM\CMSIS\5.4.0\CMSIS\Core\Include -IC:\K
-eil_v5\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include --predefine="__MICROLIB
- SETA 1" --predefine="__UVISION_VERSION SETA 526" --predefine="_RTE_ SETA 1" --
-predefine="STM32F10X_HD SETA 1" --list=startup_stm32f103xe.lst startup_stm32f10
-3xe.s
+eil_v5\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include --predefine="__UVISION_
+VERSION SETA 526" --predefine="_RTE_ SETA 1" --predefine="STM32F10X_HD SETA 1" 
+--list=startup_stm32f103xe.lst startup_stm32f103xe.s
 
 
 
@@ -569,8 +580,9 @@ Symbol: Stack_Mem
    Definitions
       At line 35 in file startup_stm32f103xe.s
    Uses
-      None
-Comment: Stack_Mem unused
+      At line 344 in file startup_stm32f103xe.s
+      At line 346 in file startup_stm32f103xe.s
+
 __initial_sp 00000400
 
 Symbol: __initial_sp
@@ -578,8 +590,7 @@ Symbol: __initial_sp
       At line 36 in file startup_stm32f103xe.s
    Uses
       At line 59 in file startup_stm32f103xe.s
-      At line 332 in file startup_stm32f103xe.s
-
+Comment: __initial_sp used once
 3 symbols
 
 
@@ -601,24 +612,25 @@ Symbol: Heap_Mem
    Definitions
       At line 46 in file startup_stm32f103xe.s
    Uses
-      None
-Comment: Heap_Mem unused
+      At line 343 in file startup_stm32f103xe.s
+      At line 345 in file startup_stm32f103xe.s
+
 __heap_base 00000000
 
 Symbol: __heap_base
    Definitions
       At line 45 in file startup_stm32f103xe.s
    Uses
-      At line 333 in file startup_stm32f103xe.s
-Comment: __heap_base used once
+      None
+Comment: __heap_base unused
 __heap_limit 00000F00
 
 Symbol: __heap_limit
    Definitions
       At line 47 in file startup_stm32f103xe.s
    Uses
-      At line 334 in file startup_stm32f103xe.s
-Comment: __heap_limit used once
+      None
+Comment: __heap_limit unused
 4 symbols
 
 
@@ -1365,7 +1377,21 @@ Symbol: WWDG_IRQHandler
       At line 77 in file startup_stm32f103xe.s
       At line 200 in file startup_stm32f103xe.s
 
-72 symbols
+__user_initial_stackheap 0000001C
+
+Symbol: __user_initial_stackheap
+
+
+
+ARM Macro Assembler    Page 12 Alphabetic symbol ordering
+Relocatable symbols
+
+   Definitions
+      At line 341 in file startup_stm32f103xe.s
+   Uses
+      At line 339 in file startup_stm32f103xe.s
+Comment: __user_initial_stackheap used once
+73 symbols
 
 
 
@@ -1379,7 +1405,8 @@ Symbol: Heap_Size
       At line 42 in file startup_stm32f103xe.s
    Uses
       At line 46 in file startup_stm32f103xe.s
-Comment: Heap_Size used once
+      At line 345 in file startup_stm32f103xe.s
+
 Stack_Size 00000400
 
 Symbol: Stack_Size
@@ -1387,7 +1414,8 @@ Symbol: Stack_Size
       At line 32 in file startup_stm32f103xe.s
    Uses
       At line 35 in file startup_stm32f103xe.s
-Comment: Stack_Size used once
+      At line 344 in file startup_stm32f103xe.s
+
 __Vectors_Size 00000130
 
 Symbol: __Vectors_Size
@@ -1419,5 +1447,13 @@ Symbol: __main
    Uses
       At line 150 in file startup_stm32f103xe.s
 Comment: __main used once
-2 symbols
-423 symbols in table
+__use_two_region_memory 00000000
+
+Symbol: __use_two_region_memory
+   Definitions
+      At line 338 in file startup_stm32f103xe.s
+   Uses
+      None
+Comment: __use_two_region_memory unused
+3 symbols
+426 symbols in table

+ 1 - 23
tshell/van_bsp_debug_shell.c

@@ -73,36 +73,14 @@ unsigned int debugver;
 FUNCALLTYPE debugFunctionList[] = {DEBUGFUNCTION(debugtest1),
 //	DEBUGFUNCTION(Van_UART_Sys_Ctr_SendTest),
 
-	 DEBUGFUNCTION(com_pwm_test),
-	 DEBUGFUNCTION(show_com_pwm),
+	
 	// DEBUGFUNCTION(showPid),
 	// DEBUGFUNCTION(Van_UART_Sys_Get_Debuging),
 	{NULL, 0}};
 
 
 
-extern int	printDrvStatusFlag;
-extern unsigned int  onechip_log_level;
-extern unsigned int  onechip_testflag;
-extern unsigned int p_rec_flag;
-extern unsigned int p_rec_data_flag;
-extern unsigned int p_DecodeNew;
-extern unsigned int p_recSystemMsg;
-extern unsigned int p_Rep_flag;
-extern unsigned int p_Rep_data_flag;
-extern unsigned int p_Ans_flag;
-extern unsigned int p_Ans_data_flag;
-extern unsigned int p_Ans_flag_1;
-extern unsigned int p_Ans_data_flag_1;
-extern unsigned int print_chip_pwm;
-extern unsigned int comAnsOutTimeDebug;
-extern unsigned int dealOutTimeDebug;
-
-
-extern uint32_t TMC5160SPIFlag;
-
 
-extern uint32_t resetSysUart;
 
 
 VAREDITTYPE debugVariableList[]

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików