[feat](trx-logbook): work a contest, and record what came back
Phase 5 of the logbook: the exchange, the entry sponsors take, and the confirmations an award counts. Contest fields go on the contact — the contest, the serials both ways as numbers and as words, and the zones — because an exchange is not always a number: a zone, a section or a name goes in as written. The serial sent and the contest stay between contacts, since they belong to the session and not to the contact just logged, and the serial counts on by itself rather than being retyped forty times an hour. Cabrillo 3.0 is written because ADIF cannot do this job: sponsors take Cabrillo and reject everything else. Its shape is not ADIF's either — the frequency is kilohertz below 30 MHz and a band designator above it, the modes are CW, PH, FM, RY and DG, and the contacts go oldest first, as a contest log is read. The header cannot be derived from a log — how many operators, how much power, what the score is claimed to be — so it comes from the operator, with single-op, low power, all bands and mixed behind it. QSL, LoTW and eQSL states are held as ADIF's single letters, and anything else is refused rather than written: a log that grew states of its own would be one no other program could read. A contact is confirmed when any one of the three says so — an award wants a card or an electronic match, not one of each, and counting them separately would tell the operator they were short of what they have. The bands report counts contacts, distinct stations and confirmations per band, ordered by wavelength as a band plan reads. Closes #54 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyX26FCpMQxiBoC7r5K1A7 Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
@@ -47,8 +47,28 @@ const MODELLED: &[&str] = &[
|
||||
"OPERATOR",
|
||||
"MY_GRIDSQUARE",
|
||||
"MY_RIG",
|
||||
"CONTEST_ID",
|
||||
"STX",
|
||||
"STX_STRING",
|
||||
"SRX",
|
||||
"SRX_STRING",
|
||||
"CQZ",
|
||||
"ITUZ",
|
||||
"QSL_SENT",
|
||||
"QSL_RCVD",
|
||||
"LOTW_QSL_SENT",
|
||||
"LOTW_QSL_RCVD",
|
||||
"EQSL_QSL_SENT",
|
||||
"EQSL_QSL_RCVD",
|
||||
];
|
||||
|
||||
/// ADIF's QSL states are single letters; anything else in that field is a
|
||||
/// misunderstanding on the writer's part and is not carried into ours.
|
||||
fn qsl_state(value: Option<&str>) -> Option<String> {
|
||||
let state = value?.trim().to_uppercase();
|
||||
matches!(state.as_str(), "Y" | "N" | "R" | "I" | "Q" | "V").then_some(state)
|
||||
}
|
||||
|
||||
/// What a file gave up, and what it could not.
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct ParseReport {
|
||||
@@ -215,6 +235,19 @@ fn qso_from_fields(fields: &[Field]) -> Result<Qso, String> {
|
||||
my_gridsquare: find(fields, "MY_GRIDSQUARE").map(|g| g.to_uppercase()),
|
||||
my_rig: find(fields, "MY_RIG").map(str::to_string),
|
||||
rig_id: None,
|
||||
contest_id: find(fields, "CONTEST_ID").map(|c| c.to_uppercase()),
|
||||
stx: find(fields, "STX").and_then(|value| value.parse().ok()),
|
||||
stx_string: find(fields, "STX_STRING").map(str::to_string),
|
||||
srx: find(fields, "SRX").and_then(|value| value.parse().ok()),
|
||||
srx_string: find(fields, "SRX_STRING").map(str::to_string),
|
||||
cqz: find(fields, "CQZ").and_then(|value| value.parse().ok()),
|
||||
ituz: find(fields, "ITUZ").and_then(|value| value.parse().ok()),
|
||||
qsl_sent: qsl_state(find(fields, "QSL_SENT")),
|
||||
qsl_rcvd: qsl_state(find(fields, "QSL_RCVD")),
|
||||
lotw_qsl_sent: qsl_state(find(fields, "LOTW_QSL_SENT")),
|
||||
lotw_qsl_rcvd: qsl_state(find(fields, "LOTW_QSL_RCVD")),
|
||||
eqsl_qsl_sent: qsl_state(find(fields, "EQSL_QSL_SENT")),
|
||||
eqsl_qsl_rcvd: qsl_state(find(fields, "EQSL_QSL_RCVD")),
|
||||
extra,
|
||||
})
|
||||
}
|
||||
@@ -273,11 +306,30 @@ pub fn write_adi(qsos: &[Qso], program_version: &str) -> String {
|
||||
("OPERATOR", &qso.operator),
|
||||
("MY_GRIDSQUARE", &qso.my_gridsquare),
|
||||
("MY_RIG", &qso.my_rig),
|
||||
("CONTEST_ID", &qso.contest_id),
|
||||
("STX_STRING", &qso.stx_string),
|
||||
("SRX_STRING", &qso.srx_string),
|
||||
("QSL_SENT", &qso.qsl_sent),
|
||||
("QSL_RCVD", &qso.qsl_rcvd),
|
||||
("LOTW_QSL_SENT", &qso.lotw_qsl_sent),
|
||||
("LOTW_QSL_RCVD", &qso.lotw_qsl_rcvd),
|
||||
("EQSL_QSL_SENT", &qso.eqsl_qsl_sent),
|
||||
("EQSL_QSL_RCVD", &qso.eqsl_qsl_rcvd),
|
||||
] {
|
||||
if let Some(value) = value {
|
||||
write_field(&mut out, name, value);
|
||||
}
|
||||
}
|
||||
for (name, value) in [
|
||||
("STX", qso.stx),
|
||||
("SRX", qso.srx),
|
||||
("CQZ", qso.cqz.map(u32::from)),
|
||||
("ITUZ", qso.ituz.map(u32::from)),
|
||||
] {
|
||||
if let Some(value) = value {
|
||||
write_field(&mut out, name, &value.to_string());
|
||||
}
|
||||
}
|
||||
if let Some(power) = qso.tx_pwr_w {
|
||||
write_field(&mut out, "TX_PWR", &format!("{power}"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user