void NetCom::rxSpike(NetComDat net, spike_net_t* spike){

  char buff[BUFFSIZE-1];
  int buff_len = 0;

  rxBuff(net, buff, &buff_len);
  buffToSpike(spike, buff, true);
}
Exemple #2
0
void NetCom::rxSpike(NetComDat net, spike_net_t* spike){

  char buff[BUFFSIZE-1];
  int buff_len = 0;
  // printf("Netcom::rxSpike() calling rxBuff()\n");
  rxBuff(net, buff, &buff_len);
//  printf("Netcom::rxSpike() converting buff to spike\n");
  buffToSpike(spike, buff, true);
  //printf("Netcom::rxSpike() the buff is converted\n");
}
bool get_next_packet(void *arte_packet, int sourcename, packetType_t sourcetype){

  bool ok_packet;
  char buff_head[4];
  char buff[4000];
  char the_type;
  uint16_t the_length;
  char the_next_byte;
  
  spike_net_t *spike;
  lfp_bank_net_t *lfp;

  char tmp_spike[MAX_PACKET_BYTES];

//spike_net_t spike;

  //fread(buff, sizeof(char), 1000, in_f);
  //buffToSpike( spike, buff, false);

  //printf("spike->n_chans: %d\n", spike->n_chans);

  //printf("still ok.\n"); fflush(stdout);

  fread  (buff_head, sizeof(char), 4,  in_f);
  fseek( in_f, -4, SEEK_CUR );
  
  the_type = buff_head[0];
  memcpy( &the_length, buff_head+1, 2 );
  memcpy( &the_next_byte, buff_head+3, 1);


  //printf("Wanted sourcetype: %c, buff_type:%c length:%d next_byte:%d\n", 
  //	 sourcetype, the_type, the_length, the_next_byte);

  fread (buff,  sizeof(char),the_length, in_f);

  //printf("still ok after fread.\n");fflush(stdout);

  if ( charToType(the_type) != sourcetype){
    return false;
  }

  if ( charToType(the_type) == NETCOM_UDP_SPIKE ){
    
    spike = (spike_net_t*)arte_packet;
    //printf("ok after spike= assignment\n"); fflush(stdout);
    buffToSpike( spike, buff, false );
    //printf("ok after buffToSpike.\n"); fflush(stdout);
    ok_packet = ( spike->name == sourcename );
    
    //spike_net_t *this_spike = (spike_net_t *)arte_packet;
    for(int i = 0; i < spike->n_chans * spike->n_samps_per_chan; i++){
      spike->data[i] = spike->data[i] / 16;
    }
    if(spike->ts > (UINT32_MAX - 30000) ){   // is it later than 10 seconds before the end of the valid time range
      ok_packet = false;
      //printf("Found spike with bad_ts:%d  Current spike_count is:%d   Dropping it.\n", spike->ts, spike_count);
    }
    if(false){
      printf("sought-after sourcename:%d sourcetype:%c  found name:%d type:%c\n",
	     sourcename, sourcetype, spike->name, the_type);
    }

    if(false & ok_packet & (sourcetype == NETCOM_UDP_SPIKE)){
      printf("test in get_next_spike: spike->ts:%d, name:%d n_chans:%d\n",
	     spike->ts, spike->name, spike->n_chans);
    }

    if(ok_packet & (sourcetype == NETCOM_UDP_SPIKE) & verbose){
      printf("OK_PACKET!  spikename:%d  sourcename:%d\n", spike->name, sourcename);
      fflush(stdout);
    }
    //printf("ABOUT TO RETURN\n");
    return (ok_packet & (sourcetype == NETCOM_UDP_SPIKE)); 
  }
   
  if (sourcetype == NETCOM_UDP_LFP){
    
    lfp = (lfp_bank_net_t *)arte_packet;
    buffToWave( lfp, buff, false );
    ok_packet = ( lfp->name == sourcename );
    for(int i = 0; i < (lfp->n_chans * lfp->n_samps_per_chan); i++){
      lfp->data[i] = lfp->data[i]/16;
    }
    if(lfp->ts > (UINT32_MAX - 10000)){
	ok_packet = false;
	//printf("dropped a bad wave packet.  timestamp was:%d\n", lfp->ts);
    }

    if(false){
    printf("lfp_packet: sought-after sourcename:%d sourcetype:%c  found name:%d type:%c\n",
	   sourcename, sourcetype, lfp->name, the_type);
    }

    return (ok_packet & (sourcetype == NETCOM_UDP_LFP));

  }

}