Exemple #1
0
// Inssert real-time science data into an EPM data packet.
void InsertGripRealtimeDataInfo( EPMTelemetryPacket *epm_packet, const GripRealtimeDataInfo *realtime_packet ) {

	char *ptr;
	int slice;
	int sensor;
	int i;

	// Point to the actual data in the packet.
	ptr = epm_packet->sections.rawData;

	// Set the acquisition ID and packet count for that acquisition.
	ptr += insert_ulong( ptr, realtime_packet->acquisitionID );
	ptr += insert_ulong( ptr, realtime_packet->rtPacketCount ); 
	for ( slice = 0; slice < RT_SLICES_PER_PACKET; slice++ ) {
		// Insert the manipulandum pose data. 
		ptr += insert_ulong( ptr, realtime_packet->dataSlice[slice].poseTick );
		for ( i = X; i <= Z; i++ ) ptr += insert_short( ptr, (short) (realtime_packet->dataSlice[slice].position[i] * 10.0));
		for ( i = X; i <= M; i++ ) ptr += insert_float( ptr, (float) realtime_packet->dataSlice[slice].quaternion[i] );
		for ( i = 0; i < 2; i++ ) ptr += insert_ulong( ptr, realtime_packet->dataSlice[slice].markerVisibility[i] );
		*ptr = realtime_packet->dataSlice[slice].manipulandumVisibility; ptr++;
		// Insert the analog data.
		ptr += insert_ulong( ptr, realtime_packet->dataSlice[slice].analogTick );
		for ( sensor = 0; sensor < 2; sensor++ ) {
			for ( i = X; i <= Z; i++ ) ptr += insert_short( ptr, (short) (realtime_packet->dataSlice[slice].ft[sensor].force[i] * 100.0));
			for ( i = X; i <= Z; i++ ) ptr += insert_short( ptr, (short) (realtime_packet->dataSlice[slice].ft[sensor].torque[i] * 1000.0));
		}
		for ( i = X; i <= Z; i++ ) ptr += insert_long( ptr, (long) (realtime_packet->dataSlice[slice].acceleration[i] * 1000.0 * 9.8));
	}
}
Exemple #2
0
int
main P2C(int, argc,  string *, argv)
{
  register char *cp;
  int blanks_done, indent, i;
  char *program_name = "";

  kpse_set_program_name (argv[0], NULL); /* In case we use FATAL.  */

  for (i = 1; i < argc; i++)
    {
      if (STREQ(argv[i],"-t"))
	tex = true;
      else
	program_name = argv[i];
    }

  while (fgets (buf, BUFSIZ, stdin))
    {
      remove_newline (buf);
      blanks_done = false;

      for (cp = buf; *cp; ++cp) ;

      while (cp != buf && *--cp == ' ') ;

      while (*cp == '.')
	{
	  join (cp + 1);
	  while (*cp)
	    ++cp;
	  while (*--cp == ' ') ;
	}

      for (cp = buf, indent = 0; *cp == ' ' || *cp == '\t'; ++cp)
	{
	  if (*cp == ' ')
	    indent++;
	  else
	    indent += 8;
	}

      if (!*cp)
	{			/* All blanks, possibly with "{" */
	  puts (buf);
	  continue;
	}
      if (*cp == '{')

        {
	  do_blanks (indent);
	  putchar ('{');
	  ++cp;
	  while (*cp == ' ' || *cp == '\t')
	    ++cp;
	  blanks_done = true;
	  if (!*cp)
	    {
	      putchar ('\n');
	      continue;
	    }
	}

      if (!blanks_done)
	do_blanks (indent);

      if (strncmp (cp, "read ( input", 12) == 0)
	{
	  char variable_name[20];
	  if (sscanf (cp, "read ( input , %s )", variable_name) != 1)
            {
  	      fprintf (stderr, "sscanf failed\n");
              uexit (1);
            }
	  printf ("%s = getint();\n", variable_name);
	  continue;
	}

      if (strncmp (cp, "lab", 3) == 0 && strchr (cp, ':'))
	{
	  do
	    {
	      putchar (*cp);
	    }
          while (*cp++ != ':');

          while (*cp == ' ')
	    ++cp;
	  putchar (' ');
	}

      if (strncmp (cp, "else write", 10) == 0)
	{
	  puts ("else");
	  do_blanks (indent);
	  cp += 5;
	  while (*cp == ' ')
	    ++cp;
	}

      if (bare (cp, '{'))
	{
	  while (*cp != '{')
	    {
	      putchar (*cp);
	      ++cp;
	    }
	  ++cp;
	  puts ("{");
	  indent += 4;
	  do_blanks (indent);
	  while (*cp == ' ')
	    ++cp;
	}

      if (strncmp (cp, "write (", 7) && strncmp (cp, "writeln (", 9))
	{
	  /* if not a write/writeln, just copy it to stdout and continue */
	  puts (cp);
	  continue;
	}
      cmd = cp;
      while (!whole (buf))	/* make sure we have whole stmt */
	{
	  fgets (&buf[strlen (buf)], BUFSIZ - strlen (buf), stdin);
	  remove_newline (buf);
	}

      while (*cp != '(')
	++cp;
      ++cp;
      while (*(cp + 1) == ' ')
	++cp;

      /* Some writes start with a variable, instead of a file. */
      if (*(cp + 1) == '"' || *(cp + 1) == '\''
          || strncmp (cp + 1, "buffer", 6) == 0
          || strncmp (cp + 1, "xchr", 4) == 0
          || strncmp (cp + 1, "k ,", 3) == 0
          || strncmp (cp + 1, "s ,", 3) == 0
          || strncmp (cp + 1, "dig", 3) == 0
          || strncmp (cp + 1, "HEX", 3) == 0
          || strncmp (cp + 1, "versionstring", 13) == 0
          || strncmp (cp + 1, "kpathseaversionstring", 21) == 0
         )
	strcpy (filename, "stdout");
      else
	{
	  file = filename;
	  while (*cp != ',' && *cp != ')')
	    *file++ = *cp++;
	  *file = '\0';
	}
      if (*cp == ')')
	{
	  printf ("putc%s ('\\n', %s);\n", oem, filename);
	  continue;
	}
      argp = ++cp;
      as = args;
      while (*cp == ' ')
	++cp;
      while (*cp != ')')
	{
	  if (*cp == '\'' || strncmp (cp, "xchr", 4) == 0
              || (strncmp (cp ,"HEX", 3) == 0
                  && (STREQ (program_name, "ofm2opl")
                      || STREQ (program_name, "opl2ofm")
                      || STREQ (program_name, "ovp2ovf")
                      || STREQ (program_name, "ovf2ovp")))
	      || strncmp (cp, "ASCII04", 7) == 0
	      || strncmp (cp, "ASCII1", 6) == 0
	      || strncmp (cp, "ASCIIall", 8) == 0              
	      || strncmp (cp, "months", 6) == 0
	      || strncmp (cp, "nameoffile", 10) == 0
	      || (strncmp (cp, "buffer", 6) == 0
                  && (STREQ (program_name, "vptovf")
                      || STREQ (program_name, "pltotf")
                      || STREQ (program_name, "ovp2ovf")
                      || STREQ (program_name, "ofm2opl")))
              || (((strncmp (cp, "buf", 3) == 0
		    || strncmp (cp, "xdig", 4) == 0
		    || strncmp (cp, "xext", 4) == 0
		    || strncmp (cp, "xhyf", 4) == 0)
                  && STREQ (program_name, "patgen")))
             )
	    {
	      *as++ = '%';
	      *as++ = 'c';
	      if (tex && strncmp (cp, "xchr", 4) == 0)
		{
		  *cp = 'X';
		  cp = strchr (cp, '[');
		  *cp = '(';
		  cp = advance_cp(cp,1);
		  *cp++ = ')';
		}
	      else if (*cp == '\'')
		cp += 2;
	    }
          
	  else if (*cp == '"')
	    {
	      *as++ = '%';
	      *as++ = 's';
	      while (*++cp != '"')	/* skip to end of string */
		if (*cp == '\\')
		  ++cp;		/* allow \" in string */
	    }

          /* More kludge -- versionstring is a string, not a number, so
             we have to use %s.  */
          else if (strncmp (cp, "versionstring", 13) == 0)
            {
              *as++ = '%';
              *as++ = 's';
            }

          else
	    {
	      *as++ = '%';
	      *as++ = 'l';
	      *as++ = 'd';
	      cp = insert_long (cp);
	      cp = skip_balanced (cp);	/* It's a numeric expression */
	    }
	  while (*cp != ',' && *cp != ')')
	    ++cp;
	  while (*cp == ',' || *cp == ' ')
	    ++cp;
	}

      if (strncmp (cmd, "writeln", 7) == 0)
	{
	  *as++ = '\\';
	  *as++ = 'n';
	}

      *as = '\0';
      if (strcmp (args, "%c") == 0)
	{
	  for (as = argp; *as; ++as) ;
	  while (*--as != ')') ;
	  *as = '\0';
	  printf ("putc%s (%s, %s);\n", oem, argp, filename);
	}
      else if (STREQ (args, "%s"))
        printf ("Fputs%s (%s, %s\n", oem, filename, argp);
      else
        printf ("fprintf%s (%s, \"%s\", %s\n", oem, filename, args, argp);
    }

  return EXIT_SUCCESS;
}