- int main(int argc,char *argv[])
- {
- char lock_serial_temp[16]={0};
- char password_temp[8]={0};
- char door_enable_temp=0,alarm_num=0,i=0;
- uint8_t fingerprintf_library[FINGERPRINT_TOTAL]={0};
- uint8_t dhcp_tempflag=0;
- uint8_t eth_lip_tempstore[4]={0xFF,0xFF,0xFF,0xFF};
- uint8_t eth_lnm_tempstore[4]={0xFF,0xFF,0xFF,0xFF};
- uint8_t eth_lgw_tempstore[4]={0xFF,0xFF,0xFF,0xFF};
- uint8_t eth_sip_tempstore[4]={0xFF,0xFF,0xFF,0xFF};
- uint16_t l_tempport=0;
- uint16_t s_tempport=0;
- uint32_t lockKeyboardTime = 0;
- uint32_t lock_Journal_count=0;
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_SetBits(GPIOB, GPIO_Pin_6 | GPIO_Pin_9);
- SystemInit();
-
- Init_Delay(16000);
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
- Get_ChipID();
- RNG_Init();
- Serial_Init(9600);
- Gate_Init();
- TIM2_Init();
- TIM5_Init();
- Motor_Init();
- SX1505_Init();
- Keyboard_Init();
- lis3dh_init();
- RTCInit();
-
- read_config_info();
- Init_Delay(1000);
- check_read_config_info();
- IWDG_Configuration();
- gcIButton_Mode=0;
-
- if ( (1 != fDataBase.userD.mode) && (2 != fDataBase.userD.mode) )
- {
- lockKeyboardTime = fDataBase.errTime.time;
- lock_Journal_count = fDataBase.Journal.count;
- g_cInputCodeLimitTimes = fDataBase.errTime.error;
-
- if((uint8_t)fDataBase.Door_Enable_flag == 0xFF)
- {
- door_enable_temp = 0;
- }
- else
- {
- door_enable_temp = fDataBase.Door_Enable_flag;
- }
-
- if((uint8_t)fDataBase.Alarm_Number == 0xFF)
- {
- alarm_num = 5;
- }
- else
- {
- alarm_num = fDataBase.Alarm_Number;
- }
-
- if(strlen(fDataBase.static_password) !=6 && (uint8_t)fDataBase.static_password[1] == 0xFF)
- {
- strcpy(password_temp,"123456");
- }
- else
- {
- strcpy(password_temp,fDataBase.static_password);
- }
-
- memset(lock_serial_temp,0,sizeof(lock_serial_temp));
- memcpy(lock_serial_temp,fDataBase.FactoryD.Lock_Serial,12);
- if(strlen(lock_serial_temp) != 12 || (uint8_t)lock_serial_temp[0] == 0xFF)
- {
- memset(lock_serial_temp,0,sizeof(lock_serial_temp));
- strcpy(lock_serial_temp,DEFAULT_LOCK_SERIAL);
- }
-
- if(fDataBase.FactoryD.TempAlarmThreshold==0xFF)
- {
- gcTemperatureThreshold = 60;
- }
- else
- {
- gcTemperatureThreshold = fDataBase.FactoryD.TempAlarmThreshold;
- }
-
- if(fDataBase.FactoryD.ShakeAlarmThreshold==0xFF)
- {
- gcShakeAlarmThreshold = 2;
- }
- else
- {
- gcShakeAlarmThreshold = fDataBase.FactoryD.ShakeAlarmThreshold;
- }
-
- for(i=0; i<FINGERPRINT_TOTAL; i++)
- {
- fingerprintf_library[i] = fDataBase.fingerprint_library[i];
- }
-
- if(0 == strncmp((char *)&fDataBase.EthD.local_ip,(char *)eth_lip_tempstore,4))
- {
- eth_lip_tempstore[0] = 192;
- eth_lip_tempstore[1] = 168;
- eth_lip_tempstore[2] = 1;
- eth_lip_tempstore[3] = 100;
-
- eth_lnm_tempstore[0] = 255;
- eth_lnm_tempstore[1] = 255;
- eth_lnm_tempstore[2] = 255;
- eth_lnm_tempstore[3] = 0;
-
- eth_lgw_tempstore[0] = 192;
- eth_lgw_tempstore[1] = 168;
- eth_lgw_tempstore[2] = 1;
- eth_lgw_tempstore[3] = 1;
-
- eth_sip_tempstore[0] = 192;
- eth_sip_tempstore[1] = 168;
- eth_sip_tempstore[2] = 1;
- eth_sip_tempstore[3] = 113;
-
- dhcp_tempflag=0;
- l_tempport=1000;
- s_tempport=6000;
- }
- else
- {
- eth_lip_tempstore[0] = fDataBase.EthD.local_ip[0];
- eth_lip_tempstore[1] = fDataBase.EthD.local_ip[1];
- eth_lip_tempstore[2] = fDataBase.EthD.local_ip[2];
- eth_lip_tempstore[3] = fDataBase.EthD.local_ip[3];
-
- eth_lnm_tempstore[0] = fDataBase.EthD.local_netmask[0];
- eth_lnm_tempstore[1] = fDataBase.EthD.local_netmask[1];
- eth_lnm_tempstore[2] = fDataBase.EthD.local_netmask[2];
- eth_lnm_tempstore[3] = fDataBase.EthD.local_netmask[3];
-
- eth_lgw_tempstore[0] = fDataBase.EthD.local_gw[0];
- eth_lgw_tempstore[1] = fDataBase.EthD.local_gw[1];
- eth_lgw_tempstore[2] = fDataBase.EthD.local_gw[2];
- eth_lgw_tempstore[3] = fDataBase.EthD.local_gw[3];
-
- eth_sip_tempstore[0] = fDataBase.EthD.server_ip[0];
- eth_sip_tempstore[1] = fDataBase.EthD.server_ip[1];
- eth_sip_tempstore[2] = fDataBase.EthD.server_ip[2];
- eth_sip_tempstore[3] = fDataBase.EthD.server_ip[3];
-
- dhcp_tempflag = fDataBase.EthD.dhcp_enable_flag;
- l_tempport = fDataBase.EthD.local_port;
- s_tempport = fDataBase.EthD.server_port;
- }
-
-
- memset(&fDataBase,0,sizeof(fDataBase));
- Init_Delay(4000);
-
- memcpy(fDataBase.static_password,password_temp,6);
- strcpy(fDataBase.FactoryD.Lock_Serial,lock_serial_temp);
- Init_Delay(100);
-
- fDataBase.errTime.time = lockKeyboardTime;
- fDataBase.errTime.error = g_cInputCodeLimitTimes;
- fDataBase.Journal.count = lock_Journal_count;
- fDataBase.Door_Enable_flag = door_enable_temp;
- fDataBase.Alarm_Number = alarm_num;
- fDataBase.FactoryD.TempAlarmThreshold = gcTemperatureThreshold;
- fDataBase.FactoryD.ShakeAlarmThreshold = gcShakeAlarmThreshold;
- for(i=0; i<FINGERPRINT_TOTAL; i++)
- {
- fDataBase.fingerprint_library[i] = fingerprintf_library[i];
- }
-
- fDataBase.EthD.local_ip[0] = eth_lip_tempstore[0];
- fDataBase.EthD.local_ip[1] = eth_lip_tempstore[1];
- fDataBase.EthD.local_ip[2] = eth_lip_tempstore[2];
- fDataBase.EthD.local_ip[3] = eth_lip_tempstore[3];
-
- fDataBase.EthD.local_netmask[0] = eth_lnm_tempstore[0];
- fDataBase.EthD.local_netmask[1] = eth_lnm_tempstore[1];
- fDataBase.EthD.local_netmask[2] = eth_lnm_tempstore[2];
- fDataBase.EthD.local_netmask[3] = eth_lnm_tempstore[3];
-
- fDataBase.EthD.local_gw[0] = eth_lgw_tempstore[0];
- fDataBase.EthD.local_gw[1] = eth_lgw_tempstore[1];
- fDataBase.EthD.local_gw[2] = eth_lgw_tempstore[2];
- fDataBase.EthD.local_gw[3] = eth_lgw_tempstore[3];
-
- fDataBase.EthD.server_ip[0] = eth_sip_tempstore[0];
- fDataBase.EthD.server_ip[1] = eth_sip_tempstore[1];
- fDataBase.EthD.server_ip[2] = eth_sip_tempstore[2];
- fDataBase.EthD.server_ip[3] = eth_sip_tempstore[3];
-
- fDataBase.EthD.local_port = l_tempport;
- fDataBase.EthD.server_port = s_tempport;
- fDataBase.EthD.dhcp_enable_flag = dhcp_tempflag;
- }
- else
- {
- uint32_t CRC32_temp=CRC32_ForBytes(fDataBase.FactoryD.Lock_Psk,LOCK_PSK_LEN);
- if (CRC32_temp != fDataBase.FactoryD.Psk_CRC32)
- {
- gcPSK_flag=1;
- }
- }
-
- gcTemperatureThreshold = fDataBase.FactoryD.TempAlarmThreshold;
- gcShakeAlarmThreshold = fDataBase.FactoryD.ShakeAlarmThreshold;
- vSemaphoreCreateBinary(IR2AppSemaphore);
- vSemaphoreCreateBinary(DataSemaphore);
- vSemaphoreCreateBinary(LedAndBuzzerSemaphore);
- vSemaphoreCreateBinary(TcpRecvData_Sem);
- xSemaphoreTake(IR2AppSemaphore,0);
- xSemaphoreTake(DataSemaphore,0);
- xSemaphoreTake(LedAndBuzzerSemaphore,0);
- xSemaphoreTake(TcpRecvData_Sem,0);
-
- xTaskCreate(HTS221_Task, (const signed char *)"FGRD_Task", 200, NULL, 5, NULL);
-
- xTaskCreate(LIS3DH_Task, (const signed char *)"SAEF_Task", 200, NULL, 5, NULL);
-
- xTaskCreate(LIS3DH_Read_Task, (const signed char *)"HTDDR_Read_Task", 200, NULL, 5, NULL);
-
- xTaskCreate(TCP_RX_Data, (const signed char *)"INT_RX_Data", 2000, NULL, 5, NULL);
-
- xTaskCreate(ETH_RX_Data, (const signed char *)"EXT_RX_Data", 1200, NULL, 5, NULL);
-
- xTaskCreate(ElockMain,(const signed char *)"TOMain",1080,NULL,7,NULL);
- xTaskCreate(AlarmTask,(const signed char *)"CLOCKTask",1200,NULL,5,NULL);
- xTaskCreate(GetKeyboardKeypressValueTask, (const signed char *)"KeyboardValueTask", 520, NULL, 5, NULL);
- xTaskCreate(DispalyAndPromptControlTask, (const signed char *)"DispalyTask", 128, NULL, 5, NULL);
- xTaskCreate(BuzzerAndLedCycleTask, (const signed char *)"BuzzerAndLedTask", 200, NULL, 6, NULL);
- vTaskStartScheduler();
-
- for( ;; );
-
- }