Пример #1
0
void
test_card_read(void)
{
    struct card_s card;
    struct card_s refcardJH, refcardOS;
    char JH[3] = { 'J', 'H', 0x00 };
    char OS[3] = { 'O', 'B', 0x00 };

    refcardJH.suite = HEART;
    refcardJH.face = JACK;

    refcardOS.suite = SECOND;
    refcardOS.face = JOKER;
    
    card = card_read(JH);
    CU_ASSERT(cards_eq(&refcardJH, &card));

    card = card_read(OS);
    CU_ASSERT(cards_eq(&refcardOS, &card));
}
Пример #2
0
static void handle_card(struct sstate *ss)
{
	unsigned char buf[2048];
	int rd;
	struct rx_info *ri = (struct rx_info*) buf;
	struct client *c;

	rd = card_read(ss, ri + 1, sizeof(buf) - sizeof(*ri), ri);
    if (rd >= 0)
    	rd += sizeof(*ri);

#ifdef __MACH__
	ri->ri_mactime = OSSwapHostToBigInt64(ri->ri_mactime);
	ri->ri_power = OSSwapHostToBigInt32(ri->ri_power);
	ri->ri_noise = OSSwapHostToBigInt32(ri->ri_noise);
	ri->ri_channel = OSSwapHostToBigInt32(ri->ri_channel);
	ri->ri_rate = OSSwapHostToBigInt32(ri->ri_rate);
	ri->ri_antenna = OSSwapHostToBigInt32(ri->ri_antenna);

#elif defined(__FreeBSD__)
#if BYTE_ORDER == BIG_ENDIAN
# define __be32_to_cpu(x)       (x)
# define __be64_to_cpu(x)       (x)
#elif BYTE_ORDER == LITTLE_ENDIAN
# define __be32_to_cpu(x)       __bswap32(x)
# define __be64_to_cpu(x)       __bswap64(x)
#endif

#else
	ri->ri_mactime = __cpu_to_be64(ri->ri_mactime);
	ri->ri_power = __cpu_to_be32(ri->ri_power);
	ri->ri_noise = __cpu_to_be32(ri->ri_noise);
	ri->ri_channel = __cpu_to_be32(ri->ri_channel);
	ri->ri_rate = __cpu_to_be32(ri->ri_rate);
	ri->ri_antenna = __cpu_to_be32(ri->ri_antenna);
#endif /* __MACH__ */

	c = ss->ss_clients.c_next;
	while (c != &ss->ss_clients) {
		client_send_packet(ss, c, buf, rd);
		c = c->c_next;
	}
}
Пример #3
0
/**
 * @brief Function for the tread reading data from the card
 * @param arg the structure with the thread parameters
 */
void *read_card_thread_func(void* arg)
{
  card_thread_parameters_t  *threadparams;
  threadparams= (card_thread_parameters_t  *) arg;

  struct pollfd pfds[2];	// Local poll file descriptors containing DVR device
  int poll_ret;
  fds_t fds;
  threadparams->card_buffer->bytes_in_write_buffer=0;
  int throwing_packets=0;
  //File descriptor for polling the DVB card
  pfds[0].fd = threadparams->fds->fd_dvr;
  //POLLIN : data available for read
  pfds[0].events = POLLIN | POLLPRI;
  pfds[1].fd = 0;
  pfds[1].events = POLLIN | POLLPRI;
  fds.pfds=pfds;
  fds.pfdsnum=1;
  log_message( log_module,  MSG_DEBUG, "Reading thread start\n");

  usleep(100000); //some waiting to be sure the main program is waiting //it is probably useless
  threadparams->unicast_data=0;
  while(!threadparams->threadshutdown&& !Interrupted)
  {
    //If we know that there is unicast data waiting, we don't poll the unicast file descriptors
    if(threadparams->unicast_data)
      poll_ret=mumudvb_poll(&fds);
    else
      poll_ret=mumudvb_poll(threadparams->fds);
    if(poll_ret)
    {
      Interrupted=poll_ret;
      log_message( log_module,  MSG_WARN, "Thread polling issue\n");
      return NULL;
    }
    if((!(threadparams->fds->pfds[0].revents&POLLIN)) && (!(threadparams->fds->pfds[0].revents&POLLPRI))) //Unicast information
      {
	threadparams->unicast_data=1;
	if(threadparams->main_waiting)
        {
        //log_message( log_module,  MSG_DEBUG, "Thread signalling -------\n");
        pthread_cond_signal(&threadparams->threadcond);
        }
	//no DVB packet, we continue
	continue;
      }
    if((threadparams->card_buffer->bytes_in_write_buffer+TS_PACKET_SIZE*threadparams->card_buffer->dvr_buffer_size)>threadparams->card_buffer->write_buffer_size)
    {
      /**@todo : use a dynamic buffer ?*/
      if(!throwing_packets)
      {
	throwing_packets=1; /** @todo count them*/
	log_message( log_module,  MSG_INFO, "Thread trowing dvb packets\n");
      }
      if(threadparams->main_waiting)
      {
        //log_message( log_module,  MSG_DEBUG, "Thread signalling -------\n");
        pthread_cond_signal(&threadparams->threadcond);
      }
      continue;
    }
    throwing_packets=0;
    pthread_mutex_lock(&threadparams->carddatamutex);
    threadparams->card_buffer->bytes_in_write_buffer+=card_read(threadparams->fds->fd_dvr,
							       threadparams->card_buffer->writing_buffer+threadparams->card_buffer->bytes_in_write_buffer,
							       threadparams->card_buffer);

    if(threadparams->main_waiting)
    {
      //log_message( log_module,  MSG_DEBUG, "Thread signalling -------\n");
      pthread_cond_signal(&threadparams->threadcond);
    }
    pthread_mutex_unlock(&threadparams->carddatamutex);
    //usleep(2000000);
  }
  return NULL;
}