Example #1
0
File: network.c Project: ADTL/TinyG
void tg_receiver()
{
//	tg_controller();	// this node executes gcode blocks received via RS485

//	int	getc_code = 0;
	int rx;

	xio_queue_RX_string_usart(XIO_DEV_RS485, "Z");		// simulate an RX char

	while (true) {
		while ((rx = xio_getc(XIO_DEV_RS485)) == -1);
		xio_putc(XIO_DEV_RS485, rx);	// write to RS485 port
//		xio_putc_rs485(rx, fdev_rs485);	// alternate form of above
//		gpio_toggle_port(1);
	}
}
Example #2
0
File: network.c Project: ADTL/TinyG
void tg_repeater()
{
//	uint8_t full_duplex = false;
	uint8_t full_duplex = true;
	unsigned char tx = 'Z';
	unsigned char rx;

	while (true) {
		tx = _nextchar(tx);
		xio_putc(XIO_DEV_RS485, tx);	// write to RS485 port
		if (full_duplex) {
			while ((rx = xio_getc(XIO_DEV_RS485)) == -1);	// blocking read
			xio_putc(XIO_DEV_USB, rx);	// echo RX to USB port
		} else {
			xio_putc(XIO_DEV_USB, tx);	// write TX to USB port
		}	
//		gpio_toggle_port(1);
//		_delay_ms(10);
	}
}
Example #3
0
catalog_t *
load_catalog (xio_file f, CONST char **error)
{
  int i;
  int line = 1;
  int size;
  int c;
  catalog_t *catalog = alloc_catalog ();
  static char errort[40];
  char name[1024];
  char value[1024];
  if (catalog == NULL)
    {
      *error = "Out of memory";
    }
  if (f == NULL)
    {
      *error = "File could not be opended";
      free_catalog (catalog);
      return NULL;
    }
  /* Just very simple parsing loop of format 
   * [blanks]name[blanks]"value"[blanks]
   * Blanks should be comments using # or space, newline, \r and tabulator
   * Value shoud contain and \ seqences where \\ means \ and
   * \[something] means something. Should be used for character "
   */
  while (!xio_feof (f))
    {

      do
	{
	  c = xio_getc (f);
	  if (c == '\n')
	    line++;
	  if (c == '#')
	    {
	      while ((c = xio_getc (f)) != '\n' && c != XIO_EOF);
	      line++;
	    }
	}
      while (c == ' ' || c == '\n' || c == '\r' || c == '\t');
      /*Skip blanks */
      if (c == XIO_EOF)
	{
	  if (xio_feof (f))
	    break;
	  free_catalog (catalog);
	  seterror ("read error");
	  xio_close (f);
	  return NULL;
	}
      i = 0;

      /*read name */
      do
	{
	  name[i] = c;
	  i++;
	  c = xio_getc (f);
	  if (c == '\n')
	    line++;
	  if (i == 1024)
	    {
	      seterror ("Name is too long(1024 or more characters)");
	      free_catalog (catalog);
	      xio_close (f);
	      return NULL;
	    }
	}
      while (c != '\n' && c != ' ' && c != '\t' && c != XIO_EOF);

      /*Skip blanks */
      while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
	{
	  c = xio_getc (f);
	  if (c == '\n')
	    line++;
	  if (c == '#')
	    {
	      while ((c = xio_getc (f)) != '\n' && c != XIO_EOF);
	      line++;
	    }
	}

      /*Skip blanks */
      if (c == XIO_EOF)
	{
	  if (xio_feof (f))
	    seterror ("Inexpected end of file after name field");
	  else
	    seterror ("read error");
	  free_catalog (catalog);
	  xio_close (f);
	  return NULL;
	}
      name[i] = 0;
      if (c != '"')
	{
	  seterror ("Begin of value field expected (\")");
	  free_catalog (catalog);
	  xio_close (f);
	  return NULL;
	}
      c = xio_getc (f);
      if (c == '\n')
	line++;
      i = 0;

      size = 0;
      do
	{
	  if (c == '\\')
	    value[i] = xio_getc (f);
	  else
	    value[i] = c;
	  i++;
	  c = xio_getc (f);
	  if (c == '\n')
	    line++, size = 0;
	  if (size == 40 && c != '"')
	    {
	      fprintf (stderr, "Warning - too long text at line %i\n", line);
	    }
	  size++;
	  if (i == 1024)
	    {
	      seterror ("Value is too long(1024 or more characters)");
	      free_catalog (catalog);
	      xio_close (f);
	      return NULL;
	    }
	}
      while (c != '"' && c != XIO_EOF);

      if (c == XIO_EOF)
	{
	  seterror ("Inexpeced end of file in value filed");
	  free_catalog (catalog);
	  xio_close (f);
	  return NULL;
	}
      value[i] = 0;
      find_variable (catalog, name, value);
    }				/*while */
  xio_close (f);
  return (catalog);
}				/*load_catalog */