فهرست منبع

解决配对功耗和阈值问题

Chenyingjia 2 سال پیش
والد
کامیت
060bda4511

+ 337 - 0
app/app_chargerpin_conn_detect.c

@@ -0,0 +1,337 @@
+#include "app_chargerpin_conn_detect.h"
+#include "system.h"
+#include "bsp_time.h"
+#include "bsp_adc.h"
+#include "ble_comm.h"
+#include "hal_led.h"
+#include "hal_mt.h"
+#include "app_flash.h"
+#include "app_pair_chargerpin.h"
+
+//=================debug=============
+#include "ringframe.h"
+extern char logbuftemp[50];
+extern int logbuftemp_len ;
+extern ringframe_t battlog;
+#define log(...) {logbuftemp_len = sprintf(logbuftemp,__VA_ARGS__); while(ringframe_in(&battlog,logbuftemp,logbuftemp_len)!=0){ringframe_throw(&battlog);}}
+
+
+//void cb_BLE_Client_PRADC(void* handle)
+//{
+////    BLE_Client_Rx_t* target = handle;
+//    DEBUG_LOG("cb_BLE_Client_ERR:%d,%d\n", 1, 1);
+//	BLE_Client_Rx_Regist(BLE_ERR, cb_BLE_Client_ERR);
+//}
+
+//=================debug=============
+
+//====================================================================================
+#define ADC_CHECKMS 1000
+#define PAIROVERTIME 3000
+#define DELAY_PAIR_COUNT 100
+struct{
+	char statu;
+	unsigned int pulluppcs_timer;
+	short adc_value;
+	pair_line_t pair_line;
+	unsigned int delay_pair_count;
+	Event into_event;
+	Event over_event;
+}host_ram={0,0,0,DISCONNECT_CHARGE,0,NULL,NULL};
+extern void app_pair_host_process(void);
+
+void app_pair_host_init(Event into,Event over)
+{
+	host_ram.adc_value=0;
+	host_ram.delay_pair_count=0;
+	host_ram.pulluppcs_timer=0;
+	host_ram.statu=0;
+	host_ram.pair_line=DISCONNECT_CHARGE;
+	host_ram.into_event=into;
+	host_ram.over_event=over;
+	Process_Start(ADC_CHECKMS, "app_pair_host_process", app_pair_host_process);
+}
+void app_pair_host_uninit(void)
+{
+	Process_Stop(app_pair_host_process);
+}
+
+#define DISCON_HOST_MAX_ADC 1200
+#define DISCON_HOST_MIN_ADC 700
+
+#define CON_HOST_MAX_ADC DISCON_HOST_MIN_ADC
+#define CON_HOST_MIN_ADC 300
+
+static void null_pcs(void)
+{
+}
+#define UPPULL_MS 5
+static void ReadAdc_timcallback(void *t)
+{
+	if(TIME_GetTicks()-host_ram.pulluppcs_timer<UPPULL_MS)return;
+	if(TIME_GetTicks()-host_ram.pulluppcs_timer==UPPULL_MS)
+	{
+			uint32_t errcode = ADC_ReadChargePin(PIN_CHARGING_CHANNEL);
+			if (ADC_OP_SUCCESS != errcode)
+			{
+				char buff[20];
+				memset(buff,0,20);
+				sprintf(buff,"ADC ERROR %d",errcode);
+				Except_TxError(EXCEPT_Pair,buff);
+				PAIR_CHARGERPIN_PRINT("ADC_ReadChargePin ======%d================================================ERROR %d\n",TIME_GetTicks(), errcode);
+			}
+	}
+	if(TIME_GetTicks()-host_ram.pulluppcs_timer>UPPULL_MS)
+	{
+		uint8_t state = bsp_Get_ChargePinADC(&host_ram.adc_value);
+		if(state==1)//adc读取成功
+		{
+			host_ram.statu=2;
+			app_pair_host_process();
+		}
+		else
+		{
+			TIME_UnRegist(ReadAdc_timcallback);
+			nrf_gpio_cfg_input(PIN_CHARGING, NRF_GPIO_PIN_NOPULL);
+			Process_Stop(null_pcs);
+
+			Except_TxError(EXCEPT_Pair,"adc overtimer");
+			PAIR_CHARGERPIN_PRINT("bsp_Get_ChargePinADC %d===========%d===========================================ERROR %d\n",host_ram.adc_value,TIME_GetTicks(), state);
+		}
+	}
+}
+
+static void app_pair_host_process(void)
+{
+	for(int i=1;i>0;i--)
+	{
+		switch(host_ram.statu)
+		{
+			case 0:
+				ADC_Disable();
+				ADC_SetPinChannel(PIN_CHARGING, PIN_CHARGING_CHANNEL, NRF_GPIO_PIN_NOPULL);
+				ADC_Initialize();
+				host_ram.statu=1;
+				break;
+			case 1:
+				if(mFlash.isHost!=HOST_SHOSE)
+				{
+					app_pair_host_uninit();
+					app_pair_chargerpin_Init();
+					PAIR_CHARGERPIN_PRINT("mFlash.isHost change %d %d\n",TIME_GetTicks(),mFlash.isHost );
+				}
+//				if (ADC_OP_SUCCESS != ADC_Read(PIN_CHARGING_CHANNEL, &host_ram.adc_value))
+//				{
+//						PAIR_CHARGERPIN_PRINT("ADC_Read ERROR %d\n", host_ram.adc_value);
+//				}
+//				PAIR_CHARGERPIN_PRINT("ADC f(  %d  ):isHost %d Ticks %d\n", host_ram.adc_value, mFlash.isHost,TIME_GetTicks());
+				nrf_gpio_cfg_input(PIN_CHARGING, NRF_GPIO_PIN_PULLUP);
+				PAIR_CHARGERPIN_PRINT("nrf_gpio_cfg_input(PIN_CHARGING, NRF_GPIO_PIN_PULLUP); %d \n",TIME_GetTicks() );
+				host_ram.pulluppcs_timer = TIME_GetTicks();
+				Process_Start(0, "null_pcs", null_pcs);
+				Process_SetHoldOn(null_pcs, 1);
+				TIME_Regist(ReadAdc_timcallback);
+				break;
+			case 2:
+				TIME_UnRegist(ReadAdc_timcallback);
+				nrf_gpio_cfg_input(PIN_CHARGING, NRF_GPIO_PIN_NOPULL);
+				Process_Stop(null_pcs);
+				log("ad:%d,%d\n",host_ram.adc_value, host_ram.pair_line);
+				PAIR_CHARGERPIN_PRINT("ADC (  %d  ): pair_line %d\n", host_ram.adc_value, host_ram.pair_line);
+						
+				if(host_ram.adc_value>DISCON_HOST_MAX_ADC)
+				{
+					PAIR_CHARGERPIN_PRINT("CHARGE\n");
+					if(host_ram.pair_line!=CHARGE)
+					{
+						PAIR_CHARGERPIN_PRINT("INTO CHARGE %d\n", 1);
+						host_ram.pair_line=CHARGE;
+					}
+					host_ram.statu=1;
+				}
+				else if(host_ram.adc_value>DISCON_HOST_MIN_ADC)
+				{
+					PAIR_CHARGERPIN_PRINT("DISCONNECT_CHARGE\n");
+					if(host_ram.pair_line!=DISCONNECT_CHARGE)
+					{
+						PAIR_CHARGERPIN_PRINT("INTO DISCONNECT_CHARGE %d\n", 1);
+						host_ram.pair_line=DISCONNECT_CHARGE;
+					}
+					host_ram.statu=1;
+				}
+				else if(host_ram.adc_value>CON_HOST_MIN_ADC)
+				{
+					PAIR_CHARGERPIN_PRINT("CONNECT_NO_CHARGE\n");
+					if(host_ram.pair_line!=CONNECT_NO_CHARGE)
+					{
+						host_ram.pair_line=CONNECT_NO_CHARGE;
+						nrf_gpio_cfg_input(PIN_CHARGING, NRF_GPIO_PIN_PULLUP);
+						host_ram.delay_pair_count=TIME_GetTicks();
+						
+						Process_UpdatePeroid(app_pair_host_process,1);
+						Process_SetHoldOn(app_pair_host_process,1);
+
+						host_ram.statu=3;		
+						PAIR_CHARGERPIN_PRINT("INTO CONNECT_NO_CHARGE %d\n", nrf_gpio_pin_read(PIN_CHARGING));		
+					}
+					else
+					{
+						host_ram.statu=1;
+					}
+				}
+				else
+				{
+					PAIR_CHARGERPIN_PRINT("ADCVALUE ======================================================ERROR %d\n", host_ram.adc_value);
+					host_ram.statu=1;
+				}
+				break;
+			case 3://上拉让从机发现配对信号
+				if ((TIME_GetTicks() - host_ram.delay_pair_count > ADC_CHECKMS)||(nrf_gpio_pin_read(PIN_CHARGING)))
+				{
+					PAIR_CHARGERPIN_PRINT(" into_event  %d \n", TIME_GetTicks());
+					host_ram.statu=4;
+					nrf_gpio_cfg_input(PIN_CHARGING, NRF_GPIO_PIN_NOPULL);
+					host_ram.delay_pair_count=TIME_GetTicks();
+					host_ram.into_event();
+					Process_UpdatePeroid(app_pair_host_process,ADC_CHECKMS);
+					Process_SetHoldOn(app_pair_host_process,0);
+				}
+				break;
+			case 4:
+				if (TIME_GetTicks() - host_ram.delay_pair_count > PAIROVERTIME)
+				{
+					PAIR_CHARGERPIN_PRINT("  over_event %d\n", TIME_GetTicks());
+					host_ram.statu=0;
+					host_ram.over_event();
+					i=3;
+				}
+				break;
+		}
+	}
+}
+//============================================================================================================
+extern void app_pair_client_process(void);
+struct{
+	char statu;
+	short adc_value;
+	pair_line_t pair_line;
+	unsigned int delay_pair_count;
+	Event into_event;
+	Event over_event;
+}client_ram={0,0,DISCONNECT_CHARGE,0,NULL,NULL};
+
+#define CONN_MAX_ADC 1000
+#define CONN_MIN_ADC 600
+void app_pair_client_init(Event into,Event over)
+{
+	client_ram.adc_value=0;
+	client_ram.delay_pair_count=0;
+	client_ram.statu=0;
+	client_ram.pair_line=DISCONNECT_CHARGE;
+	client_ram.into_event=into;
+	client_ram.over_event=over;
+	Process_Start(ADC_CHECKMS, "app_pair_client_process", app_pair_client_process);
+}
+void app_pair_client_uninit(void)
+{
+	Process_Stop(app_pair_client_process);
+}
+static void app_pair_client_process(void)
+{
+	for(int i=1;i>0;i--)
+	{
+		switch(client_ram.statu)
+		{
+			case 0:
+				ADC_Disable();
+				ADC_SetPinChannel(PIN_CHARGING, PIN_CHARGING_CHANNEL, NRF_GPIO_PIN_NOPULL);
+				ADC_Initialize();
+				client_ram.statu=1;
+				break;
+			case 1:
+				if(mFlash.isHost==HOST_SHOSE)
+				{
+					app_pair_client_uninit();
+					app_pair_chargerpin_Init();
+					PAIR_CHARGERPIN_PRINT("mFlash.isHost change %d %d\n",TIME_GetTicks(),mFlash.isHost );
+				}
+			
+				if (ADC_OP_SUCCESS != ADC_Read(PIN_CHARGING_CHANNEL, &client_ram.adc_value))
+				{
+						PAIR_CHARGERPIN_PRINT("ADC_Read ERROR %d\n", client_ram.adc_value);
+				}
+				log("ad:%d,%d\n",client_ram.adc_value, client_ram.pair_line);
+				PAIR_CHARGERPIN_PRINT("ADC (  %d  ):isHost %d Ticks %d\n", client_ram.adc_value, mFlash.isHost,TIME_GetTicks());
+				if(client_ram.adc_value>CONN_MAX_ADC)
+				{
+					PAIR_CHARGERPIN_PRINT("CHARGE\n");
+					if(client_ram.pair_line!=CHARGE)
+					{
+						PAIR_CHARGERPIN_PRINT("INTO CHARGE %d\n", 1);
+						client_ram.pair_line=CHARGE;
+					}
+				}
+				else if(client_ram.adc_value>CONN_MIN_ADC)
+				{
+					PAIR_CHARGERPIN_PRINT("CONNECT_NO_CHARGE\n");
+					if(client_ram.pair_line!=CONNECT_NO_CHARGE)
+					{
+						PAIR_CHARGERPIN_PRINT("INTO CONNECT_NO_CHARGE %d\n", 1);
+						client_ram.pair_line=CONNECT_NO_CHARGE;	
+						
+						client_ram.delay_pair_count=TIME_GetTicks();
+						Process_UpdatePeroid(app_pair_client_process,1);
+						Process_SetHoldOn(app_pair_client_process,1);
+						client_ram.statu=2;		
+						nrf_gpio_cfg(
+							PIN_CHARGING,
+							NRF_GPIO_PIN_DIR_OUTPUT,
+							NRF_GPIO_PIN_INPUT_CONNECT,
+							NRF_GPIO_PIN_NOPULL,
+							NRF_GPIO_PIN_D0H1,
+							NRF_GPIO_PIN_NOSENSE);
+						nrf_gpio_cfg_watcher(PIN_CHARGING);
+						nrf_gpio_pin_set(PIN_CHARGING);
+						
+						client_ram.into_event();	
+						PAIR_CHARGERPIN_PRINT("  into_event %d\n", TIME_GetTicks());
+						PAIR_CHARGERPIN_PRINT("  wait pair %d\n", nrf_gpio_pin_read(PIN_CHARGING));					
+					}
+				}
+				else
+				{
+					if(client_ram.pair_line!=DISCONNECT_CHARGE)
+					{
+						PAIR_CHARGERPIN_PRINT("INTO DISCONNECT_CHARGE %d\n", 1);
+						client_ram.pair_line=DISCONNECT_CHARGE;
+					}
+				}			
+				break;
+			case 2:
+				if(TIME_GetTicks() - client_ram.delay_pair_count > 100)//等
+				{
+					nrf_gpio_pin_clear(PIN_CHARGING);
+					client_ram.statu=3;
+					Process_UpdatePeroid(app_pair_client_process,ADC_CHECKMS);
+					Process_SetHoldOn(app_pair_client_process,0);
+				}
+				break;
+			case 3:
+				if (TIME_GetTicks() - client_ram.delay_pair_count > PAIROVERTIME)
+				{
+					client_ram.statu=0;
+					client_ram.over_event();
+					PAIR_CHARGERPIN_PRINT("  over_event %d\n", TIME_GetTicks());
+					i=3;
+				}
+				break;
+		}
+	}
+}
+
+
+
+
+
+
+

+ 38 - 0
app/app_chargerpin_conn_detect.h

@@ -0,0 +1,38 @@
+#ifndef APP_PAIR_CHARGERPINk__
+#define APP_PAIR_CHARGERPINk__
+
+
+typedef enum
+{
+    CHARGE = 0,
+    CONNECT_NO_CHARGE,
+    DISCONNECT_CHARGE,
+} pair_line_t;
+
+// <q> BLE_PRINTF  - µ÷ÊÔÐÅÏ¢
+#ifndef PAIR_CHARGERPIN_PRINTF
+#define PAIR_CHARGERPIN_PRINTF 1
+#endif
+#if PAIR_CHARGERPIN_PRINTF
+#define PAIR_CHARGERPIN_PRINT(...) SEGGER_RTT_printf(0, __VA_ARGS__)
+#else
+#define PAIR_CHARGERPIN_PRINT(...) 
+#endif
+
+// <q> PAIR_INFO_EN  - µ÷ÊÔÐÅÏ¢
+#ifndef PAIR_CHARGERPIN_INFO_EN
+#define PAIR_CHARGERPIN_INFO_EN 1
+#endif
+#if PAIR_CHARGERPIN_INFO_EN
+#define PAIR_CHARGERPIN_INFO(...) SEGGER_RTT_printf(0, __VA_ARGS__)
+#else
+#define PAIR_CHARGERPIN_INFO(...) ;
+#endif
+
+typedef void (*Event)(void);
+
+void app_pair_client_init(Event into,Event over);
+void app_pair_client_uninit(void);
+void app_pair_host_init(Event into,Event over);
+void app_pair_host_uninit(void);
+#endif

+ 500 - 0
app/app_one_wire.c

@@ -0,0 +1,500 @@
+#include "usr_config.h"
+#include "bsp_time.h"
+#include "system.h"
+#include "nrf_gpio.h"
+#include "app_charge.h"
+#include "app_flash.h"
+#include "ble_comm.h"
+#include "bsp_adc.h"
+#include "app_pair_chargerpin.h"
+#include "hal_led.h"
+#include "hal_charge.h"
+#include "app_one_wire.h"
+
+//发送协议
+// Host    MAC[0] MAC[1] MAC[2]>>>>>> Client
+// Client  MAC[3] MAC[4] MAC[5]>>>>>> Host
+
+//===========================================================================================================
+#define PIN_LED_RUN 100
+
+#define DATA_LENGTH 4
+#define BITWIDTH 30
+#define LOW_BIT_DELAY 15
+#define DELAY_SEND 100
+#define DELAY_REPLY 100
+#define DELAY_CHECK 100
+#define DELAY_LEDON (BITWIDTH * (8 * DATA_LENGTH + 3) * 2 + DELAY_SEND + DELAY_REPLY + DELAY_CHECK + 5 * BITWIDTH)
+#define LEDON_KEEP 100
+
+unsigned static char rxbuf[DATA_LENGTH];
+unsigned static char txbuf[DATA_LENGTH];
+unsigned static char savebuf[DATA_LENGTH];
+typedef void (*_Event)(unsigned char*,int);
+_Event _success_evt;
+static char one_ms_status = 0;
+static void null_pcs(void)
+{}
+void chargerpin_one_ms_init(_Event success_evt)
+{
+	one_ms_status = 0;
+	_success_evt=success_evt;
+	Process_Start(0, "null_pcs", null_pcs);
+	Process_SetHoldOn(null_pcs, 1);
+	TIME_Regist(chargerpin_one_ms_pcs);
+	PAIR_CHARGERPIN_PRINT("-------------------------------------------chargerpin_one_ms_init.%d\r\n", 1);
+}
+void chargerpin_one_ms_uninit(void)
+{
+	Process_Stop(null_pcs);
+	TIME_UnRegist(chargerpin_one_ms_pcs);
+	PAIR_CHARGERPIN_PRINT("-------------------------------------------chargerpin_one_ms_uninit.%d\r\n", 1);
+}
+
+
+void chargerpin_one_ms_pcs(void *t)
+{
+    unsigned int ms = *(unsigned int *)t;
+    static unsigned int bit_width = 0;
+    static unsigned int now_bit = 0;
+    static unsigned int delay_send_count = 0;
+    static unsigned int delay_reply_count = 0;
+    static unsigned int delay_check_count = 0;
+    static unsigned int delay_ledon_count = 0;
+    static int bitindex = 0;
+    static int bytesindes = 0;
+    static int value = 0;
+    static int txrxcount = 0;
+    static char lowbitdelay = 0;
+    switch (one_ms_status)
+    {
+    case 0: // init
+        bit_width = 0;
+        now_bit = 0;
+        delay_send_count = 0;
+        delay_reply_count = 0;
+        delay_check_count = 0;
+        delay_ledon_count = 0;
+        bitindex = 0;
+        bytesindes = 0;
+        value = 0;
+        txrxcount = 0;
+        one_ms_status = 0;
+        lowbitdelay = 0;
+        nrf_gpio_cfg(
+            PIN_CHARGING,
+            NRF_GPIO_PIN_DIR_OUTPUT,
+            NRF_GPIO_PIN_INPUT_CONNECT,
+            NRF_GPIO_PIN_NOPULL,
+            NRF_GPIO_PIN_D0H1,
+            NRF_GPIO_PIN_NOSENSE);
+        nrf_gpio_cfg_watcher(PIN_CHARGING);
+        one_ms_status = 1;
+        nrf_gpio_pin_clear(PIN_CHARGING);
+        PAIR_CHARGERPIN_PRINT("nrf_gpio_cfg_watcher(PIN_CHARGING); clear.%d\r\n", ms);
+        break;
+    case 1:
+        if (now_bit == nrf_gpio_pin_read(PIN_CHARGING))
+        {
+            bit_width++;
+        }
+        else
+        {
+            //由高电平切换到低电平,下降信号
+            if (now_bit == 1)
+            {
+                now_bit = 0;
+                if ((bit_width > 1.5 * BITWIDTH - LOW_BIT_DELAY / 3) && (bit_width < 1.5 * BITWIDTH + LOW_BIT_DELAY / 3))
+                {
+                    one_ms_status = 3;
+                    txrxcount = 1.5 * BITWIDTH;
+                    value = 30;
+                    if (mFlash.isHost == 0)
+                    {
+                        delay_ledon_count = 1.5 * BITWIDTH + DELAY_SEND;
+                        PAIR_CHARGERPIN_PRINT("delay_ledon_count = 1.5 * BITWIDTH + DELAY_SEND.%d\r\n", txrxcount);
+                    }
+                    else
+                    {
+                        delay_ledon_count = 2.5 * BITWIDTH + DELAY_SEND + BITWIDTH * 8 * DATA_LENGTH + 1.5 * BITWIDTH + DELAY_REPLY;
+                        PAIR_CHARGERPIN_PRINT("delay_ledon_count = 2.5 * BITWIDTH + DELAY_SEND + BITWIDTH*8*DATA_LENGTH + 1.5 * BITWIDTH + DELAY_REPLY .%d\r\n", txrxcount);
+                    }
+                    PAIR_CHARGERPIN_PRINT("-----------------------RX MODE start .%d\r\n", bit_width);
+                    break;
+                }
+                else
+                {
+                    if (mFlash.isHost)
+                    {
+                        delay_send_count = 1; //左边鞋发送数据
+                    }
+                    PAIR_CHARGERPIN_INFO("EXTI CHARGEING MOID.%d bit_width %d \r\n", ms, bit_width);
+                }
+            }
+            else
+            {
+                now_bit = 1;
+                delay_send_count = 0;
+                delay_reply_count = 0;
+                delay_check_count = 0;
+                nrf_gpio_pin_write(PIN_LED_RUN, 0);
+                delay_ledon_count = 0;
+                PAIR_CHARGERPIN_PRINT("0123delay_ledon_count = 0 .%d\r\n", txrxcount);
+                PAIR_CHARGERPIN_INFO("INTO CHARGEING MOID.%d\r\n", ms);
+            }
+            bit_width = 0;
+        }
+        if (delay_send_count != 0)
+        {
+            delay_send_count++;
+        }
+        if (delay_send_count > DELAY_SEND)
+        {
+            unsigned char macbuff[32];
+            delay_send_count = 0;
+            PAIR_CHARGERPIN_PRINT("BEGIN send MAC.%d\r\n", ms);
+            Get_MACaddr(macbuff);
+            macbuff[DATA_LENGTH - 1] = 0;
+            for (int i = 0; i < DATA_LENGTH - 1; i++)
+            {
+                macbuff[DATA_LENGTH - 1] += macbuff[i];
+            }
+            memcpy(txbuf, macbuff, DATA_LENGTH);
+            PAIR_CHARGERPIN_PRINT("host_mac send.%d\r\n", ms);
+            one_ms_status = 2;
+            txrxcount = 0;
+            for (int i = 0; i < DATA_LENGTH; i++)
+            {
+                PAIR_CHARGERPIN_PRINT("txbuf.%x\r\n", txbuf[i]);
+            }
+            break;
+        }
+        if (delay_reply_count != 0)
+        {
+            delay_reply_count++;
+        }
+        if (delay_reply_count > DELAY_REPLY)
+        {
+            unsigned char macbuff[16];
+            delay_reply_count = 0;
+            PAIR_CHARGERPIN_PRINT("BEGIN send MAC.%d\r\n", ms);
+            Get_MACaddr(macbuff);
+            memcpy(txbuf, &macbuff[3], DATA_LENGTH);
+            txbuf[DATA_LENGTH - 1] = 0;
+            for (int i = 0; i < DATA_LENGTH - 1; i++)
+            {
+                txbuf[DATA_LENGTH - 1] += txbuf[i];
+            }
+            PAIR_CHARGERPIN_PRINT("host_mac send.%d\r\n", ms);
+            one_ms_status = 2;
+            txrxcount = 0;
+            for (int i = 0; i < DATA_LENGTH; i++)
+            {
+                PAIR_CHARGERPIN_PRINT("txbuf.%x\r\n", txbuf[i]);
+            }
+            break;
+        }
+        if (delay_check_count != 0)
+        {
+            delay_check_count++;
+        }
+        if (delay_check_count > DELAY_CHECK)
+        {
+            delay_check_count = 0;
+            one_ms_status = 4;
+            txrxcount = 0;
+            PAIR_CHARGERPIN_PRINT("CHECK start.%d\r\n", ms);
+            break;
+        }
+        else if (delay_check_count > 0)
+        {
+            if (now_bit > 0)
+            {
+                delay_check_count = 0;
+                PAIR_CHARGERPIN_PRINT("CANCEL CHECK.%d\r\n", ms);
+            }
+        }
+        break;
+    case 2: // tx
+    {
+        lowbitdelay++;
+        static char send_interrupt = 0;
+        if ((now_bit == 0) && (nrf_gpio_pin_read(PIN_CHARGING)) && (lowbitdelay > LOW_BIT_DELAY))
+        {
+            if (mFlash.isHost)
+            {
+                one_ms_status = 1;
+                nrf_gpio_pin_clear(PIN_CHARGING);
+                PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
+                delay_ledon_count = 0;
+                PAIR_CHARGERPIN_PRINT("delay_ledon_count1 = 0;\r\n", txrxcount);
+                PAIR_CHARGERPIN_PRINT("EXTI SEND MODE.CAN NOT SET LOW  %d\r\n", txrxcount);
+                send_interrupt = 0;
+                break;
+            }
+            else
+            {
+                nrf_gpio_pin_clear(PIN_CHARGING);
+                PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
+                send_interrupt = 1;
+            }
+        }
+        if ((txrxcount == 0) && (send_interrupt == 0))
+        {
+            nrf_gpio_pin_set(PIN_CHARGING);
+            PAIR_CHARGERPIN_PRINT("set.%d\r\n", ms);
+            now_bit = 1;
+        }
+        if ((txrxcount == 1.5 * BITWIDTH) && (send_interrupt == 0))
+        {
+            nrf_gpio_pin_clear(PIN_CHARGING);
+            PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
+            now_bit = 0;
+            lowbitdelay = 0;
+        }
+				
+        if ((txrxcount >= (int)(2.5 * BITWIDTH) && (txrxcount - (int)(2.5 * BITWIDTH)) % BITWIDTH == 0) && (send_interrupt == 0)&&(txrxcount < BITWIDTH * (8 * DATA_LENGTH + 2.5) - 1))
+        {
+            bytesindes = ((txrxcount - (int)(2.5 * BITWIDTH)) / BITWIDTH) / 8;
+            bitindex = 7 - ((txrxcount - (int)(2.5 * BITWIDTH)) / BITWIDTH) % 8;
+            nrf_gpio_pin_write(PIN_CHARGING, (txbuf[bytesindes] >> bitindex) & 0x01);
+            lowbitdelay = 0;
+            PAIR_CHARGERPIN_PRINT("write.%d %d\r\n", ((txbuf[bytesindes] >> bitindex) & 0x01), txrxcount);
+            now_bit = (txbuf[bytesindes] >> bitindex) & 0x01;
+            PAIR_CHARGERPIN_PRINT("%d %d %d %d %x\r\n", (txrxcount - (int)(2.5 * BITWIDTH)) / BITWIDTH, bytesindes, bitindex, (txbuf[bytesindes] >> bitindex) & 0x01, txbuf[bytesindes]);
+        }
+        if (send_interrupt)
+        {
+            if (nrf_gpio_pin_read(PIN_CHARGING) == 0)
+            {
+                send_interrupt = 0;
+                delay_ledon_count = DELAY_SEND;
+                PAIR_CHARGERPIN_PRINT("delay_ledon_count = DELAY_SEND;.%d\r\n", txrxcount);
+                PAIR_CHARGERPIN_PRINT("RX SEND MODE MAC START.%d\r\n", txrxcount);
+                txrxcount = 0;
+                break;
+            }
+        }
+        if (txrxcount == BITWIDTH * (8 * DATA_LENGTH + 2.5) - 1)
+        {
+            nrf_gpio_pin_clear(PIN_CHARGING);
+            PAIR_CHARGERPIN_PRINT("clearr.%d\r\n", ms);
+            if (mFlash.isHost == 0)
+            {
+                delay_check_count = 1;
+            }
+        }
+        if (delay_check_count != 0)
+        {
+            delay_check_count++;
+        }
+        if (txrxcount >= BITWIDTH * (8 * DATA_LENGTH + 2.5) - 1 + LOW_BIT_DELAY)
+        {
+            one_ms_status = 1;
+            send_interrupt = 0;
+            now_bit = 0;
+            bit_width = 0;
+            PAIR_CHARGERPIN_PRINT("SEDN DONE .%d pin one_ms_status  %d\r\n", ms, nrf_gpio_pin_read(PIN_CHARGING));//IO口高电平就有错
+            break;
+        }
+        txrxcount++;
+    }
+    break;
+    case 3: // rx
+        if (now_bit == nrf_gpio_pin_read(PIN_CHARGING))
+        {
+            bit_width++;
+        }
+        else
+        {
+            if (now_bit == 1)
+            {
+                now_bit = 0;
+                if ((bit_width > 1.5 * BITWIDTH - 3) && (bit_width < 1.8 * BITWIDTH + 3))
+                {
+                    txrxcount = 1.5 * BITWIDTH;
+                    value = 30;
+                    delay_ledon_count = DELAY_SEND + 1.5 * BITWIDTH;
+                    PAIR_CHARGERPIN_PRINT("DELAY_SEND + 1.5 * BITWIDTHt .%d\r\n", txrxcount);
+                    PAIR_CHARGERPIN_PRINT("RX MODE restart .%d\r\n", ms);
+                }
+            }
+            else
+            {
+                now_bit = 1;
+            }
+            bit_width = 0;
+        }
+        if (txrxcount >= (int)(3.5 * BITWIDTH) && (txrxcount - (int)(3.5 * BITWIDTH)) % BITWIDTH == 0)
+        {
+            bytesindes = ((txrxcount - (int)(3.5 * BITWIDTH)) / BITWIDTH) / 8;
+            bitindex = 7 - ((txrxcount - (int)(3.5 * BITWIDTH)) / BITWIDTH) % 8;
+            if (value > 0)
+            {
+                rxbuf[bytesindes] |= 0x01 << bitindex;
+            }
+            else
+            {
+                rxbuf[bytesindes] &= ~(0x01 << bitindex);
+            }
+            PAIR_CHARGERPIN_PRINT("%d %d %d %d %x\r\n", txrxcount, bytesindes, bitindex, value, rxbuf[bytesindes]);
+            value = 0;
+            nrf_gpio_pin_toggle(PIN_LED_RUN);
+        }
+        else
+        {
+            if (now_bit)
+            {
+                value++;
+            }
+            else
+            {
+                value--;
+            }
+        }
+        if (txrxcount >= BITWIDTH * (8 * DATA_LENGTH + 2.5))
+        {
+            unsigned char dataerrcheck = 0;
+            unsigned char crc = 0;
+            one_ms_status = 1;
+            PAIR_CHARGERPIN_PRINT("RECEVIC DONE .%d\r\n", txrxcount);
+            nrf_gpio_pin_clear(PIN_LED_RUN);
+            PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
+            for (int i = 0; i < DATA_LENGTH - 1; i++)
+            {
+                crc += rxbuf[i];
+            }
+            for (int i = 0; i < DATA_LENGTH - 1; i++)
+            {
+                if (rxbuf[i] == 0)
+                {
+                    dataerrcheck++;
+                }
+            }
+            if (dataerrcheck == DATA_LENGTH - 1)
+            {
+                PAIR_CHARGERPIN_PRINT("CRC ERROR ALL 0x00.%x\r\n", crc);
+                delay_ledon_count = 0;
+                PAIR_CHARGERPIN_PRINT("delay_ledon_count 2= 0;\r\n", txrxcount);
+                break;
+            }
+            dataerrcheck = 0;
+            for (int i = 0; i < DATA_LENGTH - 1; i++)
+            {
+                if (rxbuf[i] == 0xff)
+                {
+                    dataerrcheck++;
+                }
+            }
+            if (dataerrcheck == DATA_LENGTH - 1)
+            {
+                PAIR_CHARGERPIN_PRINT("CRC ERROR ALL 0xFF.%x\r\n", crc);
+                delay_ledon_count = 0;
+                PAIR_CHARGERPIN_PRINT("delay_ledon_count 3= 0;\r\n", txrxcount);
+                break;
+            }
+            if (crc == rxbuf[DATA_LENGTH - 1])
+            {
+                if (mFlash.isHost)
+                {
+                    delay_check_count = 1; //延时校验计数器
+                }
+                else
+                {
+                    delay_reply_count = 1; //延时回复计数器
+                }
+                PAIR_CHARGERPIN_PRINT("---------------CRC SUCCESS .%x----------------\r\n", crc);
+            }
+            else
+            {
+                PAIR_CHARGERPIN_PRINT("CRC ERROR .%x\r\n", crc);
+                delay_ledon_count = 0;
+                PAIR_CHARGERPIN_PRINT("delay_ledon_count 4= 0;\r\n", txrxcount);
+            }
+            for (int i = 0; i < DATA_LENGTH; i++)
+            {
+                PAIR_CHARGERPIN_PRINT("rxbuf[%d].%x\r\n", i, rxbuf[i]);
+            }
+        }
+        txrxcount++;
+        break;
+    case 4:
+        if (nrf_gpio_pin_read(PIN_CHARGING))
+        {
+            value++;
+        }
+        else
+        {
+            value--;
+        }
+        if (mFlash.isHost)
+        {
+            if (txrxcount == 0)
+            {
+                value = 0;
+                nrf_gpio_pin_set(PIN_CHARGING);
+                PAIR_CHARGERPIN_PRINT("set.%d\r\n", ms);
+            }
+            if (txrxcount == 3 * BITWIDTH)
+            {
+                nrf_gpio_pin_clear(PIN_CHARGING);
+                PAIR_CHARGERPIN_PRINT("clear.%d\r\n", delay_ledon_count);
+            }
+            if (txrxcount >= 3 * BITWIDTH + LOW_BIT_DELAY)
+            {
+                value = 0;
+                one_ms_status = 1;
+                now_bit = 0;
+                bit_width = 0;
+            }
+        }
+        else
+        {
+            if (txrxcount == 0)
+            {
+                value = 0;
+            }
+            if (txrxcount > 3 * BITWIDTH)
+            {
+                if (value < 2 * BITWIDTH)
+                {
+                    PAIR_CHARGERPIN_PRINT("CHECK ERROR .%d\r\n", txrxcount);
+                    delay_ledon_count = 0;
+                    PAIR_CHARGERPIN_PRINT("delay_ledon_count 5= 0;\r\n", txrxcount);
+                }
+                else
+                {
+                    PAIR_CHARGERPIN_PRINT("CHECK DONE .%d\r\n", txrxcount);
+                }
+                value = 0;
+                one_ms_status = 1;
+                nrf_gpio_pin_clear(PIN_CHARGING);
+                PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
+                now_bit = 1;
+                bit_width = 0;
+            }
+        }
+        txrxcount++;
+        break;
+    }
+    if (delay_ledon_count != 0)
+    {
+        delay_ledon_count++;
+    }
+    if (delay_ledon_count == DELAY_LEDON)
+    {
+        PAIR_CHARGERPIN_PRINT("LEDCOPEN.%d\r\n", ms);
+        memcpy(savebuf, rxbuf, DATA_LENGTH - 1);
+        if(_success_evt)_success_evt(savebuf,DATA_LENGTH - 1);
+    }
+    if ((delay_ledon_count > DELAY_LEDON) && (delay_ledon_count - DELAY_LEDON == LEDON_KEEP))
+    {
+        delay_ledon_count = 0;
+        PAIR_CHARGERPIN_PRINT("delay_ledon_count 6= 0;\r\n", txrxcount);
+        PAIR_CHARGERPIN_PRINT("LEDCLOSE.%d\r\n", ms);
+    }
+}
+
+
+
+//===========================================================================================================

+ 9 - 0
app/app_one_wire.h

@@ -0,0 +1,9 @@
+#ifndef __app_one_wire_h__
+#define __app_one_wire_h__
+
+typedef void (*_Event)(unsigned char*,int);
+void chargerpin_one_ms_init(_Event success_evt);
+void chargerpin_one_ms_pcs(void *t);
+void chargerpin_one_ms_uninit(void);
+
+#endif

+ 241 - 873
app/app_pair_chargerpin.c

@@ -7,533 +7,93 @@
 #include "ble_comm.h"
 #include "bsp_adc.h"
 #include "app_pair_chargerpin.h"
+#include "app_chargerpin_conn_detect.h"
 #include "hal_led.h"
 #include "hal_charge.h"
 #include "hal_mt.h"
-
-//发送协议
-//Host    MAC[0] MAC[1] MAC[2]>>>>>> Client
-//Client  MAC[3] MAC[4] MAC[5]>>>>>> Host
-
-#define HOST_PEAR 1
-
-#define PIN_LED_RUN 100
-
-#define DATA_LENGTH 4
-#define BITWIDTH 30
-#define LOW_BIT_DELAY 15
-#define DELAY_SEND 100
-#define DELAY_REPLY 100
-#define DELAY_CHECK 100
-#define DELAY_LEDON (BITWIDTH*(8*DATA_LENGTH+3)*2+DELAY_SEND+DELAY_REPLY+DELAY_CHECK+5*BITWIDTH)
-#define LEDON_KEEP 100
-
-static uint8_t leddisplay_count=0;
-
-unsigned static char rxbuf[DATA_LENGTH];
-unsigned static char txbuf[DATA_LENGTH];
-__IO static char writefig=0;
-unsigned static char savebuf[DATA_LENGTH];
-
-static char one_ms_status = 0;
-static void chargerpin_one_ms_pcs(void* t)
+#include "app_one_wire.h"
+//==========================================================================
+char open=0;
+static uint8_t leddisplay_count = 0;
+void pair_led_pcs(void)
 {
-    unsigned int ms = *(unsigned int*)t;
-    static unsigned int bit_width = 0;
-    static unsigned int now_bit = 0;
-    static unsigned int delay_send_count = 0;
-    static unsigned int delay_reply_count = 0;
-    static unsigned int delay_check_count = 0;
-    static unsigned int delay_ledon_count = 0;
-    static int bitindex = 0;
-    static int bytesindes = 0;
-    static int value = 0;
-    static int txrxcount = 0;
-
-		static char lowbitdelay=0;
-    switch (one_ms_status)
+    leddisplay_count++;
+    if (leddisplay_count % 2 == 0)
     {
-        case 0://init				
-						bit_width = 0;
-						now_bit = 0;
-						delay_send_count = 0;
-						delay_reply_count = 0;
-						delay_check_count = 0;
-						delay_ledon_count = 0;
-						bitindex = 0;
-						bytesindes = 0;
-						value = 0;
-						txrxcount = 0;
-						one_ms_status = 0;
-						lowbitdelay=0;
-            nrf_gpio_cfg(
-                PIN_CHARGING,
-                NRF_GPIO_PIN_DIR_OUTPUT,
-                NRF_GPIO_PIN_INPUT_CONNECT,
-                NRF_GPIO_PIN_NOPULL,
-                NRF_GPIO_PIN_D0H1,
-                NRF_GPIO_PIN_NOSENSE);
-            nrf_gpio_cfg_watcher(PIN_CHARGING);
-            one_ms_status = 1;
-            nrf_gpio_pin_clear(PIN_CHARGING);
-            PAIR_CHARGERPIN_PRINT("nrf_gpio_cfg_watcher(PIN_CHARGING); clear.%d\r\n", ms);
-            break;
-        case 1:
-            if (now_bit == nrf_gpio_pin_read(PIN_CHARGING))
-            {
-              bit_width++;
-            }
-            else
-            {
-                //由高电平切换到低电平,下降信号
-                if (now_bit == 1)
-                {
-                    now_bit = 0;
-                    if ((bit_width > 1.5 * BITWIDTH - LOW_BIT_DELAY/3) && (bit_width < 1.5 * BITWIDTH + LOW_BIT_DELAY/3))
-                    {
-                        one_ms_status = 3;
-                        txrxcount = 1.5 * BITWIDTH;
-                        value = 30;
-                        if (mFlash.isHost == 0)
-                        {
-                            delay_ledon_count = 1.5 * BITWIDTH + DELAY_SEND;
-                            PAIR_CHARGERPIN_PRINT("delay_ledon_count = 1.5 * BITWIDTH + DELAY_SEND.%d\r\n", txrxcount);
-                        }
-                        else
-                        {
-                            delay_ledon_count = 2.5 * BITWIDTH + DELAY_SEND + BITWIDTH * 8 * DATA_LENGTH + 1.5 * BITWIDTH + DELAY_REPLY;
-                            PAIR_CHARGERPIN_PRINT("delay_ledon_count = 2.5 * BITWIDTH + DELAY_SEND + BITWIDTH*8*DATA_LENGTH + 1.5 * BITWIDTH + DELAY_REPLY .%d\r\n", txrxcount);
-                        }
-                        PAIR_CHARGERPIN_PRINT("-----------------------RX MODE start .%d\r\n", bit_width);
-                        break;
-                    }
-                    else
-                    {
-                        if (mFlash.isHost)
-                        {
-                            delay_send_count = 1; //左边鞋发送数据
-                        }
-                        PAIR_CHARGERPIN_INFO("EXTI CHARGEING MOID.%d bit_width %d \r\n", ms,bit_width);
-                    }
-                }
-                else
-                {
-                    now_bit = 1;
-                    delay_send_count = 0;
-                    delay_reply_count = 0;
-                    delay_check_count = 0;
-                    nrf_gpio_pin_write(PIN_LED_RUN, 0);
-                    delay_ledon_count = 0;
-                    PAIR_CHARGERPIN_PRINT("delay_ledon_count = 0 .%d\r\n", txrxcount);
-                    PAIR_CHARGERPIN_INFO("INTO CHARGEING MOID.%d\r\n", ms);
-                }
-                bit_width = 0;
-            }
-						
-            if (delay_send_count != 0)
-            {
-                delay_send_count++;
-            }
-            if (delay_send_count > DELAY_SEND)
-            {
-                unsigned char macbuff[32];
-                delay_send_count = 0;
-                PAIR_CHARGERPIN_PRINT("BEGIN send MAC.%d\r\n", ms);
-                Get_MACaddr(macbuff);
-                macbuff[DATA_LENGTH - 1] = 0;
-                for (int i = 0; i < DATA_LENGTH - 1; i++)
-                {
-                    macbuff[DATA_LENGTH - 1] += macbuff[i];
-                }
-                memcpy(txbuf, macbuff, DATA_LENGTH);
-                PAIR_CHARGERPIN_PRINT("host_mac send.%d\r\n", ms);
-                one_ms_status = 2;
-								
-                txrxcount = 0;
-                for (int i = 0; i < DATA_LENGTH; i++)
-                {
-                    PAIR_CHARGERPIN_PRINT("txbuf.%x\r\n", txbuf[i]);
-                }
-                break;
-            }
-            if (delay_reply_count != 0)
-            {
-                delay_reply_count++;
-            }
-            if (delay_reply_count > DELAY_REPLY)
-            {
-                unsigned char macbuff[16];
-                delay_reply_count = 0;
-                PAIR_CHARGERPIN_PRINT("BEGIN send MAC.%d\r\n", ms);
-                Get_MACaddr(macbuff);
-                memcpy(txbuf, &macbuff[3], DATA_LENGTH);
-                txbuf[DATA_LENGTH - 1] = 0;
-                for (int i = 0; i < DATA_LENGTH - 1; i++)
-                {
-                    txbuf[DATA_LENGTH - 1] += txbuf[i];
-                }
-                PAIR_CHARGERPIN_PRINT("host_mac send.%d\r\n", ms);
-                one_ms_status = 2;
-                txrxcount = 0;
-                for (int i = 0; i < DATA_LENGTH; i++)
-                {
-                    PAIR_CHARGERPIN_PRINT("txbuf.%x\r\n", txbuf[i]);
-                }
-                break;
-            }
-            if (delay_check_count != 0)
-            {
-                delay_check_count++;
-            }
-            if (delay_check_count > DELAY_CHECK)
-            {
-                delay_check_count = 0;
-                one_ms_status = 4;
-                txrxcount = 0;
-                PAIR_CHARGERPIN_PRINT("CHECK start.%d\r\n", ms);
-                break;
-            }
-            else if (delay_check_count > 0)
-            {
-                if (now_bit > 0)
-                {
-                    delay_check_count = 0;
-                    PAIR_CHARGERPIN_PRINT("CANCEL CHECK.%d\r\n", ms);
-                }
-            }
-            break;
-        case 2://tx
-        {
-						lowbitdelay++;
-            static char send_interrupt = 0;
-            if ((now_bit == 0) && (nrf_gpio_pin_read(PIN_CHARGING)) && (lowbitdelay>LOW_BIT_DELAY))
-            {
-                if (mFlash.isHost)
-                {
-                    one_ms_status = 1;
-                    nrf_gpio_pin_clear(PIN_CHARGING);
-                    PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
-                    delay_ledon_count = 0;
-                    PAIR_CHARGERPIN_PRINT("delay_ledon_count1 = 0;\r\n", txrxcount);
-                    PAIR_CHARGERPIN_PRINT("EXTI SEND MODE.CAN NOT SET LOW  %d\r\n", txrxcount);
-                    send_interrupt = 0;
-                    break;
-                }
-                else
-                {
-                    nrf_gpio_pin_clear(PIN_CHARGING);
-                    PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
-                    send_interrupt = 1;
-                }
-            }
-            if ((txrxcount == 0) && (send_interrupt == 0))
-            {
-                nrf_gpio_pin_set(PIN_CHARGING);
-                PAIR_CHARGERPIN_PRINT("set.%d\r\n", ms);
-                now_bit = 1;
-            }
-            if ((txrxcount == 1.5 * BITWIDTH) && (send_interrupt == 0))
-            {
-                nrf_gpio_pin_clear(PIN_CHARGING);
-                PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
-                now_bit = 0;
-								lowbitdelay=0;
-            }
-            if ((txrxcount >= (int)(2.5 * BITWIDTH) && (txrxcount - (int)(2.5 * BITWIDTH)) % BITWIDTH == 0) && (send_interrupt == 0))
-            {
-                bytesindes = ((txrxcount - (int)(2.5 * BITWIDTH)) / BITWIDTH) / 8;
-                bitindex = 7 - ((txrxcount - (int)(2.5 * BITWIDTH)) / BITWIDTH) % 8;
-                nrf_gpio_pin_write(PIN_CHARGING, (txbuf[bytesindes] >> bitindex) & 0x01);
-								lowbitdelay=0;
-                PAIR_CHARGERPIN_PRINT("write.%d %d\r\n", ((txbuf[bytesindes] >> bitindex) & 0x01), ms);
-                now_bit = (txbuf[bytesindes] >> bitindex) & 0x01;
-                PAIR_CHARGERPIN_PRINT("%d %d %d %d %x\r\n", (txrxcount - (int)(2.5 * BITWIDTH)) / BITWIDTH
-                    , bytesindes
-                    , bitindex
-                    , (txbuf[bytesindes] >> bitindex) & 0x01
-                    , txbuf[bytesindes]
-                );
-            }
-            if (send_interrupt)
-            {
-                if (nrf_gpio_pin_read(PIN_CHARGING) == 0)
-                {
-                    send_interrupt = 0;
-                    delay_ledon_count = DELAY_SEND;
-                    PAIR_CHARGERPIN_PRINT("delay_ledon_count = DELAY_SEND;.%d\r\n", txrxcount);
-                    PAIR_CHARGERPIN_PRINT("RX SEND MODE MAC START.%d\r\n", txrxcount);
-                    txrxcount = 0;
-                    break;
-                }
-            }
-						
-						if (txrxcount == BITWIDTH * (8 * DATA_LENGTH + 2.5) - 1)
-						{
-						    nrf_gpio_pin_clear(PIN_CHARGING);
-                PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
-								if (mFlash.isHost == 0)
-                {
-                    delay_check_count = 1;
-                }
-						}
-						if(delay_check_count!=0)delay_check_count++;
-            if (txrxcount >= BITWIDTH * (8 * DATA_LENGTH + 2.5) - 1 + LOW_BIT_DELAY)
-            {
-                one_ms_status = 1;
-                send_interrupt = 0;
-                now_bit = 0;
-                bit_width = 0;
-                PAIR_CHARGERPIN_PRINT("SEDN DONE .%d pin one_ms_status  %d\r\n", ms,nrf_gpio_pin_read(PIN_CHARGING));
-                break;
-            }
-            txrxcount++;
-        }
-        break;
-        case 3://rx
-            if (now_bit == nrf_gpio_pin_read(PIN_CHARGING))
-            {
-                bit_width++;
-            }
-            else
-            {
-                if (now_bit == 1)
-                {
-                    now_bit = 0;
-                    if ((bit_width > 1.5 * BITWIDTH - 3) && (bit_width < 1.8 * BITWIDTH + 3))
-                    {
-                        txrxcount = 1.5 * BITWIDTH;
-                        value = 30;
-                        delay_ledon_count = DELAY_SEND + 1.5 * BITWIDTH;
-                        PAIR_CHARGERPIN_PRINT("DELAY_SEND + 1.5 * BITWIDTHt .%d\r\n", txrxcount);
-                        PAIR_CHARGERPIN_PRINT("RX MODE restart .%d\r\n", ms);
-                    }
-                }
-                else
-                {
-                    now_bit = 1;
-                }
-                bit_width = 0;
-            }
-            if (txrxcount >= (int)(3.5 * BITWIDTH) && (txrxcount - (int)(3.5 * BITWIDTH)) % BITWIDTH == 0)
-            {
-                bytesindes = ((txrxcount - (int)(3.5 * BITWIDTH)) / BITWIDTH) / 8;
-                bitindex = 7 - ((txrxcount - (int)(3.5 * BITWIDTH)) / BITWIDTH) % 8;
-                if (value > 0)
-                {
-                    rxbuf[bytesindes] |= 0x01 << bitindex;
-                }
-                else
-                {
-                    rxbuf[bytesindes] &= ~(0x01 << bitindex);
-                }
-                PAIR_CHARGERPIN_PRINT("%d %d %d %d %x\r\n", txrxcount
-                    , bytesindes
-                    , bitindex
-                    , value
-                    , rxbuf[bytesindes]
-                );
-                value = 0;
-                nrf_gpio_pin_toggle(PIN_LED_RUN);
-            }
-            else
-            {
-                if (now_bit)
-                {
-                    value++;
-                }
-                else
-                {
-                    value--;
-                }
-            }
-            if (txrxcount >= BITWIDTH * (8 * DATA_LENGTH + 2.5))
-            {
-                unsigned char dataerrcheck = 0;
-                unsigned char crc = 0;
-                one_ms_status = 1;
-                PAIR_CHARGERPIN_PRINT("RECEVIC DONE .%d\r\n", txrxcount);
-                nrf_gpio_pin_clear(PIN_LED_RUN);
-                PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
-                for (int i = 0; i < DATA_LENGTH - 1; i++)
-                {
-                    crc += rxbuf[i];
-                }
-                for (int i = 0; i < DATA_LENGTH - 1; i++)
-                {
-                    if (rxbuf[i] == 0)
-                    {
-                        dataerrcheck++;
-                    }
-                }
-                if (dataerrcheck == DATA_LENGTH - 1)
-                {
-                    PAIR_CHARGERPIN_PRINT("CRC ERROR ALL 0x00.%x\r\n", crc);
-                    delay_ledon_count = 0;
-                    PAIR_CHARGERPIN_PRINT("delay_ledon_count 2= 0;\r\n", txrxcount);
-                    break;
-                }
-                dataerrcheck = 0;
-                for (int i = 0; i < DATA_LENGTH - 1; i++)
-                {
-                    if (rxbuf[i] == 0xff)
-                    {
-                        dataerrcheck++;
-                    }
-                }
-                if (dataerrcheck == DATA_LENGTH - 1)
-                {
-                    PAIR_CHARGERPIN_PRINT("CRC ERROR ALL 0xFF.%x\r\n", crc);
-                    delay_ledon_count = 0;
-                    PAIR_CHARGERPIN_PRINT("delay_ledon_count 3= 0;\r\n", txrxcount);
-                    break;
-                }
-                if (crc == rxbuf[DATA_LENGTH - 1])
-                {
-                    if (mFlash.isHost)
-                    {
-                        delay_check_count = 1; //延时校验计数器
-                    }
-                    else
-                    {
-                        delay_reply_count = 1; //延时回复计数器
-                    }
-										PAIR_CHARGERPIN_PRINT("---------------CRC SUCCESS .%x----------------\r\n", crc);
-                }
-                else
-                {
-                    PAIR_CHARGERPIN_PRINT("CRC ERROR .%x\r\n", crc);
-                    delay_ledon_count = 0;
-                    PAIR_CHARGERPIN_PRINT("delay_ledon_count 4= 0;\r\n", txrxcount);
-                }
-                for (int i = 0; i < DATA_LENGTH; i++)
-                {
-                    PAIR_CHARGERPIN_PRINT("rxbuf[%d].%x\r\n",i, rxbuf[i]);
-                }
-            }
-            txrxcount++;
-            break;
-        case 4:
-            if (nrf_gpio_pin_read(PIN_CHARGING))
-            {
-                value++;
-            }
-            else
-            {
-                value--;
-            }
-            if (mFlash.isHost)
-            {
-                if (txrxcount == 0)
-                {
-                    value = 0;
-                    nrf_gpio_pin_set(PIN_CHARGING);
-                    PAIR_CHARGERPIN_PRINT("set.%d\r\n", ms);
-                }
-                if (txrxcount == 3 * BITWIDTH)
-                {
-                    nrf_gpio_pin_clear(PIN_CHARGING);
-                    PAIR_CHARGERPIN_PRINT("clear.%d\r\n", delay_ledon_count);
-                }
-								if (txrxcount >= 3 * BITWIDTH + LOW_BIT_DELAY)
-                {
-                    value = 0;
-                    one_ms_status = 1;
-                    now_bit = 0;
-                    bit_width = 0;
-                }
-            }
-            else
-            {
-                if (txrxcount == 0)
-                {
-                    value = 0;
-                }
-                if (txrxcount > 3 * BITWIDTH)
-                {
-                    if (value < 2 * BITWIDTH)
-                    {
-                        PAIR_CHARGERPIN_PRINT("CHECK ERROR .%d\r\n", txrxcount);
-                        delay_ledon_count = 0;
-                        PAIR_CHARGERPIN_PRINT("delay_ledon_count 5= 0;\r\n", txrxcount);
-                    }
-                    else
-                    {
-                        PAIR_CHARGERPIN_PRINT("CHECK DONE .%d\r\n", txrxcount);
-                    }
-                    value = 0;
-                    one_ms_status = 1;
-                    nrf_gpio_pin_clear(PIN_CHARGING);
-                    PAIR_CHARGERPIN_PRINT("clear.%d\r\n", ms);
-                    now_bit = 1;
-                    bit_width = 0;
-                }
-            }
-            txrxcount++;
-            break;
+        LED_Start(LED_PAIR, COLOR_BLACK);
     }
-    if (delay_ledon_count != 0)
+    else
     {
-        delay_ledon_count++;
+        LED_Start(LED_PAIR, COLOR_WHITE);
     }
-    if (delay_ledon_count == DELAY_LEDON)
+    if (leddisplay_count > 20)
     {
-				PAIR_CHARGERPIN_PRINT("LEDCOPEN.%d\r\n", ms);
-				memcpy(savebuf,rxbuf,DATA_LENGTH-1);
-				writefig=1;
+        leddisplay_count = 0;
+        LED_Stop(LED_PAIR);
+        Process_SetHoldOn(pair_led_pcs, 0);
+        Process_Stop(pair_led_pcs);
     }
-
-    if ((delay_ledon_count > DELAY_LEDON )
-			&& (delay_ledon_count - DELAY_LEDON == LEDON_KEEP))
+}
+extern void close_white(void);
+void start_pair_led(void)
+{
+	close_white();
+	leddisplay_count = 0;
+  Process_Start(500, "pair_led_pcs", pair_led_pcs);
+  Process_SetHoldOn(pair_led_pcs, 1);
+}
+void stop_pair_led(void)
+{
+    if (leddisplay_count == 0)
     {
-        delay_ledon_count = 0;
-        PAIR_CHARGERPIN_PRINT("delay_ledon_count 6= 0;\r\n", txrxcount);
-        PAIR_CHARGERPIN_PRINT("LEDCLOSE.%d\r\n", ms);
+      return;
     }
+    Process_Stop(pair_led_pcs);
+    leddisplay_count = 0;
+		LED_Stop(LED_PAIR);
+}
+void open_white(void)
+{
+	LED_Start(LED_PAIR, COLOR_WHITE);
+	
+	PAIR_CHARGERPIN_PRINT("  ======================open_white open_white============================= \n");
+	open=1;
 }
 
-void pair_led_pcs(void)
+void close_white(void)
 {
-	leddisplay_count++;
-	if(leddisplay_count%2==0)
-	{
-		LED_Start(LED_PAIR,COLOR_BLACK);
-	}
-	else
-	{
-		LED_Start(LED_PAIR,COLOR_WHITE);
-	}
-	if(leddisplay_count>20)
-	{
-		leddisplay_count=0;
-		LED_Stop(LED_PAIR);
-		Process_SetHoldOn(pair_led_pcs,0);
-		Process_Stop(pair_led_pcs);
-	}
+	open=0;
+	LED_Stop(LED_PAIR);
+}
+char white_isopen(void)
+{
+	return open;
 }
 
-void stop_pair_led(void)
+void r_led_start(void)
 {
-	if(leddisplay_count==0)return;
-	LED_Start(LED_PAIR,COLOR_BLACK);
-	Process_SetHoldOn(pair_led_pcs,0);
-	Process_Stop(pair_led_pcs);
-	leddisplay_count=0;
+	stop_pair_led();
+	open_white();
 }
-PAIR_START_REGISTER(stop_pair_led);
+PAIR_START_REGISTER(r_led_start);
 
-void mtrun(void)
+void r_led_done(void)
 {
-//	MT_Run(200);
+	if(leddisplay_count!=0)open=0;
+	else close_white();
 }
-PAIR_START_REGISTER(mtrun);
+PAIR_DONE_REGISTER(r_led_done);
+//===========================================================================================
 
 //写配对相关的flish
-static int pair_writeflish(unsigned char* macAddr_L, unsigned char* macAddr_R)
+static int pair_writeflish(unsigned char *macAddr_L, unsigned char *macAddr_R)
 {
-	  uint8_t offest =0;
-	  if(mFlash.isHost){offest =3;}
-		
-    if (memcmp(macAddr_R, mFlash.mClient.macAddr+offest, 3) != 0)
+    uint8_t offest = 0;
+    if (mFlash.isHost)
+    {
+        offest = 3;
+    }
+    if (memcmp(macAddr_R, mFlash.mClient.macAddr + offest, 3) != 0)
     {
         goto writein;
     }
@@ -547,30 +107,42 @@ static int pair_writeflish(unsigned char* macAddr_L, unsigned char* macAddr_R)
     return 0;
 writein:
     mFlash.mClient.isConfig = 'C';
-		uint8_t i=0;
-    for (i = 0; i < 6; i++){mFlash.macHost[i] = macAddr_L[i];}
-    
-	  for (i = 0; i < 3; i++)
-		    mFlash.mClient.macAddr[i+offest] = macAddr_R[i];       //从机自身mac地址
-		
-		//保存数据到备份区域里面
-		for( i=0; i<RecordMacAddrL; i++){
-		  mBackup.macAddr_L[i] = mFlash.macHost[i];		     //主机地址
-		  mBackup.macAddr_R[i] = mFlash.mClient.macAddr[i];//从机地址
-		}
-		
-		mBackup.hardVersion = mFlash.mClient.hardVersion;
-		mBackup.sotfVersion = mFlash.mClient.sotfVersion;
-		mBackup.isConfig    = mFlash.mClient.isConfig;
-		
-		if(Flash_SaveBackup() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Pair,"pair save backup fail");
-		
+    uint8_t i = 0;
+    for (i = 0; i < 6; i++)
+    {
+        mFlash.macHost[i] = macAddr_L[i];
+    }
+    for (i = 0; i < 3; i++)
+    {
+        mFlash.mClient.macAddr[i + offest] = macAddr_R[i]; //从机自身mac地址
+    }
+    //保存数据到备份区域里面
+    for (i = 0; i < RecordMacAddrL; i++)
+    {
+        mBackup.macAddr_L[i] = mFlash.macHost[i];         //主机地址
+        mBackup.macAddr_R[i] = mFlash.mClient.macAddr[i]; //从机地址
+    }
+    mBackup.hardVersion = mFlash.mClient.hardVersion;
+    mBackup.sotfVersion = mFlash.mClient.sotfVersion;
+    mBackup.isConfig = mFlash.mClient.isConfig;
+    if (Flash_SaveBackup() != ZONE_OP_SUCCESS)
+    {
+        Except_TxError(EXCEPT_Pair, "pair save backup fail");
+    }
     DEBUG_LOG("mFlash.mClient.isConfig:%X\n", mFlash.mClient.isConfig);
     DEBUG_LOG("mFlash.mClient.macAddr:%02X %02X %02X\n", mFlash.mClient.macAddr[0], mFlash.mClient.macAddr[1], mFlash.mClient.macAddr[2]);
     DEBUG_LOG("mFlash.macHost:%02X %02X %02X \n", mFlash.macHost[0], mFlash.macHost[1], mFlash.macHost[2]);
-    if(Flash_DeleteAllStep()  != ZONE_OP_SUCCESS){Except_TxError(EXCEPT_Pair,"pair clear step fail");return 0;}
-		memset(&mFlash.mStep,0,sizeof(FlashStep_t));
-    if(Flash_SaveInfomation() != ZONE_OP_SUCCESS){Except_TxError(EXCEPT_Pair,"Flash_SaveInfomation fail");return 0;}
+    if (Flash_DeleteAllStep() != ZONE_OP_SUCCESS)
+    {
+        Except_TxError(EXCEPT_Pair, "pair clear step fail");
+        return 0;
+    }
+    memset(&mFlash.mStep, 0, sizeof(FlashStep_t));
+    if (Flash_SaveInfomation() != ZONE_OP_SUCCESS)
+    {
+        Except_TxError(EXCEPT_Pair, "Flash_SaveInfomation fail");
+        return 0;
+    }
     return 1;
 }
 
@@ -579,11 +151,10 @@ static void load_adv_name_from_flish(void)
     char buf[16];
     memset(buf, 0, sizeof(buf));
     advertising_stop();
-    sprintf(buf, "%02X%02X%02X%02X%02X%02X", mFlash.mClient.macAddr[0],mFlash.mClient.macAddr[1],mFlash.mClient.macAddr[2],mFlash.macHost[3],mFlash.macHost[4],mFlash.macHost[5]);
+    sprintf(buf, "%02X%02X%02X%02X%02X%02X", mFlash.mClient.macAddr[0], mFlash.mClient.macAddr[1], mFlash.mClient.macAddr[2], mFlash.macHost[3], mFlash.macHost[4], mFlash.macHost[5]);
     DEBUG_LOG("advName(%d):%s\n", strlen(buf), buf);
     slave_set_adv_name(buf, strlen(buf));
     slave_adv_init();
-
 }
 
 static void load_scan_name_from_flish(void)
@@ -594,384 +165,181 @@ static void load_scan_name_from_flish(void)
     DEBUG_LOG("scanName1(%d):%s\n", strlen(buf), buf);
     host_set_scan_name(buf, strlen(buf));
 }
-static unsigned char reconnect_pcs_status=0;
+static unsigned char reconnect_pcs_status = 0;
 static void reconnect_pcs(void)
 {
-	switch(reconnect_pcs_status)
-	{
-		case 0:
-			if(mFlash.isHost)
-			{
-				reconnect_pcs_status=1;
-				if(host_isconnect()==1)host_disconnect();
-			}
-			else
-			{
-				reconnect_pcs_status=2;
-				if(slave_isconnect()==1)slave_disconnect();
-			}
-			break;
-		case 1:
-			if(host_isconnect()==0)
-			{
-				load_scan_name_from_flish();
-				scan_start();
-				reconnect_pcs_status=4;
-			}	
-			break;
-		case 2:
-			if(slave_isconnect()==0)
-			{
-				load_adv_name_from_flish();
-				advertising_start();
-				reconnect_pcs_status=4;
-			}	
-			break;
-		case 4:
-			Process_SetHoldOn(reconnect_pcs,0);
-			Process_Stop(reconnect_pcs);
-			reconnect_pcs_status=5;
-	    leddisplay_count =0;
-			Process_Start(500,"pair_led_pcs",pair_led_pcs);
-			Process_SetHoldOn(pair_led_pcs,1);
-			break;
-		case 5:
-			
-			break;
-	}
+    switch (reconnect_pcs_status)
+    {
+    case 0:
+        if (mFlash.isHost)
+        {
+            reconnect_pcs_status = 1;
+            if (host_isconnect() == 1)
+            {
+                host_disconnect();
+            }
+        }
+        else
+        {
+            reconnect_pcs_status = 2;
+            if (slave_isconnect() == 1)
+            {
+                slave_disconnect();
+            }
+        }
+        break;
+    case 1:
+        if (host_isconnect() == 0)
+        {
+            load_scan_name_from_flish();
+            scan_start();
+            reconnect_pcs_status = 4;
+        }
+        break;
+    case 2:
+        if (slave_isconnect() == 0)
+        {
+            load_adv_name_from_flish();
+            advertising_start();
+            reconnect_pcs_status = 4;
+        }
+        break;
+    case 4:
+        Process_SetHoldOn(reconnect_pcs, 0);
+        Process_Stop(reconnect_pcs);
+        reconnect_pcs_status = 5;
+		
+				start_pair_led();
+        break;
+    case 5:
+        break;
+    }
 }
-
-static void app_pair_chargerpin_pcs(void)
+//===========================================================================================================
+extern void app_pair_chargerpin_pcs(void);
+void delsiflash(void)
 {
-	int rev=0;
-	if(writefig==1)
-	{
-		unsigned char Lbuff[6];
-		unsigned char Rbuff[3];
-		Get_MACaddr(Lbuff);
-		Rbuff[0]=savebuf[0];Rbuff[1]=savebuf[1];Rbuff[2]=savebuf[2];
-		rev=pair_writeflish(Lbuff,Rbuff);
-		
-		if(rev)
-		{
-			Process_Start(10,"reconnect_pcs",reconnect_pcs);
-			Process_SetHoldOn(reconnect_pcs,1);
-			reconnect_pcs_status=0;
-		}
-		else
-		{
-			leddisplay_count =0;
-			Process_Start(500,"pair_led_pcs",pair_led_pcs);
-			Process_SetHoldOn(pair_led_pcs,1);
-		}
-		writefig=0;
-	}
+	app_pair_chargerpin_pcs();
+	Process_Stop(delsiflash);
 }
-
+__IO static char writefig=0;
+unsigned char *savebuf;
+void sucess_ev_cb(unsigned char *buf,int len)
+{
+	writefig=1;
+	savebuf=buf;
+	PAIR_CHARGERPIN_PRINT("  ======================PAIR SUCCESS============================= \n");
+	Process_Start(10, "delsiflash", delsiflash);
+}
+void app_pair_chargerpin_pcs(void)
+{
+    int rev = 0;
+    if (writefig == 1)
+    {
+        unsigned char Lbuff[6];
+        unsigned char Rbuff[3];
+        Get_MACaddr(Lbuff);
+        Rbuff[0] = savebuf[0];
+        Rbuff[1] = savebuf[1];
+        Rbuff[2] = savebuf[2];
+        rev = pair_writeflish(Lbuff, Rbuff);
+        if (rev)
+        {
+            Process_Start(10, "reconnect_pcs", reconnect_pcs);
+            Process_SetHoldOn(reconnect_pcs, 1);
+            reconnect_pcs_status = 0;
+        }
+        else
+        {
+						start_pair_led();
+        }
+        writefig = 0;
+    }
+}
+//======================================================================
 void pair_start_pcs(void)
 {
-		extern void *pair_start$$Base;
-		extern void *pair_start$$Limit;
-		typedef void (*main_init_t)(void);
-		for (int p = (unsigned int)&pair_start$$Base; p < (unsigned int)&pair_start$$Limit; p += 4)
-		{
-			(*(main_init_t *)p)();
-		}
+    extern void *pair_start$$Base;
+    extern void *pair_start$$Limit;
+    typedef void (*main_init_t)(void);
+    for (int p = (unsigned int)&pair_start$$Base; p < (unsigned int)&pair_start$$Limit; p += 4)
+    {
+        (*(main_init_t *)p)();
+    }
 }
 
 void pair_done_pcs(void)
 {
-		extern void *pair_done$$Base;
-		extern void *pair_done$$Limit;
-		typedef void (*main_init_t)(void);
-		for (int p = (unsigned int)&pair_done$$Base; p < (unsigned int)&pair_done$$Limit; p += 4)
-		{
-			(*(main_init_t *)p)();
-		}
+    extern void *pair_done$$Base;
+    extern void *pair_done$$Limit;
+    typedef void (*main_init_t)(void);
+    for (int p = (unsigned int)&pair_done$$Base; p < (unsigned int)&pair_done$$Limit; p += 4)
+    {
+        (*(main_init_t *)p)();
+    }
 }
 
-typedef enum
+//=================================================================================================
+void send_start(void)
 {
-	CHARGE=0,
-	CONNECT_NO_CHARGE,
-	DISCONNECT_CHARGE,
-}pair_line_t;
-
-#define ADC_CHECKMS 1000
 #define DELAY_PAIR_COUNT 100
-
-static uint32_t pulluppcs_timer=0;
-static pair_line_t pair_line = DISCONNECT_CHARGE;
-static  short HostChargeADC_value =0;
-static volatile uint8_t Host_Pull_State =0;
-static void app_pair_host_process(void);
-
-static void ReadAdc_timcallback(void* t){
-	if(1 == Host_Pull_State){
-		 if(TIME_GetTicks() - pulluppcs_timer >= 3){
-			 uint32_t errcode = ADC_ReadChargePin(PIN_CHARGING_CHANNEL);
-			 PAIR_CHARGERPIN_PRINT("11111 %d\n",errcode);
-			 if(ADC_OP_SUCCESS == errcode){Host_Pull_State =2;
-				 pulluppcs_timer =  TIME_GetTicks();
-			 }
-       else if(TIME_GetTicks() - pulluppcs_timer >= 10){
-					DEBUG_LOG(">>>>> restart adc \r\n");
-					ADC_Disable();
-					ADC_SetPinChannel(PIN_CHARGING,PIN_CHARGING_CHANNEL,NRF_GPIO_PIN_NOPULL);		
-					ADC_Initialize();	 
-					Host_Pull_State =0;
-		   }
-		 }
-	}
-	else if(Host_Pull_State ==2){
-		 uint8_t state = bsp_Get_ChargePinADC(&HostChargeADC_value);
-	   if(state){Host_Pull_State =3;
-			 nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_NOPULL);
-			 DEBUG_LOG(">>>>> ReadAdc:%d\r\n",HostChargeADC_value);
-		 }
-		 else if(TIME_GetTicks() - pulluppcs_timer >= 10){
-			  DEBUG_LOG(">>>>> restart adc \r\n");
-			  ADC_Disable();
-			  ADC_SetPinChannel(PIN_CHARGING,PIN_CHARGING_CHANNEL,NRF_GPIO_PIN_NOPULL);		
-			  ADC_Initialize();	 
-			  Host_Pull_State =0;
-		 }
-	}
-}
-
-static void app_pair_host_process(void)
-{
-	static uint8_t status=0;
-
-	static uint32_t delay_pair_count=0;
-	static uint32_t overtime=0;
-	static uint8_t ishost=0;
-	
-	if(mFlash.isHost != ishost){ishost = mFlash.isHost;
-		  TIME_UnRegist(ReadAdc_timcallback);
-		 	delay_pair_count=0;
-	    overtime=0;
-		  status =0;
-		  pair_line = DISCONNECT_CHARGE;
-		  Host_Pull_State =0;
-		  ADC_Disable();
-			ADC_SetPinChannel(PIN_CHARGING,PIN_CHARGING_CHANNEL,NRF_GPIO_PIN_NOPULL);		
-			ADC_Initialize();	
-	}
-	
-	if(!mFlash.isHost)return;
-	
-	
+	static unsigned int delay_pair_count=0;
+	static char status=0;
 	switch(status)
 	{
 		case 0:
-			ADC_Disable();
-			ADC_SetPinChannel(PIN_CHARGING,PIN_CHARGING_CHANNEL,NRF_GPIO_PIN_NOPULL);		
-			ADC_Initialize();	
-			Process_UpdatePeroid(app_pair_host_process,ADC_CHECKMS);
-			Process_SetHoldOn(app_pair_host_process,0);
-			nrf_gpio_pin_write(PIN_LED_RUN, 0);
-			pair_done_pcs();
-			status=1;
-			break;
-		case 1:
-			if(0 == Host_Pull_State ){Host_Pull_State=1;
-				nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_PULLUP);
-				pulluppcs_timer = TIME_GetTicks();
-				TIME_Regist(ReadAdc_timcallback);
-				Process_SetHoldOn(app_pair_host_process,1);
-				Process_UpdatePeroid(app_pair_host_process,1);
-			}
-			else if(3 == Host_Pull_State){
-				  Host_Pull_State =0;
-				  Process_SetHoldOn(app_pair_host_process,0);
-				  Process_UpdatePeroid(app_pair_host_process,ADC_CHECKMS);
-					PAIR_CHARGERPIN_PRINT( "ADC (  %d  ):isHost %d pair_line %d\n", HostChargeADC_value,mFlash.isHost,pair_line);	
-					if((HostChargeADC_value < CHARGE_ADC) && (pair_line == CHARGE)){
-						 PAIR_CHARGERPIN_PRINT("--------------------------------------------------------EXIT CHARGE_ADC \n");
-					 }
-				
-				  if(HostChargeADC_value>=CHARGE_ADC){
-						
-						PAIR_CHARGERPIN_PRINT(" CHARGE_ADC \n");
-						if((pair_line != CHARGE)){pair_line=CHARGE;
-							PAIR_CHARGERPIN_PRINT("--------------------------------------------------------------------INTO CHARGE_ADC \n");
-						}
-				  }
-				  else {
-						if((HostChargeADC_value<=DISCON_L_MAX_ADC)&&(HostChargeADC_value>=DISCON_L_MIN_ADC)){
-							PAIR_CHARGERPIN_PRINT("L DISCON_L_ADC \n");
-							pair_line=DISCONNECT_CHARGE;
-						}
-						else if((HostChargeADC_value<=CON_L_MAX_ADC)&&(HostChargeADC_value>=CON_L_MIN_ADC)){
-							PAIR_CHARGERPIN_PRINT("L CON_L_MAX_ADC \n");
-							if(pair_line!=CONNECT_NO_CHARGE){pair_line=CONNECT_NO_CHARGE;
-								
-								Process_Start(ADC_CHECKMS,"app_pair_host_process",app_pair_host_process);
-								
-								Process_UpdatePeroid(app_pair_host_process,10);
-								Process_SetHoldOn(app_pair_host_process,1);
-								Host_Pull_State =3;
-								overtime=TIME_GetTicks();	
-								pair_start_pcs();
-							
-								status=2;
-								nrf_gpio_cfg_input(PIN_CHARGING,NRF_GPIO_PIN_PULLUP);
-								delay_pair_count=TIME_GetTicks();
-								PAIR_CHARGERPIN_PRINT("  SEND PAIR TAG HIGH__________ %d \n",TIME_GetTicks());
-								
-							}
-						}
-					}
-					
-				}
-			  else{
-					PAIR_CHARGERPIN_PRINT("Host_Pull_State:%d\n",Host_Pull_State);	
-				}
-		    break;
-		case 2://
-			if(TIME_GetTicks()- delay_pair_count > ADC_CHECKMS){
-					TIME_Regist(chargerpin_one_ms_pcs);	
-          delay_pair_count=TIME_GetTicks();	
-					one_ms_status = 0;
-					status=3;
-					PAIR_CHARGERPIN_PRINT("  TIME_Regist(chargerpin_one_ms_pcs); %d \n",TIME_GetTicks());
-			}
+			delay_pair_count=TIME_GetTicks();
+			Process_Start(1, "send_start", send_start);
+			Process_SetHoldOn(send_start, 1);
+			status=2;
 			break;
-		case 3:
-			if(TIME_GetTicks()- delay_pair_count > DELAY_PAIR_COUNT){
-				delay_pair_count=TIME_GetTicks();
-				nrf_gpio_pin_set(PIN_CHARGING);
-				PAIR_CHARGERPIN_PRINT("  SEND PAIR TAG HIG; %d \n",TIME_GetTicks());
-				status=4;
-			}
-			break;
-		case 4:
-			if(TIME_GetTicks()- delay_pair_count>(DELAY_PAIR_COUNT+100)){
-				nrf_gpio_pin_clear(PIN_CHARGING);
-				PAIR_CHARGERPIN_PRINT("  SEND PAIR TAG LOW; %d \n",TIME_GetTicks());
-				status=5;
-			}
-			break;
-		case 5:
-			if(writefig==1){
-				app_pair_chargerpin_pcs();
-				TIME_UnRegist(chargerpin_one_ms_pcs);
-				status=0;
-//				MT_Run(500);
-				Host_Pull_State =0;
-				PAIR_CHARGERPIN_PRINT("  ---------------------------PAIR SUCESS------------- \n");
-			}
-			if(TIME_GetTicks()-overtime > DELAY_LEDON+ADC_CHECKMS + DELAY_PAIR_COUNT + 100 + 300){
-				LED_Stop(LED_PAIR);
-				TIME_UnRegist(chargerpin_one_ms_pcs);
-				status=0;
-				Host_Pull_State =0;
-				PAIR_CHARGERPIN_PRINT("  ---------------------------PAIR OVER TIME %d------------- \n",TIME_GetTicks());
+		case 2:
+			if(nrf_gpio_pin_read(PIN_CHARGING)==0)
+			{
+				PAIR_CHARGERPIN_PRINT("  ==============================nrf_gpio_pin_read(PIN_CHARGING)==0 \n");
+				status=3;
 			}
 			break;
-		default:break;
+    case 3:
+        if (TIME_GetTicks() - delay_pair_count > DELAY_PAIR_COUNT)
+        {
+            delay_pair_count = TIME_GetTicks();
+            nrf_gpio_pin_set(PIN_CHARGING);
+            PAIR_CHARGERPIN_PRINT("  SEND PAIR TAG HIG; %d \n", TIME_GetTicks());
+            status = 4;
+        }
+        break;
+    case 4:
+        if (TIME_GetTicks() - delay_pair_count > (DELAY_PAIR_COUNT + 100))
+        {
+            nrf_gpio_pin_clear(PIN_CHARGING);
+            PAIR_CHARGERPIN_PRINT("  SEND PAIR TAG LOW; %d \n", TIME_GetTicks());
+            status = 0;
+						Process_Stop(send_start);
+        }
+        break;
 	}
 }
 
-static void app_pair_client_process(void)
+void into_event(void)
 {
-	static unsigned char status=0;
-	short ADC_value=0;
-	
-	static uint32_t overtime=0;
-	static uint8_t ishost =0;
-	
-	if(mFlash.isHost != ishost){ishost = mFlash.isHost;
-	    overtime=0;
-		  status =0;
-		  pair_line = DISCONNECT_CHARGE;
-		  ADC_Disable();
-			ADC_SetPinChannel(PIN_CHARGING,PIN_CHARGING_CHANNEL,NRF_GPIO_PIN_NOPULL);		
-			ADC_Initialize();	
-	}
-	
-	if(mFlash.isHost)return;
-	
-	switch(status)
+	chargerpin_one_ms_init(sucess_ev_cb);
+	pair_start_pcs();
+	if(mFlash.isHost==1)
 	{
-		case 0:
-			ADC_Disable();
-			ADC_SetPinChannel(PIN_CHARGING,PIN_CHARGING_CHANNEL,NRF_GPIO_PIN_NOPULL);		
-			ADC_Initialize();	
-			Process_UpdatePeroid(app_pair_client_process,ADC_CHECKMS);
-			Process_SetHoldOn(app_pair_client_process,0);
-			nrf_gpio_pin_write(PIN_LED_RUN, 0);
-			pair_done_pcs();
-			status=1;
-			break;
-		case 1:
-			if(ADC_OP_SUCCESS!=ADC_Read(PIN_CHARGING_CHANNEL,&ADC_value)){
-					PAIR_CHARGERPIN_PRINT("ADC_Read ERROR %d\n",mFlash.isHost);
-			}
-	
-		  PAIR_CHARGERPIN_PRINT( "ADC (  %d  ):isHost %d pair_line %d\n", ADC_value,mFlash.isHost,pair_line);	
-			
-		if(ADC_value>=CHARGE_ADC && CHARGE != pair_line){
-			pair_line = CHARGE;
-			PAIR_CHARGERPIN_PRINT(" CHARGE_ADC \n");
-			
-		}
-		else if((ADC_value >= CONN_MIN_ADC)&&(ADC_value <= CONN_MAX_ADC))
-		{
-				PAIR_CHARGERPIN_PRINT("  CONN_ADC  %d \n",pair_line);
-				if(CONNECT_NO_CHARGE != pair_line){pair_line=CONNECT_NO_CHARGE;
-					PAIR_CHARGERPIN_PRINT("  Process_SetHoldOn(adc_check,1);  ms %d\n",TIME_GetTicks());	
-					
-					Process_UpdatePeroid(app_pair_client_process,10);
-					Process_SetHoldOn(app_pair_client_process,1);
-					overtime=TIME_GetTicks();	
-					pair_start_pcs();
-					status=2;
-					TIME_Regist(chargerpin_one_ms_pcs);			
-					one_ms_status = 0;
-				}
-		}
-		else{
-				if(ADC_value<=DISCON_R_MAX_ADC && DISCONNECT_CHARGE != pair_line){
-					pair_line =DISCONNECT_CHARGE;
-					PAIR_CHARGERPIN_PRINT("R DISCON_R_MAX_ADC \n");
-					
-				}		
-		}
-		break;
-		case 2:
-			if(writefig==1){
-				app_pair_chargerpin_pcs();
-				TIME_UnRegist(chargerpin_one_ms_pcs);
-				status=0;
-//				MT_Run(500);
-				PAIR_CHARGERPIN_PRINT("  ---------------------------PAIR SUCESS------------- \n");
-			}
-			if(TIME_GetTicks()-overtime > DELAY_LEDON+ADC_CHECKMS + DELAY_PAIR_COUNT + 100 + 300)
-			{
-				LED_Stop(LED_PAIR);
-				TIME_UnRegist(chargerpin_one_ms_pcs);
-				status=0;
-				PAIR_CHARGERPIN_PRINT("  ---------------------------PAIR OVER TIME %d------------- \n",TIME_GetTicks());
-			}
-			break;
-		default:status=0;break;
+		send_start();
 	}
 }
-
-void write_on(void)
+void over_event(void)
 {
-	LED_Start(LED_PAIR,COLOR_WHITE);
+	chargerpin_one_ms_uninit();
+	pair_done_pcs();
 }
 
-PAIR_START_REGISTER(write_on);
 void app_pair_chargerpin_Init(void)
-{		
-   Process_Start(ADC_CHECKMS,"app_pair_client",app_pair_client_process);
-	 Process_Start(ADC_CHECKMS,"app_pair_host",app_pair_host_process);
-	
+{
+	if(mFlash.isHost!=HOST_SHOSE)
+		app_pair_client_init(into_event,over_event);
+	if(mFlash.isHost==HOST_SHOSE)
+		app_pair_host_init(into_event,over_event);
 }
-
-
-

+ 4 - 2
app/app_pair_chargerpin.h

@@ -1,10 +1,9 @@
 #ifndef APP_PAIR_CHARGERPIN__
 #define APP_PAIR_CHARGERPIN__
 
-
 // <q> BLE_PRINTF  - µ÷ÊÔÐÅÏ¢
 #ifndef PAIR_CHARGERPIN_PRINTF
-#define PAIR_CHARGERPIN_PRINTF 0
+#define PAIR_CHARGERPIN_PRINTF 1
 #endif
 #if PAIR_CHARGERPIN_PRINTF
 #define PAIR_CHARGERPIN_PRINT(...) SEGGER_RTT_printf(0, __VA_ARGS__)
@@ -22,6 +21,9 @@
 #define PAIR_CHARGERPIN_INFO(...) ;
 #endif
 
+#define HOST_SHOSE 0
+
+typedef void (*Event)(void);
 void app_pair_chargerpin_Init(void);
 
 #define PAIR_START_REGISTER(_p_handler) 	__attribute__((section("pair_start"))) void* const main_init_##_p_handler##_row = _p_handler  

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 12 - 12
pca10040/s132/arm5_no_packs/ble_app_uart_c_pca10040_s132.uvguix.Administrator


+ 129 - 105
pca10040/s132/arm5_no_packs/ble_app_uart_c_pca10040_s132.uvoptx

@@ -715,6 +715,30 @@
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>26</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\..\..\app\app_chargerpin_conn_detect.c</PathWithFileName>
+      <FilenameWithoutPath>app_chargerpin_conn_detect.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>2</GroupNumber>
+      <FileNumber>27</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\..\..\app\app_one_wire.c</PathWithFileName>
+      <FilenameWithoutPath>app_one_wire.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
   </Group>
 
   <Group>
@@ -725,7 +749,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>26</FileNumber>
+      <FileNumber>28</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -737,7 +761,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>27</FileNumber>
+      <FileNumber>29</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -749,7 +773,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>28</FileNumber>
+      <FileNumber>30</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -761,7 +785,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>29</FileNumber>
+      <FileNumber>31</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -773,7 +797,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>30</FileNumber>
+      <FileNumber>32</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -785,7 +809,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>31</FileNumber>
+      <FileNumber>33</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -797,7 +821,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>32</FileNumber>
+      <FileNumber>34</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -809,7 +833,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>33</FileNumber>
+      <FileNumber>35</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -821,7 +845,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>34</FileNumber>
+      <FileNumber>36</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -833,7 +857,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>35</FileNumber>
+      <FileNumber>37</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -845,7 +869,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>36</FileNumber>
+      <FileNumber>38</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -857,7 +881,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>37</FileNumber>
+      <FileNumber>39</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -869,7 +893,7 @@
     </File>
     <File>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>38</FileNumber>
+      <FileNumber>40</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -889,7 +913,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>4</GroupNumber>
-      <FileNumber>39</FileNumber>
+      <FileNumber>41</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -901,7 +925,7 @@
     </File>
     <File>
       <GroupNumber>4</GroupNumber>
-      <FileNumber>40</FileNumber>
+      <FileNumber>42</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -913,7 +937,7 @@
     </File>
     <File>
       <GroupNumber>4</GroupNumber>
-      <FileNumber>41</FileNumber>
+      <FileNumber>43</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -925,7 +949,7 @@
     </File>
     <File>
       <GroupNumber>4</GroupNumber>
-      <FileNumber>42</FileNumber>
+      <FileNumber>44</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -937,7 +961,7 @@
     </File>
     <File>
       <GroupNumber>4</GroupNumber>
-      <FileNumber>43</FileNumber>
+      <FileNumber>45</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -949,7 +973,7 @@
     </File>
     <File>
       <GroupNumber>4</GroupNumber>
-      <FileNumber>44</FileNumber>
+      <FileNumber>46</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -961,7 +985,7 @@
     </File>
     <File>
       <GroupNumber>4</GroupNumber>
-      <FileNumber>45</FileNumber>
+      <FileNumber>47</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -981,7 +1005,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>46</FileNumber>
+      <FileNumber>48</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -993,7 +1017,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>47</FileNumber>
+      <FileNumber>49</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1005,7 +1029,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>48</FileNumber>
+      <FileNumber>50</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1017,7 +1041,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>49</FileNumber>
+      <FileNumber>51</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1029,7 +1053,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>50</FileNumber>
+      <FileNumber>52</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1041,7 +1065,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>51</FileNumber>
+      <FileNumber>53</FileNumber>
       <FileType>4</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1053,7 +1077,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>52</FileNumber>
+      <FileNumber>54</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1065,7 +1089,7 @@
     </File>
     <File>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>53</FileNumber>
+      <FileNumber>55</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1085,7 +1109,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>54</FileNumber>
+      <FileNumber>56</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1097,7 +1121,7 @@
     </File>
     <File>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>55</FileNumber>
+      <FileNumber>57</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1109,7 +1133,7 @@
     </File>
     <File>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>56</FileNumber>
+      <FileNumber>58</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1121,7 +1145,7 @@
     </File>
     <File>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>57</FileNumber>
+      <FileNumber>59</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1133,7 +1157,7 @@
     </File>
     <File>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>58</FileNumber>
+      <FileNumber>60</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1145,7 +1169,7 @@
     </File>
     <File>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>59</FileNumber>
+      <FileNumber>61</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1165,7 +1189,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>60</FileNumber>
+      <FileNumber>62</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1177,7 +1201,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>61</FileNumber>
+      <FileNumber>63</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1189,7 +1213,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>62</FileNumber>
+      <FileNumber>64</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1201,7 +1225,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>63</FileNumber>
+      <FileNumber>65</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1213,7 +1237,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>64</FileNumber>
+      <FileNumber>66</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1225,7 +1249,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>65</FileNumber>
+      <FileNumber>67</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1237,7 +1261,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>66</FileNumber>
+      <FileNumber>68</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1249,7 +1273,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>67</FileNumber>
+      <FileNumber>69</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1261,7 +1285,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>68</FileNumber>
+      <FileNumber>70</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1273,7 +1297,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>69</FileNumber>
+      <FileNumber>71</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1285,7 +1309,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>70</FileNumber>
+      <FileNumber>72</FileNumber>
       <FileType>5</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1305,7 +1329,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>71</FileNumber>
+      <FileNumber>73</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1325,7 +1349,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>72</FileNumber>
+      <FileNumber>74</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1337,7 +1361,7 @@
     </File>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>73</FileNumber>
+      <FileNumber>75</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1349,7 +1373,7 @@
     </File>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>74</FileNumber>
+      <FileNumber>76</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1361,7 +1385,7 @@
     </File>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>75</FileNumber>
+      <FileNumber>77</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1373,7 +1397,7 @@
     </File>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>76</FileNumber>
+      <FileNumber>78</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1385,7 +1409,7 @@
     </File>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>77</FileNumber>
+      <FileNumber>79</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1397,7 +1421,7 @@
     </File>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>78</FileNumber>
+      <FileNumber>80</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1409,7 +1433,7 @@
     </File>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>79</FileNumber>
+      <FileNumber>81</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1421,7 +1445,7 @@
     </File>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>80</FileNumber>
+      <FileNumber>82</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1433,7 +1457,7 @@
     </File>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>81</FileNumber>
+      <FileNumber>83</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1445,7 +1469,7 @@
     </File>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>82</FileNumber>
+      <FileNumber>84</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1465,7 +1489,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>10</GroupNumber>
-      <FileNumber>83</FileNumber>
+      <FileNumber>85</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1477,7 +1501,7 @@
     </File>
     <File>
       <GroupNumber>10</GroupNumber>
-      <FileNumber>84</FileNumber>
+      <FileNumber>86</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1497,7 +1521,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>85</FileNumber>
+      <FileNumber>87</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1509,7 +1533,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>86</FileNumber>
+      <FileNumber>88</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1521,7 +1545,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>87</FileNumber>
+      <FileNumber>89</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1533,7 +1557,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>88</FileNumber>
+      <FileNumber>90</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1545,7 +1569,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>89</FileNumber>
+      <FileNumber>91</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1557,7 +1581,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>90</FileNumber>
+      <FileNumber>92</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1569,7 +1593,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>91</FileNumber>
+      <FileNumber>93</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1581,7 +1605,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>92</FileNumber>
+      <FileNumber>94</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1593,7 +1617,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>93</FileNumber>
+      <FileNumber>95</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1605,7 +1629,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>94</FileNumber>
+      <FileNumber>96</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1625,7 +1649,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>95</FileNumber>
+      <FileNumber>97</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1637,7 +1661,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>96</FileNumber>
+      <FileNumber>98</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1649,7 +1673,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>97</FileNumber>
+      <FileNumber>99</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1661,7 +1685,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>98</FileNumber>
+      <FileNumber>100</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1673,7 +1697,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>99</FileNumber>
+      <FileNumber>101</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1685,7 +1709,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>100</FileNumber>
+      <FileNumber>102</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1697,7 +1721,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>101</FileNumber>
+      <FileNumber>103</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1709,7 +1733,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>102</FileNumber>
+      <FileNumber>104</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1721,7 +1745,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>103</FileNumber>
+      <FileNumber>105</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1733,7 +1757,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>104</FileNumber>
+      <FileNumber>106</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1745,7 +1769,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>105</FileNumber>
+      <FileNumber>107</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1757,7 +1781,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>106</FileNumber>
+      <FileNumber>108</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1769,7 +1793,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>107</FileNumber>
+      <FileNumber>109</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1781,7 +1805,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>108</FileNumber>
+      <FileNumber>110</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1793,7 +1817,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>109</FileNumber>
+      <FileNumber>111</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1805,7 +1829,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>110</FileNumber>
+      <FileNumber>112</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1817,7 +1841,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>111</FileNumber>
+      <FileNumber>113</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1829,7 +1853,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>112</FileNumber>
+      <FileNumber>114</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1841,7 +1865,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>113</FileNumber>
+      <FileNumber>115</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1853,7 +1877,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>114</FileNumber>
+      <FileNumber>116</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1865,7 +1889,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>115</FileNumber>
+      <FileNumber>117</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1877,7 +1901,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>116</FileNumber>
+      <FileNumber>118</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1897,7 +1921,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>117</FileNumber>
+      <FileNumber>119</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1909,7 +1933,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>118</FileNumber>
+      <FileNumber>120</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1921,7 +1945,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>119</FileNumber>
+      <FileNumber>121</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1933,7 +1957,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>120</FileNumber>
+      <FileNumber>122</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1945,7 +1969,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>121</FileNumber>
+      <FileNumber>123</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1965,7 +1989,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>14</GroupNumber>
-      <FileNumber>122</FileNumber>
+      <FileNumber>124</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1977,7 +2001,7 @@
     </File>
     <File>
       <GroupNumber>14</GroupNumber>
-      <FileNumber>123</FileNumber>
+      <FileNumber>125</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1997,7 +2021,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>15</GroupNumber>
-      <FileNumber>124</FileNumber>
+      <FileNumber>126</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -2009,7 +2033,7 @@
     </File>
     <File>
       <GroupNumber>15</GroupNumber>
-      <FileNumber>125</FileNumber>
+      <FileNumber>127</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -2021,7 +2045,7 @@
     </File>
     <File>
       <GroupNumber>15</GroupNumber>
-      <FileNumber>126</FileNumber>
+      <FileNumber>128</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -2041,7 +2065,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>16</GroupNumber>
-      <FileNumber>127</FileNumber>
+      <FileNumber>129</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -2053,7 +2077,7 @@
     </File>
     <File>
       <GroupNumber>16</GroupNumber>
-      <FileNumber>128</FileNumber>
+      <FileNumber>130</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -2065,7 +2089,7 @@
     </File>
     <File>
       <GroupNumber>16</GroupNumber>
-      <FileNumber>129</FileNumber>
+      <FileNumber>131</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -2085,7 +2109,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>17</GroupNumber>
-      <FileNumber>130</FileNumber>
+      <FileNumber>132</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است