Beispiel #1
0
int llclose_transmitter(int fd) {
    info->tentativas = tentativas;

    while(info->tentativas > 0) {
        buildFrame(info->flag, "disc");
        transmitirFrame(info->frameSend, info->frameSendLength);
        start_alarm();

        info->frameTempLength = readFrame(info->frameTemp);
        char * type = malloc(5);
        type = verifyFrameType(info->frameTemp);
        if (verifyFrame(info->frameTemp, info->frameTempLength, "disc")) {
            buildFrame(info->flag, "ua");
            if(transmitirFrame(info->frameSend, info->frameSendLength))
                break;
        }
    }

    if (info->tentativas == 0) {
        printf("Número de tentativas chegou ao fim. \n");
        exit(-1);
    }

    sleep(1);
    if ( tcsetattr(info->fd,TCSANOW,&info->oldtio) == -1) {
        perror("tcsetattr");
        return -1;
    }
    close(fd);
    printf("fechou transmissor\n");
    return 1;
}
Beispiel #2
0
void molcpu_mainloop( void )
{
    static int inited = 0;

    if (!inited) {
        inited = 1;
        kvm_regs_mol2kvm();
        start_alarm();
    }

    while (1) {
        int r;
        int (*osicall)(int);

        if (mregs->interrupt) {
            if(mainloop_interrupt(0)) {
                printf("mainloop_interrupt wants us to exit the main loop\n");
                return;
            }
        }

        mregs->in_virtual_mode = 1;
        r = kvm_vcpu_ioctl(KVM_RUN, 0);
        mregs->in_virtual_mode = 0;

        if (r == -EINTR || r == -EAGAIN) {
            osicall = gRVECtable[RVEC_TIMER].rvec;
            osicall(0);
            continue;
        }

        switch (kvm_run->exit_reason) {
            case KVM_EXIT_MMIO:
                kvm_do_mmio();
                break;
            case KVM_EXIT_OSI:
            {
                __u64 *gprs = kvm_run->osi.gprs;
                int i;

                for (i = 0; i < 32; i++)
                    mregs->gpr[i] = gprs[i];

                osicall = gRVECtable[RVEC_OSI_SYSCALL].rvec;
                osicall(0);

                for (i = 0; i < 32; i++)
                    gprs[i] = mregs->gpr[i];
                break;
            }
            default:
                fprintf(stderr, "KVM: Unknown exit code: %d\n",
                        kvm_run->exit_reason);
                exit(1);
                break;
        }
    }
}
static void start_hs_wake_timer(void)
{
    if(g_hs_wake_timer == 0)
    {
        g_hs_wake_timer = create_alarm(hs_wake_timer_fn, 0, NULL);
    }

    start_alarm(g_hs_wake_timer, HS_WAKE_INTERVAL);
}
Beispiel #4
0
/* 功能:报警器控制
 * 参数:同上
 * 返回值:无
 * */
void beep_control_req(char *pskb)
{
        struct BeepControl *pBeep       = (struct BeepControl*)pskb;
        
        /* 消息处理*/
        pBeep->BeepControlMsg.MsgId     = ARM_PC_BEEP_CONTROL_RSP;
        pBeep->BeepControlMsg.MsgLen    = sizeof(*pBeep)
                                            - sizeof(pBeep->BeepControlMsg);
        if(pBeep->Flag == 1) { //打开
                pBeep->Result = start_alarm();
        } else {        //关闭
                pBeep->Result = stop_alarm(); 
        }
}
Beispiel #5
0
int llwrite(int fd, char * buffer, int length) {

    comporTramaI(TRANSMITTER, buffer, length);
    stuffing(info->frameSend, &info->frameSendLength);
    //printf("partes: %x, %x, %x, %x, %x, %x, %x, %x, %x \n", tramaI[0],tramaI[1],tramaI[2],tramaI[3],tramaI[4],tramaI[5],tramaI[6],tramaI[7],tramaI[8]);
    transmitirFrame(info->frameSend, info->frameSendLength);
    //printf("enviar frame I com sequenceNumber = %d \n", info->sequenceNumber);
    info->tentativas = tentativas;
    while(info->tentativas > 0) {
        start_alarm();
        info->frameTempLength = readFrame(info->frameTemp);
        if (info->sequenceNumber == 1) {
            if (verifyFrame(info->frameTemp, info->frameTempLength, "rr0")) {
                //printf("recebeu rr corretamente \n");
                stop_alarm();
                info->tentativas = tentativas;
                break;
            }
            else if (verifyFrame(info->frameTemp, info->frameTempLength, "rej0")) {
                //printf("recebeu rej0\n");
                transmitirFrame(info->frameSend, info->frameSendLength);
                continue;
            }
        }
        else if (info->sequenceNumber == 0) {
            if (verifyFrame(info->frameTemp, info->frameTempLength, "rr1")) {
                //printf("recebeu rr corretamente \n");
                stop_alarm();
                info->tentativas = tentativas;
                break;
            }
            else if (verifyFrame(info->frameTemp, info->frameTempLength, "rej1")) {
                //printf("recebeu rej1\n");
                transmitirFrame(info->frameSend, info->frameSendLength);
                continue;
            }
        }
    }
    if (info->tentativas == 0) {
        printf("Número de tentativas chegou ao fim. \n");
        exit(-1);
    }
    info->sequenceNumber = !info->sequenceNumber;
    //printf("retornar llwrite\n");
    return 1;
}
Beispiel #6
0
int main(int argc, char **argv)
{
    int timeout;
    pid_t pid;

    if (argc < 2) {
        fprintf(stderr, "Usage: %s <seconds> <program> [...]\n",
                argv[0]);
        return EXIT_FAILURE;
    }

    timeout = read_timeout(argv[1]);
    pid = spawn(argv+2);
    start_alarm(timeout);
    wait_alarm(pid);
    return EXIT_SUCCESS;
}
Beispiel #7
0
/* 功能:报警器控制
 * 参数:MCM请求消息
 * 返回值:无
 * */
void beep_control_req(s8 *pskb)
{
        struct stru_beep_control_req    *prBeepCtrlReq  = (struct stru_beep_control_req *)pskb; 
        struct stru_beep_control_rsp    rBeepCtrlRsp;

        /* 消息处理*/
        rBeepCtrlRsp.struMsgHeader.u16MsgType           = O_MAINMCM_BEEP_RSP;
        rBeepCtrlRsp.struMsgHeader.u16MsgLength         = sizeof(rBeepCtrlRsp)
                                                                - sizeof(rBeepCtrlRsp.struMsgHeader);
        rBeepCtrlRsp.struMsgHeader.u8TransType          = prBeepCtrlReq->struMsgHeader.u8TransType;

        if(prBeepCtrlReq->u8BeepCtrlOperation == 1) { //打开
                rBeepCtrlRsp.bSuccessful = start_alarm();
        } else {        //关闭
                rBeepCtrlRsp.bSuccessful = stop_alarm();
        }

        send_rsp_message(&rBeepCtrlRsp, 
                                sizeof(rBeepCtrlRsp), 
                                prBeepCtrlReq->struMsgHeader.u8TransType);
}
void process_all_events(void)
{	
	TROUT_FUNC_ENTER;

	if(reset_mac_trylock() == 0)
	{
		return;
      }
	
	atomic_set(&g_event_cnt, get_total_num_pending_events());
	stop_alarm(g_mac_event_timer);
	
    while(atomic_read(&g_event_cnt) > 0)
    {		     

#ifdef TROUT_WIFI_POWER_SLEEP_ENABLE
#ifdef WIFI_SLEEP_POLICY
	if (mutex_is_locked(&suspend_mutex) || (g_wifi_suspend_status != wifi_suspend_nosuspend)) {
		//libing, 20140114, fix fake connection
		pr_info("We can't do %s during suspending, g_wifi_suspend_status = %d\n", __func__, g_wifi_suspend_status);
	        reset_mac_unlock();  
                return; 	
	}
#endif
#endif
        /* Process pending events in the event queues */
        process_event_queues();
	if (counter_tmpr++ > 100)//by lihua
	{
		counter_tmpr = 0;
#ifdef WAKE_LOW_POWER_POLICY
			if(g_wifi_power_mode != WIFI_NORMAL_POWER_MODE)
			{
				pr_info("We can't do %s during low power mode, g_wifi_suspend_status = %d\n", __func__, g_wifi_suspend_status);
				break;
			}
#endif
		tempr_compensated();		
	}

#ifndef MAC_HW_UNIT_TEST_MODE
        /* Handle lack of memory for WLAN Rx packets */
//        handle_rxq_replenishment();
#endif /* MAC_HW_UNIT_TEST_MODE */

#ifdef BSS_ACCESS_POINT_MODE
#ifdef ENABLE_PS_PKT_FLUSH
        /* Find the STA with maximum PS buffers  */
        find_max_ps_ae();
#endif /* ENABLE_PS_PKT_FLUSH */
#endif /* BSS_ACCESS_POINT_MODE */

#ifdef INT_WPS_SUPP //wxb add
#ifdef IBSS_BSS_STATION_MODE
    /* Handle scan request from user/protocol */
    if(g_wps_scan_req_from_user == BTRUE)// caisf add for fix wps scan bug. 1121
    {
        handle_start_scan_req();//may be reset_mac
        g_wps_scan_req_from_user = BFALSE;
    }
#endif
#endif /* ifdef INT_WPS_SUPP  */

        /* Service Watchdog */
        service_wdt();
    }

	//chenq add 2012-11-02
//	if((BOOL_T)atomic_read(&g_mac_reset_done) == BFALSE)	//shield by chengwg, 2013-01-11!
//		return;

    /* Handle system error due to any failure */
	active_netif_queue();	//add by chengwg.
    	handle_system_error();//may be reset_mac
	/* Handle scan request from user/protocol */
	//chenq mask 2012-10-29
	//handle_start_scan_req();
#ifdef INT_WPS_SUPP //wxb add
#ifdef IBSS_BSS_STATION_MODE
    /* Handle scan request from user/protocol */
    if(g_wps_scan_req_from_user == BTRUE)// caisf add for fix wps scan bug. 1121
    {
        handle_start_scan_req(); //the function may be reset_mac
        g_wps_scan_req_from_user = BFALSE;
    }
#endif
#endif /* ifdef INT_WPS_SUPP  */

    /* Service Watchdog */
    service_wdt();
    
    if(get_total_num_pending_events() > 0)
	{    
	    if(g_mac_event_timer == NULL)
        {
            g_mac_event_timer = create_alarm(mac_time2event_work, 0, NULL);
        }
		
        start_alarm(g_mac_event_timer, 100);
	}
     reset_mac_unlock();
    TRACE_FUNC_EXIT;
}
Beispiel #9
0
int llclose_receiver(int fd) {
    info->tentativas = tentativas;
    while(1) {
        info->frameTempLength = readFrame(info->frameTemp);
        char * type = malloc(5);
        type = verifyFrameType(info->frameTemp);

        if (type == "I0" || type == "I1") {
            if (verifyFrame(info->frameTemp, info->frameTempLength, type)) {
                char * typeRR = malloc(5);
                sprintf(typeRR, "rr%d", !info->sequenceNumber);
                //printf("criar frame de %s \n", typeRR);
                buildFrame(info->flag, typeRR);
                transmitirFrame(info->frameSend, info->frameSendLength);
                free(typeRR);
                int j;
                //printf("dados recebidos: ");
                for(j = 0; j < (info->frameTempLength-6); j++) {
                    info->dados[j] = info->frameTemp[4+j];
                    //printf(" %x ", info->dados[j]);
                }
                //printf("\n");
                info->lengthDados = j;
                continue;
            }
            else {
                char * typeREJ = malloc(5);
                sprintf(typeREJ, "rej%d", !info->sequenceNumber);
                //printf("criar frame de %s \n", typeREJ);
                buildFrame(info->flag, typeREJ);
                transmitirFrame(info->frameSend, info->frameSendLength);
                free(typeREJ);
                continue;
            }
        }
        else if (verifyFrame(info->frameTemp, info->frameTempLength, "disc")) {
            buildFrame(info->flag, "disc");
            transmitirFrame(info->frameSend, info->frameSendLength);
            start_alarm();

            info->frameTempLength = readFrame(info->frameTemp);
            type = verifyFrameType(info->frameTemp);

            if (verifyFrame(info->frameTemp, info->frameTempLength, "ua")) {
                break;
            }
        }
        else {
            printf("llclose_receiver não recebeu nem I nem disc \n");
        }
    }


    if ( tcsetattr(info->fd,TCSANOW,&info->oldtio) == -1) {
        perror("tcsetattr");
        return 0;
    }
    close(fd);
    printf("fechou recetor\n");
    return 1;
}
Beispiel #10
0
int llopen(char * porta, int flag) {

    printf("FLAG (TRANS/REC) = %d \n", flag);
    info = malloc(sizeof(struct Info));
    info->dados = malloc(255);
    info->frameTemp = malloc(255);
    info->frameSend = malloc(255);
    info->timeout = timeOut;
    install_handler(atende, info->timeout);
    //printf("sequenceNumber: %d \n", info->sequenceNumber);
    info->tentativas = tentativas;
    info->flag = flag;

    info->endPorta = malloc(255);
    info->endPorta = porta;
    info->fd = open(info->endPorta, O_RDWR | O_NOCTTY);
    if (info->fd < 0) {
        perror(info->endPorta);
        exit(-1);
    }

    if ( tcgetattr(info->fd,&info->oldtio) == -1) { // save current port settings
        perror("tcgetattr");
        return -1;
    }

    bzero(&info->newtio, sizeof(info->newtio));

    info->newtio.c_cflag = BaudRate | CS8 | CLOCAL | CREAD;
    info->newtio.c_iflag = IGNPAR;
    info->newtio.c_oflag = OPOST;

    // set input mode (non-canonical, no echo,...)
    info->newtio.c_lflag = 0;

    info->newtio.c_cc[VTIME]    = 0;   // inter-character timer unused
    info->newtio.c_cc[VMIN]     = 1;   // blocking read until 5 chars received

    tcflush(info->fd, TCIFLUSH);

    if ( tcsetattr(info->fd,TCSANOW,&info->newtio) == -1) {
        perror("tcsetattr");
        return -1;
    }

    if (flag == TRANSMITTER) {
        printf("llopen de transmissor \n");
        buildFrame(flag, "set");
        transmitirFrame(info->frameSend, info->frameSendLength);
        while(info->tentativas > 0) {
            //printf("tentativasOpen = %d \n", info->tentativas);
            start_alarm();
            info->frameTempLength = readFrame(info->frameTemp);
            if (verifyFrame(info->frameTemp, info->frameTempLength, "ua")) {
                stop_alarm();
                info->tentativas = tentativas;
                return 1;
            }
        }
        if (info->tentativas == 0) {
            printf("Número de tentativas chegou ao fim. \n");
            exit(-1);
        }
    }
    else {
        printf("llopen de recetor \n");
        info->frameTempLength = readFrame(info->frameTemp);
        if (verifyFrame(info->frameTemp, info->frameTempLength, "set")) {
            buildFrame(flag, "ua");
            transmitirFrame(info->frameSend, info->frameSendLength);
            //printf("terminar llopen recetor \n");
            return 1;
        }
    }

    return info->fd;
}
Beispiel #11
0
/* Search thread main function */
void *search_loop(void *arg) {
    uint8_t ply;
    move_t mv, mv_tmp;

    SET_BLANK_MOVE(mv);
    SET_BLANK_MOVE(mv_tmp);

    pthread_mutex_lock(&mutex);

    /* Initializations */
    precompute_moves();
    precompute_distances();
    init_zobrist_keys();
    init_history();
    init_transposition_table();
    config_alarm(config->max_seconds);
    max_depth = config->max_depth;

    /* Setup board */
    board = set_board("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
    if(board == NULL)
    	quit("Error: Could not setup new board!\n");

    /* ECO = encyclopedia of chess openings */

    if(atoi(config->name) >= 50)
        if(!load_eco(board))
            quit("Error: Could not load Encyclopedia of Chess Openings!\n");

    pthread_mutex_unlock(&mutex);
 
    /* Keep alive until the status changes to QUIT */
    while(status != QUIT) {
    	switch(status) {
    	case NOP:
    	    /* NOP: just wait for a change in status */
    	    pthread_mutex_lock(&mutex);
    	    while(status == NOP)
    	    	pthread_cond_wait(&cond, &mutex);
    	    pthread_mutex_unlock(&mutex);
    	    break;
    	case FORCE:
    	    /* FORCE: wait for a change in status but don't start searches */
    	    pthread_mutex_lock(&mutex);
    	    while(status == FORCE)
    	    	pthread_cond_wait(&cond, &mutex);
    	    pthread_mutex_unlock(&mutex);
    	    break;
    	case SEARCH:
    	    /* Iterative Deepening Search */
    	    /* Save the on-move color */
    	    onmove = board->onmove;
    	    /* Sets as blank the move to be played*/
    	    SET_BLANK_MOVE(mv);
    	    /* Starts counting the time */
    	    start_alarm();
    	    /* For each depth, search with alpha-beta minimax */
    	    for(ply = 2; ply <= max_depth; ply += 2) {
    	    	mv_tmp = alpha_beta(board, -MAX_HEU, MAX_HEU, ply);
    	    	/* Did we run out of time? If so, stops deepening iterations */
    	    	if(get_timeout())
    	    	    break;
    	    	mv = mv_tmp;
    	    }
    	    /* Stops counting the time, if it hasn't already reached limit */
    	    stop_alarm();
    	    /* If the move is still blank, use the partial move found */
    	    if(IS_BLANK_MOVE(mv))
    	    	mv = mv_tmp;
    	    /* Perform the move found in the search */
    	    move(board, mv);
    	    /* Returns to the NOP status */
    	    set_status(NOP);
    	    break;
    	case PONDER:
    	    /* Reserved for future use */
    	    set_status(NOP);
    	    break;
    	default:
    	    quit("Error: Invalid search status!\n");
    	}
    }
    
    /* Clean up memory */
    clear_eco();
    clear_transposition_table();
    clear_history();
    clear_board(board);

    /* Exit Search Thread */
    return NULL;
}