const char* parse_command(CLIENT* client,char* command) { char* token; fprintf(stderr,"parse_command(Rx%d): '%s'\n",client->receiver,command); token=strtok(command," \r\n"); if(token!=NULL) { if(strcmp(token,"attach")==0) { //COMMAND: 'attach <side>' token=strtok(NULL," \r\n"); if(token!=NULL) { if(strcmp(token,"tx")==0) { //COMMAND: 'attach tx' return attach_transmitter(client); } else { //COMMAND: 'attach rx#' int rx=atoi(token); return attach_receiver(rx,client); } } else { return INVALID_COMMAND; } } else if(strcmp(token,"detach")==0) { //COMMAND: 'detach <side>' token=strtok(NULL," \r\n"); if(token!=NULL) { int rx=atoi(token); return detach_receiver(rx,client); } else { return INVALID_COMMAND; } } else if(strcmp(token,"frequency")==0) { //COMMAND: 'frequency <long freq>' token=strtok(NULL," \r\n"); if(token!=NULL) { long f=atol(token); return set_frequency(client,f); } else { return INVALID_COMMAND; } } else if(strcmp(token,"start")==0) { //COMMAND: 'start <stream> <port#>' token=strtok(NULL," \r\n"); if(token!=NULL) { if(strcmp(token,"iq")==0) { //COMMAND: 'start iq <port#>' token=strtok(NULL," \r\n"); if(token!=NULL) { client->iq_port=atoi(token); } // starts the thread to acquire USRP samples usrp_start (&receiver[client->receiver]); fprintf(stderr,"Started USRP for RX%d\n",client->receiver); //Start the audio thread if(pthread_create(&receiver[client->receiver].audio_thread_id,NULL,audio_thread,client)!=0) { fprintf(stderr,"Failed to create audio thread for rx %d\n",client->receiver); exit(1); } return OK; } else if(strcmp(token,"bandscope")==0) { //COMMAND: 'start bandscope <port#>' token=strtok(NULL," \r\n"); if(token!=NULL) { client->bs_port=atoi(token); } attach_bandscope(client); return OK; } else { // invalid command string return INVALID_COMMAND; } } else { // invalid command string return INVALID_COMMAND; } } else if(strcmp(token,"stop")==0) { //COMMAND: 'stop <stream>' token=strtok(NULL," \r\n"); if(token!=NULL) { if(strcmp(token,"iq")==0) { //COMMAND: 'stop iq' token=strtok(NULL," \r\n"); if(token!=NULL) { client->iq_port=-1; } return OK; } else if(strcmp(token,"bandscope")==0) { //COMMAND: 'stop bandscope' client->bs_port=-1; detach_bandscope(client); } else { // invalid command string return INVALID_COMMAND; } } else { // invalid command string return INVALID_COMMAND; } } else if(strcmp(token,"preamp")==0) { return NOT_IMPLEMENTED_COMMAND; } else if(strcmp(token,"record")==0) { return NOT_IMPLEMENTED_COMMAND; } else if(strcmp(token,"mox")==0) { return NOT_IMPLEMENTED_COMMAND; } else if(strcmp(token,"ocoutput")==0) { return NOT_IMPLEMENTED_COMMAND; } else { // invalid command string return INVALID_COMMAND; } } else { // empty command string return INVALID_COMMAND; } return INVALID_COMMAND; }
const char* parse_command(CLIENT* client,char* command) { char* token; fprintf(stderr,"parse_command(Rx%d): '%s'\n",client->receiver_num,command); token=strtok(command," \r\n"); if(token!=NULL) { if(strcmp(token,"attach")==0) { //COMMAND: 'attach <side>' token=strtok(NULL," \r\n"); if(token!=NULL) { //COMMAND: 'attach rx#' int rx=atoi(token); const char *resp=attach_receiver(rx,client); if (strcmp(resp, "Error") == 0) return resp; else return attach_transmitter(client, resp); } } else if(strcmp(token,"detach")==0) { //COMMAND: 'detach <side>' token=strtok(NULL," \r\n"); if(token!=NULL) { int rx=atoi(token); return detach_receiver(rx,client); } else { return INVALID_COMMAND; } } else if(strcmp(token,"frequency")==0) { //COMMAND: 'frequency <long freq>' token=strtok(NULL," \r\n"); if(token!=NULL) { long f=atol(token); return set_frequency(client,f); } else { return INVALID_COMMAND; } } else if(strcmp(token,"start")==0) { //COMMAND: 'start <stream> <port#>' token=strtok(NULL," \r\n"); if(token!=NULL) { if(strcmp(token,"iq")==0) { //COMMAND: 'start iq <port#>' token=strtok(NULL," \r\n"); if(token!=NULL) { client->iq_port=atoi(token); } //NOTE:as it is now the usrp-server, only receiver 0's is supported //then it is the only one to issue 'start' command. if (usrp_start_rx_forwarder_thread(client)!=0) exit(1); sleep(1); //some settling time... //This is executed only once if (! usrp_is_started()) { if (usrp_start (client)) fprintf(stderr,"Started USRP for Client %d\n",client->receiver_num); else { fprintf(stderr,"USRP threads start FAILED for rx %d\n",client->receiver_num); exit(1); } } sleep(1); //some settling time //Start the server side tx audio stream receiving thread //Exit program if failed (...?) if (start_tx_audio_thread(client)!=0) exit(1); return OK; } else if(strcmp(token,"bandscope")==0) { //COMMAND: 'start bandscope <port#>' token=strtok(NULL," \r\n"); if(token!=NULL) { client->bs_port=atoi(token); } attach_bandscope(client); return OK; } else { // invalid command string return INVALID_COMMAND; } } else { // invalid command string return INVALID_COMMAND; } } else if(strcmp(token,"stop")==0) { //COMMAND: 'stop <stream>' token=strtok(NULL," \r\n"); if(token!=NULL) { if(strcmp(token,"iq")==0) { //COMMAND: 'stop iq' token=strtok(NULL," \r\n"); if(token!=NULL) { client->iq_port=-1; } return OK; } else if(strcmp(token,"bandscope")==0) { //COMMAND: 'stop bandscope' client->bs_port=-1; detach_bandscope(client); } else { // invalid command string return INVALID_COMMAND; } } else { // invalid command string return INVALID_COMMAND; } } else if(strcmp(token,"mox")==0) { //Toggle the mox int v=toggle_mox(client); fprintf(stderr,"Toggled mox to %d for Client %d\n",v, client->receiver_num); return OK; } else if(strcmp(token,"preamp")==0) { return NOT_IMPLEMENTED_COMMAND; } else if(strcmp(token,"record")==0) { return NOT_IMPLEMENTED_COMMAND; } else if(strcmp(token,"ocoutput")==0) { return NOT_IMPLEMENTED_COMMAND; } else { // invalid command string return INVALID_COMMAND; } } // empty command string return INVALID_COMMAND; }