// ----------------------------------------------------------------------------- // CTCPPortListener::RunL // ----------------------------------------------------------------------------- // void CTCPPortListener::RunL() { if ( iStatus.Int() == KErrNone ) { // Allocate new RSocket first RSocket* next = new ( ELeave ) RSocket; CleanupStack::PushL( next ); User::LeaveIfError( next->Open( iSocketServer ) ); CleanupClosePushL( *next ); // temp will be passed to observer RSocket* temp = iAcceptedSocket; // Takes ownership of temp immediately iObserver->ConnectionAcceptedL( temp ); CleanupStack::Pop(); // *next CleanupStack::Pop( next ); iAcceptedSocket = next; iListeningSocket.Accept( *iAcceptedSocket, iStatus ); SetActive(); DEBUG_PRINT( DEBUG_STRING( "CTCPPortListener::RunL(), connection accepted, port %d" ), iPort ); } }
// ----------------------------------------------------------------------------- // CSocketReader::Start // ----------------------------------------------------------------------------- // void CSocketReader::Start() { DEBUG_PRINT( DEBUG_STRING( "CSocketReader::Start" ) ); if ( !IsActive() ) { IssueRead(); } }
// ----------------------------------------------------------------------------- // CTCPPortListener::IssueListen // ----------------------------------------------------------------------------- // void CTCPPortListener::IssueListen() { __ASSERT_DEBUG( iAcceptedSocket, User::Invariant() ); iListeningSocket.Listen( KMaxConnectionsInQueue ); iListeningSocket.Accept( *iAcceptedSocket, iStatus ); SetActive(); DEBUG_PRINT( DEBUG_STRING( "CTCPPortListener::IssueListen completed, port %d" ), iPort ); }
// ----------------------------------------------------------------------------- // CSocketReader::IssueRead // ----------------------------------------------------------------------------- // void CSocketReader::IssueRead() { DEBUG_PRINT( DEBUG_STRING( "CSocketReader::IssueRead +" ) ); __ASSERT_ALWAYS( !IsActive() || iStatus != KRequestPending, User::Panic( _L ( "s-reader" ), 1 ) ); TProtocolDesc desc; TInt err = iSocket.Info( desc ); DEBUG_PRINT( DEBUG_STRING( "CSocketReader::IssueRead, err = %d" ), err ); DEBUG_PRINT( DEBUG_STRING( "desc.iProtocol = %d, iUDPRemotePort=%d" ), desc.iProtocol, iUDPRemotePort ); if ( desc.iProtocol == KProtocolInetUdp && iUDPRemotePort > -1 ) { // UDP DEBUG_PRINT( DEBUG_STRING( "CSocketReader::IssueRead(), UDP, local port=%d" ), iUDPRemotePort ); iSocket.RecvFrom( iReadBuffer, iUDPRemoteAddr, 0, iStatus ); } else { // TCP DEBUG_PRINT( DEBUG_STRING( "CSocketReader::IssueRead(), TCP, local port=%d" ), iSocket.LocalPort() ); iSocket.RecvOneOrMore( iReadBuffer, 0, iStatus, iReceivedDataLength ); } SetActive(); DEBUG_PRINT( DEBUG_STRING( "CSocketReader::IssueRead() -" ) ); }
/** * This function reads in the image list file and sets * up a subject replicates list. First the file is * probed to determine the maximum line length. Then * the lines are read in and replicate names are parsed. * * @params imageNamesFile Path to a file containing an srt * @params numImages Pointer to integer that will hold the number of names read * @return A two dimensional ImageList. */ ImageList* getImageNames(char* imageNamesFile, int *numImages) { Tokenizer tok; char* token; FILE* ilf; /* Image List File */ ImageList *subject = NULL, *replicate, *header = NULL; int nImages; DEBUG_STRING(2, "Get image Names from file", imageNamesFile); ilf = fopen( imageNamesFile, "r"); DEBUG_CHECK(ilf, "Problem opening image list file"); nImages = 0; tokenizerInit (&tok, tokenizerStreamReader, ilf); while (!tokenizerEndOfFile (&tok)) { token = tokenizerGetWord (&tok); nImages++; if (header == NULL) { subject = header = createILNode(token); } else { subject->next_subject = createILNode(token); subject = subject->next_subject; } replicate = subject; while (!tokenizerEndOfLine(&tok) && !tokenizerEndOfFile(&tok)) { token = tokenizerGetWord (&tok); nImages++; replicate->next_replicate = createILNode(token); replicate = replicate->next_replicate; } } fclose(ilf); if (numImages) *numImages = nImages; return header; }
int main(int argc, const char* argv[]) { //default pcap capture filter string filter("tcp port 80"); //default pcap interface name string iface("en1"); //default pcap capture file name string pcap_file_name(""); for (int cur_arg=1; cur_arg<argc; cur_arg++) { //check for verbose option if (strcmp(argv[cur_arg], "-v")==0) { verbose = true; } else if (strcmp(argv[cur_arg], "-offline")==0) { if (++cur_arg<argc) { DEBUG_STRING("Running in offline mode with file %s\n", argv[cur_arg]); offline = true; iface.assign(argv[cur_arg]); } else { EXIT_USAGE } } } Shephard* Jesus = new Shephard(); saint = Jesus; try { HttpSniffer sniffer(iface, filter, received_packet); sniffer.start(); } catch (exception &e) { cerr << e.what() << endl; return EXIT_FAILURE; } return EXIT_SUCCESS; }
/** ****************************************************************** * @brief Programs a byte array to a specified address. * * @note This function must be used when the device voltage range is from * 2.7V to 3.6V and an External Vpp is present. * * @param Address specifies the address to be programmed. * @param Data specifies the data to be programmed. * @param length the number of bytes to be programmed * * @retval HW_NVM_OK Flash written succesfully * @retval HW_NVM_FLASH_NOT_RDY Flash was no ready for writing at start * @retval HW_NVM_FLASH_ERASE_FAILED Something went wrong while/after erasing flash * @retval HW_NVM_FLASH_WRITE_FAILED Something went wrong while/after writing to flash ******************************************************************* */ hw_nvm_ret_t hw_STM32F0_FLASH_WriteBlock(intptr_t Address, uint8_t *Data, uint32_t length) { hw_nvm_ret_t result = HW_NVM_OK; uint32_t i; DEBUG_LINE("hwFlash :: waiting for flash.."); /* Wait for last operation to be completed */ if( FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT) != FLASH_COMPLETE) { result = HW_NVM_FLASH_NOT_RDY; } DEBUG_LINE("hwFlash :: unlocking flash.."); /* Unlock the FLASH */ FLASH_Unlock(); DEBUG_STRING("hwFlash :: erasing page ["); DEBUG_HEX((uint8_t *)&Address, 4); DEBUG_LINE("]"); /* Erase FLASH and Wait for last operation to be completed */ if( FLASH_ErasePage((uint32_t)Address) != FLASH_COMPLETE ) { result = HW_NVM_FLASH_ERASE_FAILED; } /* Clear all FLASH flags */ FLASH_ClearFlag( FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_BSY ); FLASH->CR |= FLASH_CR_PG; DEBUG_LINE("hwFlash :: writing to flash.."); for(i=0;i<length;i+=2){ //Copy data into flash. if(length-i == 1){ //if last (single) byte is to be copied ((uint16_t *)Address)[i/2] = (uint16_t)Data[i] ; } else { ((uint16_t *)Address)[i/2] = ((uint16_t *)Data)[i/2] ; } /* Wait for last operation to be completed */ if( FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT) != FLASH_COMPLETE) { result = HW_NVM_FLASH_WRITE_FAILED; } } /* if the program operation is completed, disable the PG Bit */ FLASH->CR &= (~FLASH_CR_PG); DEBUG_LINE("hwFlash :: locking flash.."); /* Lock the FLASH */ FLASH_Lock(); /* Return the Program Status */ return result; }
void convertImages(Arguments* args){ char** mask = NULL; TwoPoints source, dest; FILE* eyeList; char line[ FILE_LINE_LENGTH ]; char filename[MAX_FILENAME_LENGTH]; char imagename[MAX_FILENAME_LENGTH]; char suffix[MAX_FILENAME_LENGTH]; int i; scaleArgs(args, args->scale); dest.x1 = args->eyeLx; dest.y1 = args->eyeLy; dest.x2 = args->eyeRx; dest.y2 = args->eyeRy; /* Prepare file suffix encoding preprocessing settings, blank if not requested */ if (args->configSuffix) { sprintf(suffix,"_%s", imageSuffix(args)); } else { suffix[0] = '\0'; } if(args->maskType == CL_YES){ MESSAGE("Creating Mask."); mask = generateMask(args->sizeWidth, args->sizeHeight, args->ellipseX, args->ellipseY, args->ellipseA, args->ellipseB); } eyeList = fopen(args->eyeFile,"r"); DEBUG_CHECK(eyeList,"Error opening eye coordinates file"); for(i = 1;;i++){ Image pgm; Image geo; Matrix transform; fgets(line, FILE_LINE_LENGTH, eyeList); if(feof(eyeList)) break; if(sscanf(line,"%s %lf %lf %lf %lf",filename, &(source.x1), &(source.y1), &(source.x2), &(source.y2)) != 5){ printf("Error parsing line %d of eye coordinate file. Exiting...",i); exit(1); } /* shift the eye coordinates if neccessary */ source.x1 += args->shiftX; source.y1 += args->shiftY; source.x2 += args->shiftX; source.y2 += args->shiftY; sprintf(imagename,"%s\\%s.pgm",args->inputDir,filename); MESSAGE1ARG("Processing image: %s",filename); pgm = readPGMImage(imagename); if(args->histType == HIST_PRE){ DEBUG(1," Performing Pre Histogram Equalization."); histEqual(pgm,256); } if(args->preNormType == CL_YES){ DEBUG(1," Performing Pre Pixel Normalization."); ZeroMeanOneStdDev(pgm); } if(args->preEdge){ smoothImageEdge(pgm, args->preEdge); } if(args->geoType == CL_YES){ DEBUG(1," Performing Geometric Normalization."); transform = generateTransform(&source,&dest,args->reflect); geo = transformImage(pgm,args->sizeWidth,args->sizeHeight,transform); } else{ transform = makeIdentityMatrix(3); geo = transformImage(pgm,args->sizeWidth,args->sizeHeight,transform); } if(args->noise != 0.0){ DEBUG(1," Adding Gausian Noise."); gaussianNoise(geo,args->noise); } if(args->histType == HIST_POST){ DEBUG(1," Performing Post Histogram Equalization."); histEqualMask(geo,256, (const char**) mask); } if(args->nrmType == CL_YES){ DEBUG(1," Performing final value normalization and Applying Mask."); ZeroMeanOneStdDevMasked(geo, (const char **) mask); } else{ DEBUG(1," No Value Normalization. Just Applying Mask."); applyMask(geo, (const char **) mask); } if(args->postEdge){ smoothImageEdge(geo, args->postEdge); } if(args->nrmDir){ sprintf(imagename,"%s\\%s%s.nrm", args->nrmDir, filename, suffix); DEBUG_STRING(1," Saving nrm: %s",imagename); writeFeretImage(geo,imagename); } if(args->pgmDir){ sprintf(imagename,"%s\\%s%s.pgm", args->pgmDir, filename, suffix); DEBUG_STRING(1," Saving pgm: %s",imagename); writePGMImage(geo,imagename,0); } if(args->sfiDir){ sprintf(imagename,"%s\\%s%s.sfi", args->sfiDir, filename, suffix); DEBUG_STRING(1," Saving sfi: %s",imagename); writeRawImage(geo,imagename); } freeImage(geo); freeImage(pgm); freeMatrix(transform); } fclose(eyeList); }
// ----------------------------------------------------------------------------- // CExprUDPMsg::TryParsingL // ----------------------------------------------------------------------------- // TInt CExprUDPMsg::TryParsingL( TDes8& aData, TInt& aLength ) { __ASSERT_ALWAYS( aData.Left( KUDPPrefix().Length() ) == KUDPPrefix, User::Panic( _L("Protocol"), 1 ) ); // UDP:0123,000e,[Some test data] TInt frameOverhead = KUDPPrefix().Length() + KHexDecimalLength + KPortSuffix().Length() + KHexDecimalLength + KLengthSuffix().Length() + KDataSuffix().Length() + KMessageSuffix().Length(); if ( aData.Length() >= frameOverhead ) { TPtrC8 portPtr( aData.Mid( KUDPPrefix().Length(), KHexDecimalLength ) ); TLex8 portLexer( portPtr ); TUint port; if ( portLexer.Val( port, EHex ) != KErrNone ) { return KErrCorrupt; } DEBUG_PRINT( DEBUG_STRING( "CExprUDPMsg::TryParsingL, port = %d" ), port ); //Check port suffix if ( aData.Mid( KUDPPrefix().Length() + KHexDecimalLength, KPortSuffix().Length() ) != KPortSuffix ) { return KErrCorrupt; } TPtrC8 lengthPtr( aData.Mid( KUDPPrefix().Length() + KHexDecimalLength + KPortSuffix().Length(), KHexDecimalLength ) ); TLex8 lengthLexer( lengthPtr ); TUint length; if ( lengthLexer.Val( length, EHex ) != KErrNone ) { return KErrCorrupt; } DEBUG_PRINT( DEBUG_STRING( "CExprUDPMsg::TryParsingL, length = %d" ), length ); //Check length suffix if ( aData.Mid( KUDPPrefix().Length() + KHexDecimalLength + KPortSuffix().Length() + KHexDecimalLength, KLengthSuffix().Length() ) != KLengthSuffix ) { return KErrCorrupt; } DEBUG_PRINT( DEBUG_STRING( "CExprUDPMsg::TryParsingL, parsing data" ), length ); if ( aData.Length() >= TInt( frameOverhead + length ) ) { TInt messagePos = KUDPPrefix().Length() + KHexDecimalLength + KPortSuffix().Length() + KHexDecimalLength + KLengthSuffix().Length(); TPtrC8 message( aData.Mid( messagePos, length ) ); if ( aData.Mid( messagePos + length, KDataSuffix().Length() ) != KDataSuffix ) { return KErrCorrupt; } DEBUG_PRINT( DEBUG_STRING( "CExprUDPMsg::TryParsingL, message OK" ) ); if ( aData.Mid( messagePos + length + KDataSuffix().Length(), KMessageSuffix().Length() ) != KMessageSuffix ) { return KErrCorrupt; } // send parsed results iObserver->FrameParsedL( port, message ); // set the length of the handled message aLength = frameOverhead + length; return KErrNone; } } return KErrNone; }