コード例 #1
0
// If the specified parameter character is found, fetch 'value' and set 'seen'. Otherwise leave value and seen alone.
void GCodeBuffer::TryGetIValue(char c, int32_t& val, bool& seen)
{
	if (Seen(c))
	{
		val = GetIValue();
		seen = true;
	}
}
コード例 #2
0
// If the specified parameter character is found, fetch 'value' and set 'seen'. Otherwise leave value and seen alone.
void GCodeBuffer::TryGetFValue(char c, float& val, bool& seen)
{
	if (Seen(c))
	{
		val = GetFValue();
		seen = true;
	}
}
コード例 #3
0
// Add a byte to the code being assembled.  If false is returned, the code is
// not yet complete.  If true, it is complete and ready to be acted upon.
bool GCodeBuffer::Put(char c)
{
	if (c == ';')
	{
		inComment = true;
	}
	else if (c == '\n' || c == '\r' || c == 0)
	{
		gcodeBuffer[gcodePointer] = 0;
		if (reprap.Debug(moduleGcodes) && gcodeBuffer[0] != 0 && !writingFileDirectory) // Don't bother with blank/comment lines
		{
			reprap.GetPlatform()->MessageF(DEBUG_MESSAGE, "%s: %s\n", identity, gcodeBuffer);
		}

		// Deal with line numbers and checksums
		if (Seen('*'))
		{
			const int csSent = GetIValue();
			const int csHere = CheckSum();
			if (csSent != csHere)
			{
				if (Seen('N'))
				{
					snprintf(gcodeBuffer, GCODE_LENGTH, "M998 P%ld", GetIValue());
				}
				Init();
				return true;
			}

			// Strip out the line number and checksum
			gcodePointer = 0;
			while (gcodeBuffer[gcodePointer] != ' ' && gcodeBuffer[gcodePointer] != 0)
			{
				gcodePointer++;
			}

			// Anything there?
			if (gcodeBuffer[gcodePointer] == 0)
			{
				// No...
				gcodeBuffer[0] = 0;
				Init();
				return false;
			}

			// Yes...
			gcodePointer++;
			int gp2 = 0;
			while (gcodeBuffer[gcodePointer] != '*' && gcodeBuffer[gcodePointer] != 0)
			{
				gcodeBuffer[gp2] = gcodeBuffer[gcodePointer++];
				gp2++;
			}
			gcodeBuffer[gp2] = 0;
		}
		else if ((checksumRequired && machineState->previous == nullptr) || IsEmpty())
		{
			// Checksum not found or buffer empty - cannot do anything
			gcodeBuffer[0] = 0;
			Init();
			return false;
		}
		Init();
		bufferState = GCodeBufferState::ready;
		return true;
	}
	else if (!inComment || writingFileDirectory)
	{
		gcodeBuffer[gcodePointer++] = c;
		if (gcodePointer >= (int)GCODE_LENGTH)
		{
			reprap.GetPlatform()->MessageF(GENERIC_MESSAGE, "Error: G-Code buffer '$s' length overflow\n", identity);
			gcodePointer = 0;
			gcodeBuffer[0] = 0;
		}
	}

	return false;
}
コード例 #4
0
ファイル: tryurng1.cpp プロジェクト: RuiVarela/Smokin
void test1(double N)
{
   Uniform U;
   double sum = 0.0, sumsq = 0.0, ar1 = 0.0, last = 0.0;
   double j;
   Array<double> chi0(0,15);
   Array<double> chi1(0,255);
   Array<double> chi1x(0,255);
   Array<double> chi2(0,65535);
   Array<double> chi2x(0,65535);
   chi0 = 0; chi1 = 0; chi1x = 0; chi2 = 0; chi2x = 0;

   Array<double> crawl7(0,127);
   Array<double> crawl8(0,255);
   Array<double> crawl15(0,32767);
   Array<double> crawl16(0,65535);
   crawl7 = 0;
   crawl8 = 0;
   crawl15 = 0;
   crawl16 = 0;
   unsigned long crawler = 0;


   int m_bits = (int)(log(N) / 0.693 - 0.471);  // number of bits in sparse monkey test
   unsigned long M = 1; M <<= (m_bits - 3);     // 2**m_bits / 8
   String Seen(M, (char)0);                     // to accumulate results
   unsigned long mask1 = (M - 1);

   for (j = 0; j < N; ++j)
   {
      double u = U.Next();
      if (u == 1.0) { cout << "Reject value == 1" << endl; continue; }
      double v = u - 0.5;
      sum += v;
      sumsq += v * v;
      ar1 += v * (last - 0.5);
      int k = (int)floor(u * 256); ++chi1(k);
      int m = (int)floor(u * 65536); ++chi2(m);
      int a = (int)floor(u * 16); ++chi0(a);
      if (j > 0)
      {
         int b = (int)floor(last * 16);
         ++chi1x(a + 16 * b);
         int l = (int)floor(last * 256); ++chi2x(k + 256 * l);
      }
      last = u;

      crawler <<= 1; if (v >= 0) ++crawler;
      if (j >= 6)  ++crawl7(crawler & 0x7F);
      if (j >= 7)  ++crawl8(crawler & 0xFF);
      if (j >= 14) ++crawl15(crawler & 0x7FFF);
      if (j >= 15) ++crawl16(crawler & 0xFFFF);

      
      if ( j >= (unsigned int)(m_bits-1) )
      {
         unsigned char mask2 = 1; mask2 <<= crawler & 7;
         Seen[(crawler >> 3) & mask1] |= mask2;
      }

   }
コード例 #5
0
ファイル: GCodes.cpp プロジェクト: bowerandy/RepRapFirmware
bool GCodeBuffer::Put(char c)
{
  bool result = false;
  gcodeBuffer[gcodePointer] = c;
  
  if(c == ';')
    inComment = true;
    
  if(c == '\n' || !c)
  {
    gcodeBuffer[gcodePointer] = 0;
    Init();
    if(reprap.Debug() && gcodeBuffer[0]) // Don't bother with blank/comment lines
    {
      platform->Message(HOST_MESSAGE, identity);
      platform->Message(HOST_MESSAGE, gcodeBuffer);
      platform->Message(HOST_MESSAGE, "\n"); 
    }

    // Deal with line numbers and checksums

    if(Seen('*'))
    {
    	int csSent = GetIValue();
    	int csHere = CheckSum();
    	Seen('N');
    	if(csSent != csHere)
    	{
    		snprintf(gcodeBuffer, GCODE_LENGTH, "M998 P%d", GetIValue());
    		Init();
    		result = true;
    		return result;
    	}

    	// Strip out the line number and checksum

    	while(gcodeBuffer[gcodePointer] != ' ' && gcodeBuffer[gcodePointer])
    		gcodePointer++;

    	// Anything there?

    	if(!gcodeBuffer[gcodePointer])
    	{
    		// No...
    		gcodeBuffer[0] = 0;
    		Init();
    		result = true;
    		return result;
    	}

    	// Yes...

    	gcodePointer++;
    	int gp2 = 0;
    	while(gcodeBuffer[gcodePointer] != '*' && gcodeBuffer[gcodePointer])
    	{
    		gcodeBuffer[gp2] = gcodeBuffer[gcodePointer++];
    		gp2++;
    	}
    	gcodeBuffer[gp2] = 0;
    	Init();
    }

    result = true;
  } else
  {
    if(!inComment)
      gcodePointer++;
  }
  
  if(gcodePointer >= GCODE_LENGTH)
  {
    platform->Message(HOST_MESSAGE, "G Code buffer length overflow.\n");
    gcodePointer = 0;
    gcodeBuffer[0] = 0;
  }
  
  return result;
}