Ejemplo n.º 1
0
ChUINT4 XlParser::position()
{
    // sanity checks
    checkStream();

    // get the position
    return m_pStream->getPos();
}
Ejemplo n.º 2
0
double getPositiveDouble(const char* message)
{
	double value;
	if (!quietMode)
		cerr << "Enter positive " << message << "(double): ";
	cin  >> value;
	checkStream(cin);
	return value;
}
Ejemplo n.º 3
0
int getInt(const char* message)
{

	int value;
	if (!quietMode)
		cerr << "Enter " << message << " (integer): ";
	cin  >> value;
	checkStream(cin);
	return value;
}
Ejemplo n.º 4
0
	//---------------------------------------------------------------------
	void StreamSerialiser::undoReadChunk(uint32 id)
	{
		Chunk* c = popChunk(id);

		checkStream();

		mStream->seek(c->offset);

		OGRE_DELETE c;

	}
uint8_t readU8(const RVNGInputStreamPtr &input, bool /* bigEndian */)
{
  checkStream(input);

  unsigned long numBytesRead;
  uint8_t const *p = input->read(sizeof(uint8_t), numBytesRead);

  if (p && numBytesRead == sizeof(uint8_t))
    return *(uint8_t const *)(p);
  throw EndOfStreamException();
}
Ejemplo n.º 6
0
	//---------------------------------------------------------------------
	void StreamSerialiser::readData(void* buf, size_t size, size_t count)
	{
		checkStream(true, true, false);

		size_t totSize = size * count;
		mStream->read(buf, totSize);

		if (mFlipEndian)
			Bitwise::bswapChunks(buf, size, count);

	}
const unsigned char *readNBytes(const RVNGInputStreamPtr &input, const unsigned long numBytes)
{
  checkStream(input);

  unsigned long readBytes = 0;
  const unsigned char *const s = input->read(numBytes, readBytes);

  if (numBytes != readBytes)
    throw EndOfStreamException();

  return s;
}
Ejemplo n.º 8
0
int getFilterSize()
{
	int filtersize;
	if (!quietMode)
		cerr << "Enter filter size (positive, odd integer) : ";
	cin  >> filtersize;
	if (filtersize % 2 !=1 || filtersize<=0)
	{
		cerr << "Sorry, the filter size must be a positive, odd integer." << endl;
		filtersize=0;
	}
	checkStream(cin);
	return filtersize;
}
Ejemplo n.º 9
0
	//---------------------------------------------------------------------
	void StreamSerialiser::readChunkEnd(uint32 id)
	{
		Chunk* c = popChunk(id);

		checkStream();

		// skip to the end of the chunk if we were not there already
		// this lets us quite reading a chunk anywhere and have the read marker
		// automatically skip to the next one
		if (mStream->tell() < (c->offset + CHUNK_HEADER_SIZE + c->length))
			mStream->seek(c->offset + CHUNK_HEADER_SIZE + c->length);

		OGRE_DELETE c;
	}
Ejemplo n.º 10
0
	//---------------------------------------------------------------------
	void StreamSerialiser::writeChunkBegin(uint32 id, uint16 version /* = 1 */)
	{
		checkStream(false, false, true);

		if (mReadWriteHeader)
			writeHeader();

		if (mEndian == ENDIAN_AUTO)
			OGRE_EXCEPT(Exception::ERR_INVALID_STATE, 
				"Endian mode has not been determined, did you disable header without setting?", 
				"StreamSerialiser::writeChunkBegin");

		writeChunkImpl(id, version);

	}
uint64_t readU64(const RVNGInputStreamPtr &input, bool bigEndian)
{
  checkStream(input);

  unsigned long numBytesRead;
  uint8_t const *p = input->read(sizeof(uint64_t), numBytesRead);

  if (p && numBytesRead == sizeof(uint64_t))
  {
    if (bigEndian)
      return (uint64_t)p[7]|((uint64_t)p[6]<<8)|((uint64_t)p[5]<<16)|((uint64_t)p[4]<<24)|((uint64_t)p[3]<<32)|((uint64_t)p[2]<<40)|((uint64_t)p[1]<<48)|((uint64_t)p[0]<<56);
    return (uint64_t)p[0]|((uint64_t)p[1]<<8)|((uint64_t)p[2]<<16)|((uint64_t)p[3]<<24)|((uint64_t)p[4]<<32)|((uint64_t)p[5]<<40)|((uint64_t)p[6]<<48)|((uint64_t)p[7]<<56);
  }
  throw EndOfStreamException();
}
uint16_t readU16(const RVNGInputStreamPtr &input, bool bigEndian)
{
  checkStream(input);

  unsigned long numBytesRead;
  uint8_t const *p = input->read(sizeof(uint16_t), numBytesRead);

  if (p && numBytesRead == sizeof(uint16_t))
  {
    if (bigEndian)
      return static_cast<uint16_t>((uint16_t)p[1]|((uint16_t)p[0]<<8));
    return static_cast<uint16_t>((uint16_t)p[0]|((uint16_t)p[1]<<8));
  }
  throw EndOfStreamException();
}
Ejemplo n.º 13
0
bool XlParser::seek(ChUINT4 in_ulOffset)
{
    // sanity checks
    checkStream();
    
    if (in_ulOffset > m_pStream->getInfo()->getSize())
    {
        return false;
    }
     m_pStream->seek(in_ulOffset, SsrwOO_START);

    // sync up
    m_ulCurrentOffset = in_ulOffset;

    return true;
}
Ejemplo n.º 14
0
	//---------------------------------------------------------------------
	size_t StreamSerialiser::getOffsetFromChunkStart() const
	{
		checkStream(false, false, false);

		if (mChunkStack.empty())
		{
			return 0;
		}
		else
		{
			size_t pos = mStream->tell();
			size_t diff = pos - mChunkStack.back()->offset;
			if(diff >= CHUNK_HEADER_SIZE)
				return diff - CHUNK_HEADER_SIZE;
			else
				return 0; // not in a chunk?

		}

	}
Ejemplo n.º 15
0
	//---------------------------------------------------------------------
	void StreamSerialiser::writeData(const void* buf, size_t size, size_t count)
	{
		checkStream(false, false, true);

		size_t totSize = size * count;
		if (mFlipEndian)
		{
			void* pToWrite = OGRE_MALLOC(totSize, MEMCATEGORY_GENERAL);
			memcpy(pToWrite, buf, totSize);

			Bitwise::bswapChunks(pToWrite, size, count);
			mStream->write(pToWrite, totSize);

			OGRE_FREE(pToWrite, MEMCATEGORY_GENERAL);
		}
		else
		{
			mStream->write(buf, totSize);
		}

	}
Ejemplo n.º 16
0
 ///\brief Checks all streams, restoring if needed.
 ///\param data The stream configuration for the server.
 ///\returns True if the server status changed
 bool CheckAllStreams(JSON::Value & data){
   long long int currTime = Util::epoch();
   jsonForEach(data, jit) {
     checkStream(jit.key(), (*jit));
     if (!jit->isMember("name")){
       (*jit)["name"] = jit.key();
     }
     if (!hasViewers(jit.key())){
       if (jit->isMember("source") && (*jit)["source"].asString().substr(0, 1) == "/" && jit->isMember("error")
           && (*jit)["error"].asString().substr(0,15) != "Stream offline:"){
         (*jit)["online"] = 2;
       }else{
         if (jit->isMember("error") && (*jit)["error"].asString() == "Available"){
           jit->removeMember("error");
         }
         (*jit)["online"] = 0;
       }
     }else{
       // assume all is fine
       jit->removeMember("error");
       (*jit)["online"] = 1;
     }
   }
Ejemplo n.º 17
0
	//---------------------------------------------------------------------
	uint32 StreamSerialiser::peekNextChunkID()
	{
		checkStream();

		if (eof())
			return 0;

		// Have we figured out the endian mode yet?
		if (mReadWriteHeader)
			readHeader();

		if (mEndian == ENDIAN_AUTO)
			OGRE_EXCEPT(Exception::ERR_INVALID_STATE, 
			"Endian mode has not been determined, did you disable header without setting?", 
			"StreamSerialiser::peekNextChunkID");

		size_t homePos = mStream->tell();
		uint32 ret;
		read(&ret);
		mStream->seek(homePos);

		return ret;
	}
Ejemplo n.º 18
0
	//---------------------------------------------------------------------
	StreamSerialiser::StreamSerialiser(const DataStreamPtr& stream, Endian endianMode, 
		bool autoHeader, RealStorageFormat realFormat)
		: mStream(stream)
		, mEndian(endianMode)
		, mFlipEndian(false)
		, mReadWriteHeader(autoHeader)
		, mRealFormat(realFormat)
	{
		if (mEndian != ENDIAN_AUTO)
		{
#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
			if (mEndian == ENDIAN_LITTLE)
				mFlipEndian = true;
#else
			if (mEndian == ENDIAN_BIG)
				mFlipEndian = true;
#endif

		}

		checkStream();

	}
Ejemplo n.º 19
0
	//---------------------------------------------------------------------
	void StreamSerialiser::writeChunkEnd(uint32 id)
	{
		checkStream(false, false, true);

		Chunk* c = popChunk(id);

		// update the sizes
		size_t currPos = mStream->tell();
		c->length = static_cast<uint32>(currPos - c->offset - CHUNK_HEADER_SIZE);

		// seek to 'length' position in stream for this chunk
		// skip id (32) and version (16)
		mStream->seek(c->offset + sizeof(uint32) + sizeof(uint16));
		write(&c->length);
		// write updated checksum
		uint32 checksum = calculateChecksum(c);
		write(&checksum);

		// seek back to previous position
		mStream->seek(currPos);

		OGRE_DELETE c;

	}
void skip(const RVNGInputStreamPtr &input, unsigned long numBytes)
{
  checkStream(input);

  seekRelative(input, static_cast<long>(numBytes));
}
Ejemplo n.º 21
0
	//---------------------------------------------------------------------
	bool StreamSerialiser::eof() const
	{ 
		checkStream();
		return mStream->eof(); 
	}
Ejemplo n.º 22
0
void process_func (int value)
{

	Image* resultImage = NULL;
	static int samplingMode = I_NEAREST;
	static int gaussianFilterSize = 3;
	static double gaussianSigma = 1.0;

	//  check if we have an image to process 
	if (!currentImage)
	{
		cerr << "Sorry, no image is loaded!" << endl;
		return;
	}

	switch (value)
	{
	case M_PROCESS_BLUR_BOX:  // enum #6
		{
			int filterSize = getFilterSize();
			if (filterSize>0)
				resultImage = ip_blur_box(currentImage, filterSize);
			break;
		}


	case M_PROCESS_BLUR_GAUSSIAN:  // enum #7
		{
			int filterSize = getFilterSize();
			if (filterSize<=0)
				break;
			double sigma = getPositiveDouble("sigma");
			if (sigma>0)
				resultImage = ip_blur_gaussian(currentImage, filterSize, sigma);
			break;
		}


	case M_PROCESS_BLUR_TRIANGLE:  // enum #8
		{
			int filterSize = getFilterSize();
			if (filterSize>0)
				resultImage = ip_blur_triangle(currentImage, filterSize);
			break;
		}


	case M_PROCESS_BRIGHTEN:  // enum #9
		{
			double alpha = getDouble("alpha");
			resultImage = ip_brighten(currentImage, alpha);
			break;
		}

	case M_PROCESS_COLOR_SHIFT: // enum #10
		resultImage=ip_color_shift(currentImage);
		break;

	case M_PROCESS_CONTRAST:  // enum #11
		{
			double alpha=getDouble("alpha");
			resultImage = ip_contrast(currentImage, alpha);
			break;
		}


	case M_PROCESS_COMPOSITE: // enum #12
		{
			char filename[MAX_NAME];
			// we don't do a lot of checks here; i.e. second image and
			// mask valid images and the same size as current image
			if (!quietMode)
				cerr << "Enter filename of second image (string - no spaces) : ";
			cin  >> filename;
			Image* secondImage = new Image();
			secondImage->read(filename);
			if (!quietMode)
				cerr << "Enter filename of mask (string - no spaces) : ";
			cin  >> filename;
			Image* mask = new Image();
			mask->read(filename);
			checkStream(cin);
			resultImage = ip_composite(currentImage, secondImage, mask);
			delete secondImage;
			delete mask;
			break;
		}


	case M_PROCESS_CROP: // enum #13
		{
			int x0, y0, x1, y1;
			if (!quietMode)
			{
				cerr << "Current image width and height: " << currentImage->getWidth()-1 << " " 
					<< currentImage->getHeight()-1 << endl;
				cerr << "Enter region to crop (left top right bottom (ints)) : ";
			}
			cin >> x0 >> y0 >> x1 >> y1;
			checkStream(cin);
			if (x0>=0 || x0<x1 || x1<currentImage->getWidth() || y0>=0 || y0<y1 || y1<currentImage->getHeight())
			{
				resultImage = ip_crop(currentImage, x0,y0,x1,y1);
			}
			else
			{
				cerr<< "Invalid region." << endl;
			}

			break;
		}


	case M_PROCESS_EDGE_DETECT: // enum #14
		resultImage = ip_edge_detect(currentImage);
		break;


	case M_PROCESS_EXTRACT:  // enum #15
		{
			int channel = getInt("channel [0,2]");
			if (channel<0 || channel>2) 
			{
				cerr << "Invalid channel."<< endl;
			}
			else
			{
				resultImage = ip_extract(currentImage, channel);
			}
			break;
		}

	case M_PROCESS_FUN_WARP:  // enum #16
		resultImage = ip_fun_warp(currentImage,samplingMode);
		break;

	case M_PROCESS_GREY: // enum #17
		resultImage = ip_grey(currentImage);
		break;

	case M_PROCESS_IMAGE_SHIFT: // enum #18
		{
			double dx = getDouble("dx");
			double dy = getDouble("dy");
			resultImage = ip_image_shift(currentImage,dx, dy);
			break;
		}

	case M_PROCESS_INVERT:  // enum #19
		resultImage = ip_invert(currentImage);
		break;

	case M_PROCESS_MISC: // enum #20
		resultImage = ip_misc(currentImage);
		break;


	case M_PROCESS_QUANTIZE_SIMPLE:  // enum #21
		{

			int bitsPerChannel = getInt("bits per channel [1,8]");
			if (bitsPerChannel<=0 || bitsPerChannel>8)
			{
				cerr << "Invalid number bits." << endl;
			}
			else
			{
				resultImage = ip_quantize_simple(currentImage, bitsPerChannel);
			}
			break;
		}


	case M_PROCESS_QUANTIZE_ORDERED:  //enum #22
		{
			int bitsPerChannel = getInt("bits per channel [1,8]");

			if (bitsPerChannel<=0 || bitsPerChannel>8)
			{
				cerr << "Invalid number bits." << endl;
			}
			else
			{
				resultImage = ip_quantize_ordered(currentImage, bitsPerChannel);
			}
			break;
		}


	case M_PROCESS_QUANTIZE_FLOYD_STEINBERG: // enum #23
		{
			int bitsPerChannel = getInt("bits per channel [1,8]");

			if (bitsPerChannel<=0 || bitsPerChannel>8)
			{
				cerr << "Invalid number bits." << endl;
			}
			else
			{
				resultImage = ip_quantize_fs(currentImage, bitsPerChannel);
			}
			break;
		}


	case M_PROCESS_ROTATE: // enum #24
		{
			if (!quietMode) 
			{
				cerr<< "Current image width/height: " << currentImage->getWidth()-1 << " " 
					<< currentImage->getHeight()-1 << endl;
			}
			double theta = getDouble("angle");
			double x = getDouble("point x");
			double y = getDouble("point y");
			resultImage = ip_rotate(currentImage, theta, x, y, samplingMode, 
				gaussianFilterSize, gaussianSigma);
			break;
		}


	case M_PROCESS_SATURATE:  // enum #25
		{
			double alpha = getDouble("alpha");
			resultImage = ip_saturate(currentImage, alpha);
			break;
		}


	case M_PROCESS_SCALE: // enum #26
		{
			double xFactor = getDouble("scale factor for x");
			double yFactor = getDouble("scale factor for y");
			resultImage = ip_scale(currentImage, xFactor, yFactor, samplingMode, gaussianFilterSize, gaussianSigma);
			break;
		}

	case M_PROCESS_SET_SAMPLING_BILINEAR: // enum #27
		samplingMode=I_BILINEAR;
		break;

	case M_PROCESS_SET_SAMPLING_NEAREST:  // enum #28
		samplingMode=I_NEAREST;
		break;

	case M_PROCESS_SET_SAMPLING_GAUSSIAN: // enum #29
		gaussianFilterSize=getInt("filter size (positive, even integer)");
		if (gaussianFilterSize%2!=0 || gaussianFilterSize<=0)
		{
			gaussianFilterSize=3;
			cerr<<"Invalid value, using default size of 3"<<endl;
		}
		gaussianSigma=getDouble("sigma (non-negative)");
		if (gaussianSigma <0) 
		{
			gaussianSigma=1;
			cerr<<"Invalid value, using default sigma of 1"<<endl;
		}
		samplingMode=I_GAUSSIAN;
        break;

	case M_PROCESS_THRESHOLD: // enum #23
		{
			double threshold=getDouble("threshold [0,1]");
			resultImage = ip_threshold(currentImage, threshold);
			break;
		}


	default:
		break;
	}

	if (resultImage != NULL)
	{
		delete currentImage;
		currentImage = resultImage;

		if (currentImage->getWidth()  != window_width    ||
			currentImage->getHeight() != window_height)
			reshape(currentImage->getWidth(), currentImage->getHeight());

		if (!quietMode)
			cerr << "done!" << endl;

		if (!textMode)
			glutPostRedisplay();
	}
}
Ejemplo n.º 23
0
void menu_func (int value)
{
	// variables used in the switch statement
	char filename[MAX_LINE];

	switch (value)
	{
	case M_QUIT:  // enum #0
		exit(0);
		break;



	case M_HELP:  // enum #1
		menu_help();
		break;



	case M_FILE_OPEN:   // enum #2
		if (!quietMode)
			cerr << "Open file (string - no spaces) : ";
		cin  >> filename;
		checkStream(cin);
		image_load(filename);
		break;


	case M_FILE_SAVE:   // enum #3
		if (!quietMode)
			cerr << "Save as (string - no spaces) : ";
		cin  >> filename;
		checkStream(cin);
		image_save(filename);
		break;


	case M_FILE_INFO:  // enum #4
		image_print_info();
		break;


	case M_FILE_REVERT:  // enum #5
		image_revert();
		break;

	case M_VIEW_PIXEL_VALUE: // enum #31
		{
			if (!currentImage) 
			{
				cerr << "Sorry, no image is loaded." << endl;
				break;
			}
			if (!quietMode)
			{
				cerr << "Current image width and height: " << currentImage->getWidth()-1 << " " 
					<< currentImage->getHeight()-1 << endl;
			}
			int x=getInt("x value of pixel to view");
			int y=getInt("y value of pixel to view");
			if (x<0 || x>=currentImage->getWidth() || y<0 || y>=currentImage->getHeight())
			{
				cerr << "Invalid pixel location." << endl;
				break;
			}
			cerr << "R: " << currentImage->getPixel(x,y,RED);
			cerr << ", G: " << currentImage->getPixel(x,y,GREEN);
			cerr << ", B: " << currentImage->getPixel(x,y,BLUE) << endl;
			break;
		}

	default:
		process_func(value);
	}
	return;
}
Ejemplo n.º 24
0
int main( int argc, char **argv )
{
  char *name = nullptr;
  struct Option *map;
  struct Cell_head window;

  G_gisinit( argv[0] );

  G_define_module();

  map = G_define_standard_option( G_OPT_R_OUTPUT );

  if ( G_parser( argc, argv ) )
    exit( EXIT_FAILURE );

  name = map->answer;

#ifdef Q_OS_WIN
  _setmode( _fileno( stdin ), _O_BINARY );
  _setmode( _fileno( stdout ), _O_BINARY );
  //setvbuf( stdin, NULL, _IONBF, BUFSIZ );
  // setting _IONBF on stdout works on windows correctly, data written immediately even without fflush(stdout)
  //setvbuf( stdout, NULL, _IONBF, BUFSIZ );
#endif

  QgsGrassDataFile stdinFile;
  stdinFile.open( stdin );
  QDataStream stdinStream( &stdinFile );

  QFile stdoutFile;
  stdoutFile.open( stdout, QIODevice::WriteOnly | QIODevice::Unbuffered );
  QDataStream stdoutStream( &stdoutFile );

  qint32 proj, zone;
  stdinStream >> proj >> zone;

  QgsRectangle extent;
  qint32 rows, cols;
  stdinStream >> extent >> cols >> rows;
  checkStream( stdinStream );

  QString err = QgsGrass::setRegion( &window, extent, rows, cols );
  if ( !err.isEmpty() )
  {
    G_fatal_error( "Cannot set region: %s", err.toUtf8().constData() );
  }
  window.proj = ( int ) proj;
  window.zone = ( int ) zone;

  G_set_window( &window );

  Qgis::DataType qgis_type;
  qint32 type;
  stdinStream >> type;
  checkStream( stdinStream );
  qgis_type = ( Qgis::DataType )type;

  RASTER_MAP_TYPE grass_type;
  switch ( qgis_type )
  {
    case Qgis::Int32:
      grass_type = CELL_TYPE;
      break;
    case Qgis::Float32:
      grass_type = FCELL_TYPE;
      break;
    case Qgis::Float64:
      grass_type = DCELL_TYPE;
      break;
    default:
      G_fatal_error( "QGIS data type %d not supported", qgis_type );
      return 1;
  }

  cf = Rast_open_new( name, grass_type );
  if ( cf < 0 )
  {
    G_fatal_error( "Unable to create raster map <%s>", name );
    return 1;
  }

  void *buf = Rast_allocate_buf( grass_type );

  int expectedSize = cols * QgsRasterBlock::typeSize( qgis_type );
  bool isCanceled = false;
  QByteArray byteArray;
  for ( int row = 0; row < rows; row++ )
  {
    stdinStream >> isCanceled;
    checkStream( stdinStream );
    if ( isCanceled )
    {
      break;
    }
    double noDataValue;
    stdinStream >> noDataValue;
    stdinStream >> byteArray;
    checkStream( stdinStream );

    if ( byteArray.size() != expectedSize )
    {
      G_fatal_error( "Wrong byte array size, expected %d bytes, got %d, row %d / %d", expectedSize, byteArray.size(), row, rows );
      return 1;
    }

    qint32 *cell = nullptr;
    float *fcell = nullptr;
    double *dcell = nullptr;
    if ( grass_type == CELL_TYPE )
      cell = ( qint32 * ) byteArray.data();
    else if ( grass_type == FCELL_TYPE )
      fcell = ( float * ) byteArray.data();
    else if ( grass_type == DCELL_TYPE )
      dcell = ( double * ) byteArray.data();

    void *ptr = buf;
    for ( int col = 0; col < cols; col++ )
    {
      if ( grass_type == CELL_TYPE )
      {
        if ( ( CELL )cell[col] == ( CELL )noDataValue )
        {
          Rast_set_c_null_value( ( CELL * )ptr, 1 );
        }
        else
        {
          Rast_set_c_value( ptr, ( CELL )( cell[col] ), grass_type );
        }
      }
      else if ( grass_type == FCELL_TYPE )
      {
        if ( ( FCELL )fcell[col] == ( FCELL )noDataValue )
        {
          Rast_set_f_null_value( ( FCELL * )ptr, 1 );
        }
        else
        {
          Rast_set_f_value( ptr, ( FCELL )( fcell[col] ), grass_type );
        }
      }
      else if ( grass_type == DCELL_TYPE )
      {
        if ( ( DCELL )dcell[col] == ( DCELL )noDataValue )
        {
          Rast_set_d_null_value( ( DCELL * )ptr, 1 );
        }
        else
        {
          Rast_set_d_value( ptr, ( DCELL )dcell[col], grass_type );
        }
      }

      ptr = G_incr_void_ptr( ptr, Rast_cell_size( grass_type ) );
    }
    Rast_put_row( cf, buf, grass_type );

#ifndef Q_OS_WIN
    // Because stdin is somewhere buffered on Windows (not clear if in QProcess or by Windows)
    // we cannot in QgsGrassImport wait for this because it hangs. Setting _IONBF on stdin does not help
    // and there is no flush() on QProcess.
    // OTOH, smaller stdin buffer is probably blocking QgsGrassImport so that the import can be canceled immediately.
    stdoutStream << ( bool )true; // row written
    stdoutFile.flush();
#endif
  }

  if ( isCanceled )
  {
    Rast_unopen( cf );
  }
  else
  {
    Rast_close( cf );
    struct History history;
    Rast_short_history( name, "raster", &history );
    Rast_command_history( &history );
    Rast_write_history( name, &history );
  }

  exit( EXIT_SUCCESS );
}
Ejemplo n.º 25
0
void manageConnection(void)
{
	k = SYSTM001_GetTime();
	k = SYSTM001_GetSysTickCount(100);
	z++;
	if(statusSent == 1) //jak statusSent jest rowny jeden to inicjalizujemy modul po kolei zwiêkszaj¹c stageOfInitializationBt
	{					//a¿ do stageOfInitializationBt == 6
		removeTimer(&StatusReceive, &TimerIdReceive);

		statusSent = 0;
	}

	if(stageOfInitializationBt == OUT_OF_INIT) //tutaj stageOfInitializationBt == 7 czyli mamy doczynienia z ostatnim etapem inicjalizacji
	{
		removeTimer(&Status, &TimerId); //usuniecie timera odpowiedzialnego za wysylanie w celu inicjalizacji

		stageOfInitializationBt++; //zwiekszenie licznika inicjalizacji w celu wyslania ostatniej komendy w ostatnim kroku
	}

	if(((stageOfInitializationBt - 1) == OUT_OF_INIT)) //wyslanie ostaniej ostaniej komendy
	{
		lastStageOfInitializationBt = OUT_OF_INIT;

		makeTimer(500, SYSTM001_PERIODIC, timerHandlerConnectionSet, NULL, &statusSetConnection, &TimerIDSetConnection); //wys³anie ostaniej komendy

		if(TimerIDSetConnection != 0)
		{
			stageOfInitializationBt++;
		}
	}
	else if(lastStageOfInitializationBt == (OUT_OF_INIT + 1))
	{
		removeTimer(&statusSetConnection, &TimerIDSetConnection);//usuniecie timera o odpowiedzialnego za wyslanie ostaniej komendy

		if(statusSetConnection == DAVEApp_SUCCESS)
		{
			removeTimer(&StatusReceive, &TimerIdReceive);

			lastStageOfInitializationBt++;
			turnOnSendingReceiving = 1;
		}
	}

	if(turnOnSendingReceiving == 1)
	{
		//deklaracja do odbioru

		makeTimer(500, SYSTM001_PERIODIC, receive, NULL, &receiveStatus, &receiveID);

		//deklaracja do wysylania
		makeTimer(1500, SYSTM001_PERIODIC, transmit, NULL, &transmitStatus, &transmitID);

		initStatus = 1;
		turnOnSendingReceiving = 0;

	}

	//blueToothHandle();

	//check stream, if disconnection occured
	checkStream();
	//check stream, if disconnection occured

	if(chosenSensor == 1)
	{
		//zastopowanie odbioru i transmisji danych
		removeTimer(&receiveStatus, &receiveID);
		removeTimer(&transmitStatus, &transmitID);
		//zastopowanie odbioru i transmisji danych

		makeTimer(1500, SYSTM001_PERIODIC, transmitToSensor, NULL, &transmitStatus, &transmitID);
	}
	else if(chosenSensor == 2)
	{
		//zastopowanie odbioru i transmisji danych
		removeTimer(&receiveStatus, &receiveID);
		removeTimer(&transmitStatus, &transmitID);
		//zastopowanie odbioru i transmisji danych
		//cos tam

		//elo melo
	}
}
Ejemplo n.º 26
0
//***************************************************************************
// PRIVATE METHOD:
// ossimFfRevb::loadFromStream(istream& is)
// Initializes data members from an EOSAT Fast Format Rev B header.
//***************************************************************************
void ossimFfRevb::loadFromStream(ossim::istream& is)
{
   if (!is)
   {
      theErrorStatus = OSSIM_ERROR;

      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimFfRevb::loadFromStream:\n"
                                          << "Null stream passed in.  Returning from method."
                                          << std::endl;
      return;
   }

   //***
   // See .h for enumerations for field sizes and offsets. 
   //***

   //***
   // NOTE:  Because of header inconsistencies all seeks will be relative to
   //        the beginning of the stream.
   //***

   //***
   // Temporary buffer for fields that need to be converted to integers or
   // floats.
   //***
   char tmpBuff[25];

   int i; // For iterations.

   is.seekg(PRODUCT_ORDER_NUMBER_OFFSET, std::ios_base::beg);
   is.get(theProductOrderNumber, 
          PRODUCT_ORDER_NUMBER_SIZE + 1,
          ' ');
   if (checkStream(is)) return;
 
   is.seekg(PATH_ROW_NUMBER_OFFSET, std::ios_base::beg);
   is.get(thePathRowNumber, PATH_ROW_NUMBER_SIZE + 1);
   if (checkStream(is)) return;

   is.seekg(DATE_OFFSET, std::ios_base::beg);
   is.get(theAcquisitionDate, DATE_SIZE + 1);
   if (checkStream(is)) return;

   is.seekg(SAT_NUMBER_OFFSET, std::ios_base::beg);
   is.get(theSatNumber, SAT_NUMBER_SIZE + 1);
   if (checkStream(is)) return;

   is.seekg(INSTRUMENT_TYPE_OFFSET, std::ios_base::beg);
   is.get(theInstrumentType, INSTRUMENT_TYPE_SIZE + 1);
   if (checkStream(is)) return;

   is.seekg(PRODUCT_TYPE_OFFSET, std::ios_base::beg);
   is.get(theProductType, PRODUCT_TYPE_SIZE+ 1);
   if (checkStream(is)) return;

   is.seekg(PRODUCT_SIZE_OFFSET, std::ios_base::beg);
   is.get(theProductSize, PRODUCT_SIZE_SIZE+ 1);
   if (checkStream(is)) return;

   is.seekg(MAP_SHEET_NAME_OFFSET, std::ios_base::beg);
   is.get(theMapSheetName, MAP_SHEET_SIZE + 1);
   if (checkStream(is)) return;

   is.seekg(PROCESSING_TYPE_OFFSET, std::ios_base::beg);
   is.get(theProcessingType, PROCESSING_TYPE_SIZE + 1);
   if (checkStream(is)) return;

   is.seekg(RESAMPLING_ALGO_OFFSET, std::ios_base::beg);
   is.get(theResampAlgorithm, RESAMPLING_ALGO_SIZE + 1);
   if (checkStream(is)) return;

   for (i=0; i<NUMBER_OF_BANDS; i++)
   {      
      is.seekg(RADIANCE_OFFSET[i], std::ios_base::beg);
      is.get(theBandRadiance[i], RADIANCE_SIZE + 1);
      if (checkStream(is)) return;
   }

   is.seekg(VOLUME_NUMBER_OFFSET, std::ios_base::beg);
   is.get(theVolumeNumber, VOLUME_NUMBER_SIZE + 1);
   if (checkStream(is)) return;

   is.seekg(FIRST_LINE_IN_VOLUME_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, FIRST_LINE_IN_VOLUME_SIZE + 1);
   if (checkStream(is)) return;

   the1stLineInVolume = atoi(tmpBuff);

   is.seekg(LINES_PER_VOLUME_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, LINES_PER_VOLUME_SIZE + 1);
   if (checkStream(is)) return;

   theLinesPerVolume = atoi(tmpBuff);
   
   is.seekg(ORIENTATION_ANGLE_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, ORIENTATION_ANGLE_SIZE + 1);
   if (checkStream(is)) return;

   theOrientationAngle = atof(tmpBuff);

   is.seekg(MAP_PROJ_NAME_OFFSET, std::ios_base::beg);
   is.get(theMapProjName, MAP_PROJ_NAME_SIZE + 1);
   if (checkStream(is)) return;
   
   is.seekg(USGS_PROJ_NUMBER_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, USGS_PROJ_NUMBER_SIZE + 1);
   if (checkStream(is)) return;

   theUsgsProjNumber = atoi(tmpBuff);

   is.seekg(USGS_MAP_ZONE_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, USGS_MAP_ZONE_SIZE + 1);
   if (checkStream(is)) return;

   theUsgsMapZone = atoi(tmpBuff);

   //***
   // Get the fifteen projection parameters.
   //***
   for (i=0; i < NUMBER_OF_PROJECTION_PARAMETERS; i++)
   {
      is.seekg(PROJ_PARAM_OFFSET[i], std::ios_base::beg);
      is.get(theUsgsProjParam[i], USGS_PROJ_PARAMS_SIZE + 1);
      if (checkStream(is)) return;
   }
   
   is.seekg(ELLIPSOID_OFFSET, std::ios_base::beg);
   is.get(theEllipsoid, ELLIPSOID_SIZE + 1);
   if (checkStream(is)) return;

   is.seekg(MAJOR_AXIS_OFFSET, std::ios_base::beg);
   is.get(tmpBuff,  MAJOR_AXIS_SIZE+ 1);
   if (checkStream(is)) return;

   theSemiMajorAxis = atof(tmpBuff);
   
   is.seekg(MINOR_AXIS_OFFSET, std::ios_base::beg);
   is.get(tmpBuff,  MINOR_AXIS_SIZE+ 1);
   if (checkStream(is)) return;

   theSemiMinorAxis = atof(tmpBuff);

   is.seekg(PIXEL_GSD_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, PIXEL_GSD_SIZE + 1);
   if (checkStream(is)) return;

   theGsd = atof(tmpBuff);
   
   is.seekg(PIXELS_PER_LINE_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, PIXELS_PER_LINE_SIZE + 1);
   if (checkStream(is)) return;

   thePixelsPerLine = atoi(tmpBuff);

   is.seekg(LINES_PER_IMAGE_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, LINES_PER_IMAGE_SIZE + 1);
   if (checkStream(is)) return;

   theLinesPerImage = atoi(tmpBuff);

   //***
   // Start of upper left data:  longitude, latitude, easting, and northing. 
   //***
   is.seekg(UL_LON_OFFSET, std::ios_base::beg);
   is.get(theUlLon, LON_SIZE + 1);
   if (checkStream(is)) return;

   is.seekg(UL_LAT_OFFSET, std::ios_base::beg);
   is.get(theUlLat, LAT_SIZE + 1);
   if (checkStream(is)) return;
   
   is.seekg(UL_EASTING_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, EASTING_SIZE + 1);
   if (checkStream(is)) return;

   theUlEasting = atof(tmpBuff);

   is.seekg(UL_NORTHING_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, NORTHING_SIZE + 1);
   if (checkStream(is)) return;

   theUlNorthing = atof(tmpBuff);

   //***
   // End of upper left data.
   //***

   //***
   // Start of upper right data: longitude, latitude, easting, and northing. 
   //***
   is.seekg(UR_LON_OFFSET, std::ios_base::beg);
   is.get(theUrLon, LON_SIZE + 1);
   if (checkStream(is)) return;
   
   is.seekg(UR_LAT_OFFSET, std::ios_base::beg);
   is.get(theUrLat, LAT_SIZE + 1);
   if (checkStream(is)) return;
   
   is.seekg(UR_EASTING_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, EASTING_SIZE + 1);
   if (checkStream(is)) return;

   theUrEasting = atof(tmpBuff);

   is.seekg(UR_NORTHING_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, NORTHING_SIZE + 1);
   if (checkStream(is)) return;

   theUrNorthing = atof(tmpBuff);
   
   //***
   // End of upper right data.
   //***

   //***
   // Start of lower right data: longitude, latitude, easting, and northing. 
   //***
   is.seekg(LR_LON_OFFSET, std::ios_base::beg);
   is.get(theLrLon, LON_SIZE + 1);
   if (checkStream(is)) return;
   
   is.seekg(LR_LAT_OFFSET, std::ios_base::beg);
   is.get(theLrLat, LAT_SIZE + 1);
   if (checkStream(is)) return;
   
   is.seekg(LR_EASTING_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, EASTING_SIZE + 1);
   if (checkStream(is)) return;

   theLrEasting = atof(tmpBuff);

   is.seekg(LR_NORTHING_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, NORTHING_SIZE + 1);
   if (checkStream(is)) return;

   theLrNorthing = atof(tmpBuff);

   //***
   // End of lower right data.
   //***

   //***
   // Start of lower left data:  longitude, latitude, easting, and northing. 
   //***
   is.seekg(LL_LON_OFFSET, std::ios_base::beg);
   is.get(theLlLon, LON_SIZE + 1);
   if (checkStream(is)) return;
   
   is.seekg(LL_LAT_OFFSET, std::ios_base::beg);
   is.get(theLlLat, LAT_SIZE + 1);
   if (checkStream(is)) return;
   
   is.seekg(LL_EASTING_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, EASTING_SIZE + 1);
   if (checkStream(is)) return;

   theLlEasting = atof(tmpBuff);

   is.seekg(LL_NORTHING_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, NORTHING_SIZE + 1);
   if (checkStream(is)) return;

   theLlNorthing = atof(tmpBuff);

   //***
   // End of lower left data.
   //***

   is.seekg(BANDS_PRESENT_OFFSET, std::ios_base::beg);
   is.get(theBandsPresentString, BANDS_PRESENT_SIZE + 1);
   if (checkStream(is)) return;

   is.seekg(BLOCKING_FACTOR_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, BLOCKING_FACTOR_SIZE + 1);
   if (checkStream(is)) return;

   theBlockingFactor = atoi(tmpBuff);

   is.seekg(RECORD_LENGTH_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, RECORD_LENGTH_SIZE + 1);
   if (checkStream(is)) return;

   theRecordSize = atoi(tmpBuff);

   is.seekg(SUN_ELEVATION_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, SUN_ELEVATION_SIZE + 1);
   if (checkStream(is)) return;

   theSunElevation = atoi(tmpBuff);

   is.seekg(SUN_AZIMUTH_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, SUN_AZIMUTH_SIZE + 1);
   if (checkStream(is)) return;

   theSunAzimuth = atoi(tmpBuff);

   //***
   // Start of scene center data:  longitude, latitude, easting, northing,
   // sample, line. 
   //***
   is.seekg(CENTER_LON_OFFSET, std::ios_base::beg);
   is.get(theCenterLon, LON_SIZE + 1);
   if (checkStream(is)) return;

   is.seekg(CENTER_LAT_OFFSET, std::ios_base::beg);
   is.get(theCenterLat, LAT_SIZE + 1);
   if (checkStream(is)) return;
   
   is.seekg(CENTER_EASTING_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, EASTING_SIZE + 1);
   if (checkStream(is)) return;

   theCenterEasting = atof(tmpBuff);

   is.seekg(CENTER_NORTHING_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, NORTHING_SIZE + 1);
   if (checkStream(is)) return;

   theCenterNorthing = atof(tmpBuff);

   is.seekg(CENTER_SAMPLE_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, CENTER_SAMPLE_SIZE + 1);
   if (checkStream(is)) return;

   theCenterSample = atoi(tmpBuff);

   is.seekg(CENTER_LINE_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, CENTER_LINE_SIZE + 1);
   if (checkStream(is)) return;

   theCenterLine = atoi(tmpBuff);

   //***
   // End of scene center data.
   //***

   is.seekg(OFFSET_OFFSET, std::ios_base::beg);
   is.get(tmpBuff, OFFSET_SIZE + 1);
   if (checkStream(is)) return;

   theOffset = atoi(tmpBuff);

   is.seekg(FORMAT_VERSION_OFFSET, std::ios_base::beg);
   is.get(theFormatVersion, FORMAT_VERSION_SIZE + 1);
   if (checkStream(is)) return;

}
Ejemplo n.º 27
0
void ImageFactory::getNextString(char destination[]){
	do{
		checkStream();
		*stream >> destination;
	} while (isComment(destination) || !strcmp(destination, ""));
}