Value *intdoubleNE(CodeGenerator *codegen, Value *lhs, Value *rhs) { if (lhs->getType()->isIntegerTy()) { lhs = intToDouble(codegen, lhs); } else { rhs = intToDouble(codegen, rhs); } return codegen->getBuilder().CreateFCmpONE(lhs, rhs, "intdoubleNE"); }
sdrServer::sdrServer(int frequency, int port, int samplerate, bool ipv4, bool ipv6, bool debug) { mFrequency = intToDouble(frequency); mSampleRate = intToDouble(samplerate); mGain = gain_list[8]; mPort = port; mIpv4 = ipv4; mIpv6 = ipv6; mDebug = debug; mPartialCommandPtr = mPartialCommand; mI = NULL; mQ = NULL; mS = NULL; mBandwidth = mir_sdr_BW_1_536; try { mSocket.init(this, true); } catch(error *e) { fprintf(stderr,"%s\n", e->text()); exit(-1); } }
int operateKnx(int sockfd,int knxGatewayId, int timeout) { time_t inizio,curtime; int out=0; int numbytes; int recvLen=512; int sendLen=512; unsigned char *recvBuf; char *sendBuf; int received=0; char source[20]; char dest[20]; unsigned int value; int i; // legge da knxGateway // aggiorna valori recvBuf=(unsigned char *)malloc(recvLen); if(knxGateways[knxGatewayId].enabled>2) //try to reload { knxGateways[knxGatewayId].status='1'; //loading inizio=time(NULL); do { usleep(5000); } while((knxGateways[knxGatewayId].enabled>2)&&(time(NULL)-inizio<timeout)); if(knxGateways[knxGatewayId].enabled>2) knxGateways[knxGatewayId].enabled-=3; } if(knxGateways[knxGatewayId].enabled!=1) { if(knxGateways[knxGatewayId].enabled>1) knxGateways[knxGatewayId].enabled=1; else knxGateways[knxGatewayId].status='d'; return -1; } //receive received=0; do { numbytes=recv(sockfd, &recvBuf[received], recvLen-received, MSG_DONTWAIT); if(numbytes>0) received+=numbytes; } while((received>0)&&(recvBuf[received-1]!=0x0d)); if(received>0) { recvBuf[received]='\0'; switch(recvBuf[2]) { case 'i': if(parseKnxOutput(recvBuf,source,dest,&value)!=-1) { i=group_addressToId(dest); if(i!=-1) { strcpy(knxTable[i].group_address,dest); strcpy(knxTable[i].physical_address,source); knxTable[i].value=value; if(knxTable[i].data_type=='F') knxTable[i].value_eng=intToDouble(value); else knxTable[i].value_eng=value; printf("aggiornato %s da %s, valore %d\n",dest,source,value); } else printf("%s non trovato\n",dest); } break; default: printf("%s\n",recvBuf); break; } } //send request value or update for(i=0;i<NUMKNXCHANNELS;i++) { if((knxTable[i].enabled)&&(knxTable[i].req_value!=-1)) { sendBuf=(char *)malloc(sendLen); if(knxTable[i].input_output==1) { sprintf(sendBuf,"trs (%s) \r", knxTable[i].group_address); } else { if(knxTable[i].data_type!='F') sprintf(sendBuf,"tds (%s %d) $%x \r", knxTable[i].group_address, 1, knxTable[i].req_value); else sprintf(sendBuf,"tds (%s %d) $%x $%x\r", knxTable[i].group_address, 2, (knxTable[i].req_value>>8), (knxTable[i].req_value&0xff)); } printf("richiedo: %s\n",sendBuf); if (!send(sockfd,sendBuf,strlen(sendBuf),0)) out=-1; knxTable[i].req_value=-1; free(sendBuf); break; //one update per loop! } }
void sdrServer::processSdrCommand(sdr_command *sdrcmd) { int cmd = sdrcmd->cmd; int arg = htonl(sdrcmd->param); switch(cmd) { case 1: // Set Frequency mOldFrequency = mFrequency; mFrequency = intToDouble(arg); if(mDebug) printf("Set frequency in Mhz to %f\n", mFrequency); mFrequencyChanged = true; break; case 2: // Set Sample Rate mOldSampleRate = mSampleRate; mSampleRate = intToDouble(arg); if(mDebug) printf("Set sample rate in Hz to %f\n", mSampleRate); mSamplerateChanged = true; break; case 3: // Set Gain Mode if(mDebug) printf("Set gain mode to %d\n", arg); break; case 4: // Set Tuner Gain mOldGain = mGain; mGain = arg; if(mDebug) printf("Set tuner gain to %d\n", mGain); mGainChanged = true; break; case 5: // Set Freq Correction if(mDebug) printf("Set frequency correction %f\n", intToDouble(arg)); break; case 6: // Set IF Gain if(mDebug) printf("Set if gain to %d\n", arg); break; case 7: // Set test mode if(mDebug) printf("Set test mode to %d\n", arg); break; case 8: // Set AGC mode if(mDebug) printf("Set agc mode to %d\n", arg); mAgc = arg != 0; break; case 9: // Set direct sampling // Sample directly off IF or tuner if(mDebug) printf("Set direct sampling to %d\n", arg); break; case 10: // Set offset tuning // Essentially whether to use IF stage or not if(mDebug) printf("Set offset tuning to %d\n", arg); break; case 11: // Set rtl xtal if(mDebug) printf("Set rtl xtal to %d\n", arg); break; case 12: // Set tuner xtal if(mDebug) printf("Set tuner xtal to %d\n", arg); break; case 13: // Set gain by index if(mDebug) printf("Set gain to index %d\n", arg); if(arg<0 || arg>(int)(sizeof(gain_list)/sizeof(gain_list[0]))) break; mGain = gain_list[arg]; if(mDebug) printf(" %d\n", mGain); mGainChanged = true; break; default: if(mDebug) printf("Unknown Cmd = %d, arg = %d\n", cmd, arg ); break; } }