Пример #1
0
static void print_compare(struct can_frame *exp, struct can_frame *rec)
{
	printf("expected: ");
	print_frame(exp);
	printf("received: ");
	print_frame(rec);
}
Пример #2
0
//========================================================================
void AHexEditorActor::Tick(float DeltaTime)
{
	print_frame(InputModeStr[m_InputType].c_str(), DeltaTime);

	UpdateBarrierPlacing();
	UpdatePlatformPlacing();

	m_PortalAI->Update(DeltaTime);

	if (m_AttachingPlatform)
	{
		print_frame("Click on the platform target", DeltaTime);
	}

//  	Raycast<AActor>(this, [&](auto& resultActor, auto& traceResult)
//  		{
//  			print_frame((*resultActor->GetHumanReadableName()), DeltaTime);
//  
//  			auto tileCenter = m_Grid.GetPosition(m_Grid.GetCoordinates(traceResult.Location));
//  			DrawDebugCircle(GetWorld(), tileCenter, 50, 32, FColor::Red, false, -1.f, 0, 3);
//  		}); 

//	for (auto& c : m_Grid.GetStorage())
//	{
//		std::stringstream ss;
//		ss << c.first.s << "," << c.first.t << "\n";
//		DrawDebugString(GetWorld(), pos, ss.str().c_str());
//	}
}
Пример #3
0
int main(int argc, char *argv[]) {
	int s;
	struct sockaddr_can addr;
	socklen_t addr_len;
	struct can_frame cf;
	can_err_mask_t err_mask;
	struct ifreq ifr;
	struct timeval ts;
	FILE *fo, *fe;

	if((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
		return EXIT_FAILURE;
	}

	/* Listen on all CAN interfaces */
	addr.can_family  = AF_CAN;
	addr.can_ifindex = 0; 

	if(bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
		return EXIT_FAILURE;
	}

	/* Receive all error frames */
	err_mask = CAN_ERR_MASK;
	setsockopt(s, SOL_CAN_RAW, CAN_RAW_ERR_FILTER,
			&err_mask, sizeof(err_mask));

	/* Log to first argument as a file */
	if(argc > 1) {
		fo = fe = fopen(argv[1], "w");
	} else {
		fo = stdout;
		fe = stderr;
	}

	while(1) {
		/* Print received CAN frames */
		addr_len = sizeof(addr);
		if(recvfrom(s, &cf, sizeof(cf), 0,
					(struct sockaddr *)&addr, &addr_len) > 0) {

			/* Find approximate receive time */
			gettimeofday(&ts, NULL);

			/* Find name of receive interface */
			ifr.ifr_ifindex = addr.can_ifindex;
			ioctl(s, SIOCGIFNAME, &ifr);

			/* Print fames to STDOUT, errors to STDERR */
			if(cf.can_id & CAN_ERR_FLAG) {
				print_frame(fe, ifr.ifr_name, &ts, &cf);
			} else {
				print_frame(fo, ifr.ifr_name, &ts, &cf);
			}
		}
	}

	return EXIT_SUCCESS;
}
Пример #4
0
static void process_incoming(tcpc_t c) 
{
    struct wcamcli  *wc   = c->arg;
    tcpc_handler_t func;
    __u8 *req = wc->req;
    __u8  rsp[FRAME_ERR_SZ];

    rsp[1] = req[CMD0_POS];
    rsp[2] = req[CMD1_POS];

    print_frame(req);

    if (req[LEN_POS] > FRAME_DAT_MAX) {
        rsp[0] = ERR_LEN;
    } else if ((rsp[1] & SUBS_MASK) < SUBS_MAX) {
        func = process_incomings[rsp[1] & SUBS_MASK];
        if (func)
            rsp[0] = (*func)(c);
        else
            rsp[0] = ERR_SUBS;
    } else {
        rsp[0] = ERR_SUBS;
    }
    
    if ((rsp[0] != ERR_SUCCESS) && ((rsp[1] & TYPE_MASK) == TYPE_SREQ)) {
        build_and_send_rsp(c, (TYPE_SRSP << TYPE_BIT_POS) | SUBS_ERR, 
                           0, FRAME_ERR_SZ, rsp);
    }
}
Пример #5
0
Файл: can.c Проект: gxliu/imx
/* 阻塞读CAN */
int can_read(struct can_frame *pstCanFrame)
{
    int ret = 0;
    
    if((canfd <= 0) || INVALID_POINTER(pstCanFrame))
    {
        DEBUG_MSG("E:input param error!\r\n");
        return -1;
    }
    ret = read(canfd, pstCanFrame, sizeof(*pstCanFrame));
    if(ret < sizeof(*pstCanFrame))
    {
        ERROR_MSG("E:read failed!\r\n");
        return -1;
    }
    /* 判断设备是否错误 */
    if(pstCanFrame->can_id & CAN_ERR_FLAG)
    { 
        handle_err_frame(pstCanFrame);
        DEBUG_MSG("E:CAN device error!\r\n");
        return -1;
    }
    /* 打印CAN帧 */
    print_frame(pstCanFrame);

    return 0;
}
Пример #6
0
static struct ast_frame *hook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
{
	int i;
	int show_frame = 0;
	struct frame_trace_data *framedata = data;
	if (!frame) {
		return frame;
	}

	if ((event != AST_FRAMEHOOK_EVENT_WRITE) && (event != AST_FRAMEHOOK_EVENT_READ)) {
		return frame;
	}

	for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
		if (frame->frametype == frametype2str[i].type) {
			if ((framedata->list_type == 0) && (framedata->values[i])) { /* white list */
				show_frame = 1;
			} else if ((framedata->list_type == 1) && (!framedata->values[i])){ /* black list */
				show_frame = 1;
			}
			break;
		}
	}

	if (show_frame) {
		ast_verbose("%s on Channel %s\n", event == AST_FRAMEHOOK_EVENT_READ ? "<--Read" : "--> Write", ast_channel_name(chan));
		print_frame(frame);
	}
	return frame;
}
Пример #7
0
void geneprot_handler(struct frame *tf)
{
	print_frame(tf);
	exit(curtask);
	schedule();
	panic("geneprot not implemented!\n");
}
Пример #8
0
static int can_echo_gen(void)
{
	struct can_frame tx_frames[CAN_MSG_COUNT];
	struct can_frame rx_frame;
	unsigned char counter = 0;
	int send_pos = 0, recv_pos = 0, unprocessed = 0, loops = 0;
	int i;

	while (running) {
		if (unprocessed < CAN_MSG_COUNT) {
			/* still send messages */
			tx_frames[send_pos].can_dlc = CAN_MSG_LEN;
			tx_frames[send_pos].can_id = CAN_MSG_ID;
			for (i = 0; i < CAN_MSG_LEN; i++)
				tx_frames[send_pos].data[i] = counter + i;
			if (send_frame(&tx_frames[send_pos]))
				return -1;

			/* increment to be equal to expected */
			tx_frames[send_pos].can_id++;
			for (i = 0; i < CAN_MSG_LEN; i++)
				tx_frames[send_pos].data[i]++;

			send_pos++;
			if (send_pos == CAN_MSG_COUNT)
				send_pos = 0;
			unprocessed++;
			if (verbose == 1)
				echo_progress(counter);
			counter++;

			if ((counter % 33) == 0)
				millisleep(3);
			else
				millisleep(1);
		} else {
			if (recv_frame(&rx_frame))
				return -1;

			if (verbose > 1)
				print_frame(&rx_frame);

			/* compare with expected */
			compare_frame(&tx_frames[recv_pos], &rx_frame);

			loops++;
			if (test_loops && loops >= test_loops)
				break;

			recv_pos++;
			if (recv_pos == CAN_MSG_COUNT)
				recv_pos = 0;
			unprocessed--;
		}
	}

	printf("\nTest messages sent and received: %d\n", loops);

	return 0;
}
Пример #9
0
int main(int argc, char **argv) {


    while ( !read_bits_psk() ) {
//
// read_bit_PSK:
/*
synch: ...,du,ud,du  oder  ...,ud,du,ud
bit 0: ud,du  oder  du,ud
bit 1: du,du  oder  ud,ud  (phase shift)
Header
_uuddu udududduududduud udduudududududud duududduudduuddu (oder:)
_dduud dududuudduduuddu duuddudududududu udduduudduudduud (invers)
  0 0  0 1 1 0 0 1 0 0  1 0 0 1 1 1 1 1  0 0 1 0 0 0 0 0
*/
// header_found
// bits2byte
// framebytes
//
                    if (option_raw) print_frame();
                    else print_pos();

    }


    return 0;
}
Пример #10
0
/* This is the function that we call periodically during the one
   second startup time to see if we have a bootloader request on
   the CAN Bus. */
uint8_t
bload_check(void) {
    struct CanFrame frame;
    uint8_t result, channel, send_node;
    
    result = can_poll_int();

    if(result & (1<<CAN_RX0IF)) {
     /* If the filters and masks are okay this should be
        a firware update command addressed to us. */
        can_read(0, &frame);
		print_frame(frame); /* Debugging Stuff */
        if(frame.data[0] == node_id && frame.data[1] == FIX_FIRMWARE &&
           frame.data[2] == BL_VERIFY_LSB && frame.data[3] == BL_VERIFY_MSB) {
            /* Save the data from the frame that we need later. */  
            channel = frame.data[4];
            send_node = frame.id & 0x0FF;
            /* Build success frame */
            frame.id = FIX_NODE_SPECIFIC + node_id;
            frame.length = 3;
            frame.data[0] = send_node;
            frame.data[1] = FIX_FIRMWARE;
            frame.data[2] = 0x00;
            can_send(0, 3, frame);
			/* Jump to load firmware */
            load_firmware(channel); /* We should never come back from here */
        } 
    }
    return 0;
}
Пример #11
0
/**
 * Envoi d'une trame a tous les joueurs encore connectes (broadcast)
 * S'il y'a un probleme d'envoi, le joueur concerne est deconnecte et desinscrit
 * 
 * @param the_players Liste des joueurs
 * @param frame Trame a envoyer
 */
void send_broadcast(Players the_players, Frame frame) {
    size_t i = 0;
    Player current_player;
    
    /*debug*/
    print_frame(frame);
    
    for(i=0; i < the_players->size; i++) {
        current_player = the_players->player[i];
        
        /* Envoi de la trame a tous les joueurs inscrits 
         * Desinscription et deconnexion du joueur en cas de deconnexion brutale 
         */
        if(current_player->is_registered) {
            if(send_frame(current_player->sock, frame) == ERROR) {
                /*debug*/
                printf("Suppression d'un joueurs");
                
                remove_player_by_sock(current_player->sock, the_players, 1);
            }
        }
    }
     
    free_frame(frame);
}
Пример #12
0
void
TRAP_gfault(interrupt_frame f)
{
    //panic("General protection fault\n");
    print_frame("general protection fault", &f);
    __asm__("hlt");
    while(1);
}
Пример #13
0
void
TRAP_unhandled(interrupt_frame f)
{
    while(1) __asm__("hlt");
    print_frame("unhandled exception", &f);
    __asm__("hlt");
    while(1);
}
Пример #14
0
void handle_timedout_frames(Sender * sender,
                            LLnode ** outgoing_frames_head_ptr)
{
    //TODO: Suggested steps for handling timed out datagrams
    //    1) Iterate through the sliding window protocol information you maintain for each receiver
    //    2) Locate frames that are timed out and add them to the outgoing frames
    //    3) Update the next timeout field on the outgoing frames
    //
    
    struct timeval now;
    struct timeval tmp;
    long long interval;
    if (sender->fin == 2)
    {
	return;
    }
    if (sender->fin == 1)
    {
    }
    
	//find the timeout and send out
    int pos;
    int seq;
    gettimeofday(&now, NULL);
    for (seq = (sender->LAR + 1); seq <= sender->LFS; seq++)
    {
	//seq = sender->LAR + 1;
	pos = seq % sender->SWS;

	tmp = sender->timestamp[pos];
	
	interval = (now.tv_sec - tmp.tv_sec) * 1000000
		   + (now.tv_usec - tmp.tv_usec);

	//if (interval < 100000)
	if (interval < 50000)
	    return;
	fprintf(stderr, "sender:timeout!seq=%d\n",seq);
	fprintf(stderr, "sender,%ld:%ld\n", now.tv_sec, now.tv_usec);
	fprintf(stderr, "sender,%ld:%ld\n", tmp.tv_sec, tmp.tv_usec);
	
	Frame* outgoing_frame;
	outgoing_frame = (Frame*)sender->buffer[pos];
	sender->timestamp[pos] = now;

	//char * buf = convert_frame_to_char(outgoing_frame);

	//outgoing_frame->checksum = chksum((unsigned short*) buf, 
	//			    MAX_FRAME_SIZE / 2);
	//buf = convert_frame_to_char(outgoing_frame);
	char* buf = add_chksum(outgoing_frame);
	char* outgoing_charbuf = buf;
	    
	print_frame(outgoing_frame);
	ll_append_node(outgoing_frames_head_ptr,
		       outgoing_charbuf);
    }
}
Пример #15
0
/* This function print the table for the game */
void game_print(struct game *myGame){
    int i,j;
    
    NEW_LINE;
    print_frame(myGame);
    NEW_LINE;
    for (i = myGame->rows - 1; i >= 0; i--) {
        for (j = 0; j < myGame->columns ; j++) {
            printf("%c%c%c%c",'|',' ',myGame->state.table[i][j],' ');
        }
        printf("%c",'|');
        NEW_LINE;
        print_frame(myGame);
        NEW_LINE;
    }
    NEW_LINE;
    
}
Пример #16
0
static void can_rx_cb (struct ev_loop *loop, ev_io *w, int revents)
{
	(void)loop; (void)revents;
	struct can_frame cf;

	while (read(w->fd, &cf, sizeof(cf)) == sizeof(cf)) {
		print_frame(&config, &cf, " ");

		if (w->fd == sock_i) {
			if (attack && cf.can_id == 0x102 && cf.data[0] == 0x40 && cf.data[1] == 0x03) {
				/* (5.1.2) */
				remember_ch_i = cf;

				/* (5.1.3) */
				struct can_frame m = { .can_id = 0x103, .can_dlc = 8, .data = {0x40, 0x02, 0, 0, 0, 0, 0, 0} };
				print_frame(&config, &m, "!!! REPLACED WITH");
				write(sock_j, &m, sizeof(m));
				continue;
			}
			write(sock_j, &cf, sizeof(cf));
			if (attack && cf.can_id == 0x102 && cf.data[0] == 0x83) {
				/* (5.1.12) */
				struct can_frame m = cf;
				m.can_id = 0x103;
				//m.data[0] = 0x82;
				print_frame(&config, &m, "!!! REPLAY AS j");
				write(sock_j, &m, sizeof(m));
				continue;
			}

		} else if (w->fd == sock_j) {
			if (attack && cf.can_id == 0x100 && cf.data[0] == 0x02 && cf.data[1] == 0x03) {
				/* (5.1.6) */
				printf("!!! REMOVED\n");
				/* (5.1.7) */
				print_frame(&config, &remember_ch_i, "!!! REPLAYED");
				write(sock_j, &remember_ch_i, sizeof(cf));
				continue;
			}

			write(sock_i, &cf, sizeof(cf));
		}
	}
Пример #17
0
int build_rsp(__u8 *rsp, __u8 type, __u8 id, 
                         __u8 len, __u8 *data)
{
    rsp[LEN_POS]  = len;
    rsp[CMD0_POS] = type;
    rsp[CMD1_POS] = id;
    memcpy(&rsp[DAT_POS], data, len);
    print_frame(rsp);
    return len + FRAME_HDR_SZ;
}
Пример #18
0
void build_and_send_rsp(tcpc_t c, __u8 type, __u8 id, 
                        __u8 len, __u8 *data)
{
    struct wcamcli  *wc   = c->arg;
    __u8  *rsp = wc->rsp;

    rsp[LEN_POS]  = len;
    rsp[CMD0_POS] = type;
    rsp[CMD1_POS] = id;
    memcpy(&rsp[DAT_POS], data, len);
    print_frame(rsp);
    tcpc_send(c, rsp, len + FRAME_HDR_SZ);
}
Пример #19
0
static void print_menu()
{   
    int array_size = 0;

    menu_size = &array_size;
    m_item = init_menu(menu_size);
    print_frame();
    add_menu_label();
    print_menu_items();
    add_designer_label();
    main_loop();
    endwin();
    attroff(COLOR_PAIR(1));
}
Пример #20
0
/** ----------------------------------------------------------------------------------*/
 int got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packetReceived)
{
		static int count = 1;                /* packet counter */
		u_char *packet;						/* Packet Pointer */
		struct data_to_pass data;
		u_int numBytes;
		u_int dataLength;
		PRINT_DEBUG("Packet number %d: has been captured \n", count);


		if (header->caplen != header->len)
		{
			PRINT_DEBUG("Snaplen value is not enough to capture the whole packet as it is on wire \n");
			exit(1);
		}
		//data.frameLength = header->caplen ;
		//data.frame = (u_char *) malloc(header->caplen);
		//memcpy(data.frame,packetReceived,data.frameLength);

/** Write the length of the received frame to the pipe, then write the frame contents
 * This part is an atomic critical section. Need to be handled carefully
 */
		dataLength = header->caplen ;

		print_frame (packetReceived,dataLength);
		fflush(stdout);
		numBytes = write(income_pipe_fd, &dataLength, sizeof(u_int) );
		if (numBytes <= 0)
			{
			PRINT_DEBUG("numBytes written %d\n", numBytes);
			return (0);
			}

		numBytes = write(income_pipe_fd, packetReceived,dataLength );

		if (numBytes <= 0)
					{
					PRINT_DEBUG("numBytes written %d\n", numBytes);
					return (0);
					}
		PRINT_DEBUG("A frame of length %d has been captured \n", numBytes);




		count++;
		return(1);


}  // end of the function got_packet
Пример #21
0
/**
 * \brief receiv the logs
 * \param srv_fd the listener socket
 */
int log_listener(int srv_fd)
{
	fd_set fake_set;
	int max_sock_fd, ret = 0;
	struct timeval timeout_tv;

	max_sock_fd = srv_fd;
	
	while(g_run)	
	{
		char rcv_buf[sizeof(log_frame_st)] = {'\0'};
		FD_ZERO(&fake_set);	
		FD_SET(srv_fd, &fake_set);

		timeout_tv.tv_sec = 1;
		timeout_tv.tv_usec = 0;

		ret = select(max_sock_fd + 1, &fake_set, NULL, NULL, &timeout_tv);
		if(ret < 0)
		{
			if(errno == EAGAIN || errno == EINTR)
			{
				continue;
			}
			LOGERROR("select run error!");
			g_run = 0;
			break;
		} else if(ret == 0)
		{
			LOGREAL("timeout!");
			/* process the data */
			continue;
		}

		if(FD_ISSET(srv_fd, &fake_set))
		{
			/* ignore the read failed */
			ret = read_frame(srv_fd, rcv_buf, sizeof(rcv_buf));	
			if(ret > 0)
			{
				print_frame(rcv_buf);
			}
			LOGALARM("%d:%s:%d", ret, rcv_buf, sizeof(rcv_buf));
		}
		/* process the data */

	}

	return 0;
}
Пример #22
0
/**
 * Repondre a une requete d'un joueur
 * NOTA: cette fonction est bloquante et attend une requete d'un joueur 
 * 
 * @param sock Socket du joueur ayant envoye une requete
 * @param the_players Liste des joueurs
 * @return Resultat de l'echange compose de 2 champs:
 *         - type: correspond le plus souvent au type de trame
 *                 ou a une fin de connexion
 *         - content: correspond au contenu brut de l'echange, a savoir
 *                    une structure Player, un identifiant ou un ordre.
 */
Result* respond(int sock, Players the_players) {
    Result* result = NULL;
    Frame frame = recv_frame(sock);
    
    /*debug*/
    print_frame(frame);
    
    if(check_frame(frame) == SUCCESS) {
        
        /* Deconnexion du joueur */
        if(frame->pennant == SPECIAL_FRAME) {
            result = malloc(sizeof(Result));
            remove_player_by_sock(sock, the_players, 1);
            
            result->type = NOT_CONNECTED;
            result->content = NULL;
        
        /* Traitement du serveur a la requete du client */
        } else {
            switch(frame->id) {      
                case Connect:
                    result = respond_connect(sock, the_players, frame);
                    break;

                case Initiate:
                    result = respond_initiate(sock, the_players, frame);
                    break;

                case Order:
                    result = respond_order(sock, the_players, frame);
                    break;
                
                /* Type de trame inconnu ou non autorisee du protocole 
                 * @todo si type de trame existant, renvoyer une erreur specifique
                 */
                default:
                    PRINT_UNKNOWN_FRAME_TYPE(frame->id);
                    break;
            }
        }
    }
    
    if(frame != NULL) {
        free_frame(frame);
    }
    
    return result;
}
Пример #23
0
static void ping_port()
{   
    int size = 0;
    ports_num = &size;

    port = init_ports(ports_num);
    print_menu_items();
    add_designer_label();
    print_port_items();
    monit_keys();
    clear();
    print_frame();
    add_menu_label();
    print_menu_items();
    add_designer_label();
}
Пример #24
0
static void hdlc_accept(void *user_data, const uint8_t *msg, int len, int ok)
{
    int type;
    int frame_no;
    int i;

    if (len < 0)
    {
        /* Special conditions */
        fprintf(stderr, "HDLC status is %s (%d)\n", signal_status_to_str(len), len);
        return;
    }

    if (ok)
    {
        if (msg[0] != 0xFF  ||  !(msg[1] == 0x03  ||  msg[1] == 0x13))
        {
            fprintf(stderr, "Bad frame header - %02x %02x\n", msg[0], msg[1]);
            return;
        }
        print_frame("HDLC: ", msg, len);
        type = msg[2] & 0xFE;
        switch (type)
        {
        case T4_FCD:
            if (len <= 4 + 256)
            {
                frame_no = msg[3];
                /* Just store the actual image data, and record its length */
                memcpy(&ecm_data[frame_no][0], &msg[4], len - 4);
                ecm_len[frame_no] = (int16_t) (len - 4);
            }
            break;
        case T30_DCS:
            check_rx_dcs(msg, len);
            break;
        }
    }
    else
    {
        fprintf(stderr, "Bad HDLC frame ");
        for (i = 0;  i < len;  i++)
            fprintf(stderr, " %02x", msg[i]);
        fprintf(stderr, "\n");
    }
}
Пример #25
0
void KitSocket::_worker(void)
{
	int bytes;
	sflap_frame frame;

	// send the server a keepalive every 15 minutes
	if(++keepalivecount >= (15 * 60 * 1000 / KITSOCKET_WORKER_PERIOD))
	{
		keepalivecount = 0;
		if(keepAlive) writeKeepAlive();
	}

	// check for stuff to read from the server
	bytes = ::read(sock(), (void *)&frame, 6);
	if(bytes < 0)
	{
		ERRNO_SWITCH(break,
		print_frame("KitSocket::_worker() -- reading -- bytes < 0", frame); disconnectSocket(); return);
	}
Пример #26
0
static void main_loop()
{   
    int ch;
    int key_id = 0;
    int j = 0;
    while ( (ch = getch()) != 'q') {
        switch(ch) {
        case KEY_UP:
                if (key_id <= 0)
                    key_id = *menu_size;
                else 
                    key_id -= 1;
            break;
        case KEY_DOWN:
                if (key_id >= *menu_size)
                    key_id = 0;
                else
                    key_id += 1;
            break;
        }
        /*traverse through menu_item structure to print colored menu*/
        clear();
        print_frame();
        add_menu_label();
        for (; j < *menu_size; ++j) {       
            if (j == key_id) {
                init_pair(1, COLOR_RED, COLOR_BLACK);
                attron(COLOR_PAIR(1));
                mvprintw(j+4, 2, "%s", m_item[j].item_name); 
                attroff(COLOR_PAIR(1));
                if ( (char)(ch) == '\n') {
                    m_item[j].item_operation(); 
                }
            }
            else {
                mvprintw(j+4, 2, "%s", m_item[j].item_name); 
            }
        }
        add_designer_label();
        refresh();
        j = 0;
    }
}
Пример #27
0
void do_calculations_const (Shypothesis **samples, char **groups, int norm, xmlDocPtr doc) {
	
	int i;
	double woc;
	BOOL **garbage;
	char **hyps;
	int no_hyps;
	
	garbage=garbage_init();
	woc = 0;
	hyps = get_hyp_names_XML ( &no_hyps, doc );
	
	for (i=0; i<N; i++) {
		samples[i] = get_const_samples_XML (groups[i], norm, garbage, doc);
	}	
	
	for(i=0;i<N;i++) /* set the bel and pl */
	{
		set_beliefs(samples[i]);
		set_plausibilities(samples[i]);
	}		
			
	for(i=0;i<N-1;i++) /* combine the sets */
	{		
		woc = combine_bpn(samples[0], samples[i+1], garbage, CONST_MODE );
		set_beliefs(samples[0]);		
		set_plausibilities(samples[0]);		
	}
	
	set_commonalities(samples[0]);
	set_doubts(samples[0]);
	set_bint(samples[0]);
	
	
	fprintf(lp, "\nCONST Evidence Combined:\n");	
	print_frame(samples[0], hyps);
	fprintf (lp, "Weight of Conflict: %.3f\n",woc);	
	
	garbage_free ( garbage );
					
	G_free (samples);
}
Пример #28
0
void do_frame(int sd)
{
	int len;
	char buf[2000];
	struct ether_header *eth = NULL;

	bzero(buf, sizeof(buf));

	len = recvfrom(sd, buf, sizeof(buf), 0, NULL, NULL);
	if(len <= 0)
		return;

	g.packet_frame++;
	g.bytes += len;

	printf("\033[H\033[2J");
	fflush(stdout);

	printf("***************************************************\n");
	printf("****************** 第 %03d 个frame *******************\n",
			g.packet_frame);
	printf("*****************************************************\n");
	

	if(g.print_flag_frame)
		print_frame(buf);

	eth = (void *)buf;
	switch(ntohs(eth->ether_type))
	{
		case ETHERTYPE_IP:
			do_ip(eth + 1);
			break;
		case ETHERTYPE_ARP:
			do_arp(eth + 1);
			break;
		case ETHERTYPE_REVARP:
			do_rarp(eth + 1);
			break;
	}
}
Пример #29
0
int main() {

  // setup
  struct leap_event *event;
  struct leap_controller *controller = leap_controller();
  struct leap_listener *listener = leap_listener(1000);
  leap_add_listener(controller, listener);

  // poll for events until we get 5000
  int limit = 5000;
  int counter = 0;
  int i, j;
  while (counter < limit) {
    while ((event = leap_poll_listener(listener)) != NULL) {
      printf("New event (%d): Type: %d\n", counter, event->event_code);
      print_frame(&event->frame);
      print_bounds(&event->frame.bounds);
      for (i = 0; i < event->frame.hand_count; i++) {
        struct leap_hand *hand = &event->frame.hands[i];
        print_hand(hand);
        for (j = 0; j < hand->finger_count; ++j) {
          struct leap_finger *finger = &hand->fingers[j];
          print_finger(finger);
        }
      }

      ++counter;
      if (counter > limit)
        break;
    }
    sleep_(100);
  }

  // shutdown
  leap_remove_listener(controller, listener);
  leap_listener_dispose(listener);
  leap_controller_dispose(controller);
}
Пример #30
0
static void trap_dispatch(struct frame *tf)
{

	switch(tf->tf_trapno) 
	{
		case T_PGFLT: 
		{	
			//print_frame(tf);
			do_page_fault(tf);
			break;
		}
		case T_GPFLT:
		{
			panic("GPFLT!\n");
			do_exit(curtask);
			break;
		}
		case T_BRKPT : 
		{
			print_frame(tf);
			panic("break point handler not implemented!\n");
			break;
		}
		case T_DIVIDE:
		{
			printk("CPU:%d USER T_DIVIDE\n",get_cpuid());
			do_exit(curtask);
		}
		case T_SYSCALL:
		{	
			tf->tf_regs.reg_eax = syscall_handler(tf); 
			break;
		}
		case IRQ_SPURIOUS: 
		{
			printk("CPU:%d Spurious interrupt on irq 7\n",get_cpuid());
			print_frame(tf);
			return;
		}
		case IRQ_TIMER : 
		{ 
			lapic_eoi();
			schedule_tick();
			break; 
		}
		case IRQ_KBD : 
		{
			irq_eoi();
			printk("CPU:%d IRQ_KBD \n",get_cpuid()); 
			inb(0x60);
			
			break;
		}
		case IRQ_SERIAL :
		{	
			panic("SERIAL handler not implemented!\n");
			break;
		}
		case IRQ_IDE0 : 
		case IRQ_IDE1 : 
		{	
			irq_eoi();
			do_hd_interrupt(tf);
			break;
		}
		case IRQ_ERROR :
		{ 
			print_frame(tf);
			panic("ERROR handler not implemented!\n");
			break;
		}
		default:
		{	
			 if (tf->tf_cs == _KERNEL_CS_) 
				panic("unhandled trap in kernel");
			 else {	
				print_frame(tf);
				return;	
			 }
			 break;
		}
	}
}