Browse Source

租期锁功能完成,还未测试

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
9d1c7bc1f2
4 changed files with 158 additions and 24 deletions
  1. 4 0
      inc/app.h
  2. 113 4
      src/MainTask.c
  3. 27 6
      src/TcpTask.c
  4. 14 14
      src/hal_module_adapter.c

+ 4 - 0
inc/app.h

@@ -117,6 +117,10 @@ typedef struct AppDataType
     UINT16 SysReStart;
     UINT8  RelayControl;
     UINT8  ErrorMsg;
+    UINT8  userLock;
+    UINT8  rentalLock;
+    UINT8  rentaltype;
+    UINT8  ExpiryTimeArray[6];
 }AppDataBody;
 typedef struct _AppDataHeader
 {

+ 113 - 4
src/MainTask.c

@@ -73,6 +73,8 @@ static void appAfterSlp2(void *pdata, slpManLpState state);
 void montior_timer_callback(TimerHandle_t xTimer);
 void work_timer_callback(TimerHandle_t xTimer);
 void BattWorkStateDelayFunc(UINT8 battWorkCurrentState);
+INT8 rentalEndDetectFunc(void);
+void BattLockFunc(void);
 static void setDefaultAppDataValue(void);
 void appLoadConfig(void);
 void appSaveConfig(void);
@@ -216,10 +218,6 @@ static void MainTask(void* arg)
                     {
                         BattChrgEndFlag=TRUE;
                     }
-                    else
-                    {
-                        BattChrgEndFlag=FALSE;
-                    }
                     if(AppDataInfo.ErrorMsg != 0)
                     {
                         if(osOK==osMutexAcquire(Error_Mutex, 100))
@@ -850,7 +848,11 @@ static void setDefaultAppDataInfo(void)
     AppDataInfo.AccMileage = 0;
     AppDataInfo.SysReStart = 0;
     AppDataInfo.RelayControl = 0;
+    AppDataInfo.userLock = 0;
+    AppDataInfo.rentalLock = 0;
     AppDataInfo.ErrorMsg = 0;
+    AppDataInfo.rentaltype = 0;
+    memset(AppDataInfo.ExpiryTimeArray, 0x00, sizeof(AppDataInfo.ExpiryTimeArray));
     return;
 }
 void BattWorkStateDelayFunc(UINT8 battWorkCurrentState)
@@ -880,3 +882,110 @@ void BattWorkStateDelayFunc(UINT8 battWorkCurrentState)
 		workDelayCounter = 0;
 	}
 }
+INT8 rentalEndDetectFunc(void)
+{
+	OsaUtcTimeTValue TimeStracture;
+	UTC8TimeType UTC8Time,ExpiryTime;
+	UINT16 year;
+    UINT8 month,day,hour,minute,sec;
+	INT8 readRet;
+	readRet = appGetSystemTimeUtcSync(&TimeStracture);
+	if(readRet==0)
+	{
+		year=(TimeStracture.UTCtimer1&0xffff0000)>>16;
+		month=(TimeStracture.UTCtimer1&0xff00)>>8;
+		day=TimeStracture.UTCtimer1&0xff;
+		hour=(TimeStracture.UTCtimer2&0xff000000)>>24;
+		minute=(TimeStracture.UTCtimer2&0xff0000)>>16;
+		sec=(TimeStracture.UTCtimer2&0xff00)>>8;
+		UTCToBeijing((UTC8TimeType *)&UTC8Time,year,month,day,hour,minute,sec);	
+
+        if(((UTC8Time.year - 0x07D0) & 0xFF)==AppDataInfo.ExpiryTimeArray[0])//年份相等判定月份
+        {
+            if(UTC8Time.month==AppDataInfo.ExpiryTimeArray[1])//月份相等判定日期
+            {
+                if(UTC8Time.day==AppDataInfo.ExpiryTimeArray[2])//日期相等判定小时
+                {
+                    if(UTC8Time.hour<=AppDataInfo.ExpiryTimeArray[3])//小时相等不锁定,小时超出锁定
+                    {
+                        return 0;
+                    }
+                    else
+                    {
+                        return 1;
+                    }
+                }
+                else if(UTC8Time.day>AppDataInfo.ExpiryTimeArray[2])
+                {
+                    return 1;
+                }
+                else if(UTC8Time.day<AppDataInfo.ExpiryTimeArray[2])
+                {
+                    return 0;
+                }
+            }
+            else if(UTC8Time.month>AppDataInfo.ExpiryTimeArray[1])//实际月份大于终止月份
+            {
+                return 1;
+            }
+            else if(UTC8Time.month<AppDataInfo.ExpiryTimeArray[1])//实际月份小于终止月份
+            {
+                return 0;
+            }
+        }
+        else if(((UTC8Time.year - 0x07D0) & 0xFF)>AppDataInfo.ExpiryTimeArray[0])//实际年份大于终止年份
+        {
+            return 1;
+        }
+        else if(((UTC8Time.year - 0x07D0) & 0xFF)<AppDataInfo.ExpiryTimeArray[0])//年比较,实际年份小于终止年份
+        {
+            return 0;
+        }
+	}
+    else
+    {
+        return 0;//没有获取到时间返回
+    }
+
+}
+void BattLockFunc(void)
+{
+    if(AppDataInfo.rentaltype==0)//测试模式
+    {
+        ;
+    }
+    else if (AppDataInfo.rentaltype==1)//零售模式
+    {
+        if(AppDataInfo.rentalLock==TRUE)
+        {
+            AppDataInfo.userLock = FALSE;
+            AppDataInfo.rentalLock=FALSE;
+            AppDataInfo.appDataModify=TRUE; 
+        }
+    }
+    else if(AppDataInfo.rentaltype==2)// 租赁模式
+    {
+        if(rentalEndDetectFunc()==1 && AppDataInfo.rentalLock==FALSE)//租期判定是否超期函数
+        {
+            AppDataInfo.rentalLock=TRUE;
+            AppDataInfo.appDataModify=TRUE;
+        }
+        else if(rentalEndDetectFunc()==0 && AppDataInfo.rentalLock==TRUE)
+        {
+            AppDataInfo.rentalLock=FALSE;
+            AppDataInfo.appDataModify=TRUE;
+            AppDataInfo.userLock = FALSE;
+        }
+    }
+
+    if(AppDataInfo.rentalLock==FALSE&&AppDataInfo.userLock==FALSE)
+    {
+        AppNVMData.isBattLocked = FALSE;
+        AppNVMData.appDataModify = TRUE;
+    }
+    else if(AppDataInfo.rentalLock==TRUE||AppDataInfo.userLock==TRUE)
+    {
+        AppNVMData.isBattLocked = TRUE;
+        AppNVMData.appDataModify = TRUE;
+    }   
+}

+ 27 - 6
src/TcpTask.c

@@ -748,14 +748,14 @@ static void TcpDataInfoRecvHandle()
                         TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer,30);
                         if(*(Ptr+31)==0x01)//0x01代表锁定
                         {
-                            AppNVMData.appDataModify = TRUE;
-                            AppNVMData.isBattLocked = TRUE;
+                            AppDataInfo.userLock = TRUE;
+                            AppDataInfo.appDataModify = TRUE;
                             tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
                         }
                         else if(*(Ptr+31)==0x02)              //0x02代表解锁
                         {
-                            AppNVMData.appDataModify = TRUE;
-                            AppNVMData.isBattLocked = FALSE;
+                            AppDataInfo.userLock = FALSE;
+                            AppDataInfo.appDataModify = TRUE;
                             tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
                         }
                         TcpService=0x00;
@@ -806,15 +806,36 @@ static void TcpDataInfoRecvHandle()
                         }
                         TcpService=0x00;
                         
+                    }
+                    else if(*(Ptr+30)==0x85)//租期设置
+                    {
+                        UINT8 rentalStartArray[6] = {0},ExpiryUTC8TimeArray[6] = {0};
+                        UINT16 rentaldays = 0;
+                        TcpCmdAnswer[3] = 0x01;
+                        MEMCPY(&TcpCmdAnswer[4],(Ptr+4),BATT_SN_LEN);
+                        TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
+                        TcpCmdAnswer[22] = 0x00;
+                        TcpCmdAnswer[23] = 0x06;
+                        MEMCPY(&TcpCmdAnswer[24],(Ptr+24),6);
+                        TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer,30);
+                        AppDataInfo.rentaltype = *(Ptr+31);
+                        MEMCPY(rentalStartArray,(Ptr+32),6);
+                        rentaldays = *(Ptr+38)<<8|*(Ptr+39);
+                        ExpiryTimeCal(rentalStartArray,rentaldays,ExpiryUTC8TimeArray);
+                        MEMCPY(AppDataInfo.ExpiryTimeArray,ExpiryUTC8TimeArray,6);
+                        AppDataInfo.appDataModify = TRUE;
+                        tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
+                        TcpService=0x00;
+                        
                     }
                     else
                     {
                         TcpCmdAnswer[3] = 0x0f;
-                        memcpy(&TcpCmdAnswer[4],(Ptr+4),BATT_SN_LEN);
+                        MEMCPY(&TcpCmdAnswer[4],(Ptr+4),BATT_SN_LEN);
                         TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
                         TcpCmdAnswer[22] = 0x00;
                         TcpCmdAnswer[23] = 0x06;
-                        memcpy(&TcpCmdAnswer[24],(Ptr+24),6);
+                        MEMCPY(&TcpCmdAnswer[24],(Ptr+24),6);
                         TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer,30);
                         tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
                     }

+ 14 - 14
src/hal_module_adapter.c

@@ -197,14 +197,14 @@ led_pin_config_t gLedCfg[LED_INX_MAX]={{LED_PORT_0,LED_GPIO_PIN_1,LED_PAD_INDEX1
 									 {LED_PORT_1,LED_GPIO_PIN_3,LED_PAD_INDEX3, PAD_MuxAlt0},\
 									 {LED_PORT_0,LED_GPIO_PIN_4,LED_PAD_INDEX4, PAD_MuxAlt0},\
 								       {LED_PORT_1,LED_GPIO_PIN_5,LED_PAD_INDEX5, PAD_MuxAlt0}};
-void ExpiryTimeCal(UTC8TimeType* UTC8Time,UINT16 rentalDays,UTC8TimeType* ExpiryUTC8Time)
-{
-	int year=0,month=0,day=0,hour=0;
-    int lastday = 0;// ÔµÄ×îºóÒ»ÌìÈÕÆÚ
-	
-	year=UTC8Time->year;
-	month=UTC8Time->month;
-	day=UTC8Time->day + rentalDays;
+void ExpiryTimeCal(UINT8 *StartTimeArray,UINT16 rentalDays,UINT8 *ExpiryTimeArray)
+{
+    UINT8 lastday = 0;
+	UINT8 year = 0,month = 0,hour = 0,minute = 0,second = 0;
+	UINT16 day = 0;
+	year= *(StartTimeArray+0);
+	month=*(StartTimeArray+1);
+	day=  *(StartTimeArray+2) + rentalDays;
 	if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
 	{
 		lastday = 31;
@@ -246,12 +246,12 @@ void ExpiryTimeCal(UTC8TimeType* UTC8Time,UINT16 rentalDays,UTC8TimeType* Expiry
 				lastday = 28;
 		}
 	}
-	ExpiryUTC8Time->year = year;
-	ExpiryUTC8Time->month = month;
-	ExpiryUTC8Time->day = day;
-	ExpiryUTC8Time->hour = UTC8Time->hour;
-	ExpiryUTC8Time->minute = UTC8Time->minute;
-	ExpiryUTC8Time->second = UTC8Time->second;
+	*(ExpiryTimeArray+0) = year;
+	*(ExpiryTimeArray+1) = month;
+	*(ExpiryTimeArray+2) = day;
+	*(ExpiryTimeArray+3) = *(StartTimeArray+3);
+	*(ExpiryTimeArray+4) = *(StartTimeArray+4);
+	*(ExpiryTimeArray+5) = *(StartTimeArray+5);
 	return;
 }
 void UTCToBeijing(UTC8TimeType* UTC8Time,unsigned int UTCyear,unsigned char UTCmonth,unsigned char UTCday,unsigned int UTChour,unsigned char UTCminute,unsigned char UTCsecond)