void* ozy_ep6_ep2_io_thread(void* arg) { unsigned char input_buffer[OZY_BUFFER_SIZE*ozy_buffers]; int bytes; int i; while(1) { // read an input buffer (blocks until all bytes read) bytes=ozy_read(0x86,input_buffer,OZY_BUFFER_SIZE*ozy_buffers); if (bytes < 0) { fprintf(stderr,"ozy_ep6_ep2_io_thread: OzyBulkRead read failed %d\n",bytes); } else if (bytes != OZY_BUFFER_SIZE*ozy_buffers) { fprintf(stderr,"ozy_ep6_ep2_io_thread: OzyBulkRead only read %d bytes\n",bytes); } else { // process input buffers for(i=0;i<ozy_buffers;i++) { process_ozy_input_buffer(&input_buffer[i*OZY_BUFFER_SIZE]); } if(record) { bytes=fwrite(input_buffer,sizeof(char),OZY_BUFFER_SIZE*ozy_buffers,recording); } } current_receiver++; if(current_receiver==receivers) { current_receiver=0; } } }
void* playback_thread(void* arg) { unsigned char input_buffer[OZY_BUFFER_SIZE*ozy_buffers]; int bytes; int i; while(1) { // read an input buffer (blocks until all bytes read) bytes=fread(input_buffer,sizeof(char), OZY_BUFFER_SIZE*ozy_buffers,recording); if (bytes <= 0) { fclose(recording); fprintf(stderr,"restarting playback: %s\n",filename); recording=fopen(filename,"r"); bytes=fread(input_buffer,sizeof(char), OZY_BUFFER_SIZE*ozy_buffers,recording); } // process input buffers for(i=0;i<ozy_buffers;i++) { process_ozy_input_buffer(&input_buffer[i*OZY_BUFFER_SIZE]); } current_receiver++; if(current_receiver==receivers) { current_receiver=0; } usleep(playback_sleep); } }
void* metis_receive_thread(void* arg) { struct sockaddr_in addr; int length; unsigned char buffer[2048]; int bytes_read; length=sizeof(addr); while(1) { bytes_read=recvfrom(discovery_socket,buffer,sizeof(buffer),0,(struct sockaddr*)&addr,&length); if(bytes_read<0) { perror("recvfrom socket failed for metis_receive_thread"); exit(1); } if(buffer[0]==0xEF && buffer[1]==0xFE) { switch(buffer[2]) { case 1: if(!discovering) { // get the end point ep=buffer[3]&0xFF; // get the sequence number sequence=((buffer[4]&0xFF)<<24)+((buffer[5]&0xFF)<<16)+((buffer[6]&0xFF)<<8)+(buffer[7]&0xFF); //fprintf(stderr,"received data ep=%d sequence=%ld\n",ep,sequence); switch(ep) { case 6: // EP6 // process the data process_ozy_input_buffer(&buffer[8]); process_ozy_input_buffer(&buffer[520]); break; case 4: // EP4 process_bandscope_buffer(&buffer[8]); process_bandscope_buffer(&buffer[520]); break; default: fprintf(stderr,"unexpected EP %d length=%d\n",ep,bytes_read); break; } } else { fprintf(stderr,"unexpected data packet when in discovery mode\n"); } break; case 2: // response to a discovery packet if(discovering) { if(found<MAX_METIS_CARDS) { // get MAC address from reply sprintf(metis_cards[found].mac_address,"%02X:%02X:%02X:%02X:%02X:%02X", buffer[3]&0xFF,buffer[4]&0xFF,buffer[5]&0xFF,buffer[6]&0xFF,buffer[7]&0xFF,buffer[8]&0xFF); fprintf(stderr,"Metis MAC address %s\n",metis_cards[found].mac_address); // get ip address from packet header sprintf(metis_cards[found].ip_address,"%d.%d.%d.%d", addr.sin_addr.s_addr&0xFF, (addr.sin_addr.s_addr>>8)&0xFF, (addr.sin_addr.s_addr>>16)&0xFF, (addr.sin_addr.s_addr>>24)&0xFF); fprintf(stderr,"Metis IP address %s\n",metis_cards[found].ip_address); found++; } else { fprintf(stderr,"too many metis cards!\n"); } } else { fprintf(stderr,"unexepected discovery response when not in discovery mode\n"); } break; default: fprintf(stderr,"unexpected packet type: 0x%02X\n",buffer[2]); break; }
void* metis_receive_thread(void* arg) { struct sockaddr_in addr; unsigned int length; int bytes_read; length=sizeof(addr); while(1) { bytes_read=recvfrom(discovery_socket,input_buffer,sizeof(input_buffer),0,(struct sockaddr*)&addr,&length); if(bytes_read<0) { perror("recvfrom socket failed for metis_receive_thread"); exit(1); } if(input_buffer[0]==0xEF && input_buffer[1]==0xFE) { switch(input_buffer[2]) { case 1: if(!discovering) { // get the end point ep=input_buffer[3]&0xFF; // get the sequence number sequence=((input_buffer[4]&0xFF)<<24)+((input_buffer[5]&0xFF)<<16)+((input_buffer[6]&0xFF)<<8)+(input_buffer[7]&0xFF); //fprintf(stderr,"received data ep=%d sequence=%ld\n",ep,sequence); switch(ep) { case 6: // process the data process_ozy_input_buffer(&input_buffer[8]); process_ozy_input_buffer(&input_buffer[520]); break; case 4: //fprintf(stderr,"EP4 data\n"); break; default: fprintf(stderr,"unexpected EP %d length=%d\n",ep,bytes_read); break; } } else { fprintf(stderr,"unexpected data packet when in discovery mode\n"); } break; case 2: // response to a discovery packet - hardware is not yet sending case 3: // response to a discovery packet - hardware is already sending if(discovering) { if(found<MAX_METIS_CARDS) { // get MAC address from reply sprintf(metis_cards[found].mac_address,"%02X:%02X:%02X:%02X:%02X:%02X", input_buffer[3]&0xFF,input_buffer[4]&0xFF,input_buffer[5]&0xFF,input_buffer[6]&0xFF,input_buffer[7]&0xFF,input_buffer[8]&0xFF); fprintf(stderr,"Metis MAC address %s\n",metis_cards[found].mac_address); // get ip address from packet header sprintf(metis_cards[found].ip_address,"%d.%d.%d.%d", addr.sin_addr.s_addr&0xFF, (addr.sin_addr.s_addr>>8)&0xFF, (addr.sin_addr.s_addr>>16)&0xFF, (addr.sin_addr.s_addr>>24)&0xFF); fprintf(stderr,"Metis IP address %s\n",metis_cards[found].ip_address); metis_cards[found].code_version = input_buffer[9]; switch (input_buffer[10]) { case 0x00: metis_cards[found].board_id = "Metis"; break; case 0x01: metis_cards[found].board_id = "Hermes"; break; case 0x02: metis_cards[found].board_id = "Griffin"; break; default: metis_cards[found].board_id = "unknown"; break; } fprintf(stderr,"Board id: %s",metis_cards[found].board_id); fprintf(stderr," version: %1.2F\n",metis_cards[found].code_version /10.0); found++; if(input_buffer[2]==3) { fprintf(stderr,"Metis is sending\n"); } } else { fprintf(stderr,"too many metis cards!\n"); } } else { fprintf(stderr,"unexepected discovery response when not in discovery mode\n"); } break; default: fprintf(stderr,"unexpected packet type: 0x%02X\n",input_buffer[2]); break; }