Esempio n. 1
0
/* Parses the specified NMEA sentence and saves the values of interest
 * to the statevars variable
 */
static void parse_gps_sentence(char * sentence) {
  if (strncmp(sentence, GPGGA_START, START_LENGTH) == 0) {
    // ---- DEBUG
    //uwrite_print_buff("GPGGA found!\r\n");
    //uwrite_print_buff(sentence);
    // Copy the GPGGA sentence to statevars regardless of checksum; and
    // include any null chars as well (versus strcpy)
    memcpy(statevars.gps_sentence0, sentence, GPS_SENTENCE_BUFF_SZ);

    // Parse the sentence only if the checksum is valid
    if (validate_checksum(sentence) == 1) {
      parse_gpgga(sentence);
      // TODO: Consider changing the macro to STATUS_GPS_VALID_GPGGA_RCVD
      statevars.status |= STATUS_GPS_GPGGA_RCVD;
    }
  } else if (strncmp(sentence, GPGSA_START, START_LENGTH) == 0) {
    // ---- DEBUG
    //uwrite_print_buff("GPGSA found!\r\n");
    //uwrite_print_buff(sentence);

    memcpy(statevars.gps_sentence1, sentence, GPS_SENTENCE_BUFF_SZ);

    if (validate_checksum(sentence) == 1) {
      parse_gpgsa(sentence);
      statevars.status |= STATUS_GPS_GPGSA_RCVD;
    }
  } else if (strncmp(sentence, GPRMC_START, START_LENGTH) == 0) {
    // ---- DEBUG
    //uwrite_print_buff("GPRMC found!\r\n");
    //uwrite_print_buff(sentence);

    memcpy(statevars.gps_sentence2, sentence, GPS_SENTENCE_BUFF_SZ);

    if (validate_checksum(sentence) == 1) {
      parse_gprmc(sentence);
      statevars.status |= STATUS_GPS_GPRMC_RCVD;
    }
  } else if (strncmp(sentence, GPVTG_START, START_LENGTH) == 0) {
    // ---- DEBUG
    //uwrite_print_buff("GPVTG found!\r\n");
    //uwrite_print_buff(sentence);

    memcpy(statevars.gps_sentence3, sentence, GPS_SENTENCE_BUFF_SZ);

    if (validate_checksum(sentence) == 1) {
      parse_gpvtg(sentence);
      statevars.status |= STATUS_GPS_GPVTG_RCVD;
    }
  } else {
    // We don't care about the GPGSV sentences

    // ---- DEBUG
    //uwrite_print_buff("GPGSV ignored\r\n");
  }

  return;
}
Esempio n. 2
0
gchar *
cockpit_package_resolve (GHashTable *listing,
                         const gchar *package,
                         const gchar *path)
{
  CockpitPackage *mod;

  /*
   * This is *not* a security check. We're accessing files as the user.
   * What this does is prevent package authors from drawing outside the
   * lines. Keeps everyone honest.
   */
  if (strstr (path, "../") || strstr (path, "/..") || !validate_path (path))
    {
      g_message ("invalid 'path' used as a resource: %s", path);
      return NULL;
    }

  if (!validate_checksum (package) && !validate_package (package))
    {
      g_message ("invalid 'package' name: %s", package);
      return NULL;
    }

  mod = g_hash_table_lookup (listing, package);
  if (mod == NULL)
    {
      g_debug ("resource package was not found: %s", package);
      return NULL;
    }

  return g_build_filename (mod->directory, path, NULL);
}
bool NexstarMessageReceiver::process(int data) {
	// Too long delay between uint8_ts?
	unsigned long current_millis=millis();

	if (last_receive_timestamp != -1
			&& current_millis - last_receive_timestamp > 250) {
		reset();
		return false;
	}
	last_receive_timestamp = current_millis;

	if ((!preamble_received) && (data == MSG_PREAMBLE)) {
		index = 0;
		preamble_received = true;
		message.data[index++] = data;
		return false;
	}

	if (preamble_received && (index == 1)) {
		length_received = true;
		message.data[index++] = data;

		// Plausi check
		if (data > 15) {
			reset();
			return false;
		}

		last_index = data + 3;

		return false;
	}

	if (length_received && (index > 1)) {
		message.data[index++] = data;
	}

	// Wir sind fertig
	if (index == last_index) {
		reset();
		finished = true;

		valid = validate_checksum();

		return valid;
	}

	return false;
}
Esempio n. 4
0
static void serial_parse_buffer(SerialInstance* instance)
{
  uint index = 0;

  if (instance->_ReceiveBuffer[index] != STX)
    return;

  increment_index(&index);

  InputCommand command = (InputCommand)instance->_ReceiveBuffer[index];
  increment_index(&index);

  // Extract out the sub-command
  uchar subcommand = instance->_ReceiveBuffer[index];
  increment_index(&index);

  // Extract out the length 1 (LSB)
  uchar length1 = instance->_ReceiveBuffer[index];
  increment_index(&index);

  // Extract out the length 2 (MSB)
  uchar length2 = instance->_ReceiveBuffer[index];
  increment_index(&index);

  ushort length = length1 | (length2 << 8);

  // Only continue if our Buffer is large enough
  if (instance->_BufferIndex - RX_MIN_SIZE < length)
    return;

  // Extract out the data-frame
  uchar dataframe[length];
  for (int i = 0; i < length; i++)
  {
    dataframe[i] = instance->_ReceiveBuffer[index];
    increment_index(&index);
  }

  // Extract out the checksum
  uchar crc1 = instance->_ReceiveBuffer[index];
  increment_index(&index);
  uchar crc2 = instance->_ReceiveBuffer[index];
  increment_index(&index);

  ushort checksum = crc1 | (crc2 << 8);

  if (!validate_checksum(checksum, command, subcommand, length, dataframe))
  {
    // Unexpected / bad data
    serial_instance_write(instance, NAK);
    return;
  }
  // Finally, we should have an ETX
  if (instance->_ReceiveBuffer[index] != ETX)
  {
    serial_instance_write(instance, NAK);
    return;
  }

  // Build output
  SysInput input = {0};
  input.Type = SysInput_Serial;
  input.Command = command;
  input.Subcommand = subcommand;
  input.Length = length;

  for (int i = 0; i < length; i++)
    input.Dataframe[i] = dataframe[i];

  // Send the acknowledgment byte back
  serial_instance_write(instance, ACK);

  // Scramble the frame
  instance->_ReceiveBuffer[0] = 0x00;
  instance->_ReceiveBuffer[index] = 0x00;

  // Handle the input. TODO: Could put this in the application domain
  if (InputHandler != NULL)
    InputHandler((void*)instance, input);
}