/**
 * M28: Start SD Write
 */
void GcodeSuite::M28() {

  #if ENABLED(FAST_FILE_TRANSFER)

    #if NUM_SERIAL > 1
      const int16_t port = command_queue_port[cmd_queue_index_r];
    #endif

    bool binary_mode = false;
    char *p = parser.string_arg;
    if (p[0] == 'B' && NUMERIC(p[1])) {
      binary_mode = p[1] > '0';
      p += 2;
      while (*p == ' ') ++p;
    }

    // Binary transfer mode
    if ((card.flag.binary_mode = binary_mode)) {
      SERIAL_ECHO_START_P(port);
      SERIAL_ECHO_P(port, " preparing to receive: ");
      SERIAL_ECHOLN_P(port, p);
      card.openFile(p, false);
      #if NUM_SERIAL > 1
        card.transfer_port = port;
      #endif
    }
    else
      card.openFile(p, false);

  #else

    card.openFile(parser.string_arg, false);

  #endif
}
예제 #2
0
bool cmp(const std::string &a, const std::string &b) 
/* compare function for sorting filenames Compare alphabetically and 
 * numerically. Use this way: for files of type vector<string>, 
 * sort(files.begin(), files.end(), cmp). */
{
  unsigned i=0, j=0, m, n, an, bn; 
  while( i < a.size() && j < b.size() ) {

    if (NUMERIC(a[i]) && NUMERIC(b[j])) {

      m = i;
      while( m < a.size() && NUMERIC(a[m]) )
        m++; 

      n = j; 
      while( n < b.size() && NUMERIC(a[n]) )
        n++;

      an = atoi( a.substr(i,m).c_str() ); 
      bn = atoi( b.substr(j,n).c_str() );

      if (an < bn) return true; 
      else if (an > bn) return false;

      i = m; 
      j = n; 

    }

    if (a[i] < b[j])
      return true;
    else if (a[i] > b[j]) 
      return false; 

    i++; 
    j++;
  }

  return a.size() < b.size();
} // cmp()
예제 #3
0
CTimeSpanX &CTimeSpanX::operator+=(const CTimeSpanX &d)
{
	if(d.impl_->direction == d.impl_->direction)
	{
		NUMERIC(d.impl_->t) += NUMERIC(d.impl_->t);
	}
	else
	{
		if(NUMERIC(d.impl_->t) > NUMERIC(impl_->t))
		{
			impl_->direction = !impl_->direction;
			NUMERIC(impl_->t) = NUMERIC(d.impl_->t) - NUMERIC(impl_->t);
		}
		else
		{
			NUMERIC(impl_->t) -= NUMERIC(d.impl_->t);
		}
	}
	return *this;
}
예제 #4
0
CTimeSpanX CTimeX::operator-(const CTimeX &t) const
{
	CTimeSpanX d;
	if(*this < t)
	{
		d.impl_->direction = true;
		NUMERIC(d.impl_->t) = NUMERIC(t.impl_->t) - NUMERIC(impl_->t);
	}
	else
	{
		d.impl_->direction = false;
		NUMERIC(d.impl_->t) = NUMERIC(impl_->t) - NUMERIC(t.impl_->t);
	}
	return d;
}
예제 #5
0
//-----------------------------------------------------------
static int MultiIo(
					CamKey			Key,
					BYTE			A,
					BYTE			F,
					int				Count,
					BYTE			*Data,
					BYTE			Mem,
					TranslatedIosb	*iosb,
					int				dmode,
					int				Enhanced
					)
{
	char	tmp[7];
	int		highwayType, mode, status;

	if( MSGLVL(FUNCTION_NAME) )
		printf( "\033[01;31mMultiIo(F=%d, count=%d)-->>\033[0m\n", F, Count );
	sprintf(tmp, "GK%c%d", Key.scsi_port, Key.scsi_address);

	if( (status = QueryHighwayType( tmp )) == SUCCESS ) {
		highwayType = NUMERIC(tmp[5]);				// extract type

		switch( highwayType ) {						// check highway type
			case JORWAY:
			case JORWAY_OLD:
				if( MSGLVL(DETAILS) )
					printf( "-->>JorwayDoIo()\n" );

				mode = JORWAYMODE(dmode, (Enhanced && highwayType == JORWAY), Count > 1);
				if( mode != NO_MODE )
					status = JorwayDoIo(
									Key, 			// module info
									A, 				// module sub address
									F, 				// module function
									Count,			// data count int bytes
									Data, 			// data
									Mem, 			// 16 or 24 bit data
									iosb,			// status struct
									dmode,			// mode
									Enhanced		// highway mode
									);
				else
					status = NOT_SUPPORTED();

				break;

			case KINSYSCO:
				if( MSGLVL(DETAILS) )
					printf( "-->>KsMultiIo()\n" );

				status = KsMultiIo(
									Key,			// module info
									A,				// module sub-address
									F,				// module function
									Count,			// data count in bytes
									Data,			// data
									Mem,			// 16 or 24 bit data
									iosb,			// status struct
									KSMODE(dmode),	// mode
									Enhanced		// enhanced
									);
				break;

		        case JORWAY_73A:

				mode = JORWAYMODE(dmode, (Enhanced && highwayType == JORWAY), Count > 1);
				if( mode != NO_MODE )
					status = Jorway73ADoIo(
									Key, 			// module info
									A, 				// module sub address
									F, 				// module function
									Count,			// data count int bytes
									Data, 			// data
									Mem, 			// 16 or 24 bit data
									iosb,			// status struct
									dmode,			// mode
									Enhanced		// highway mode
									);
				else
					status = NOT_SUPPORTED();

				break;

			default:
				if( MSGLVL(IMPORTANT) )
					fprintf( stderr, "highway type(%d) not supported\n", highwayType );

				status = FAILURE;
				break;
		} // end of switch()
	} // end of if()

    if( MSGLVL(DETAILS) ) {
	  if (!iosb) printf("MultiIo null iosb ptr"); else
     printf("MultiIo(iosb)::->> bytecount= %d\n", iosb->bytcnt);  // [2002.12.13]
	}
	return status;
}
예제 #6
0
//-----------------------------------------------------------
static int SingleIo(
					CamKey			Key,
					BYTE			A,
					BYTE			F,
					BYTE			*Data,
					BYTE			Mem,
					TranslatedIosb	*iosb,
					int				dmode
					)
{
	char	tmp[7];
	int		highwayType, status;

	if( MSGLVL(FUNCTION_NAME) )
		printf( "\033[01;31mSingleIo(F=%d)-->\033[0m", F );
	sprintf(tmp, "GK%c%d", Key.scsi_port, Key.scsi_address);
	if( (status = QueryHighwayType( tmp )) == SUCCESS ) {
		highwayType = NUMERIC(tmp[5]);				// extract type

		switch( highwayType ) {						// check highway type
			case JORWAY:
			case JORWAY_OLD:
				if( MSGLVL(DETAILS) )
					printf( "-->>JorwayDoIo()\n" );

				status = JorwayDoIo(
									Key, 			// module info
									A, 				// module sub address
									F, 				// module function
									1, 				// implied count of 1
									Data, 			// data
									Mem, 			// 16 or 24 bit data
									iosb,			// status struct
									dmode,			// mode
									0				// non-enhanced
									);
				break;

			case KINSYSCO:
				if( MSGLVL(DETAILS) )
					printf( "-->>KsSingleIo()\n" );

				status = KsSingleIo(
									Key,			// module info
									A,				// module sub-address
									F,				// module function
									Data,			// data
									Mem,			// 16 or 24 bit data
									iosb,			// status struct
									KSMODE(dmode)	// mode
									);
				break;

			case JORWAY_73A:
				if( MSGLVL(DETAILS) )
					printf( "-->>JorwayDoIo()\n" );

				status = Jorway73ADoIo(
									Key, 			// module info
									A, 				// module sub address
									F, 				// module function
									1, 				// implied count of 1
									Data, 			// data
									Mem, 			// 16 or 24 bit data
									iosb,			// status struct
									dmode,			// mode
									0				// non-enhanced
									);
				break;

			default:
				if( MSGLVL(IMPORTANT) )
					fprintf( stderr, "highway type(%d) not supported\n", highwayType );

				status = FAILURE;
				break;
		} // end of switch()
		if( MSGLVL(FUNCTION_NAME) )  // show data, if there is some
		if (Data) {
		  if (Mem==16) printf( "\033[01;31mSingleIo(F=%d)-->>%d\033[0m\n", F, *(short *) Data ); else
		  printf( "\033[01;31mSingleIo(F=%d)-->>%d\033[0m\n", F, *(int *) Data );
		}

	} // end of if()

//printf("SingleIo(iosb)::->> bytecount= %d\n", iosb->bytcnt);	// [2002.12.13]
	return status;
}
예제 #7
0
int parse_options( param_t &options, int argc, const char **argv ) 
/* Parse command line options and return a status, informing the up stream 
 * if the parameters weren't inputted correctly. */ 
{
  options.shrink_factor = options.low = options.high = options.erode = options.dilate = -1; 
  options.prefix[0] = '\0';

  for (int i = 1; i < argc; i++) 
  {
  
    /* binary threshold */
    if (strcmp(argv[i], "-t") == 0 && (argc - i) > 2) { 
      if (!NUMERIC(argv[i+1][0]) || !NUMERIC(argv[i+2][0])) 
        return 0; 
      options.low = atoi(argv[++i]); 
      options.high = atoi(argv[++i]); 
      if (options.low < 0 || options.low > options.high || options.high > 255)
        return 0; 
    } 
    
    /* binary morpholoy */ 
    else if (strcmp(argv[i], "-m") == 0 && (argc - i) > 2) { 
      if (!NUMERIC(argv[i+1][0]) || !NUMERIC(argv[i+2][0])) 
        return 0; 
      options.erode = atoi(argv[++i]); 
      options.dilate = atoi(argv[++i]); 
      if (options.erode < 0 || options.dilate < 0)
        return 0; 
      if (options.low == -1) {
        options.low = 40; 
        options.high = 60;
      }
    }
    
    /* output file prefix */ 
    else if (strcmp(argv[i], "-f") == 0 && (argc - i) > 1) { 
      i++; 
      for (int j = 0; j < strlen(argv[i]); j++) {
        if (!ALPHABETIC(argv[i][j])) 
          return 0;
      }
      strcpy(options.prefix, argv[i]); 
    }
    
    /* shrink factor */ 
    else if (strcmp(argv[i], "-s") == 0 && (argc - i) > 1) { 
      options.shrink_factor = atoi(argv[++i]);
      if (options.shrink_factor < 1)
        return 0; 
    }
    else 
      return 0; 
    
  }
  
  if (options.shrink_factor < 0) 
    options.shrink_factor = 1; 

  if (options.prefix[0] == '\0')
    strcpy(options.prefix, "test"); 

  return 1; 

} // parse_options()
예제 #8
0
static void NUMERIC (WDIM, r)
(
    int update,		/* TRUE for update, FALSE for downdate */
    cholmod_sparse *C,	/* in packed or unpacked, and sorted form */
			/* no empty columns */
    Int rank,		/* rank of the update/downdate */
    cholmod_factor *L,	/* with unit diagonal (diagonal not stored) */
			/* temporary workspaces: */
    double W [ ],	/* n-by-WDIM dense matrix, initially zero */
    Path_type Path [ ],
    Int npaths,
    cholmod_common *Common
)
{
    double Alpha [8] ;
    double *Cx, *Wpath, *W1, *a ;
    Int j, p, ccol, pend, wfirst, e, path, packed ;
    Int *Ci, *Cp, *Cnz ;

    /* ---------------------------------------------------------------------- */
    /* get inputs */
    /* ---------------------------------------------------------------------- */

    Ci = C->i ;
    Cx = C->x ;
    Cp = C->p ;
    Cnz = C->nz ;
    packed = C->packed ;
    ASSERT (IMPLIES (!packed, Cnz != NULL)) ;
    ASSERT (L->n == C->nrow) ;
    DEBUG (CHOLMOD(dump_real) ("num_d: in W:", W, WDIM, L->n, FALSE, 1,Common));

    /* ---------------------------------------------------------------------- */
    /* scatter C into W */
    /* ---------------------------------------------------------------------- */

    for (path = 0 ; path < rank ; path++)
    {
	/* W (:, path) = C (:, Path [path].col) */
	ccol = Path [path].ccol ;
	Wpath = W + path ;
	PRINT1 (("Ordered Columns [path = "ID"] = "ID"\n", path, ccol)) ;
	p = Cp [ccol] ;
	pend = (packed) ? (Cp [ccol+1]) : (p + Cnz [ccol]) ;
	/* column C can be empty */
	for ( ; p < pend ; p++)
	{
	    ASSERT (Ci [p] >= 0 && Ci [p] < (Int) (C->nrow)) ;
	    Wpath [WDIM * Ci [p]] = Cx [p] ;
	    PRINT1 (("    row "ID" : %g\n", Ci [p], Cx [p])) ;
	}
	Alpha [path] = 1.0 ;
    }
    DEBUG (CHOLMOD(dump_real) ("num_d: W:", W, WDIM, L->n, FALSE, 1,Common)) ;

    /* ---------------------------------------------------------------------- */
    /* numeric update/downdate of the paths */
    /* ---------------------------------------------------------------------- */

    /* for each disjoint subpath in Tbar in DFS order do */
    for (path = rank ; path < npaths ; path++)
    {

	/* determine which columns of W to use */
	wfirst = Path [path].wfirst ;
	e = Path [path].end ;
	j = Path [path].start ;
	ASSERT (e >= 0 && e < (Int) (L->n)) ;
	ASSERT (j >= 0 && j < (Int) (L->n)) ;

	W1 = W + wfirst ;	/* pointer to row 0, column wfirst of W */
	a = Alpha + wfirst ;	/* pointer to Alpha [wfirst] */

	PRINT1 (("Numerical update/downdate of path "ID"\n", path)) ;
	PRINT1 (("start "ID" end "ID" wfirst "ID" rank "ID" ccol "ID"\n", j, e,
		wfirst, Path [path].rank, Path [path].ccol)) ;

#if WDIM == 1
	NUMERIC (WDIM,1) (update, j, e, a, W1, L, Common) ;
#else

	switch (Path [path].rank)
	{
	    case 1:
		NUMERIC (WDIM,1) (update, j, e, a, W1, L, Common) ;
		break ;

#if WDIM >= 2
	    case 2:
		NUMERIC (WDIM,2) (update, j, e, a, W1, L, Common) ;
		break ;
#endif

#if WDIM >= 4
	    case 3:
		NUMERIC (WDIM,3) (update, j, e, a, W1, L, Common) ;
		break ;
	    case 4:
		NUMERIC (WDIM,4) (update, j, e, a, W1, L, Common) ;
		break ;
#endif

#if WDIM == 8
	    case 5:
		NUMERIC (WDIM,5) (update, j, e, a, W1, L, Common) ;
		break ;
	    case 6:
		NUMERIC (WDIM,6) (update, j, e, a, W1, L, Common) ;
		break ;
	    case 7:
		NUMERIC (WDIM,7) (update, j, e, a, W1, L, Common) ;
		break ;
	    case 8:
		NUMERIC (WDIM,8) (update, j, e, a, W1, L, Common) ;
		break ;
#endif

	}
#endif

    }
}
예제 #9
0
파일: gcode.cpp 프로젝트: OrangeFlare/4MAX
// Populate all fields by parsing a single line of GCode
// 58 bytes of SRAM are used to speed up seen/value
void GCodeParser::parse(char *p) {

  reset(); // No codes to report

  // Skip spaces
  while (*p == ' ') ++p;

  // Skip N[-0-9] if included in the command line
  if (*p == 'N' && NUMERIC_SIGNED(p[1])) {
    #if ENABLED(FASTER_GCODE_PARSER)
      //set('N', p + 1);     // (optional) Set the 'N' parameter value
    #endif
    p += 2;                  // skip N[-0-9]
    while (NUMERIC(*p)) ++p; // skip [0-9]*
    while (*p == ' ')   ++p; // skip [ ]*
  }

  // *p now points to the current command, which should be G, M, or T
  command_ptr = p;

  // Get the command letter, which must be G, M, or T
  const char letter = *p++;

  // Nullify asterisk and trailing whitespace
  char *starpos = strchr(p, '*');
  if (starpos) {
    --starpos;                          // *
    while (*starpos == ' ') --starpos;  // spaces...
    starpos[1] = '\0';
  }

  // Bail if the letter is not G, M, or T
  switch (letter) { case 'G': case 'M': case 'T': break; default: return; }

  // Skip spaces to get the numeric part
  while (*p == ' ') p++;

  // Bail if there's no command code number
  if (!NUMERIC(*p)) return;

  // Save the command letter at this point
  // A '?' signifies an unknown command
  command_letter = letter;

  // Get the code number - integer digits only
  codenum = 0;
  do {
    codenum *= 10, codenum += *p++ - '0';
  } while (NUMERIC(*p));

  // Allow for decimal point in command
  #if USE_GCODE_SUBCODES
    if (*p == '.') {
      p++;
      while (NUMERIC(*p))
        subcode *= 10, subcode += *p++ - '0';
    }
  #endif

  // Skip all spaces to get to the first argument, or nul
  while (*p == ' ') p++;

  // The command parameters (if any) start here, for sure!

  #if DISABLED(FASTER_GCODE_PARSER)
    command_args = p; // Scan for parameters in seen()
  #endif

  // Only use string_arg for these M codes
  if (letter == 'M') switch (codenum) { case 23: case 28: case 30: case 117: case 118: case 928: string_arg = p; return; default: break; }

  #if ENABLED(DEBUG_GCODE_PARSER)
    const bool debug = codenum == 800;
  #endif

  /**
   * Find all parameters, set flags and pointers for fast parsing
   *
   * Most codes ignore 'string_arg', but those that want a string will get the right pointer.
   * The following loop assigns the first "parameter" having no numeric value to 'string_arg'.
   * This allows M0/M1 with expire time to work: "M0 S5 You Win!"
   */
  string_arg = NULL;
  while (char code = *p++) {                    // Get the next parameter. A NUL ends the loop

    // Special handling for M32 [P] !/path/to/file.g#
    // The path must be the last parameter
    if (code == '!' && letter == 'M' && codenum == 32) {
      string_arg = p;                           // Name starts after '!'
      char * const lb = strchr(p, '#');         // Already seen '#' as SD char (to pause buffering)
      if (lb) *lb = '\0';                       // Safe to mark the end of the filename
      return;
    }

    // Arguments MUST be uppercase for fast GCode parsing
    #if ENABLED(FASTER_GCODE_PARSER)
      #define PARAM_TEST WITHIN(code, 'A', 'Z')
    #else
      #define PARAM_TEST true
    #endif

    if (PARAM_TEST) {

      while (*p == ' ') p++;                    // Skip spaces between parameters & values
      const bool has_num = DECIMAL_SIGNED(*p);  // The parameter has a number [-+0-9.]

      #if ENABLED(DEBUG_GCODE_PARSER)
        if (debug) {
          SERIAL_ECHOPAIR("Got letter ", code); // DEBUG
          SERIAL_ECHOPAIR(" at index ", (int)(p - command_ptr - 1)); // DEBUG
          if (has_num) SERIAL_ECHOPGM(" (has_num)");
        }
      #endif

      if (!has_num && !string_arg) {            // No value? First time, keep as string_arg
        string_arg = p - 1;
        #if ENABLED(DEBUG_GCODE_PARSER)
          if (debug) SERIAL_ECHOPAIR(" string_arg: ", hex_address((void*)string_arg)); // DEBUG
        #endif
      }

      #if ENABLED(DEBUG_GCODE_PARSER)
        if (debug) SERIAL_EOL();
      #endif

      #if ENABLED(FASTER_GCODE_PARSER)
        set(code, has_num ? p : NULL            // Set parameter exists and pointer (NULL for no number)
          #if ENABLED(DEBUG_GCODE_PARSER)
            , debug
          #endif
        );
      #endif
    }
    else if (!string_arg) {                     // Not A-Z? First time, keep as the string_arg
      string_arg = p - 1;
      #if ENABLED(DEBUG_GCODE_PARSER)
        if (debug) SERIAL_ECHOPAIR(" string_arg: ", hex_address((void*)string_arg)); // DEBUG
      #endif
    }

    if (!WITHIN(*p, 'A', 'Z')) {
      while (*p && NUMERIC(*p)) p++;            // Skip over the value section of a parameter
      while (*p == ' ') p++;                    // Skip over all spaces
    }
  }
}
예제 #10
0
CTimeSpanX &CTimeSpanX::operator*=(int n)
{
	NUMERIC(impl_->t) *= n;
	return *this;
}
예제 #11
0
CTimeX &CTimeX::operator+=(const CTimeSpanX &d)
{
	if(d.impl_->direction) NUMERIC(impl_->t) += NUMERIC(d.impl_->t);
	else NUMERIC(impl_->t) -= NUMERIC(d.impl_->t);
	return *this;
}
예제 #12
0
bool CTimeX::operator==(const CTimeX &t) const
{
	return NUMERIC(impl_->t) == NUMERIC(t.impl_->t);
}