Ejemplo n.º 1
0
int f_mngRestoreFactoryDone(unsigned *pMsg)
{
	func_t func;
	
    switch(((msg_t *)pMsg)->msgType) 
	{
	case CACT_OVER:
		break;

	case CMSG_INIT:	
		//DISP_menu_MNGSYS_line2nd_RestoreDoing();
		DISP_menu_MNGSYS_line3rd_succ(5);

		vp_stor(CVOPID_RESTORE);
    	vp_stor(CVOPID_SUCESS);
    			
    	g_tick = 0;
    	SetTimer_irq(&g_timer[0], TIMER_1SEC, CMSG_TMR);
		break;
	case CMSG_TMR:
		if(g_tick++ >= 10) {
    		g_tick = 0;
    		SetTimer_irq(&g_timer[0], TIMER_100MS, CMSG_INIT);
    		
    		fstack_init(&g_fstack);
			func.func = f_idle;
    		fstack_push(&g_fstack, &func);
		}
		break;
	
	case CPMT_OVER:
		promptInit();
		g_tick = 0;
		SetTimer_irq(&g_timer[0], TIMER_100MS, CMSG_INIT);
		
    	fstack_init(&g_fstack);
		func.func = f_idle;
    	fstack_push(&g_fstack, &func);
		break;
		
	default:					/** 可能的错误 **/
		break;
	}
	return	0;
}
Ejemplo n.º 2
0
/*******************************************************************************
 * Description: 开锁操作完成后,是否要查低电压报警
 * 低电报警
 *******************************************************************************/
int f_LowPowerAlarm(unsigned *pMsg)
{
//	msg_t msg;
    func_t func;

    switch(((msg_t *)pMsg)->msgType)
	{
	case CMSG_TMR:		/** 低电报警提示计时 **/
		g_tick++;
		if(g_tick >= 10)
		{
		GOTO_ALLOFF:
    		promptInit();
    		
			fstack_init(&g_fstack);
			func.func = f_idle;
    		fstack_push(&g_fstack, &func);
    		
    		g_tick = 0;
			SetTimer_irq(&g_timer[0], TIMER_1SEC, CMSG_TMR);
			//SetTimer_irq(&g_timer[0], TIMER_1SEC, CMSG_INIT);
			
    		All_Screen(0);
        	DISP_idle();
			/*******************************************************************/
		}
		break;
		
	case CMSG_INIT:
    	promptInit();
		g_tick = 0;
    	SetTimer_irq(&g_timer[0], TIMER_1SEC, CMSG_TMR);
    	
    	if(g_flag & (1 << 9)){		/** 查低电报警 **/
    		/** 报警提示 **/
    		vp_stor(CVOPID_POWERLOW);
    		promptDelay(TIMER_500MS);
    		
    		DISP_lowPower();
    	} else {
    		goto GOTO_ALLOFF;				/** 无报警动作,直接结束 **/
    	}
		break;

	case CPMT_OVER:							/** 锁体操作过程结束 **/
    	promptInit();
    	bbbeep();
    	promptDelay(TIMER_500MS);
		break;
			
	default:
		break;
	}
    return  0;
}
Ejemplo n.º 3
0
/** Initialize a request.
 *
 *  This handles setting up a request for curl. It is preferable to call this
 *  once for multiple requests to help curl reuse connections when possible.
 *  Use the other set and reset methods to change things for multiple requests.
 *
 *  @request      struct request_t* the request_t to initialize
 *  @uri          struct str_t*     the uri for the initial request
 *  @header_count size_t            the number of elements in headers[]
 *  @headers      struct str_t[]    the headers, if any, for this request
 *  @msg          const char*       a message for POST, NULL if not POST
 *  @type         enum request_type the type of the request, GET, POST, ...
 */
int ci_init(struct request_t* request, struct str_t* uri,
		size_t header_count, const struct str_t const headers[],
		const char const* msg, enum request_type_e type)
{
	// TODO: Errors
	union func_u func;
	int ret = 0;

	memset(request, 0, sizeof(struct request_t));

	fstack_init(&request->cleanup, 10);

	CURL* handle = curl_easy_init();
	func.func1 = curl_easy_cleanup;
	fstack_push(&request->cleanup, handle, &func, 1);

	curl_easy_setopt(handle, CURLOPT_VERBOSE, 1);
	curl_easy_setopt(handle, CURLOPT_USE_SSL, CURLUSESSL_ALL); // SSL

	curl_easy_setopt(handle, CURLOPT_HEADER, 1); // Enable headers, necessary?
	// set curl_post_callback for parsing the server response
	curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ci_callback_controller);
	// set curl_post_callback's last parameter to state
	curl_easy_setopt(handle, CURLOPT_WRITEDATA, &request->response);

	if(header_count)
	{
		ret = ci_create_header(request, header_count, headers);
		curl_easy_setopt(handle, CURLOPT_HTTPHEADER, request->headers); // Set headers
	}

	curl_easy_setopt(handle, CURLOPT_USERAGENT, "darkcloud/0.1");

	switch(type)
	{
		case GET:
			break;
		case POST:
			curl_easy_setopt(handle, CURLOPT_POSTFIELDS, msg);
			break;
		default:
			break;
	}

	request->handle = handle;

	ret = ci_set_uri(request, uri);

	return ret;
}
Ejemplo n.º 4
0
int dci_init(struct dci_state *state)
{
	union func_u func;
	
	str_init_create(&plus, "+", 0);
	str_init_create(&amp, "&", 0);
	str_init_create(&que, "?", 0);
	str_init_create(&slash, "/", 0);
	
	struct stack_t *estack = (struct stack_t*)malloc(sizeof(struct stack_t));
	if(!estack)
		return 1;
	if(fstack_init(estack, 20))
		return 1;

	struct stack_t *gstack = (struct stack_t*)malloc(sizeof(struct stack_t));
	if(!gstack)
		return 1;
	if(fstack_init(gstack, 20))
		return 1;

	state->stack = estack;
	state->head = NULL;
	state->tail = NULL;
	state->callback_error = 0;
	state->num_files = 0;

	// init the socket stuff //
	if(curl_global_init(CURL_GLOBAL_SSL) != 0)
		goto init_fail;

	func.func2 = curl_global_cleanup;
	fstack_push(estack, NULL, &func, 2);

	state->curlmulti = curl_multi_init();
//	if(state->curlmulti == NULL)
//		goto init_fail;
//	func.func3 = curl_global_cleanup;
//	fstack_push(estack, state->curlmulti, &func, 3);
	
	//dci_get_file_list("/", state);
	
	goto init_success;

init_fail:
	while(estack->size)
		fstack_pop(estack);

	while(gstack->size)
		fstack_pop(gstack);

	fstack_destroy(estack);
	free(estack);
	fstack_destroy(gstack);
	free(gstack);
	return 1;

init_success:
	while(gstack->size)
		fstack_pop(gstack);

	fstack_destroy(gstack);
	free(gstack);
	return 0;
}
Ejemplo n.º 5
0
int main()
{
    int i;
	msg_t msg;
	func_t func;
	
/** 外设初始化开始 **/
	Peripheral_Init();
/** 外设初始化结束 **/

    charQueueInit(&g_com1TxQue);
    //charQueueInit(&g_com2TxQue);
    MFPACK_FIFO_CLEAN("清空指纹传感器缓冲区");
    MBTACK_FIFO_CLEAN("清空蓝牙接收缓冲区");
    actionQueueInit(&g_actionQueue, &(g_timer[1]), CACT_TOUT, CACT_OVER);
    actionQueueInit(&g_promptQueue, &(g_timer[2]), CPMT_TOUT, CPMT_OVER);
    actionQueueInit(&g_blinkQueue, &(g_timer[3]), CBLK_TOUT, CBLK_OVER);
    
    adcSample_Init(&g_adcData, &(g_timer[4]), CADC_TOUT, TIMER_300MS);
    
    for(i = 0; i < TIMER_NUM; i++) {
        ClrTimer(&g_timer[i]);
    }
    
    //SetTimer(&g_timer[0], TIMER_1SEC, CMSG_TMR);
    msgq_init(&g_msgq);
    
	#if	1
	msg.msgType = CMSG_PWON;
	msgq_in(&g_msgq, &msg);
	
	fstack_init(&g_fstack);
    func.func = f_idle;
    fstack_push(&g_fstack, &func);
	#endif
	
	AWU_Config();
	//enableInterrupts();
	IRQ_enable();
	//MIRQ_disable();
	/* Infinite loop */
	while(1)
	{
        //IWDG_ReloadCounter();
        
       	//Refresh_WWDG_Window();
       	//Test_WWDGReset();
       	
        keyscan();
        //vop_busy();
        //fingerCheck();
        PeripheralInput_Check();
        
        DAEMON_USART1_Send(&g_com1TxQue);   /** output to fingerprint **/
        DAEMON_USART3_Send(&g_com3TxQue);   /** output to bluetooth **/
        //DAEMON_USART1_Recive(&g_comRevBuf);
        
        actionDoing(&g_actionQueue);
        actionDoing(&g_promptQueue);
        actionDoing(&g_blinkQueue);

		if(msgq_out_irq(&g_msgq, &msg) == FALSE) {     	/** 有消息吗? **/
			continue;
		}
		if(sysProcess(&msg) == TRUE) {   			/** 是系统消息吗? **/
			continue;
		}

		if(fstack_top(&g_fstack, &func) == FALSE) {    /** 当前处于工作状态吗? **/
		  /** something wrong happend, Power Down or recover it **/
		  	fstack_init(&g_fstack);
			func.func = f_idle;
			fstack_push(&g_fstack, &func);
			
			g_tick = 0;
			SetTimer_irq(&g_timer[0], TIMER_1SEC, CMSG_TMR);
			continue;
		}
		func.func((unsigned *)&msg);
	}
}