Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ version says how old a build is, not how big its changes are. Whether a saved

## [Unreleased]

- UV5R-Mini: Forbid TX is preserved when reading and writing channels, including CSV imports with TX frequency set to zero.

## [2026.11.0] — 2026-11-27

- Channel wizard: new Marine (Australia) preset, the Australian VHF marine voice channels (#209).
Expand Down
1 change: 1 addition & 0 deletions src/components/channels/ChannelEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const ChannelEditModal: React.FC<ChannelEditModalProps> = ({
...validateChannel(editedChannel, bandLimits, maxChannels, {
maxNameLength,
blankTxAnyBand: caps?.blankTxAnyBand,
forbidTxBlanksFrequency: caps?.forbidTxBlanksFrequency,
checkRxBand,
}),
];
Expand Down
2 changes: 2 additions & 0 deletions src/radios/uv5rmini/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const UV5RMINI_MEMORY_REGIONS: MemoryRegionSpec[] = [
export const UV5RMINI_CAPABILITIES: RadioCapabilities = {
memoryRegions: UV5RMINI_MEMORY_REGIONS,
bandLimits: DEFAULT_BAND_LIMITS,
blankTxAnyBand: true,
forbidTxBlanksFrequency: true,
// Its settings write lays every mapped field over the radio's own block.
writesSettingsOnEveryWrite: true,
writeValidations: {
Expand Down
8 changes: 2 additions & 6 deletions src/radios/uv5rmini/channelFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,8 @@ export function writeChannelToImage(
}
out.set(raw.rawBytes);
out.set(encodeBcdFreq(raw.rxFreqHz), 0);
if (raw.duplex === 'off') {
for (let i = 4; i < 8; i++) out[i] = 0xff;
} else {
const txHz = raw.txFreqHz || raw.rxFreqHz;
out.set(encodeBcdFreq(txHz), 4);
}
if (raw.duplex === 'off' || raw.txFreqHz === 0) out.fill(0xff, 4, 8);
else out.set(encodeBcdFreq(raw.txFreqHz), 4);
out.set(encodeTone(raw.rxtone), 8);
out.set(encodeTone(raw.txtone), 10);
const nameStr = (raw.name || '').trim().slice(0, 12);
Expand Down
27 changes: 11 additions & 16 deletions src/radios/uv5rmini/channelMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import type { Channel, CTCSSDCS } from '../../models';
import { isNoTxFrequency, NO_TX_FREQUENCY } from '../../services/validation/frequencyValidator';
import type { Uv5rMiniChannelRaw } from './channelFormat';
import { encodeBcdFreq, encodeTone } from './channelFormat';

Expand Down Expand Up @@ -32,12 +33,6 @@ function ctcssDcsToStr(c: CTCSSDCS): string {
/** Convert NeonPlug Channel to UV5R-Mini raw shape (for write). */
export function channelToUv5rMiniRaw(ch: Channel): Uv5rMiniChannelRaw {
const rxHz = Math.round((ch.rxFrequency || 0) * 1e6);
const txHz = Math.round((ch.txFrequency ?? ch.rxFrequency ?? 0) * 1e6);
let duplex = '';
if (rxHz > 0) {
if (txHz === 0 || txHz === rxHz) duplex = '';
else duplex = txHz > rxHz ? '+' : '-';
}
const rawBytes = new Uint8Array(32);
if (rxHz === 0) {
rawBytes.fill(0xff);
Expand All @@ -55,13 +50,13 @@ export function channelToUv5rMiniRaw(ch: Channel): Uv5rMiniChannelRaw {
rawBytes,
};
}
rawBytes.fill(0);
const txHz = ch.forbidTx || isNoTxFrequency(ch.txFrequency)
? 0
: Math.round((ch.txFrequency ?? 0) * 1e6);
const duplex = txHz === 0 ? 'off' : txHz === rxHz ? '' : txHz > rxHz ? '+' : '-';
rawBytes.set(encodeBcdFreq(rxHz), 0);
if (duplex !== 'off') {
rawBytes.set(encodeBcdFreq(txHz), 4);
} else {
rawBytes[4] = rawBytes[5] = rawBytes[6] = rawBytes[7] = 0xff;
}
if (duplex === 'off') rawBytes.fill(0xff, 4, 8);
else rawBytes.set(encodeBcdFreq(txHz), 4);
rawBytes.set(encodeTone(ctcssDcsToStr(ch.rxCtcssDcs ?? DEFAULT_CTCSSDCS)), 8);
rawBytes.set(encodeTone(ctcssDcsToStr(ch.txCtcssDcs ?? DEFAULT_CTCSSDCS)), 10);
rawBytes[12] = 1;
Expand All @@ -79,7 +74,7 @@ export function channelToUv5rMiniRaw(ch: Channel): Uv5rMiniChannelRaw {
num: ch.number,
empty: false,
rxFreqHz: rxHz,
txFreqHz: duplex === 'off' ? 0 : txHz,
txFreqHz: txHz,
duplex,
rxtone: ctcssDcsToStr(ch.rxCtcssDcs ?? DEFAULT_CTCSSDCS),
txtone: ctcssDcsToStr(ch.txCtcssDcs ?? DEFAULT_CTCSSDCS),
Expand All @@ -93,14 +88,14 @@ export function channelToUv5rMiniRaw(ch: Channel): Uv5rMiniChannelRaw {
/** Convert UV5R-Mini raw channel to NeonPlug Channel. */
export function uv5rMiniRawToChannel(raw: Uv5rMiniChannelRaw): Channel {
const rxMhz = raw.rxFreqHz / 1e6;
const txMhz = raw.txFreqHz > 0 ? raw.txFreqHz / 1e6 : rxMhz;
const forbidTx = raw.duplex === 'off' || raw.txFreqHz === 0;
return {
number: raw.num,
name: raw.name || '—',
rxFrequency: rxMhz,
txFrequency: txMhz,
txFrequency: forbidTx ? NO_TX_FREQUENCY : raw.txFreqHz / 1e6,
mode: 'Analog',
forbidTx: false,
forbidTx,
loneWorker: false,
bandwidth: raw.mode === 'FM' ? '25kHz' : '12.5kHz',
scanAdd: false,
Expand Down
7 changes: 2 additions & 5 deletions src/services/validation/channelProblems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import type { Channel } from '../../models/Channel';
import { isNoTxFrequency, isRxInNoTxBand, isValidFrequencyRange } from './frequencyValidator';
import { isChannelTxOmitted, isNoTxFrequency, isValidFrequencyRange } from './frequencyValidator';
import { isChannelWritable, type WriteFilterOptions } from './writeFilter';

export interface ChannelWriteRule extends WriteFilterOptions {
Expand Down Expand Up @@ -40,10 +40,7 @@ export function channelProblems(channel: Channel, rule: ChannelWriteRule): Chann
: rule.outOfBand
? `Too high to store, ${LEFT_OUT}`
: `Outside this radio's bands, ${LEFT_OUT}`;
const blankTx =
rule.outOfBand || rule.blankTxAnyBand
? isNoTxFrequency(channel.txFrequency)
: isRxInNoTxBand(channel.rxFrequency) && channel.forbidTx && isNoTxFrequency(channel.txFrequency);
const blankTx = isChannelTxOmitted(channel, rule) || (rule.outOfBand && isNoTxFrequency(channel.txFrequency));

if (bad(channel.rxFrequency)) problems.rx = why(channel.rxFrequency);
if (!blankTx && bad(channel.txFrequency)) problems.tx = why(channel.txFrequency);
Expand Down
11 changes: 3 additions & 8 deletions src/services/validation/channelValidator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Channel } from '../../models/Channel';
import type { RadioBandLimits } from '../../types/radioCapabilities';
import { isNoTxFrequency, isRxInNoTxBand, isValidFrequencyRange } from './frequencyValidator';
import { isChannelTxOmitted, isValidFrequencyRange, type ChannelTxOptions } from './frequencyValidator';
import { isValidColorCode, isValidTimeSlot } from './dmrValidator';

export interface ValidationError {
Expand All @@ -14,11 +14,9 @@ const DEFAULT_MAX_CHANNELS = 4000;
/** Default longest name when capabilities don't specify: the DM-32's 16. */
const DEFAULT_MAX_NAME_LENGTH = 16;

export interface ChannelValidationOptions {
export interface ChannelValidationOptions extends ChannelTxOptions {
/** capabilities.maxChannelNameLength */
maxNameLength?: number;
/** capabilities.blankTxAnyBand: a blank TX is allowed whatever the RX. */
blankTxAnyBand?: boolean;
/** False where a write keeps a channel whatever its RX (the DA-7X2's planner checks TX only). */
checkRxBand?: boolean;
}
Expand Down Expand Up @@ -48,10 +46,7 @@ export function validateChannel(
if (channel.rxFrequency <= 0) {
errors.push({ field: 'rxFrequency', message: 'RX frequency must be greater than 0' });
}
// The same blank-TX rule as isValidChannelFrequency.
const blankTx = options.blankTxAnyBand
? isNoTxFrequency(channel.txFrequency)
: isRxInNoTxBand(channel.rxFrequency) && channel.forbidTx && isNoTxFrequency(channel.txFrequency);
const blankTx = isChannelTxOmitted(channel, options);
if (!blankTx && channel.txFrequency <= 0) {
errors.push({ field: 'txFrequency', message: 'TX frequency must be greater than 0' });
}
Expand Down
29 changes: 17 additions & 12 deletions src/services/validation/frequencyValidator.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Channel } from '../../models/Channel';
import type { RadioBandLimits } from '../../types/radioCapabilities';
import type { RadioBandLimits, RadioCapabilities } from '../../types/radioCapabilities';
import { DEFAULT_BAND_LIMITS } from '../../types/radioCapabilities';

/** RX range where TX is not used (aviation/FM receive-only). TX bytes stored as 0xFF on radio. */
export const NO_TX_BAND_RX_MIN_MHZ = 87;
export const NO_TX_BAND_RX_MAX_MHZ = 136;

/** Display value for "no TX" (0xFF on radio). Shown when RX is in 87–136 MHz and Forbid TX. */
/** Display value for "no TX" (0xFF on radio). */
export const NO_TX_FREQUENCY = 1666.666;

/** True if txFrequency is the sentinel for "no TX" (receive-only in 87–136 band). */
/** True if txFrequency is the sentinel for "no TX". */
export function isNoTxFrequency(txFrequency: number): boolean {
return txFrequency >= 1666 && txFrequency < 1667;
}
Expand Down Expand Up @@ -40,22 +40,26 @@ export function hasBlankTx(channel: Pick<Channel, 'rxFrequency' | 'txFrequency'>
return isNoTxFrequency(channel.txFrequency) && (blankTxAnyBand === true || isRxInNoTxBand(channel.rxFrequency));
}

export type ChannelTxOptions = Pick<RadioCapabilities, 'blankTxAnyBand' | 'forbidTxBlanksFrequency'>;

/** Whether the radio stores no TX frequency, so only RX needs a band check. */
export function isChannelTxOmitted(channel: Channel, options?: ChannelTxOptions): boolean {
return (options?.forbidTxBlanksFrequency === true && channel.forbidTx) ||
((options?.blankTxAnyBand === true || channel.forbidTx) && hasBlankTx(channel, options?.blankTxAnyBand));
}

/**
* Check if a channel's frequencies are within supported ranges.
* When limits is provided (e.g. from getCapabilitiesForModel(radioInfo?.model)?.bandLimits), uses those.
* A channel with a blank TX only has its RX checked: in 87–136 MHz with Forbid TX on any radio,
* and in any band, Forbid TX or not, on a radio with `blankTxAnyBand`.
* When the radio stores no TX frequency, only RX is checked.
*/
export function isValidChannelFrequency(
channel: Channel,
limits?: RadioBandLimits | null,
options?: { blankTxAnyBand?: boolean }
options?: ChannelTxOptions
): boolean {
if (channel.rxFrequency <= 0) return false;
const blankTx = options?.blankTxAnyBand
? isNoTxFrequency(channel.txFrequency)
: isRxInNoTxBand(channel.rxFrequency) && channel.forbidTx && isNoTxFrequency(channel.txFrequency);
if (blankTx) {
if (isChannelTxOmitted(channel, options)) {
return isValidFrequencyRange(channel.rxFrequency, limits);
}
if (channel.txFrequency <= 0) return false;
Expand All @@ -72,11 +76,12 @@ export function isValidChannelFrequency(
export function isWritableChannelFrequency(
channel: Channel,
limits: RadioBandLimits | null | undefined,
options: { blankTxAnyBand?: boolean; outOfBand?: boolean }
options: ChannelTxOptions & { outOfBand?: boolean }
): boolean {
if (!options.outOfBand) return isValidChannelFrequency(channel, limits, options);
const storable = (mhz: number) => mhz > 0 && mhz < 1000;
return storable(channel.rxFrequency) && (isNoTxFrequency(channel.txFrequency) || storable(channel.txFrequency));
return storable(channel.rxFrequency) &&
(isNoTxFrequency(channel.txFrequency) || isChannelTxOmitted(channel, options) || storable(channel.txFrequency));
}

/** Band limits from radio capabilities (e.g. getCapabilitiesForModel(radioInfo?.model)?.bandLimits). */
Expand Down
10 changes: 3 additions & 7 deletions src/services/validation/writeFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ import type { Channel } from '../../models/Channel';
import type { Zone } from '../../models/Zone';
import type { ScanList } from '../../models/ScanList';
import type { RadioBandLimits } from '../../types/radioCapabilities';
import { isWritableChannelFrequency } from './frequencyValidator';
import { isWritableChannelFrequency, type ChannelTxOptions } from './frequencyValidator';

export interface WriteFilterOptions {
export interface WriteFilterOptions extends ChannelTxOptions {
/**
* False on the DA-7X2, whose write planner checks channel frequencies itself
* and which sends every scan list by its slot, empty ones included.
*/
filterBand: boolean;
bandLimits?: RadioBandLimits | null;
blankTxAnyBand?: boolean;
outOfBand?: boolean;
}

Expand All @@ -42,10 +41,7 @@ export interface WritableCodeplug {
export function isChannelWritable(channel: Channel, options: WriteFilterOptions): boolean {
return (
!options.filterBand ||
isWritableChannelFrequency(channel, options.bandLimits, {
blankTxAnyBand: options.blankTxAnyBand,
outOfBand: options.outOfBand,
})
isWritableChannelFrequency(channel, options.bandLimits, options)
);
}

Expand Down
1 change: 1 addition & 0 deletions src/services/writeFilterOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function writeFilterOptionsFor(
!(model != null && (D890_MODEL_IDS as readonly string[]).includes(model)) && !caps?.writeKeepsEveryBand,
bandLimits: caps?.bandLimits,
blankTxAnyBand: caps?.blankTxAnyBand,
forbidTxBlanksFrequency: caps?.forbidTxBlanksFrequency,
outOfBand,
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/radioCapabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ export interface RadioCapabilities {
* TX may have a blank TX, and a write leaves any other out.
*/
blankTxAnyBand?: boolean;
/** Forbid TX blanks the stored TX frequency rather than setting a separate flag. */
forbidTxBlanksFrequency?: boolean;
/**
* The write never drops a channel for being out of band.
*
Expand Down
26 changes: 26 additions & 0 deletions tests/fixtures/uv5rmini/receive-only.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Channel Number,Name,RX Frequency,TX Frequency,Forbid TX
14,ISS,145.800000,0.000000,Yes
15,APRS,144.390000,0.000000,Yes
16,WX400,162.400000,0.000000,Yes
17,WX425,162.425000,0.000000,Yes
18,WXOC,162.450000,0.000000,Yes
19,WX475,162.475000,0.000000,Yes
20,WX500,162.500000,0.000000,Yes
21,WX525,162.525000,0.000000,Yes
22,WXLA,162.550000,0.000000,Yes
23,LAXATIS,133.800000,0.000000,Yes
24,LAXDEP,135.650000,0.000000,Yes
25,LAXTWS,120.950000,0.000000,Yes
26,LAXTWN,133.900000,0.000000,Yes
27,LAXGND,121.650000,0.000000,Yes
28,SOCAL,124.300000,0.000000,Yes
29,MAR16,156.800000,0.000000,Yes
30,MAR13,156.650000,0.000000,Yes
31,MAR14,156.700000,0.000000,Yes
32,MAR77,156.875000,0.000000,Yes
33,MAR73,156.675000,0.000000,Yes
34,MAR09,156.450000,0.000000,Yes
35,AMTRAK,160.455000,0.000000,Yes
36,ALAMEDA,160.365000,0.000000,Yes
37,BNSF,160.590000,0.000000,Yes
38,UPROAD,160.320000,0.000000,Yes
Loading