Enums and Masks – Synchronisation
The RFM69CW/RFM69HCW module (based on the Semtech SX1231/SX1231H) has configurable (RegSyncConfig) synchronisation sequences (the length, tolerance for errors and the individual byte values).

By default synchronisation is enabled and a default sequence of bytes is used, in my library synchronisation is NOT enabled until a SyncValue is provided.
I added some additional constants and enumerations for the other settings configured in RegSyncConfig.
// RegSyncConfig
// This is private because default ignored and flag set based on SyncValues parameter being specified rather than default
private enum RegSyncConfigSyncOn
{
Off = 0b00000000,
On = 0b10000000
}
public enum RegSyncConfigFifoFileCondition
{
SyncAddressInterrupt = 0b00000000,
FifoFillCondition = 0b01000000
}
private const RegSyncConfigFifoFileCondition SyncFifoFileConditionDefault = RegSyncConfigFifoFileCondition.SyncAddressInterrupt;
readonly byte[] SyncValuesDefault = {0x01, 0x01, 0x01, 0x01};
public const byte SyncValuesSizeDefault = 4;
public const byte SyncValuesSizeMinimum = 1;
public const byte SyncValuesSizeMaximum = 8;
private const byte SyncToleranceDefault = 0;
public const byte SyncToleranceMinimum = 0;
public const byte SyncToleranceMaximum = 7;
I also added some guard conditions to the initialise method which validate the syncFifoFileCondition, syncTolerance and syncValues length.
public void Initialise(RegOpModeMode modeAfterInitialise,
BitRate bitRate = BitRateDefault,
ushort frequencyDeviation = frequencyDeviationDefault,
double frequency = FrequencyDefault,
ListenModeIdleResolution listenModeIdleResolution = ListenModeIdleResolutionDefault, ListenModeRXTime listenModeRXTime = ListenModeRXTimeDefault, ListenModeCrieria listenModeCrieria = ListenModeCrieriaDefault, ListenModeEnd listenModeEnd = ListenModeEndDefault,
byte listenCoefficientIdle = ListenCoefficientIdleDefault,
byte listenCoefficientReceive = ListenCoefficientReceiveDefault,
bool pa0On = pa0OnDefault, bool pa1On = pa1OnDefaut, bool pa2On = pa2OnDefault, byte outputpower = OutputpowerDefault,
PaRamp paRamp = PaRampDefault,
bool ocpOn = OcpOnDefault, byte ocpTrim = OcpTrimDefault,
LnaZin lnaZin = LnaZinDefault, LnaCurrentGain lnaCurrentGain = LnaCurrentGainDefault, LnaGainSelect lnaGainSelect = LnaGainSelectDefault,
byte dccFrequency = DccFrequencyDefault, RxBwMant rxBwMant = RxBwMantDefault, byte RxBwExp = RxBwExpDefault,
byte dccFreqAfc = DccFreqAfcDefault, byte rxBwMantAfc = RxBwMantAfcDefault, byte bxBwExpAfc = RxBwExpAfcDefault,
ushort preambleSize = PreambleSizeDefault,
RegSyncConfigFifoFileCondition? syncFifoFileCondition = null, byte? syncTolerance = null, byte[] syncValues = null,
RegPacketConfig1PacketFormat packetFormat = RegPacketConfig1PacketFormat.FixedLength,
RegPacketConfig1DcFree packetDcFree = RegPacketConfig1DcFreeDefault,
bool packetCrc = PacketCrcOnDefault,
bool packetCrcAutoClearOff = PacketCrcAutoClearOffDefault,
RegPacketConfig1CrcAddressFiltering packetAddressFiltering = PacketAddressFilteringDefault,
byte payloadLength = PayloadLengthDefault,
byte addressNode = NodeAddressDefault, byte addressbroadcast = BroadcastAddressDefault,
TxStartCondition txStartCondition = TxStartConditionDefault, byte fifoThreshold = FifoThresholdDefault,
byte interPacketRxDelay = InterPacketRxDelayDefault, bool restartRx = RestartRxDefault, bool autoRestartRx = AutoRestartRxDefault,
byte[] aesKey = null
)
{
RegOpModeModeCurrent = modeAfterInitialise;
PacketFormat = packetFormat;
#region RegSyncConfig + RegSyncValue1 to RegSyncValue8 guard conditions
if (syncValues != null)
{
// If sync enabled (i.e. SyncValues array provided) check that SyncValues not to short/long and SyncTolerance not to small/big
if ((syncValues.Length < SyncValuesSizeMinimum) || (syncValues.Length > SyncValuesSizeMaximum))
{
throw new ArgumentException($"The syncValues array length must be between {SyncValuesSizeMinimum} and {SyncValuesSizeMaximum} bytes", "syncValues");
}
if (syncTolerance.HasValue)
{
if ((syncTolerance < SyncToleranceMinimum) || (syncTolerance > SyncToleranceMaximum))
{
throw new ArgumentException($"The syncTolerance size must be between {SyncToleranceMinimum} and {SyncToleranceMaximum}", "syncTolerance");
}
}
}
else
{
// If sync not enabled (i.e. SyncValues array null) check that no syncFifoFileCondition or syncTolerance configuration specified
if (syncFifoFileCondition.HasValue)
{
throw new ArgumentException($"If Sync not enabled syncFifoFileCondition is not supported", "syncFifoFileCondition");
}
if (syncTolerance.HasValue)
{
throw new ArgumentException($"If Sync not enabled SyncTolerance is not supported", "syncTolerance");
}
}
#endregion
I also ensure that the syncFifoFileCondition and syncTolerance are not specified if synchronisation is not enabled.
The Arduino client code works though I need modify it so I can do more testing of the initialise method parameter options.
Pingback: RFM69 hat library receive lockups | devMobile's blog