/* Start the js process. */ static void js_start(void) { int pid; char *jsprog; #if defined(DOSLIKE) && !defined(HAVE_PTHREAD_H) debugPrint(5, "no pthread, so no communication channels for javascript"); allowJS = false; return; #endif // defined(DOSLIKE) && !defined(HAVE_PTHREAD_H) #ifndef DOSLIKE /* doesn't hurt to do this more than once */ signal(SIGPIPE, SIG_IGN); #endif // !DOSLIKE debugPrint(5, "setting of communication channels for javascript"); if (PIPE(pipe_in)) { i_puts(MSG_JSEnginePipe); allowJS = false; return; } if (PIPE(pipe_out)) { i_puts(MSG_JSEnginePipe); allowJS = false; close(pipe_in[0]); close(pipe_in[1]); return; } #if defined(DOSLIKE) #if defined(HAVE_PTHREAD_H) /* windows implementation of fork() using pthreads */ pid = pthread_create(&tid, NULL, child_proc, 0); #else // !HAVE_PTHREAD_h pid = 1; #endif // HAVE_PTHREAD_H y/n if (pid) { i_puts(MSG_JSEngineFork); allowJS = false; close(pipe_in[0]); close(pipe_in[1]); close(pipe_out[0]); close(pipe_out[1]); return; } js_pid = 1; #else // !(defined(DOSLIKE) && defined(HAVE_PTHREAD_H) pid = fork(); if (pid < 0) { i_puts(MSG_JSEngineFork); allowJS = false; close(pipe_in[0]); close(pipe_in[1]); close(pipe_out[0]); close(pipe_out[1]); return; } if (pid) { /* parent */ js_pid = pid; close(pipe_in[1]); close(pipe_out[0]); return; } /* child here, exec the back end js process */ close(pipe_in[0]); close(pipe_out[1]); sprintf(arg1, "%d", pipe_out[0]); sprintf(arg2, "%d", pipe_in[1]); debugPrint(5, "spawning edbrowse-js %s %s", arg1, arg2); execlp(progname, "edbrowse", "--mode", "js", arg1, arg2, NULL); /* oops, process did not exec */ /* write a message from this child, saying js would not exec */ head.magic = EJ_MAGIC; head.highstat = EJ_HIGH_PROC_FAIL; head.lowstat = EJ_LOW_EXEC; write(pipe_in[1], &head, sizeof(head)); exit(90); #endif // defined(DOSLIKE) && defined(HAVE_PTHREAD_H) y/n } /* js_start */
void keyAction(unsigned char key, int x, int y) { switch (key) { case ';': zoomIn = true; break; case '/': zoomOut = true; break; case 'a': panL = true; break; case 's': panD = true; break; case 'd': panR = true; break; case 'w': panU = true; break; case 'j': mouseL = true; break; case 'k': mouseD = true; break; case 'l': mouseR = true; break; case 'i': mouseU = true; break; case '1': var1up = true; break; case '2': var1down = true; break; case '9': var2up = true; break; case '0': var2down = true; break; case ' ': debugPrint(); break; default: break; } }
void serialSignalHandler( int signo, void *param) { debugPrint( "serialSignalHandler\n" ); serialSignal_t *dev = (serialSignal_t *)param ; dev->rxSignal(); }
// // writes the specified flash variable with the specified value // bool writeFlashVar( char const *name, char const *value ) { bool worked = false ; readVars_t rv ; char const *devName = GetFlashDev(); debugPrint( "opening flash device %s\n", devName ); if( rv.worked() ) { unsigned const nameLen = strlen( name ); unsigned const dataLen = strlen( value ); unsigned const avail = rv.maxSize() - rv.bytesUsed(); unsigned int bDevice = IsDevice(devName); if (bDevice && ( avail > nameLen + dataLen + 2 )) { int fd = open( devName, O_WRONLY ); if( 0 <= fd ) { mtd_info_t meminfo; if( ioctl( fd, MEMGETINFO, (unsigned long)&meminfo) == 0) { if( meminfo.erasesize == rv.maxSize() ) { unsigned offset = meminfo.size-meminfo.erasesize+ rv.bytesUsed(); if( offset == (unsigned)lseek( fd, offset, SEEK_SET ) ) { // // build memory image of new entry // char *entryStart = (char *)rv.startChar() + rv.bytesUsed(); memcpy( entryStart, name, nameLen ); char *upd = entryStart + nameLen ; *upd++ = '=' ; memcpy( upd, value, dataLen ); upd += dataLen ; *upd++ = '\n' ; unsigned const entryLen = upd-entryStart ; int const numWrote = write( fd, entryStart, entryLen ); if( (unsigned)numWrote == entryLen ) { // printf( "wrote %u bytes of new entry\n", numWrote ); } else perror( "write" ); } else perror( "lseek2" ); } else fprintf( stderr, "erase size mismatch: rv %u, mi %u\n", rv.maxSize(), meminfo.erasesize ); } else { perror( "MEMGETINFO" ); } close( fd ); } else perror(devName); } else { fprintf( stderr, "Collapse vars\n" ); // // first, find number of entries by searching for newlines // unsigned maxEntries = 0 ; unsigned spaceLeft = rv.bytesUsed(); char const *next = rv.startChar(); while( 0 < spaceLeft ) { void const *nl = memchr( next, '\n', spaceLeft ); if( nl ) { maxEntries++ ; unsigned offs = (char *)nl - next + 1 ; next += offs ; spaceLeft -= offs ; } else break; } if ( 1 ) { printf( "%u entries in list\n", maxEntries+1 ); unsigned numUnique = 0 ; unsigned uniqueSize = 0 ; entry_t * const entries = (entry_t *)malloc(sizeof(entry_t)*(maxEntries+1) ); memset( entries, 0, maxEntries*sizeof(entry_t) ); varIter_t it( rv ); entry_t nextEntry ; while( it.next( nextEntry.name, nextEntry.nameLen, nextEntry.data, nextEntry.dataLen ) ) { unsigned i ; for( i = 0 ; i < numUnique ; i++ ) { if( ( entries[i].nameLen == nextEntry.nameLen ) && ( 0 == memcmp( entries[i].name, nextEntry.name, nextEntry.nameLen ) ) ) { break; } } if( i < numUnique ) { uniqueSize -= entries[i].dataLen ; uniqueSize += nextEntry.dataLen ; entries[i].data = nextEntry.data ; entries[i].dataLen = nextEntry.dataLen ; } // duplicate else { entries[numUnique++] = nextEntry ; uniqueSize += nextEntry.nameLen ; uniqueSize += nextEntry.dataLen ; } // first timer } // for each entry in flash // // now add original entry (remember why we're here) // unsigned i ; for( i = 0 ; i < numUnique ; i++ ) { if( ( entries[i].nameLen == nameLen ) && ( 0 == memcmp( entries[i].name, name, nameLen ) ) ) { break; } } if( i < numUnique ) { uniqueSize -= entries[i].dataLen ; uniqueSize += dataLen ; entries[i].data = value ; entries[i].dataLen = dataLen ; } // duplicate else { entries[i].name = name ; entries[i].nameLen = nameLen ; entries[i].data = value ; entries[i].dataLen = dataLen ; uniqueSize += nameLen ; uniqueSize += dataLen ; numUnique++ ; } // new entry uniqueSize += 2*numUnique ; printf( "%u unique entries, %u bytes\n", numUnique, uniqueSize ); if( uniqueSize < rv.maxSize() ) { printf( "saving %u bytes\n", uniqueSize ); int fd = open( devName, O_WRONLY ); if( 0 <= fd ) { if (bDevice) { mtd_info_t meminfo; if( 0 == ioctl( fd, MEMGETINFO, (unsigned long)&meminfo) ) { if( meminfo.erasesize == rv.maxSize() ) { unsigned offset = meminfo.size-meminfo.erasesize ; erase_info_t erase; erase.start = offset ; erase.length = meminfo.erasesize; if( 0 == ioctl( fd, MEMERASE, (unsigned long)&erase) ) { if( offset == (unsigned)lseek( fd, offset, SEEK_SET ) ) { writeEntries(fd, entries,numUnique,uniqueSize); worked = true ; } else perror( "lseek3" ); } else fprintf( stderr, "erase error %m\n" ); } else fprintf( stderr, "erase size mismatch: rv %u, mi %u\n", rv.maxSize(), meminfo.erasesize ); } else perror( "MEMGETINFO" ); } else { writeEntries(fd, entries,numUnique,uniqueSize); worked = true ; } close( fd ); } else perror(devName); } else fprintf( stderr, "Flash parameter area is full!\n" ); free( entries ); } else fprintf( stderr, "Error counting entries: why is size so big?\n" ); } } return worked ; }
void RepRapSerial::SendData(string s, const int lineNr) { if( !m_bConnected ) return; if( com->errorStatus() ) { m_bConnecting = false; m_bConnected = false; m_bPrinting = false; { ToolkitLock guard; gui->MVC->serialConnectionLost(); } return; } // Apply Downstream Multiplier float DSMultiplier = 1.0f; float ExtrusionMultiplier = 1.0f; if(gui) { ToolkitLock guard; DSMultiplier = gui->DownstreamMultiplierSlider->value(); ExtrusionMultiplier = gui->DownstreamExtrusionMultiplierSlider->value(); } if(DSMultiplier != 1.0f) { size_t pos = s.find( "F", 0); if( pos != string::npos ) //string::npos means not defined { size_t end = s.find( " ", pos); if(end == string::npos) end = s.length()-1; string number = s.substr(pos+1,end); string start = s.substr(0,pos+1); string after = s.substr(end+1,s.length()-1); float old_speed = ToFloat(number); s.clear(); std::stringstream oss; oss << start << old_speed*DSMultiplier << " " <<after; s=oss.str(); } } if(ExtrusionMultiplier != 1.0f) { size_t pos = s.find( "E", 0); if( pos != string::npos ) //string::npos means not defined { size_t end = s.find( " ", pos); if(end == string::npos) end = s.length()-1; string number = s.substr(pos+1,end); string start = s.substr(0,pos+1); string after = s.substr(end+1,s.length()-1); float old_speed = ToFloat(number); s.clear(); std::stringstream oss; oss << start << old_speed*ExtrusionMultiplier << " " <<after; s=oss.str(); } } string buffer; std::stringstream oss; oss << " N" << lineNr << " ";//*"; buffer += oss.str();// Hydra // strip comments string tmp=s; size_t found; found=tmp.find_first_of(";"); if(found!=string::npos) tmp=tmp.substr(0,found); found=tmp.find_last_not_of(" "); if(found!=string::npos) tmp=tmp.substr(0,found+1); for(uint i=0;i<tmp.length();i++) if((tmp[i] < '*' || tmp[i] > 'z') && tmp[i] != ' ') // *-z (ascii 42-122) tmp.erase(tmp.begin()+i--); buffer += tmp; buffer += " *";// Hydra oss.str( "" ); // Calc checksum. short checksum = 0; unsigned char count=0; while(buffer[count] != '*') checksum = checksum^buffer[count++]; oss << checksum;//std::setfill('0') << std::setw(2) << buffer.length()+2; buffer += oss.str(); debugPrint( string("SendData:") + buffer); buffer += "\r\n"; com->write(buffer); }
/* * King sized, man-trap for the un-wary. This method is called * from a separate AsyncSerial thread; we need to get data * synchronisation right. */ void RepRapSerial::OnEvent(char* data, size_t dwBytesRead) { // Read data, until there is nothing left data[dwBytesRead] = '\0'; InBuffer += data; // Buffer data for later analysis // Endchars = \r\n // debugPrint( string("Received:\"") + szBuffer +"\" (" + stringify(dwBytesRead)); { // Check inbuffer for good stuff // remove leading \n, \r, and spaces (also added \t for good measure) while(InBuffer.length() > 0 && (InBuffer.substr(0,1) == "\n" || InBuffer.substr(0,1) == "\r" || InBuffer.substr(0,1) == " " || InBuffer.substr(0,1) == "\t")) InBuffer = InBuffer.substr(1, InBuffer.length()-1); if(InBuffer[0] == 1) // Ctrl { InBuffer = InBuffer.substr(2, InBuffer.length()-2); debugPrint("Recieved a Ctrl character", true); } if(InBuffer.size() == 0) return; size_t found; found=InBuffer.find_first_of("\r\n"); while (found!=string::npos && found != 0) { bool knownCommand = true; string command = InBuffer.substr(0,found); if(0) { stringstream oss; oss << "Command:" << command; debugPrint(oss.str(), true); } if (command == "ok") // most common, first { if(m_bPrinting) SendNextLine(); } else if(command.substr(0,5) == "Echo:") // search, there's a parameter int (temperature) { string parameter = command.substr(5,command.length()-5); echo( string("Echo:") + parameter); // Check parameter } else if(command.substr(0,2) == "T:") // search, there's a parameter int (temperature) { string parameter = command.substr(2,command.length()-2); debugPrint( string("Received:") + command+ " with parameter " + parameter); ToolkitLock guard; // Reduce re-draws by only updating the GUI on a real change const char *old_value = gui->CurrentTempText->value(); if (!old_value || strcmp (parameter.c_str(), old_value)) gui->CurrentTempText->value(parameter.c_str()); } else if(command == "start") { debugPrint( string("Received: start")); } else if(command.substr(0,3) == "E: ") // search, there's a parameter int (temperature_error, wait_till_hot) { string parameter = command.substr(3,command.length()-3); debugPrint( string("Received:") + command+ " with parameter " + parameter); // Check parameter } // this is the common case for the modern 5D reprap firmware else if(command.substr(0,3) == "ok ") // search, there's a parameter string (debugstring) { //starting from the "ok", we'll parse the rest as "tokens" string s = get_next_token(command.substr(0,command.length())); uint l = s.length(); while ( s.length() > 0 ) { string remainder = command.substr(l,command.length()); uint ws = count_leading_whitespace(remainder); // s = the current token , l = the offset of this token in command //cout << "s:" << s << endl; // we already know this is how the line starts: if ( s == "ok" ) { // do nothing more // temperature token: } else if ( s.substr(0,2) == "T:" ) { temp_param = s.substr(2,s.length()); // Reduce re-draws by only updating the GUI on a real change const char *old_value = gui->CurrentTempText->value(); if (!old_value || strcmp (temp_param.c_str(), old_value)) gui->CurrentTempText->value(temp_param.c_str()); // bed temperature token: } else if ( s.substr(0,2) == "B:" ) { bedtemp_param = s.substr(2,s.length()); // Reduce re-draws by only updating the GUI on a real change const char *old_value = gui->CurrentBedTempText->value(); if (!old_value || strcmp (bedtemp_param.c_str(), old_value)) gui->CurrentBedTempText->value(bedtemp_param.c_str()); // a token we don't yet understand , dump to stdout for now } else { cout << "unknown token:" << s << endl; } s = get_next_token(remainder); l += s.length() + ws; } string parameter = command.substr(3,command.length()-3); debugPrint( string("Received:") + command+ " with parameter " + parameter + "**************************************", true); if(m_bPrinting) SendNextLine(); } else if(command.substr(0,5) == "huh? ") // search, there's a parameter string (unknown command) { string parameter = command.substr(6,command.length()-5); debugPrint( string("Received:") + command+ " with parameter " + parameter, true); if(m_bPrinting) SendNextLine(); } else if(command.substr(0,7) == "Resend:") // search, there's a parameter string (unknown command) { string parameter = command.substr(7,command.length()-7); debugPrint( string("Received:") + command+ " with parameter " + parameter, true); std::stringstream iss(parameter); iss >> m_iLineNr; // Rewind to requested line if(m_bPrinting) SendNextLine(); } else if(command.substr(0,3) == "rs ") // search, there's a parameter string (unknown command) { string parameter = command.substr(3,command.length()-3); debugPrint( string("Received:") + command+ " with parameter " + parameter, true); std::stringstream iss(parameter); iss >> m_iLineNr; // Rewind to requested line if(m_bPrinting) SendNextLine(); }
std::ostream &operator<<(std::ostream &os, const Buffer &buf) { debugPrint(os, buf); return os; }
void protectedMemoryDebugPrint(ProtectedMemory *memory) { if(memory == NULL) return; debugPrint("struct ProtectedMemory [%p]\n{\n", (void *)memory); debugPrint("\twritable -> %p\n", memory->writable); debugPrint("\texecutable -> %p\n", memory->executable); debugPrint("\twritableAligned -> %p\n", memory->writableAligned); debugPrint("\texecutableAligned -> %p\n", memory->executableAligned); debugPrint("\twritableHandle -> %i\n", memory->writableHandle); debugPrint("\texecutableHandle -> %i\n", memory->executableHandle); debugPrint("\tsize -> %"PRIu64" = 0x%"PRIx64"\n", memory->size, memory->size); debugPrint("\talignment -> %"PRIu64" = 0x%"PRIx64"\n", memory->alignment, memory->alignment); debugPrint("\tpageSize -> %ld = 0x%lX\n", memory->pageSize, memory->pageSize); debugPrint("\talignedSize -> %"PRIu64" = 0x%"PRIx64"\n", memory->alignedSize, memory->alignedSize); debugPrint("}\n"); }
void runGameplay(GameVars* gameVars) { //GAME //Draw the court drawCourt(); //Draw the scores drawScores(gameVars); //Game play states switch (gameVars->gameState) { case GSGameStart: { #ifdef DEBUG debugPrint("START\x80"); #endif //Draw Ready message drawReady(0x80); //Wait for a number of frames waitForFramesThenMoveOnToNextState(60, gameVars); } break; case GSWaitForServe: { #ifdef DEBUG debugPrint("SERVE\x80"); #endif //Score max? if (gameVars->player1.score >= maxScoreForPlayer || gameVars->player2.score >= maxScoreForPlayer) { //Served - move to next state moveToNextGameState(gameVars, GEWinner); return; } //Draw player paddles movePaddles(gameVars); //Inform who is about to serve drawServe(gameVars->player1ServeNext); //wait for user to start game with button 4 readButton(); //Player 1 Button 4 or P2 Button 4 if ( (gameVars->player1ServeNext && (_BTN_CUR_MASK & _JOY1_B4)) || (!gameVars->player1ServeNext && (_BTN_CUR_MASK & _JOY2_B4)) ) { //Position the ball and make visible serve(gameVars); //Served - move to next state moveToNextGameState(gameVars, GENone); } } break; case GSPlay: { #ifdef DEBUG debugPrint("PLAY\x80"); #endif //GAME PLAY ACTION drawCenterLine(gameVars); //Draw player paddles movePaddles(gameVars); //Only deal with visible balls if(gameVars->ball.visibility == false) return; //Move ball - check for goal moveBallSprite(gameVars); } break; case GSScored: { #ifdef DEBUG debugPrint("SCORED\x80"); #endif //Goal! drawPoint(!gameVars->player1ServeNext); waitForFramesThenMoveOnToNextState(60, gameVars); } break; case GSGameOver: { #ifdef DEBUG debugPrint("GAMEOVER\x80"); #endif //Display 'Game Over' drawGameOver(gameVars->player1.score > gameVars->player2.score); //wait for user to select replay or menu readButton(); //Player 1 Button 1 if (_BTN_CUR_MASK & _JOY1_B1) { //Reset scores resetPlayerScores(gameVars); //Replay - move to next state moveToNextGameState(gameVars, GEPlayAgain); } else if (_BTN_CUR_MASK & _JOY1_B2) { //Reset scores resetPlayerScores(gameVars); //Menu - move to next state moveToNextGameState(gameVars, GEBackToMenu); } } break; default: break; } }
void UltrasonicNode::getDataFromRep(const OCRepresentation& rep) { rep.getValue("ultrasonic", ultrasonic); debugPrint({"ultrasonic: ", to_string(ultrasonic)}); }
bool mjpeg_decoder_t::decode_complete(void const *&y, void const *&u, void const *&v, void *&opaque, unsigned &displayIdx, int &picType, bool &errors ) { displayIdx = 0 ; errors = false ; if( startedDecode_ && !vpu_IsBusy() ){ DecOutputInfo outinfo = {0}; RetCode ret = vpu_DecGetOutputInfo(handle_, &outinfo); debugPrint("vpu_DecGetOutputInfo(%d): %d display, %d decode\n", ret, outinfo.indexFrameDisplay, outinfo.indexFrameDecoded); if (ret == RETCODE_SUCCESS) { startedDecode_ = false ; debugPrint("success %d\n", outinfo.decodingSuccess); debugPrint("indexFrame decoded %d (0x%x)\n", outinfo.indexFrameDecoded, outinfo.indexFrameDecoded); debugPrint("indexFrame display %d (0x%x)\n", outinfo.indexFrameDisplay, outinfo.indexFrameDisplay); debugPrint("picType %d\n", outinfo.picType); picType = outinfo.picType ; if( 0 != outinfo.numOfErrMBs) { debugPrint("%d errMBs\n", outinfo.numOfErrMBs); errors = true ; } debugPrint("qpInfo %p\n", outinfo.qpInfo); debugPrint("hscale %d\n", outinfo.hScaleFlag); debugPrint("vscale %d\n", outinfo.vScaleFlag); debugPrint("index rangemap %d\n", outinfo.indexFrameRangemap); debugPrint("prescan result %d\n", outinfo.prescanresult); debugPrint("picstruct %d\n", outinfo.pictureStructure); debugPrint("topfield first %d\n", outinfo.topFieldFirst); debugPrint("repeat first %d\n", outinfo.repeatFirstField); debugPrint("field seq %d\n", outinfo.fieldSequence); debugPrint("size %dx%d\n", outinfo.decPicWidth, outinfo.decPicHeight); debugPrint("nsps %d\n", outinfo.notSufficientPsBuffer); debugPrint("nsslice %d\n", outinfo.notSufficientSliceBuffer); debugPrint("success %d\n", outinfo.decodingSuccess); debugPrint("interlaced %d\n", outinfo.interlacedFrame); debugPrint("mp4packed %d\n", outinfo.mp4PackedPBframe); debugPrint("h264Npf %d\n", outinfo.h264Npf); debugPrint("prog/repeat %d\n", outinfo.progressiveFrame); debugPrint("crop %d:%d->%d:%d\n", outinfo.decPicCrop.left,outinfo.decPicCrop.top, outinfo.decPicCrop.right, outinfo.decPicCrop.bottom); if( (0 <= outinfo.indexFrameDisplay) && (fbcount > outinfo.indexFrameDisplay) ){ unsigned mask = 1<<outinfo.indexFrameDisplay ; assert(0 != (decoder_fbs&mask)); decoder_fbs &= ~mask ; assert(0 == (app_fbs & mask)); app_fbs |= mask ; frame_buf *pfb = pfbpool+outinfo.indexFrameDisplay ; y = (void *)(pfb->addrY + pfb->desc.virt_uaddr - pfb->desc.phy_addr); u = (char *)y + ySize(); v = (char *)u + uvSize(); displayIdx = outinfo.indexFrameDisplay ; debugPrint("returning display index %u:%p\n", displayIdx,y); return true ; } else { fprintf(stderr, "Invalid display fb index: %d\n", outinfo.indexFrameDisplay); startDecode(); } } else { fprintf( stderr, "Error %d from vpu_DecGetOutputInfo\n", ret ); } } else { debugPrint( "VPU is busy\n" ); vpu_WaitForInt(0); } return false ; }
mjpeg_decoder_t::mjpeg_decoder_t(vpu_t &vpu) : w_(0) , h_(0) , ystride_(0) , uvstride_(0) , imgSize_(0) , handle_(0) , phy_bsbuf_addr(0) , phy_ps_buf(0) , phy_slice_buf(0) , phy_slicebuf_size(0) , virt_bsbuf_addr(0) , bsbuf_end(0) , numRead(0) , fbcount(0) , fb(0) , pfbpool(0) , mvcol_memdesc(0) , startedDecode_(false) , app_fbs(0) , decoder_fbs(0) , state_(ERR) { vpu_mem_desc mem_desc = {0}; mem_desc.size = STREAM_BUF_SIZE; int ret = IOGetPhyMem(&mem_desc); if (ret) { fprintf(stderr,"Unable to obtain physical mem\n"); return; } if (IOGetVirtMem(&mem_desc) <= 0) { fprintf(stderr,"Unable to obtain virtual mem\n"); IOFreePhyMem(&mem_desc); return; } vpu_mem_desc slice_mem_desc = {0}; phy_bsbuf_addr = mem_desc.phy_addr; virt_bsbuf_addr = mem_desc.virt_uaddr; bsbuf_end = virt_bsbuf_addr + mem_desc.size ; DecOpenParam oparam ; memset(&oparam,0,sizeof(oparam)); oparam.bitstreamFormat = STD_MJPG ; oparam.bitstreamBuffer = phy_bsbuf_addr; oparam.bitstreamBufferSize = STREAM_BUF_SIZE; oparam.reorderEnable = 1 ; oparam.mp4DeblkEnable = 0 ; oparam.dynamicAllocEnable = 1 ; oparam.psSaveBuffer = 0 ; oparam.psSaveBufferSize = 0 ; ret = vpu_DecOpen(&handle_, &oparam); if (ret != RETCODE_SUCCESS) { fprintf(stderr,"vpu_DecOpen failed: %d\n", ret); return ; } debugPrint("vpu_DecOpen success\n" ); ret = vpu_DecGiveCommand(handle_,DEC_SET_REPORT_USERDATA, &userData); debugPrint("vpu_DecGiveCommand: %d(DEC_SET_REPORT_USERDATA)/%d\n", DEC_SET_REPORT_USERDATA,ret); if (ret != RETCODE_SUCCESS) { fprintf(stderr, "Failed to set user data report, ret %d\n", ret ); return ; } else printf( "disabled userdata\n" ); /* Parse bitstream and get width/height/framerate etc */ ret = vpu_DecSetEscSeqInit(handle_, 1); if (ret != RETCODE_SUCCESS) { fprintf(stderr, "Failed to set Esc Seq, ret %d\n", ret ); return ; } else debugPrint("vpu_DecSetEscSeqInit(1): %d\n", ret); state_ = INIT ; }
bool mjpeg_decoder_t::fill_buf( void const *data, unsigned length, void *opaque ) { if( length < STREAM_BUF_SIZE ){ memcpy((void *)virt_bsbuf_addr,data,length); numRead = length ; vpu_DecUpdateBitstreamBuffer(handle_,length); debugPrint( "copied %u bytes, state == %d\n", length, state_ ); if( INIT == state_ ) { RetCode ret; DecInitialInfo initinfo = {0}; ret = vpu_DecGetInitialInfo(handle_, &initinfo); debugPrint("vpu_DecGetInitialInfo: %d\n", ret); if (ret != RETCODE_SUCCESS) { fprintf(stderr, "vpu_DecGetInitialInfo failed %d\n", ret); return false ; } else { vpu_DecSetEscSeqInit(handle_, 0); debugPrint("vpu_DecSetEscSeqInit(0): %d\n", ret); if (initinfo.streamInfoObtained) { printf( "have stream info\n" ); printf("Decoder: width = %d, height = %d, fps = %lu, minfbcount = %u\n", initinfo.picWidth, initinfo.picHeight, initinfo.frameRateInfo, initinfo.minFrameBufferCount); assert(0 == fbcount); assert(0 == fb); assert(0 == pfbpool); fbcount = initinfo.minFrameBufferCount + 2 ; fb = (FrameBuffer *)calloc(fbcount, sizeof(fb[0])); if (fb == NULL) { fprintf(stderr,"Failed to allocate fb\n"); return false ; } pfbpool = (frame_buf *)calloc(fbcount, sizeof(pfbpool[0])); if (pfbpool == NULL) { fprintf(stderr, "Failed to allocate pfbpool\n"); return false ; } printf("fb == %p, pfbpool == %p, malloc == %p\n", fb, pfbpool, malloc(0x10000) ); w_ = initinfo.picWidth ; h_ = initinfo.picHeight ; ystride_ = (initinfo.picWidth + 15)&~15; uvstride_ = ((initinfo.picWidth/2)+15)&~15; printf( "strides: %u/%u\n", ystride_, uvstride_ ); unsigned paddedHeight = (h_+15)&~15 ; // Why??? unsigned ySize = ystride_ * paddedHeight ; unsigned uvSize = uvstride_ * (paddedHeight/2); imgSize_ = paddedHeight*(ystride_+uvstride_); printf( "imgSize == %u, ySize %u, uvSize %u\n", imgSize_, ySize, uvSize ); imgSize_ += (ystride_*paddedHeight) / 4 ; // Why? printf( "padded == %u\n", imgSize_ ); for (unsigned i = 0; i < fbcount ; i++) { decoder_fbs |= (1 <<i); struct frame_buf *f = pfbpool + i ; debugPrint( "pfbpool[%u] == %p\n", i, f); f->desc.size = imgSize_ ; int err = IOGetPhyMem(&f->desc); if (err) { printf("Frame buffer allocation failure: %d\n", err); return false ; } debugPrint( "allocated frame buffer %u == 0x%x\n", i, f->desc.phy_addr ); f->addrY = f->desc.phy_addr; f->addrCb = f->addrY + ySize ; f->addrCr = f->addrCb + uvSize ; f->mvColBuf = f->addrCr + uvSize ; f->desc.virt_uaddr = IOGetVirtMem(&(f->desc)); debugPrint( "virt == %p\n", f->desc.virt_uaddr ); if (f->desc.virt_uaddr <= 0) { fprintf(stderr, "Error mapping frame buffer memory\n" ); return false ; } fb[i].bufY = f->addrY; fb[i].bufCb = f->addrCb; fb[i].bufCr = f->addrCr; fb[i].bufMvCol = f->mvColBuf ; } debugPrint( "allocated frame buffers\n" ); for( unsigned i = 0 ; i < fbcount ; i++ ) { debugPrint("fb[%d].bufY = 0x%lx\n", i, fb[i].bufY ); debugPrint("fb[%d].bufCb = 0x%lx\n", i, fb[i].bufCb ); debugPrint("fb[%d].bufCr = 0x%lx\n", i, fb[i].bufCr ); debugPrint("fb[%d].bufMvCol = 0x%lx\n", i, fb[i].bufMvCol ); } DecBufInfo bufinfo = {0}; ret = vpu_DecRegisterFrameBuffer(handle_, fb, fbcount, ystride_, &bufinfo); debugPrint("vpu_DecRegisterFrameBuffer: %d, %u fbs, stride %u\n", ret, fbcount,ystride_); if (ret != RETCODE_SUCCESS) { fprintf(stderr,"Register frame buffer failed\n"); return false ; } debugPrint( "registered frame buffers\n"); int rot_angle = 0 ; ret = vpu_DecGiveCommand(handle_, SET_ROTATION_ANGLE, &rot_angle); debugPrint("vpu_DecGiveCommand: %d(SET_ROTATION_ANGLE)/%d, angle %d\n", SET_ROTATION_ANGLE,ret, rot_angle); if (ret != RETCODE_SUCCESS) fprintf(stderr,"rot_angle %d\n", ret); int mirror = 0 ; ret = vpu_DecGiveCommand(handle_, SET_MIRROR_DIRECTION,&mirror); debugPrint("vpu_DecGiveCommand: %d(SET_MIRROR_DIRECTION)/%d, mirror %d\n", SET_MIRROR_DIRECTION,ret, mirror); if (ret != RETCODE_SUCCESS) fprintf(stderr,"mirror %d\n", ret); int rot_stride = ystride_ ; ret = vpu_DecGiveCommand(handle_, SET_ROTATOR_STRIDE, &rot_stride); debugPrint("vpu_DecGiveCommand: %d(SET_ROTATOR_STRIDE)/%d, stride %d\n", SET_ROTATOR_STRIDE,ret, rot_stride); if (ret != RETCODE_SUCCESS) fprintf(stderr,"rotstride %d\n", ret); state_ = DECODING ; debugPrint("before decode: image size %u, ySize %u, uvSize %u\n", yuvSize(), this->ySize(), this->uvSize() ); startDecode(); } } } return true ; } else return false ; }
/** * scan * * starts from the given node and iterates through all * child directories and builds vectors of all file * and directory nodes in the FS * * @param pnode pointer to DirInfo node to scan */ bool FileSystem::scan(DirInfo* pnode) { debugPrint("Scanning Node: " + pnode->getPath()); // Check if given path exists if ( !boost::filesystem::exists( pnode->getPath() ) ) { cout << pnode->getPath() << " doesn't exist" << endl; return false; } if (pnode->isHidden()) { return false; } // Create a boost directory iterator boost::filesystem::directory_iterator end_itr; try { for ( boost::filesystem::directory_iterator itr( pnode->getPath() ); itr != end_itr; ++itr ) { // Is iterated object a directory if ( is_directory(itr->status()) ) { DirInfo* dir = new DirInfo(itr->path().filename().string(), pnode); // Keeps track of node to deconstruct pointer allNodes.push_back(dir); // All directories list (for quick dir operations) allDirs.push_back(dir); // Add this node to it's parent children list pnode->addChild(dir); // Create a boost path object to extract fs info boost::filesystem::path p(dir->getPath()); dir->setModifyTime( last_write_time(p) ); dir->isDir(true); // Recursively scan dirs scan(dir); // directory size is only available after all dir and files add their // sizes to their parent dirs to be added here pnode->addSize(dir->getSize()); // If iterated object is not directory, then it must be a file } else { FileInfo* file = new FileInfo(itr->path().filename().string(), pnode); // Keeps track of node to deconstruct pointer allNodes.push_back(file); // All files list (for quick file operations) allFiles.push_back(file); // Add this node to it's parent children list pnode->addChild(file); // Create a boost path object to extract fs info boost::filesystem::path p(file->getPath()); try { file->setSize( file_size(p) ); } catch (boost::filesystem::filesystem_error err) { file->setSize( 0 ); } try { file->setModifyTime( last_write_time(p) ); } catch (boost::filesystem::filesystem_error err) { file->setModifyTime( 0 ); } // Update parent size file->getParent()->addSize(file->getSize()); } } } catch (boost::filesystem::filesystem_error) { cout << "Cannot open file: " << pnode->getPath() << ". Permission denied!" << endl; } return true; }
std::ostream &operator<<(std::ostream &os, const KeyPress &kp) { debugPrint(os, kp); return os; }
// Print debug info // Returns true if out of sync bool printRadioStats(writeSoraCtx *ctx, readSoraCtx *rctx) { HRESULT hres; static ULONG debug_ups_count=0, last_debug_ups_count=0; static ULONG d_cnt_Radio_TX_FIFO_rden=0, last_d_cnt_Radio_TX_FIFO_rden = 0; static ULONG d_cnt_Radio_TX_FIFO_pempty=0, last_d_cnt_Radio_TX_FIFO_pempty = 0; static ULONG d_cnt_Sora_FRL_2nd_RX_data=0, last_d_cnt_Sora_FRL_2nd_RX_data = 0; static ULONG d_cnt_RX_FIFO_2nd_data_out=0, last_d_cnt_RX_FIFO_2nd_data_out=0; static ULONG cnt_upsample_out=0, cnt_ups_ddr2_rden=0, cnt_Radio_TX_FIFO_full=0, cnt_TX_DDR_fifo_full=0; static ULONG last_cnt_upsample_out = 0, last_cnt_ups_ddr2_rden = 0, last_cnt_Radio_TX_FIFO_full = 0, last_cnt_TX_DDR_fifo_full = 0; static ULONG Total_idle_cnt = 0, last_Total_idle_cnt = 0; static ULONG last_idle_duration=0, last_pc_idle_duration=0, last_pc_idle_w_inactive=0; static ULONG cmd_fifo_cnt=0, dbg_sync_cnt=0, deb_FRL_data_count=0, deb_FRL_TS_count=0; static ULONG cnt_cmd_fifo_empty=0, last_cnt_cmd_fifo_empty=0; static ULONG dbg_sync_underflow = 0, last_dbg_sync_underflow = 0; static ULONG dbg_sync_overflow = 0, last_dbg_sync_overflow = 0; ULONG TXOutAddr, TXOutSize, deb_reg; ULONG RXOverflow1, RXOverflow2; bool isOutOfSync; bool warning = false; static int toggle = 0; hres = ReadRegister(0x0510, &Total_idle_cnt); hres = ReadRegister(0x0514, &last_idle_duration); hres = ReadRegister(0x0518, &last_pc_idle_duration); hres = ReadRegister(0x051c, &last_pc_idle_w_inactive); // *** ControlQueue hres = ReadRegister(0x0520, &cmd_fifo_cnt); // *** RX_data_fifo_SORA_FRL_2nd_inst/RX_TS_fifo_2nd_inst // Data and TS count in RX_data_fifo_SORA_FRL_2nd_inst/RX_TS_fifo_2nd_inst hres = ReadRegister(0x0530, &deb_FRL_data_count); hres = ReadRegister(0x0534, &deb_FRL_TS_count); hres = ReadRegister(0x0528, &d_cnt_Sora_FRL_2nd_RX_data); // Test difference in input sequence (special debugging) hres = ReadRegister(0x052c, &d_cnt_RX_FIFO_2nd_data_out); // Test difference in input sequence (special debugging) hres = ReadRegister(0x0080, &RXOverflow1); // Counts [RX_FIFO_full, RX_TS_FIFO_full] hres = ReadRegister(0x0084, &RXOverflow2); // Counts [RX_FIFO_2nd_full, RX_TS_FIFO_2nd_full] // *** rxtx_queue_inst // Counts overflows/underflows for rxtx_queue_inst hres = ReadRegister(0x0538, &dbg_sync_underflow); hres = ReadRegister(0x053c, &dbg_sync_overflow); hres = ReadRegister(0x0524, &dbg_sync_cnt); // Data count // *** Upsampler hres = ReadRegister(0x0540, &cnt_upsample_out); hres = ReadRegister(0x0544, &cnt_ups_ddr2_rden); hres = ReadRegister(0x0558, &debug_ups_count); // *** dma_ddr2 // ToFRL_data_fifo_inst full counter hres = ReadRegister(0x0548, &cnt_Radio_TX_FIFO_full); hres = ReadRegister(0x054c, &cnt_TX_DDR_fifo_full); // *** Sora_FRL_RCB_inst hres = ReadRegister(0x055c, &d_cnt_Radio_TX_FIFO_rden); // counts Radio_TX_FIFO_rden (from Sora_FRL_RCB_inst) hres = ReadRegister(0x0560, &d_cnt_Radio_TX_FIFO_pempty); // counts Radio_TX_FIFO_rden (from dma_ddr2_if) // *** register_table hres = ReadRegister(0x0564, &cnt_cmd_fifo_empty); // Queue sync counter hres = ReadRegister(0x0568, &TXOutAddr); hres = ReadRegister(0x056c, &TXOutSize); hres = ReadRegister(0x0570, &deb_reg); // These should all be zeros in normal conditions if (Total_idle_cnt - last_Total_idle_cnt > 0 || rctx->rxBlocked) { warning = true; } if ((LONG)dbg_sync_underflow - (LONG)last_dbg_sync_underflow > 0) { warning = true; } if ((LONG)cnt_ups_ddr2_rden - (LONG)last_cnt_ups_ddr2_rden == 0) { warning = true; } if (outOfSyncs != 0) { isOutOfSync = true; warning = true; } else { isOutOfSync = false; } printf("\n"); if (debugPrint(DEBUG_PRINT_RADIO)) { /* printf("Total_idle_cnt: %u, last_idle_duration: %u, last_pc_idle_duration: %u, last_pc_idle_w_inactive: %u\n", Total_idle_cnt - last_Total_idle_cnt, last_idle_duration, last_pc_idle_duration, last_pc_idle_w_inactive); printf(" queues: %u, %u, %u, %u\n", cmd_fifo_cnt, dbg_sync_cnt, deb_FRL_data_count, deb_FRL_TS_count); printf(" prepareBlocked: %llu, transferBlocked: %llu, txBlocked: %llu, rxBlocked: %llu\n", ctx->prepareBlocked, ctx->transferBlocked, ctx->txBlocked, rctx->rxBlocked); printf("debugGlobalCnt = %ld, debugGlobalCnt2=%ld\n", debugGlobalCnt, debugGlobalCnt2); printf("cnt_upsample_out = %ld, cnt_ups_ddr2_rden = %ld, cnt_Radio_TX_FIFO_full = %ld, cnt_TX_DDR_fifo_full = %ld\n", cnt_upsample_out - last_cnt_upsample_out, cnt_ups_ddr2_rden - last_cnt_ups_ddr2_rden, cnt_Radio_TX_FIFO_full - last_cnt_Radio_TX_FIFO_full, cnt_TX_DDR_fifo_full - last_cnt_TX_DDR_fifo_full); printf("%ld %ld\n", (LONG)d_cnt_Sora_FRL_2nd_RX_data - (LONG)last_d_cnt_Sora_FRL_2nd_RX_data, (LONG)d_cnt_RX_FIFO_2nd_data_out - (LONG)last_d_cnt_RX_FIFO_2nd_data_out); */ // These should all be zeros in normal conditions if (Total_idle_cnt - last_Total_idle_cnt > 0 || rctx->rxBlocked) { printf(" ******** "); } printf("Total_idle_cnt: %u, prepareBlockedPC: %llu, transferBlockedPC: %llu, transferBlockedFPGA: %llu, rxBlocked: %llu/%llu\n", Total_idle_cnt - last_Total_idle_cnt, ctx->prepareBlocked, ctx->transferBlocked, ctx->transferBlockedFPGA, rctx->rxBlocked, rctx->rxBlocked + rctx->rxSucc); printf(" prepareBuf: %d, transferBuf: %d\n", ctx->prepareBuf, ctx->transferBuf); printf(" queues: %u, %u, %u, %u, %u\n", cmd_fifo_cnt, dbg_sync_cnt, deb_FRL_data_count, deb_FRL_TS_count, debug_ups_count); // These (debugGlobalCnt and debugGlobalCnt2) should be zeros when sending a sawf unction (0-999, 0-999, ...) printf(" cnt_Sora_FRL_2nd_RX_data=%ld, cnt_RX_FIFO_2nd_data_out=%ld\n", (LONG)d_cnt_Sora_FRL_2nd_RX_data - (LONG)last_d_cnt_Sora_FRL_2nd_RX_data, (LONG)d_cnt_RX_FIFO_2nd_data_out - (LONG)last_d_cnt_RX_FIFO_2nd_data_out); // These should all be zeros in normal conditions if ((LONG)dbg_sync_underflow - (LONG)last_dbg_sync_underflow > 0) { printf(" ******** "); warning = true; } printf(" cnt_cmd_fifo_empty = %ld, dbg_sync_underflow = %ld, dbg_sync_overflow = %ld\n", (LONG)cnt_cmd_fifo_empty - (LONG)last_cnt_cmd_fifo_empty, (LONG)dbg_sync_underflow - (LONG)last_dbg_sync_underflow, (LONG)dbg_sync_overflow - (LONG)last_dbg_sync_overflow); printf(" deb_reg = %lu\n", deb_reg); /* // DEBUG printf(" cnt_cmd_fifo_empty = %ld, TXOutAddr = %lu, TXOutSize = %lu\n", (LONG)cnt_cmd_fifo_empty - (LONG)last_cnt_cmd_fifo_empty, TXOutAddr, TXOutSize); printf("allocBuf(%d): ", naB); for (int ii = 0; ii < naB; ii++) printf("%lu ", allocBuf[ii]); printf("\nusedBuf(%d): ", nuB); for (int ii = 0; ii < nuB; ii++) printf("%lu (%lu) ", usedBuf[ii], usedBufSiz[ii]); printf("\n"); printf("\nDallocBuf(%d): ", da); for (int ii = 0; ii < da; ii++) printf("%lu ", DallocBuf[ii]); printf("\nDusedBuf(%d): ", du); for (int ii = 0; ii < du; ii++) printf("%lu ", DusedBuf[ii]); printf("\nDusedInd(%d): ", du); for (int ii = 0; ii < du; ii++) printf("%lu ", DusedInd[ii]); */ // These should all be zeros in normal conditions if ((LONG)cnt_ups_ddr2_rden - (LONG)last_cnt_ups_ddr2_rden == 0) { printf(" ******** "); warning = true; } printf(" cnt_ups_ddr2_rden = %ld, cnt_upsample_out = %ld, cnt_Radio_TX_FIFO_full = %ld, cnt_TX_DDR_fifo_full = %ld\n", (LONG)cnt_ups_ddr2_rden - (LONG)last_cnt_ups_ddr2_rden, (LONG)cnt_upsample_out - (LONG)last_cnt_upsample_out, (LONG)cnt_Radio_TX_FIFO_full - (LONG)last_cnt_Radio_TX_FIFO_full, (LONG)cnt_TX_DDR_fifo_full - (LONG)last_cnt_TX_DDR_fifo_full); printf(" cnt_Radio_TX_FIFO_rden = %ld, cnt_Radio_TX_FIFO_pempty = %ld\n", (LONG)d_cnt_Radio_TX_FIFO_rden - (LONG)last_d_cnt_Radio_TX_FIFO_rden, (LONG)d_cnt_Radio_TX_FIFO_pempty - (LONG)last_d_cnt_Radio_TX_FIFO_pempty); // These should all be zeros in normal conditions if (outOfSyncs != 0) { isOutOfSync = true; warning = true; printf(" ******** "); } else { isOutOfSync = false; } printf(" outOfSyncs = %lu\n", outOfSyncs); // DEBUG printf("RX DEBUG: %u %u\n", RXOverflow1, RXOverflow2); // Print queue size samples for debugging printf("samp_PC_queue: "); for (int i = 0; i < no_tx_bufs + 1; i++) { printf("%d ", samp_PC_queue[i]); samp_PC_queue[i] = 0; } printf("\nsamp_FPGA_queue: "); for (int i = 0; i < cmd_fifo_queue_size + 1; i++) { printf("%d ", samp_FPGA_queue[i]); samp_FPGA_queue[i] = 0; } printf("\nsamp_FPGA_queue_underflow: "); for (int i = 0; i < cnt_samp_FPGA_underflow; i++) { printf("%llu ", samp_FPGA_underflow[i]); } cnt_samp_FPGA_underflow = 0; #ifdef READ_IN_WORKER_THREAD printf("\nsamp_RX_queue: free=%llu, full=%llu\n", samp_RX_queue_free, samp_RX_queue_full); samp_RX_queue_full = 0; samp_RX_queue_free = 0; #endif printf("\n"); } /* if (isOutOfSync) printf("!!! OUT OF SYNC !!!\n"); if (warning) printf("*** "); printf("%c rxSCH=%ld, rxIP=%ld, rxCCH=%ld, rxRACH=%ld, txSCH=%ld, txIP=%ld, txCCH=%ld, errIP=%ld, errFrag=%ld, errRLC=%ld, errRRC=%ld\n", (toggle == 0) ? '.' : '*', rxSCH, rxIP, rxCCH, rxRACH, txSCH, txIP, txCCH, errIP, errFrag, errRLC, errRRC); */ if (isOutOfSync) printf("!!! OUT OF SYNC !!!\n"); if (warning) printf("*** "); printf("%c rxSCH, rxIP, rxCCH, rxRACH, txSCH, txIP, txCCH, errIP, errFrg, errRLC, errRRC, errQue, rrcRCN, rrcATT\n", (toggle == 0) ? '.' : '*'); prtStat(rxSCH); prtStat(rxIP); prtStat(rxCCH); prtStat(rxRACH); prtStat(txSCH); prtStat(txIP); prtStat(txCCH); prtStat(errIP); prtStat(errFrag); prtStat(errRLC); prtStat(errRRC); prtStat(errQue); prtStat(RRCRecComp); prtStat(RRCAttComp); printf("\n"); printf("MCS stats: "); for (int i = 0; i < MAC_NO_MCS; i++) { if (txMCS[i] > 0) printf("%2d(%3ld) ", i, txMCS[i]); } printf("\n"); printf("NBR stats: "); for (int i = 0; i < MAC_NO_NBR; i++) { if (txNBR[i] > 0) printf("%2d(%3ld) ", i, txNBR[i]); } printf("\n"); last_Total_idle_cnt = Total_idle_cnt; last_cnt_upsample_out = cnt_upsample_out; last_cnt_ups_ddr2_rden = cnt_ups_ddr2_rden; last_cnt_Radio_TX_FIFO_full = cnt_Radio_TX_FIFO_full; last_cnt_TX_DDR_fifo_full = cnt_TX_DDR_fifo_full; last_d_cnt_Sora_FRL_2nd_RX_data = d_cnt_Sora_FRL_2nd_RX_data; last_d_cnt_RX_FIFO_2nd_data_out = d_cnt_RX_FIFO_2nd_data_out; last_debug_ups_count = debug_ups_count; last_d_cnt_Radio_TX_FIFO_rden = d_cnt_Radio_TX_FIFO_rden; last_d_cnt_Radio_TX_FIFO_pempty = d_cnt_Radio_TX_FIFO_pempty; last_cnt_cmd_fifo_empty = cnt_cmd_fifo_empty; last_dbg_sync_underflow = dbg_sync_underflow; last_dbg_sync_overflow = dbg_sync_overflow; outOfSyncs = 0; ctx->prepareBlocked = 0; ctx->transferBlocked = 0; ctx->transferBlockedFPGA = 0; rctx->rxBlocked = 0; rxSCH = 0; rxCCH = 0; rxRACH = 0; rxIP = 0; txSCH = 0; txIP = 0; txCCH = 0; errIP = 0, errFrag = 0, errRLC = 0, errRRC = 0, errQue = 0; RRCRecComp = 0, RRCAttComp = 0; memset(txMCS, 0, sizeof(int32)*MAC_NO_MCS); memset(txNBR, 0, sizeof(int32)*MAC_NO_NBR); toggle = toggle ^ 1; fflush(stdout); return (isOutOfSync); }
std::ostream &operator<<(std::ostream &os, const Range &range) { debugPrint(os, range); return os; }
void dmtcp::ConnectionRewirer::onData ( jalib::JReaderInterface* sock ) { JASSERT ( sock->bytesRead() == sizeof ( DmtcpMessage ) ) ( sock->bytesRead() ) ( sizeof ( DmtcpMessage ) ); DmtcpMessage& msg = * ( DmtcpMessage* ) sock->buffer(); msg.assertValid(); if ( msg.type == DMT_FORCE_RESTART ) { JTRACE ( "got DMT_FORCE_RESTART, exiting ConnectionRewirer" ) ( _pendingOutgoing.size() ) ( _pendingIncoming.size() ); _pendingIncoming.clear(); _pendingOutgoing.clear(); finishup(); return; } JASSERT ( msg.type==DMT_RESTORE_WAITING ) ( msg.type ).Text ( "unexpected message" ); // Find returns iterator 'i' w/ 0 or more elts, with first elt matching key. iterator i = _pendingOutgoing.find ( msg.restorePid ); if ( i == _pendingOutgoing.end() ) { // 'i' is an iterator over 0 elements. JTRACE ( "got RESTORE_WAITING MESSAGE [not used]" ) ( msg.restorePid ) ( _pendingOutgoing.size() ) ( _pendingIncoming.size() ); } else { // 'i' is an iterator over 1 element. JTRACE ( "got RESTORE_WAITING MESSAGE, reconnecting..." ) ( msg.restorePid ) ( msg.restorePort ) ( msg.restoreAddrlen ) ( _pendingOutgoing.size() ) ( _pendingIncoming.size() ); const dmtcp::vector<int>& fds = i->second; JASSERT ( fds.size() > 0 ); int fd0 = fds[0]; jalib::JSocket remote = jalib::JSocket::Create(); remote.changeFd ( fd0 ); errno = 0; JASSERT ( remote.connect ( ( sockaddr* ) &msg.restoreAddr,msg.restoreAddrlen,msg.restorePort ) ) ( msg.restorePid ) ( msg.restorePort ) ( JASSERT_ERRNO ) .Text ( "failed to restore connection" ); { DmtcpMessage peerMsg; peerMsg.type = DMT_RESTORE_RECONNECTED; peerMsg.restorePid = msg.restorePid; addWrite ( new jalib::JChunkWriter ( remote, ( char* ) &peerMsg,sizeof ( peerMsg ) ) ); } for ( size_t n = 1; n<fds.size(); ++n ) { JTRACE ( "restoring extra fd" ) ( fd0 ) ( fds[n] ); JASSERT ( _real_dup2 ( fd0,fds[n] ) == fds[n] ) ( fd0 ) ( fds[n] ) ( msg.restorePid ) .Text ( "dup2() failed" ); } _pendingOutgoing.erase ( i ); } if ( pendingCount() ==0 ) finishup(); #ifdef DEBUG else debugPrint(); #endif }
std::ostream &operator<<(std::ostream &os, const RangeComponent &c) { debugPrint(os, c); return os; }
void RepRapSerial::DisConnect(const char* reason) { debugPrint(reason); DisConnect(); }
static void rebuildSelector(struct htmlTag *sel, jsobjtype oa, int len2) { int i1, i2, len1; bool check2; char *s; const char *selname; bool changed = false; struct htmlTag *t; jsobjtype oo; /* option object */ len1 = cw->numTags; i1 = i2 = 0; selname = sel->name; if (!selname) selname = "?"; debugPrint(4, "testing selector %s %d %d", selname, len1, len2); sel->lic = (sel->multiple ? 0 : -1); while (i1 < len1 && i2 < len2) { /* there is more to both lists */ t = tagList[i1++]; if (t->action != TAGACT_OPTION) continue; if (t->controller != sel) continue; /* find the corresponding option object */ if ((oo = get_array_element_object(oa, i2)) == NULL) { /* Wow this shouldn't happen. */ /* Guess I'll just pretend the array stops here. */ len2 = i2; --i1; break; } t->jv = oo; /* should already equal oo */ t->rchecked = get_property_bool(oo, "defaultSelected"); check2 = get_property_bool(oo, "selected"); if (check2) { if (sel->multiple) ++sel->lic; else sel->lic = i2; } ++i2; if (t->checked != check2) changed = true; t->checked = check2; s = get_property_string(oo, "text"); if (s && !t->textval || !stringEqual(t->textval, s)) { nzFree(t->textval); t->textval = s; changed = true; } else nzFree(s); s = get_property_string(oo, "value"); if (s && !t->value || !stringEqual(t->value, s)) { nzFree(t->value); t->value = s; } else nzFree(s); } /* one list or the other or both has run to the end */ if (i2 == len2) { for (; i1 < len1; ++i1) { t = tagList[i1]; if (t->action != TAGACT_OPTION) continue; if (t->controller != sel) continue; /* option is gone in js, disconnect this option tag from its select */ t->jv = 0; t->controller = 0; t->action = TAGACT_NOP; changed = true; } } else if (i1 == len1) { for (; i2 < len2; ++i2) { if ((oo = get_array_element_object(oa, i2)) == NULL) break; t = newTag("option"); t->lic = i2; t->controller = sel; t->jv = oo; t->step = 2; // already decorated t->textval = get_property_string(oo, "text"); t->value = get_property_string(oo, "value"); t->checked = get_property_bool(oo, "selected"); if (t->checked) { if (sel->multiple) ++sel->lic; else sel->lic = i2; } t->rchecked = get_property_bool(oo, "defaultSelected"); changed = true; } } if (!changed) return; debugPrint(4, "selector %s has changed", selname); /* If js change the menu, it should have also changed select.value * according to the checked options, but did it? * Don't know, so I'm going to do it here. */ s = displayOptions(sel); if (!s) s = emptyString; set_property_string(sel->jv, "value", s); javaSetsTagVar(sel->jv, s); nzFree(s); if (!sel->multiple) set_property_number(sel->jv, "selectedIndex", sel->lic); } /* rebuildSelector */
void UARTIntHandler(uint8_t uartId) { char toSend = 0; # ifdef _DEBUG_ switch(uartId) { case UART_ID_5: debugPrint("U5: "); break; case UART_ID_2: debugPrint("U2: "); break; default: debugPrint("U?: "); break; } if(uarts[uartId]->MaskedIntStatus & UART_MIS_CTSMIS) debugPrint("Clear to Send Modem:"); if(uarts[uartId]->MaskedIntStatus & UART_MIS_RXMIS) debugPrint("Receive:"); if(uarts[uartId]->MaskedIntStatus & UART_MIS_TXMIS) debugPrint("Transmit:"); if(uarts[uartId]->MaskedIntStatus & UART_MIS_RTMIS) debugPrint("Receive Time-Out:"); if(uarts[uartId]->MaskedIntStatus & UART_MIS_FEMIS) debugPrint("Framing Error:"); if(uarts[uartId]->MaskedIntStatus & UART_MIS_PEMIS) debugPrint("Parity Error:"); if(uarts[uartId]->MaskedIntStatus & UART_MIS_BEMIS) debugPrint("Break Error:"); if(uarts[uartId]->MaskedIntStatus & UART_MIS_OEMIS) debugPrint("Overrun Error:"); if(uarts[uartId]->MaskedIntStatus & UART_MIS_9BITMIS) debugPrint("9-Bit Mode:"); if(uarts[uartId]->MaskedIntStatus & UART_MIS_LMSBMIS) debugPrint("LIN Mode Sync Break:"); if(uarts[uartId]->MaskedIntStatus & UART_MIS_LMSBMIS) debugPrint("LIN Mode Edge 1:"); if(uarts[uartId]->MaskedIntStatus & UART_MIS_LME5MIS) debugPrint("LIN Mode Edge 5:"); if(uarts[uartId]->RxStatus & UART_RSR_FE) debugPrint("Framing Error:"); if(uarts[uartId]->RxStatus & UART_RSR_PE) debugPrint("Parity Error:"); if(uarts[uartId]->RxStatus & UART_RSR_BE) debugPrint("Break Error:"); if(uarts[uartId]->RxStatus & UART_RSR_OE) debugPrint("Overrun Error:"); debugPrint("\n\r"); # endif StartCritical(); //add characters until receive queue is empty while(!(uarts[uartId]->Flag & UART_FR_RXFE)) { cBufAddChar(&rxBuffer[uartId], uarts[uartId]->Data); } if(uarts[uartId]->RxStatus & UART_RSR_OE) print("Overrun Error\n\r"); //check if uP has characters if (cBufGetChar(&txBuffer[uartId], &toSend) > 0) { //nothing to send - disable tx interrupts uarts[uartId]->IntMask &= ~UART_IM_TXIM; } else { //send characters until tx fifo is full or //tx buffer is empty do { uarts[uartId]->Data = toSend; } while(!(uarts[uartId]->Flag & UART_FR_TXFF) && cBufGetChar(&txBuffer[uartId], &toSend) == 0); } EndCritical(); }
/* Read the entire message from js, then take action. * Thus messages will remain in sync. */ static int readMessage(void) { int l; char *msg; /* error message from js */ if (readFromJS(&head, sizeof(head)) < 0) return -1; /* read failed */ if (head.magic != EJ_MAGIC) { /* this should never happen */ js_kill(); i_puts(MSG_JSEngineSync); markAllDead(); return -1; } if (head.highstat >= EJ_HIGH_HEAP_FAIL) { js_kill(); /* perhaps a helpful message, before we close down js sessions */ if (head.highstat == EJ_HIGH_PROC_FAIL) allowJS = false; if (head.lowstat == EJ_LOW_EXEC) i_puts(MSG_JSEngineExec); if (head.lowstat == EJ_LOW_MEMORY) i_puts(MSG_JavaMemError); if (head.lowstat == EJ_LOW_RUNTIME) i_puts(MSG_JSEngineRun); if (head.lowstat == EJ_LOW_SYNC) i_puts(MSG_JSEngineSync); markAllDead(); return -1; } if (head.side) { effects = allocMem(head.side + 1); if (readFromJS(effects, head.side) < 0) { free(effects); effects = 0; return -1; } effects[head.side] = 0; // because debugPrint always puts on a newline effects[head.side - 1] = 0; debugPrint(4, "< side effects\n%s", effects); processEffects(); } /* next grab the error message, if there is one */ l = head.msglen; if (l) { msg = allocMem(l + 1); if (readFromJS(msg, l)) { free(msg); return -1; } msg[l] = 0; if (debugLevel >= 3) { /* print message, this will be in English, and mostly for our debugging */ if (jsSourceFile) { if (debugFile) fprintf(debugFile, "%s line %d: ", jsSourceFile, head.lineno); else printf("%s line %d: ", jsSourceFile, head.lineno); } debugPrint(3, "%s", msg); } free(msg); } /* Read in the requested property, if there is one. * The calling function must handle the property. */ l = head.proplength; proptype = head.proptype; if (l) { propval = allocMem(l + 1); if (readFromJS(propval, l)) { free(propval); propval = 0; return -1; } propval[l] = 0; } /* stop at the first js error when debugging */ if (head.msglen && debugLevel >= 5) { head.highstat = EJ_HIGH_CX_FAIL; head.lowstat = 0; debugPrint(5, "js abort due to error while debugging"); } if (head.highstat == EJ_HIGH_CX_FAIL) { if (head.lowstat == EJ_LOW_VARS) i_puts(MSG_JSEngineVars); if (head.lowstat == EJ_LOW_CX) i_puts(MSG_JavaContextError); if (head.lowstat == EJ_LOW_WIN) i_puts(MSG_JavaWindowError); if (head.lowstat == EJ_LOW_DOC) i_puts(MSG_JavaObjError); if (head.lowstat == EJ_LOW_CLOSE) i_puts(MSG_PageDone); else i_puts(MSG_JSSessionFail); freeJavaContext(cw); /* should I free and zero the property at this point? */ } return 0; } /* readMessage */
/* Let's jump right into it - parse a cookie, as received from a website. */ bool receiveCookie(const char *url, const char *str) { struct cookie *c; const char *p, *q, *server; char *date, *s; debugPrint(3, "cookie %s", str); server = getHostURL(url); if (server == 0 || !*server) return false; /* Cookie starts with name=value. If we can't get that, go home. */ for (p = str; *p != ';' && *p; p++) ; for (q = str; *q != '='; q++) if (!*q || q >= p) return false; if (str == q) return false; c = allocZeroMem(sizeof(struct cookie)); c->tail = false; c->name = pullString1(str, q); ++q; if (p - q > 0) c->value = pullString1(q, p); else c->value = emptyString; c->server = cloneString(server); if (date = extractHeaderParam(str, "expires")) { c->expires = parseHeaderDate(date); nzFree(date); } else if (date = extractHeaderParam(str, "max-age")) { int n = stringIsNum(date); if (n >= 0) { time_t now = time(0); c->expires = now + n; } nzFree(date); } c->path = extractHeaderParam(str, "path"); if (!c->path) { /* The url indicates the path for this cookie, if a path is not explicitly given */ const char *dir, *dirend; getDirURL(url, &dir, &dirend); c->path = pullString1(dir, dirend); } else { if (!c->path[0] || c->path[strlen(c->path) - 1] != '/') c->path = appendString(c->path, "/"); if (c->path[0] != '/') c->path = prependString(c->path, "/"); } if (!(c->domain = extractHeaderParam(str, "domain"))) { c->domain = cloneString(server); } else { /* Is this safe for tail-matching? */ const char *domtemp = c->domain; if (domtemp[0] == '.') domtemp++; if (!domainSecurityCheck(server, domtemp)) { nzFree(c->domain); c->domain = cloneString(server); } else { /* It's safe to do tail-matching with this domain. */ c->tail = true; /* Guarantee that it does in fact start with dot, prepending if necessary.. */ if (c->domain[0] != '.') c->domain = prependString(c->domain, "."); } } if (s = extractHeaderParam(str, "secure")) { c->secure = true; nzFree(s); } cookieForLibcurl(c); freeCookie(c); nzFree(c); return true; } /* receiveCookie */
readVars_t :: readVars_t( void ) : worked_( false ) , image_( 0 ) , bytesUsed_( 0 ) , maxSize_( 0 ) { image_ = 0 ; bytesUsed_ = 0 ; maxSize_ = 0 ; char const *devName = GetFlashDev(); unsigned int bDevice = IsDevice(devName); debugPrint( "opening flash device %s\n", devName ); int fd = open( devName, O_RDONLY ); if ( 0 <= fd ) { unsigned offset ; if (bDevice && ( 0 == flashVarOffset(fd, offset, maxSize_) )){ debugPrint( "flashVar offset 0x%x, max size %u\n", offset, maxSize_ ); } else { maxSize_ = 0x40000; } if (maxSize_) { image_ = (char *)malloc( maxSize_ ); debugPrint( "maxSize 0x%x\n", maxSize_ ); char *nextIn = (char *)image_ ; while( bytesUsed_ < maxSize_ ) { int numRead = read( fd, nextIn, pageSize ); if (numRead>0) { bytesUsed_ += numRead ; nextIn += numRead ; } if( pageSize == (unsigned)numRead ) { if( '\xff' == nextIn[-1] ) break; // end of data } else { if (bDevice) perror( "read" ); break; } } #ifdef TESTREST unsigned bytesRead = bytesUsed_ ; char *nextBlank = nextIn ; while( bytesRead < maxSize_ ) { int numRead = read( fd, nextBlank, pageSize ); if( pageSize == numRead ) { if( ( '\xff' == *nextBlank ) && ( 0 == memcmp( nextBlank, nextBlank+1, pageSize-1 ) ) ) { bytesRead += pageSize ; nextBlank += pageSize ; } else { fprintf( stderr, "non-blank at offset %u\n", bytesRead ); break; } } else { perror( "read2" ); break; } } if( bytesRead == maxSize_ ) printf( "remainder of %u bytes is blank\n", maxSize_ ); else fprintf( stderr, "something isn't blank at position %lu\n", bytesUsed_ ); #endif // // the tail of image_[0..bytesUsed_-1] is blank, walk until non-blank // while( 0 < bytesUsed_ ) { if( '\xff' == nextIn[-1] ) { --nextIn ; --bytesUsed_ ; } else break; } worked_ = true ; } close( fd ); } else perror(devName); }