static std::string latlon_abs_normalized(const int32_t normalized, const char suffixes[2]) {
	const auto suffix = suffixes[(normalized < 0) ? 0 : 1];
	const uint32_t normalized_abs = std::abs(normalized);
	const uint32_t t = (normalized_abs * 5) / 3;
	const uint32_t degrees = t / (100 * 10000);
	const uint32_t fraction = t % (100 * 10000);
	return to_string_dec_uint(degrees) + "." + to_string_dec_uint(fraction, 6, '0') + suffix;
}
static std::string speed_over_ground(const SpeedOverGround value) {
	if( value == 1023 ) {
		return "not available";
	} else if( value == 1022 ) {
		return ">= 102.2 knots";
	} else {
		return to_string_dec_uint(value / 10) + "." + to_string_dec_uint(value % 10, 1) + " knots";
	}
}
static std::string course_over_ground(const CourseOverGround value) {
	if( value > 3600 ) {
		return "invalid";
	} else if( value == 3600 ) {
		return "not available";
	} else {
		return to_string_dec_uint(value / 10) + "." + to_string_dec_uint(value % 10, 1) + " deg";
	}
}
static std::string ticks_to_percent_string(const uint32_t ticks) {
	constexpr size_t decimal_digits = 1;
	constexpr size_t decimal_factor = decimal_digits * 10;

 	const uint32_t percent_x10 = ticks / (base_m4_clk_f / (100 * decimal_factor));
 	const uint32_t percent_x10_clipped = std::min(percent_x10, static_cast<uint32_t>(100 * decimal_factor) - 1);
	return
		to_string_dec_uint(percent_x10_clipped / decimal_factor, 2) + "." +
		to_string_dec_uint(percent_x10_clipped % decimal_factor, decimal_digits, '0');
}
Beispiel #5
0
void RecentEntriesView<TPMSRecentEntries>::draw(
	const Entry& entry,
	const Rect& target_rect,
	Painter& painter,
	const Style& style,
	const bool is_selected
) {
	const auto& draw_style = is_selected ? style.invert() : style;

	std::string line = tpms::format::type(entry.type) + " " + tpms::format::id(entry.id);

	if( entry.last_pressure.is_valid() ) {
		line += " " + tpms::format::pressure(entry.last_pressure.value());
	} else {
		line += " " "   ";
	}

	if( entry.last_temperature.is_valid() ) {
		line += " " + tpms::format::temperature(entry.last_temperature.value());
	} else {
		line += " " "   ";
	}

	if( entry.received_count > 999 ) {
		line += " +++";
	} else {
		line += " " + to_string_dec_uint(entry.received_count, 3);
	}

	line.resize(target_rect.width() / 8, ' ');
	painter.draw_string(target_rect.pos, draw_style, line);
}
Beispiel #6
0
void TPMSLogger::on_packet(const tpms::Packet& packet, const uint32_t target_frequency) {
	const auto hex_formatted = packet.symbols_formatted();

	// TODO: function doesn't take uint64_t, so when >= 1<<32, weirdness will ensue!
	const auto tuning_frequency_str = to_string_dec_uint(target_frequency, 10);

	std::string entry = tuning_frequency_str + " FSK 38.4 19.2 " + hex_formatted.data + "/" + hex_formatted.errors;
	log_file.write_entry(packet.received_at(), entry);
}
static std::string true_heading(const TrueHeading value) {
	if( value == 511 ) {
		return "not available";
	} else if( value > 359 ) {
		return "invalid";
	} else {
		return to_string_dec_uint(value) + " deg";
	}
}
Beispiel #8
0
DebugMemoryView::DebugMemoryView(NavigationView& nav) {
	add_children({ {
		&text_title,
		&text_label_m0_free,
		&text_label_m0_free_value,
		&text_label_m0_heap_fragmented_free,
		&text_label_m0_heap_fragmented_free_value,
		&text_label_m0_heap_fragments,
		&text_label_m0_heap_fragments_value,
		&button_done
	} });

	const auto m0_free = chCoreStatus();
	text_label_m0_free_value.set(to_string_dec_uint(m0_free, 5));

	size_t m0_fragmented_free_space = 0;
	const auto m0_fragments = chHeapStatus(NULL, &m0_fragmented_free_space);
	text_label_m0_heap_fragmented_free_value.set(to_string_dec_uint(m0_fragmented_free_space, 5));
	text_label_m0_heap_fragments_value.set(to_string_dec_uint(m0_fragments, 5));

	button_done.on_select = [&nav](Button&){ nav.pop(); };
}
void RecentEntriesTable<ERTRecentEntries>::draw(
	const Entry& entry,
	const Rect& target_rect,
	Painter& painter,
	const Style& style
) {
	std::string line = ert::format::id(entry.id) + " " + ert::format::commodity_type(entry.commodity_type) + " " + ert::format::consumption(entry.last_consumption);

	if( entry.received_count > 999 ) {
		line += " +++";
	} else {
		line += " " + to_string_dec_uint(entry.received_count, 3);
	}

	line.resize(target_rect.width() / 8, ' ');
	painter.draw_string(target_rect.location(), style, line);
}
static std::string rate_of_turn(const RateOfTurn value) {
	switch(value) {
	case -128: return "not available";
	case -127: return "left >5 deg/30sec";
	case    0: return "0 deg/min";
	case  127: return "right >5 deg/30sec";
	default:
		{
			std::string result = (value < 0) ? "left " : "right ";
			const float value_deg_sqrt = value / 4.733f;
			const int32_t value_deg = value_deg_sqrt * value_deg_sqrt;
			result += to_string_dec_uint(value_deg);
			result += " deg/min";
			return result;
		}
	}
}
Beispiel #11
0
void RecentEntriesView<ERTRecentEntries>::draw(
	const Entry& entry,
	const Rect& target_rect,
	Painter& painter,
	const Style& style,
	const bool is_selected
) {
	const auto& draw_style = is_selected ? style.invert() : style;

	std::string line = ert::format::id(entry.id) + " " + ert::format::commodity_type(entry.commodity_type) + " " + ert::format::consumption(entry.last_consumption);

	if( entry.received_count > 999 ) {
		line += " +++";
	} else {
		line += " " + to_string_dec_uint(entry.received_count, 3);
	}

	line.resize(target_rect.width() / 8, ' ');
	painter.draw_string(target_rect.pos, draw_style, line);
}
void AISRecentEntryDetailView::paint(Painter& painter) {
	View::paint(painter);

	const auto s = style();
	const auto rect = screen_rect();

	auto field_rect = Rect { rect.left(), rect.top() + 16, rect.width(), 16 };

	field_rect = draw_field(painter, field_rect, s, "MMSI", ais::format::mmsi(entry_.mmsi));
	field_rect = draw_field(painter, field_rect, s, "Name", entry_.name);
	field_rect = draw_field(painter, field_rect, s, "Call", entry_.call_sign);
	field_rect = draw_field(painter, field_rect, s, "Dest", entry_.destination);
	field_rect = draw_field(painter, field_rect, s, "Last", to_string_datetime(entry_.last_position.timestamp));
	field_rect = draw_field(painter, field_rect, s, "Pos ", ais::format::latlon(entry_.last_position.latitude, entry_.last_position.longitude));
	field_rect = draw_field(painter, field_rect, s, "Stat", ais::format::navigational_status(entry_.navigational_status));
	field_rect = draw_field(painter, field_rect, s, "RoT ", ais::format::rate_of_turn(entry_.last_position.rate_of_turn));
	field_rect = draw_field(painter, field_rect, s, "SoG ", ais::format::speed_over_ground(entry_.last_position.speed_over_ground));
	field_rect = draw_field(painter, field_rect, s, "CoG ", ais::format::course_over_ground(entry_.last_position.course_over_ground));
	field_rect = draw_field(painter, field_rect, s, "Head", ais::format::true_heading(entry_.last_position.true_heading));
	field_rect = draw_field(painter, field_rect, s, "Rx #", to_string_dec_uint(entry_.received_count));
}
Beispiel #13
0
std::string commodity_type(CommodityType value) {
	return to_string_dec_uint(value, 2);
}
Beispiel #14
0
std::string consumption(Consumption value) {
	return to_string_dec_uint(value, 10);
}
Beispiel #15
0
std::string id(ID value) {
	return to_string_dec_uint(value, 10);
}
Beispiel #16
0
std::string type(Reading::Type type) {
	return to_string_dec_uint(toUType(type), 2);
}
static std::string mmsi(
	const ais::MMSI& mmsi
) {
	return to_string_dec_uint(mmsi, 9);
}