Rename cmtFreqToChan to getChannelFromFrequency and simplify handling of current channel
This commit is contained in:
parent
1259f09503
commit
cfb37906ca
@ -24,52 +24,45 @@ float HoymilesRadio_CMT::getFrequencyFromChannel(const uint8_t channel)
|
|||||||
return (CMT_BASE_FREQ + (CMT_BASE_CH_OFFSET860 + channel) * FH_OFFSET * CMT2300A_ONE_STEP_SIZE) / 1000000.0;
|
return (CMT_BASE_FREQ + (CMT_BASE_CH_OFFSET860 + channel) * FH_OFFSET * CMT2300A_ONE_STEP_SIZE) / 1000000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HoymilesRadio_CMT::cmtSwitchChannel(const uint8_t channel)
|
uint8_t HoymilesRadio_CMT::getChannelFromFrequency(const uint32_t freq_kHz)
|
||||||
{
|
|
||||||
_radio->setChannel(channel);
|
|
||||||
cmtCurrentCh = channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t HoymilesRadio_CMT::cmtFreqToChan(const String& func_name, const String& var_name, const uint32_t freq_kHz)
|
|
||||||
{
|
{
|
||||||
if ((freq_kHz % 250) != 0) {
|
if ((freq_kHz % 250) != 0) {
|
||||||
Hoymiles.getMessageOutput()->printf("%s %s %.3f MHz is not divisible by 250 kHz!\r\n",
|
Hoymiles.getMessageOutput()->printf("%.3f MHz is not divisible by 250 kHz!\r\n", freq_kHz / 1000.0);
|
||||||
func_name.c_str(), var_name.c_str(), freq_kHz / 1000.0);
|
|
||||||
return 0xFF; // ERROR
|
return 0xFF; // ERROR
|
||||||
}
|
}
|
||||||
if (freq_kHz < CMT_MIN_FREQ_KHZ || freq_kHz > CMT_MAX_FREQ_KHZ) {
|
if (freq_kHz < CMT_MIN_FREQ_KHZ || freq_kHz > CMT_MAX_FREQ_KHZ) {
|
||||||
Hoymiles.getMessageOutput()->printf("%s %s %.2f MHz is out of Hoymiles/CMT range! (%.2f MHz - %.2f MHz)\r\n",
|
Hoymiles.getMessageOutput()->printf("%.2f MHz is out of Hoymiles/CMT range! (%.2f MHz - %.2f MHz)\r\n",
|
||||||
func_name.c_str(), var_name.c_str(), freq_kHz / 1000.0, CMT_MIN_FREQ_KHZ / 1000.0, CMT_MAX_FREQ_KHZ / 1000.0);
|
freq_kHz / 1000.0, CMT_MIN_FREQ_KHZ / 1000.0, CMT_MAX_FREQ_KHZ / 1000.0);
|
||||||
return 0xFF; // ERROR
|
return 0xFF; // ERROR
|
||||||
}
|
}
|
||||||
if (freq_kHz < 863000 || freq_kHz > 870000) {
|
if (freq_kHz < 863000 || freq_kHz > 870000) {
|
||||||
Hoymiles.getMessageOutput()->printf("%s !!! caution: %s %.2f MHz is out of EU legal range! (863 - 870 MHz)\r\n",
|
Hoymiles.getMessageOutput()->printf("!!! caution: %.2f MHz is out of EU legal range! (863 - 870 MHz)\r\n",
|
||||||
func_name.c_str(), var_name.c_str(), freq_kHz / 1000.0);
|
freq_kHz / 1000.0);
|
||||||
}
|
}
|
||||||
return (freq_kHz * 1000 - CMT_BASE_FREQ) / CMT2300A_ONE_STEP_SIZE / FH_OFFSET - CMT_BASE_CH_OFFSET860; // frequency to channel
|
return (freq_kHz * 1000 - CMT_BASE_FREQ) / CMT2300A_ONE_STEP_SIZE / FH_OFFSET - CMT_BASE_CH_OFFSET860; // frequency to channel
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HoymilesRadio_CMT::cmtSwitchDtuFreq(const uint32_t to_freq_kHz)
|
bool HoymilesRadio_CMT::cmtSwitchDtuFreq(const uint32_t to_freq_kHz)
|
||||||
{
|
{
|
||||||
const uint8_t toChannel = cmtFreqToChan("[cmtSwitchDtuFreq]", "to_freq_kHz", to_freq_kHz);
|
const uint8_t toChannel = getChannelFromFrequency(to_freq_kHz);
|
||||||
if (toChannel == 0xFF) {
|
if (toChannel == 0xFF) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmtSwitchChannel(toChannel);
|
_radio->setChannel(toChannel);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HoymilesRadio_CMT::cmtSwitchInvAndDtuFreq(const uint64_t inv_serial, const uint32_t from_freq_kHz, const uint32_t to_freq_kHz)
|
bool HoymilesRadio_CMT::cmtSwitchInvAndDtuFreq(const uint64_t inv_serial, const uint32_t from_freq_kHz, const uint32_t to_freq_kHz)
|
||||||
{
|
{
|
||||||
const uint8_t fromChannel = cmtFreqToChan("[cmtSwitchInvAndDtuFreq]", "from_freq_kHz", from_freq_kHz);
|
const uint8_t fromChannel = getChannelFromFrequency(from_freq_kHz);
|
||||||
const uint8_t toChannel = cmtFreqToChan("[cmtSwitchInvAndDtuFreq]", "to_freq_kHz", to_freq_kHz);
|
const uint8_t toChannel = getChannelFromFrequency(to_freq_kHz);
|
||||||
if (fromChannel == 0xFF || toChannel == 0xFF) {
|
if (fromChannel == 0xFF || toChannel == 0xFF) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmtSwitchChannel(fromChannel);
|
_radio->setChannel(fromChannel);
|
||||||
cmtTx56toCh = toChannel;
|
cmtTx56toCh = toChannel;
|
||||||
|
|
||||||
// CMD56 for inverter frequency/channel switch
|
// CMD56 for inverter frequency/channel switch
|
||||||
@ -83,7 +76,7 @@ bool HoymilesRadio_CMT::cmtSwitchInvAndDtuFreq(const uint64_t inv_serial, const
|
|||||||
cmtTxBuffer[13] = 0x14;
|
cmtTxBuffer[13] = 0x14;
|
||||||
cmtTxBuffer[14] = crc8(cmtTxBuffer, 14);
|
cmtTxBuffer[14] = crc8(cmtTxBuffer, 14);
|
||||||
|
|
||||||
Hoymiles.getMessageOutput()->printf("TX CMD56 %.2f MHz --> ", getFrequencyFromChannel(cmtCurrentCh));
|
Hoymiles.getMessageOutput()->printf("TX CMD56 %.2f MHz --> ", getFrequencyFromChannel(_radio->getChannel()));
|
||||||
dumpBuf(cmtTxBuffer, 15);
|
dumpBuf(cmtTxBuffer, 15);
|
||||||
|
|
||||||
cmtTxLength = 15;
|
cmtTxLength = 15;
|
||||||
@ -155,7 +148,7 @@ enumCMTresult HoymilesRadio_CMT::cmtProcess(void)
|
|||||||
fragment_t f;
|
fragment_t f;
|
||||||
memset(f.fragment, 0xcc, MAX_RF_PAYLOAD_SIZE);
|
memset(f.fragment, 0xcc, MAX_RF_PAYLOAD_SIZE);
|
||||||
CMT2300A_ReadFifo(&f.len, 1); // first byte in FiFo is length
|
CMT2300A_ReadFifo(&f.len, 1); // first byte in FiFo is length
|
||||||
f.channel = cmtCurrentCh;
|
f.channel = _radio->getChannel();
|
||||||
f.rssi = CMT2300A_GetRssiDBm();
|
f.rssi = CMT2300A_GetRssiDBm();
|
||||||
if (f.len > MAX_RF_PAYLOAD_SIZE) {
|
if (f.len > MAX_RF_PAYLOAD_SIZE) {
|
||||||
f.len = MAX_RF_PAYLOAD_SIZE;
|
f.len = MAX_RF_PAYLOAD_SIZE;
|
||||||
@ -255,7 +248,7 @@ enumCMTresult HoymilesRadio_CMT::cmtProcess(void)
|
|||||||
CMT2300A_GoSleep();
|
CMT2300A_GoSleep();
|
||||||
|
|
||||||
if (cmtTx56toCh != 0xFF) {
|
if (cmtTx56toCh != 0xFF) {
|
||||||
cmtSwitchChannel(cmtTx56toCh);
|
_radio->setChannel(cmtTx56toCh);
|
||||||
cmtTx56toCh = 0xFF;
|
cmtTx56toCh = 0xFF;
|
||||||
cmtNextState = CMT_STATE_IDLE;
|
cmtNextState = CMT_STATE_IDLE;
|
||||||
} else {
|
} else {
|
||||||
@ -479,7 +472,7 @@ void HoymilesRadio_CMT::sendEsbPacket(CommandAbstract* cmd)
|
|||||||
cmd->setRouterAddress(DtuSerial().u64);
|
cmd->setRouterAddress(DtuSerial().u64);
|
||||||
|
|
||||||
Hoymiles.getMessageOutput()->printf("TX %s %.2f MHz --> ",
|
Hoymiles.getMessageOutput()->printf("TX %s %.2f MHz --> ",
|
||||||
cmd->getCommandName().c_str(), getFrequencyFromChannel(cmtCurrentCh));
|
cmd->getCommandName().c_str(), getFrequencyFromChannel(_radio->getChannel()));
|
||||||
cmd->dumpDataPayload(Hoymiles.getMessageOutput());
|
cmd->dumpDataPayload(Hoymiles.getMessageOutput());
|
||||||
|
|
||||||
// Still here for to handle CMD56 correctly (inverter serial etc.)
|
// Still here for to handle CMD56 correctly (inverter serial etc.)
|
||||||
|
|||||||
@ -75,8 +75,8 @@ private:
|
|||||||
uint32_t _inverterTargetFrequency = HOYMILES_CMT_WORK_FREQ;
|
uint32_t _inverterTargetFrequency = HOYMILES_CMT_WORK_FREQ;
|
||||||
|
|
||||||
static float getFrequencyFromChannel(const uint8_t channel);
|
static float getFrequencyFromChannel(const uint8_t channel);
|
||||||
void cmtSwitchChannel(const uint8_t channel);
|
static uint8_t getChannelFromFrequency(const uint32_t freq_kHz);
|
||||||
uint8_t cmtFreqToChan(const String& func_name, const String& var_name, const uint32_t freq_kHz);
|
|
||||||
bool cmtSwitchDtuFreq(const uint32_t to_freq_kHz);
|
bool cmtSwitchDtuFreq(const uint32_t to_freq_kHz);
|
||||||
bool cmtSwitchInvAndDtuFreq(const uint64_t inv_serial, const uint32_t from_freq_kHz, const uint32_t to_freq_kHz);
|
bool cmtSwitchInvAndDtuFreq(const uint64_t inv_serial, const uint32_t from_freq_kHz, const uint32_t to_freq_kHz);
|
||||||
enumCMTresult cmtProcess(void);
|
enumCMTresult cmtProcess(void);
|
||||||
@ -88,8 +88,6 @@ private:
|
|||||||
uint32_t cmtRxTimeout = 200;
|
uint32_t cmtRxTimeout = 200;
|
||||||
uint32_t cmtRxTimeCount = 0;
|
uint32_t cmtRxTimeCount = 0;
|
||||||
|
|
||||||
uint8_t cmtCurrentCh; // current used channel, should be stored per inverter und set before next Tx, if hopping is used
|
|
||||||
|
|
||||||
uint8_t cmtTx56toCh = 0xFF; // send CMD56 active to Channel xx, inactive = 0xFF
|
uint8_t cmtTx56toCh = 0xFF; // send CMD56 active to Channel xx, inactive = 0xFF
|
||||||
|
|
||||||
uint8_t cmtRxTimeoutCnt = 0; // Rx timeout counter !!! should be stored per inverter !!!
|
uint8_t cmtRxTimeoutCnt = 0; // Rx timeout counter !!! should be stored per inverter !!!
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user