void Connector::handleReadyRead() { qDebug()<<"Connector::handleReadyRead"; ba.append(readAll()); if (ba.size() >= exceptByte) { emit readAllData(); } }
void Connector::stopRead() { qDebug("stop Read"); disconnect(this, SIGNAL(readyRead()), this, SLOT(handleReadyRead())); disconnect(this, SIGNAL(readAllData()), this, SLOT(handleReadData())); //清空 ba.clear(); clear(); }
void Connector::startRead(qint8 start, qint8 num) { qDebug("start Read"); exceptByte = 5 + 48 * num; // 数据头+数据 qDebug()<<QString("start = %1, num = %2").arg(start).arg(num); stopRead(); connect(this, SIGNAL(readyRead()), this, SLOT(handleReadyRead())); connect(this, SIGNAL(readAllData()), this, SLOT(handleReadData())); this->start = start; this->num = num; callForData(start, num); }
static int preCondition(sqlite3** pphandle) { int ret = 0; const char* pathname = DB_FILENAME; ret = sqlite3_open(pathname, pphandle); if (ret != SQLITE_OK) { fprintf(stderr, "open %s failure, return code = %d\n", DB_FILENAME, ret); return ret; } applyMemoryPool(pathname); readAllData(*pphandle); return 0; }
int main(int argc, char *argv[]) { int i = 0; unsigned int N = 0; int spec = 0; int showHead = 0; //int samplerate = 0; //unsigned int numOfSamples = 0; char fileName[300]; struct WaveHeader *wav; FILE *fWavIn = NULL; //ToDO: better error handling if (argc < 3) { showUsage(); return 1; } printf("Total args %d\n", argc); for (i = 1; i < (argc); i++) { if (strcasecmp("-spec", argv[i])==0) { spec = 1; if (i+1 == argc) { fprintf(stderr,"\n**ERROR: No sample size associated with \"-spec\"**\n"); return 1; } N = atoi(argv[++i]); if (N < 5) { fprintf(stderr, "\n**ERROR: <%s> is not a valid sample size (use 5+)**\n", argv[i]); return 1; } continue; } if (strcmp("-?", argv[i])==0) { showUsage(); return 1; } if (strcasecmp("-showhead", argv[i])==0) { showHead = 1; continue; } if (strcasecmp("-file", argv[i])==0) { //require a filename to go along with the -file //check -file isn't the last arg, otherwise it throws a sigsegv if (i+1 == argc) { fprintf(stderr,"\n**ERROR: No filename listed with \"-file\"\n"); return 1; } strncpy(fileName, argv[++i],300); fWavIn = fopen(fileName, "rb"); if (!fWavIn) { fprintf(stderr,"\n**ERROR: Could not open file \"%s\"\n", fileName); return 1; } continue; } } //it's a little hacky, but this checks if we have a file if(fWavIn==NULL) { showUsage(); return 1; } //return 0; wav = malloc(sizeof(struct WaveHeader)); strncpy(wav->wavName,fileName ,300); if (readHeader(fWavIn, wav) != 0) { fprintf(stderr, "Error reading (%s), check if it is a valid wav file\n",fileName); return 1; } if (showHead == 1) { printHeader(wav); } readAllData(fWavIn,wav); //process the data if (spec == 1) { writeFFT(N, wav); } /* //test code to write out raw data as it was read in for (i = 0; i < numOfSamples; i++) { fwrite(&wav->chan1[i],1,2,fOut); if (wav->nChannels > 1) fwrite(&wav->chan2[i],1,2,fOut); if (wav->nChannels > 2) fwrite(&wav->chan3[i],1,2,fOut); if (wav->nChannels > 3) fwrite(&wav->chan4[i],1,2,fOut); } */ //free up memory freeChannelMemory(wav); free(wav); fclose(fWavIn); return 0; }