Beispiel #1
0
void game_state::tick_all()
{
    for(int i=0; i<player_list.size(); i++)
    {
        player& play = player_list[i];

        udp_sock& fd = play.sock;

        bool any_read = true;

        while(any_read && sock_readable(fd))
        {
            sockaddr_storage store;

            auto data = udp_receive_from(fd, &store);

            any_read = data.size() > 0;

            if(fd.invalid())
                continue;

            /*int which_player = -1;

            for(int j=0; j<player_list.size(); j++)
            {
                if(player_list[j].store == store)
                {
                    which_player = j;

                    //printf("received from %i\n", j);
                }
            }*/

            //printf("F %i\n", which_player);

            byte_fetch fetch;
            fetch.ptr.swap(data);

            while(!fetch.finished())
            {
                int32_t found_canary = fetch.get<int32_t>();

                while(found_canary != canary_start && !fetch.finished())
                {
                    found_canary = fetch.get<int32_t>();
                }

                int32_t type = fetch.get<int32_t>();

                if(type == message::FORWARDING)
                    process_received_message(fetch, store);
            }
        }
    }
}
Beispiel #2
0
/**
 * @brief  This function handles CAN1 RX1 request.
 * @note   We are using RX1 instead of RX0 to avoid conflicts with the
 *         USB IRQ handler.
 */
static void PIOS_CAN_RxGeneric(void)
{
	CAN_ClearITPendingBit(can_dev->cfg->regs, CAN_IT_FMP1);

	bool valid = PIOS_CAN_validate(can_dev);
	PIOS_Assert(valid);

	CanRxMsg RxMessage;
	CAN_Receive(CAN1, CAN_FIFO1, &RxMessage);

	bool rx_need_yield = false;
	if (RxMessage.StdId == CAN_COM_ID) {
		if (can_dev->rx_in_cb) {
			(void) (can_dev->rx_in_cb)(can_dev->rx_in_context, RxMessage.Data, RxMessage.DLC, NULL, &rx_need_yield);
		}
	} else {
		rx_need_yield = process_received_message(RxMessage);
	}

#if defined(PIOS_INCLUDE_FREERTOS)
	portEND_SWITCHING_ISR(rx_need_yield ? pdTRUE : pdFALSE);
#endif /* defined(PIOS_INCLUDE_FREERTOS) */
}