/**
 * Reads the NMEA sentence into the specified structure.
 *
 * @param[out] nmea Structure to hold the parsed data.
 * @param[in] s Start of the string to parse (inclusive).
 * @param[in] e End of the string to parse (exclusive).
 * @retval -1 Parameter failure, parsing error.
 * @retval  0 Success
 */
static int read(struct nmea_t * nmea, const char * s, const char * e)
{
	struct nmea_ii_dbt_t * v;
	int state = 0;
	const char * p;

	if (nmea == NULL || s == NULL || e == NULL) return -1;
	nmea->type = NMEA_II_DBT;
	v = &nmea->sentence.ii_dbt;
	p = find_token_end(s);
	for (state = -1; state < 6 && s < e; ++state) {
		switch (state) {
			case  0: if (nmea_fix_parse(s, p, &v->depth_feet) != p) return -1; break;
			case  1: v->depth_unit_feet = (s == p) ? NMEA_UNIT_FEET : *s; break;
			case  2: if (nmea_fix_parse(s, p, &v->depth_meter) != p) return -1; break;
			case  3: v->depth_unit_meter = (s == p) ? NMEA_UNIT_METER : *s; break;
			case  4: if (nmea_fix_parse(s, p, &v->depth_fathom) != p) return -1; break;
			case  5: v->depth_unit_fathom = (s == p) ? NMEA_UNIT_FATHOM : *s; break;
			default: break;
		}
		s = p + 1;
		p = find_token_end(s);
	}
	return 0;
}
/**
 * Reads the NMEA sentence into the specified structure.
 *
 * @param[out] nmea Structure to hold the parsed data.
 * @param[in] s Start of the string to parse (inclusive).
 * @param[in] e End of the string to parse (exclusive).
 * @retval -1 Parameter failure, parsing error.
 * @retval  0 Success
 */
static int read(struct nmea_t * nmea, const char * s, const char * e)
{
	struct nmea_bod_t * v;
	int state = 0;
	const char * p;

	if (nmea == NULL || s == NULL || e == NULL) return -1;
	nmea->type = NMEA_BOD;
	v = &nmea->sentence.bod;
	p = find_token_end(s);
	for (state = -1; state < 6; ++state) {
		switch (state) {
			case  0: if (nmea_fix_parse(s, p, &v->bearing_true) != p) return -1; break;
			case  1: v->type_true = (s == p) ? NMEA_TRUE : *s; break;
			case  2: if (nmea_fix_parse(s, p, &v->bearing_magn) != p) return -1; break;
			case  3: v->type_magn = (s == p) ? NMEA_MAGNETIC : *s; break;
			case  4: if (parse_int(s, p, &v->waypoint_to) != p) return -1; break;
			case  5: if (parse_int(s, p, &v->waypoint_from) != p) return -1; break;
			default: break;
		}
		s = p + 1;
		p = find_token_end(s);
	}
	return 0;
}
Exemple #3
0
	int Tokenizer::splitter( const string &trimmed_sent, V2_STR &data )
	{
		size_t	beg = 0, end = find_token_end( trimmed_sent, 0 ), n_tokens = 0;

		V1_STR	one_row;
		one_row.push_back( "token" );		

		while( end != string::npos ) {
			string	token = trimmed_sent.substr( beg, end - beg );

			if( token != " " ) {				// Put all tokens except a space token into the 'data' container
				one_row.back() = token;
				data.push_back( one_row );
				++n_tokens;
			}

			beg = end;
			end = find_token_end( trimmed_sent, beg );
		}

		return n_tokens;
	}
/**
 * Reads the NMEA sentence into the specified structure.
 *
 * @param[out] nmea Structure to hold the parsed data.
 * @param[in] s Start of the string to parse (inclusive).
 * @param[in] e End of the string to parse (exclusive).
 * @retval -1 Parameter failure, parsing error.
 * @retval  0 Success
 */
static int read(struct nmea_t * nmea, const char * s, const char * e)
{
	struct nmea_ii_vlw_t * v;
	int state = 0;
	const char * p;

	if (nmea == NULL || s == NULL || e == NULL) return -1;
	nmea->type = NMEA_II_VLW;
	v = &nmea->sentence.ii_vlw;
	p = find_token_end(s);
	for (state = -1; state < 4 && s < e; ++state) {
		switch (state) {
			case  0: if (nmea_fix_parse(s, p, &v->distance_cum) != p) return -1; break;
			case  1: v->distance_cum_unit = (s == p) ? NMEA_UNIT_NM : *s; break;
			case  2: if (nmea_fix_parse(s, p, &v->distance_reset) != p) return -1; break;
			case  3: v->distance_reset_unit = (s == p) ? NMEA_UNIT_NM : *s; break;
			default: break;
		}
		s = p + 1;
		p = find_token_end(s);
	}
	return 0;
}
/**
 * Reads the NMEA sentence into the specified structure.
 *
 * @param[out] nmea Structure to hold the parsed data.
 * @param[in] s Start of the string to parse (inclusive).
 * @param[in] e End of the string to parse (exclusive).
 * @retval -1 Parameter failure, parsing error.
 * @retval  0 Success
 */
static int read(struct nmea_t * nmea, const char * s, const char * e)
{
	struct nmea_ii_mwv_t * v;
	int state = 0;
	const char * p;

	if (nmea == NULL || s == NULL || e == NULL) return -1;
	nmea->type = NMEA_II_MWV;
	v = &nmea->sentence.ii_mwv;
	p = find_token_end(s);
	for (state = -1; state < 5 && s < e; ++state) {
		switch (state) {
			case  0: if (nmea_fix_parse(s, p, &v->angle) != p) return -1; break;
			case  1: v->type = (s == p) ? NMEA_RELATIVE : *s; break;
			case  2: if (nmea_fix_parse(s, p, &v->speed) != p) return -1; break;
			case  3: v->speed_unit = (s == p) ? NMEA_UNIT_KNOT : *s; break;
			case  4: v->status = (s == p) ? NMEA_STATUS_OK : *s; break;
			default: break;
		}
		s = p + 1;
		p = find_token_end(s);
	}
	return 0;
}
/**
 * Reads the NMEA sentence into the specified structure.
 *
 * @param[out] nmea Structure to hold the parsed data.
 * @param[in] s Start of the string to parse (inclusive).
 * @param[in] e End of the string to parse (exclusive).
 * @retval -1 Parameter failure, parsing error.
 * @retval  0 Success
 */
static int read(struct nmea_t * nmea, const char * s, const char * e)
{
	struct nmea_rte_t * v;
	int state = 0;
	const char * p;

	if (nmea == NULL || s == NULL || e == NULL) return -1;
	nmea->type = NMEA_RTE;
	v = &nmea->sentence.rte;
	p = find_token_end(s);
	for (state = -1; state < 13 && s < e; ++state) {
		switch (state) {
			case  0: if (parse_int(s, p, &v->n_messages) != p) return -1; break;
			case  1: if (parse_int(s, p, &v->message_number) != p) return -1; break;
			case  2: v->message_mode = (s == p) ? NMEA_COMPLETE_ROUTE : *s; break;
			case  3:
			case  4:
			case  5:
			case  6:
			case  7:
			case  8:
			case  9:
			case 10:
			case 11:
			case 12:
				if ((unsigned int)(p-s+1) < sizeof(v->waypoint_id[state-3])
					&& parse_str(s, p, v->waypoint_id[state-3]) != p)
					return -1;
				break;
			default: break;
		}
		s = p + 1;
		p = find_token_end(s);
	}
	return 0;
}