Add GDx CPS channel decoding
This commit is contained in:
parent
663673b697
commit
8f3c46a262
|
|
@ -0,0 +1,145 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, *
|
||||
* Niccolò Izzo IU2KIN *
|
||||
* Frederik Saraci IU2NRO *
|
||||
* Silvano Seva IU2KWO *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef NVMDATA_GDx_H
|
||||
#define NVMDATA_GDx_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* \internal Data structures matching the one used by original GDx firmware to
|
||||
* manage channel data inside nonvolatile flash memory.
|
||||
*
|
||||
* Taken by dmrconfig repository: https://github.com/sergev/dmrconfig/blob/master/gd77.c
|
||||
*/
|
||||
typedef struct {
|
||||
// Bytes 0-15
|
||||
uint8_t name[16]; // Channel Name
|
||||
|
||||
// Bytes 16-23
|
||||
uint32_t rx_frequency; // RX Frequency: 8 digits BCD
|
||||
uint32_t tx_frequency; // TX Frequency: 8 digits BCD
|
||||
|
||||
// Byte 24
|
||||
uint8_t channel_mode; // Mode: Analog or Digital
|
||||
|
||||
// Bytes 25-26
|
||||
uint8_t _unused25[2]; // 0
|
||||
|
||||
// Bytes 27-28
|
||||
uint8_t tot; // TOT x 15sec: 0-Infinite, 1=15s... 33=495s
|
||||
uint8_t tot_rekey_delay; // TOT Rekey Delay: 0s...255s
|
||||
|
||||
// Byte 29
|
||||
uint8_t admit_criteria; // Admit Criteria: Always, Channel Free or Color Code
|
||||
|
||||
// Bytes 30-31
|
||||
uint8_t _unused30; // 0x50
|
||||
uint8_t scan_list_index; // Scan List: None, ScanList1...250
|
||||
|
||||
// Bytes 32-35
|
||||
uint16_t ctcss_dcs_receive; // CTCSS/DCS Dec: 4 digits BCD or 0xffff
|
||||
uint16_t ctcss_dcs_transmit; // CTCSS/DCS Enc: 4 digits BCD
|
||||
|
||||
// Bytes 36-39
|
||||
uint8_t _unused36; // 0
|
||||
uint8_t tx_signaling_syst; // Tx Signaling System: Off, DTMF
|
||||
uint8_t _unused38; // 0
|
||||
uint8_t rx_signaling_syst; // Rx Signaling System: Off, DTMF
|
||||
|
||||
// Bytes 40-43
|
||||
uint8_t _unused40; // 0x16
|
||||
uint8_t privacy_group; // Privacy Group: 0=None, 1=53474c39
|
||||
|
||||
uint8_t colorcode_tx; // Color Code: 0...15
|
||||
uint8_t group_list_index; // Group List: None, GroupList1...128
|
||||
|
||||
// Bytes 44-47
|
||||
uint8_t colorcode_rx; // Color Code: 0...15
|
||||
uint8_t emergency_system_index; // Emergency System: None, System1...32
|
||||
uint16_t contact_name_index; // Contact Name: Contact1...
|
||||
|
||||
// Byte 48
|
||||
uint8_t _unused48 : 6, // 0
|
||||
emergency_alarm_ack : 1, // Emergency Alarm Ack
|
||||
data_call_conf : 1; // Data Call Confirmed
|
||||
|
||||
// Byte 49
|
||||
uint8_t private_call_conf : 1, // Private Call Confirmed
|
||||
_unused49_1 : 3, // 0
|
||||
privacy : 1, // Privacy: Off or On
|
||||
_unused49_5 : 1, // 0
|
||||
repeater_slot : 1, // Repeater Slot: 0=slot1 or 1=slot2
|
||||
_unused49_7 : 1; // 0
|
||||
|
||||
// Byte 50
|
||||
uint8_t dcdm : 1, // Dual Capacity Direct Mode
|
||||
_unused50_1 : 4, // 0
|
||||
non_ste_frequency : 1, // Non STE = Frequency
|
||||
_unused50_6 : 2; // 0
|
||||
|
||||
// Byte 51
|
||||
uint8_t squelch : 1, // Squelch
|
||||
bandwidth : 1, // Bandwidth: 12.5 or 25 kHz
|
||||
|
||||
rx_only : 1, // RX Only Enable
|
||||
talkaround : 1, // Allow Talkaround
|
||||
_unused51_4 : 2, // 0
|
||||
vox : 1, // VOX Enable
|
||||
power : 1; // Power: Low, High
|
||||
|
||||
// Bytes 52-55
|
||||
uint8_t _unused52[4]; // 0
|
||||
}
|
||||
gdxChannel_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t bitmap[16]; // bit set when channel valid
|
||||
gdxChannel_t chan[128];
|
||||
}
|
||||
gdxChannelBank_t;
|
||||
|
||||
typedef struct {
|
||||
// Bytes 0-15
|
||||
uint8_t name[16]; // Zone Name
|
||||
|
||||
// Bytes 16-47
|
||||
uint16_t member[16]; // Member: channels 1...16
|
||||
}
|
||||
gdxZone_t;
|
||||
|
||||
typedef struct {
|
||||
// Bytes 0-15
|
||||
uint8_t name[16]; // Contact Name, ff terminated
|
||||
|
||||
// Bytes 16-19
|
||||
uint8_t id[4]; // BCD coded 8 digits
|
||||
|
||||
// Byte 20
|
||||
uint8_t type; // Call Type: Group Call, Private Call or All Call
|
||||
|
||||
// Bytes 21-23
|
||||
uint8_t receive_tone; // Call Receive Tone: 0=Off, 1=On
|
||||
uint8_t ring_style; // Ring style: 0-10
|
||||
uint8_t _unused23; // 0xff for used contact, 0 for blank entry
|
||||
}
|
||||
gdxContact_t;
|
||||
|
||||
#endif /* NVMDATA_GDx_H */
|
||||
|
|
@ -18,98 +18,13 @@
|
|||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <interfaces/delays.h>
|
||||
#include <interfaces/nvmem.h>
|
||||
#include <calibInfo_GDx.h>
|
||||
#include "AT24Cx.h"
|
||||
#include "W25Qx.h"
|
||||
|
||||
/**
|
||||
* \internal Data structure matching the one used by original GDx firmware to
|
||||
* manage channel data inside nonvolatile memory.
|
||||
*
|
||||
* Taken by dmrconfig repository: https://github.com/sergev/dmrconfig/blob/master/gd77.c
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
// Bytes 0-15
|
||||
uint8_t name[16];
|
||||
|
||||
// Bytes 16-23
|
||||
uint32_t rx_frequency;
|
||||
uint32_t tx_frequency;
|
||||
|
||||
// Byte 24
|
||||
uint8_t channel_mode;
|
||||
|
||||
// Bytes 25-26
|
||||
uint8_t _unused25[2];
|
||||
|
||||
// Bytes 27-28
|
||||
uint8_t tot;
|
||||
uint8_t tot_rekey_delay;
|
||||
|
||||
// Byte 29
|
||||
uint8_t admit_criteria;
|
||||
|
||||
// Bytes 30-31
|
||||
uint8_t _unused30;
|
||||
uint8_t scan_list_index;
|
||||
|
||||
// Bytes 32-35
|
||||
uint16_t ctcss_dcs_receive;
|
||||
uint16_t ctcss_dcs_transmit;
|
||||
|
||||
// Bytes 36-39
|
||||
uint8_t _unused36;
|
||||
uint8_t tx_signaling_syst;
|
||||
uint8_t _unused38;
|
||||
uint8_t rx_signaling_syst;
|
||||
|
||||
// Bytes 40-43
|
||||
uint8_t _unused40;
|
||||
uint8_t privacy_group;
|
||||
|
||||
uint8_t colorcode_tx;
|
||||
uint8_t group_list_index;
|
||||
|
||||
// Bytes 44-47
|
||||
uint8_t colorcode_rx;
|
||||
uint8_t emergency_system_index;
|
||||
uint16_t contact_name_index;
|
||||
|
||||
// Byte 48
|
||||
uint8_t _unused48 : 6,
|
||||
emergency_alarm_ack : 1,
|
||||
data_call_conf : 1;
|
||||
|
||||
// Byte 49
|
||||
uint8_t private_call_conf : 1,
|
||||
_unused49_1 : 3,
|
||||
privacy : 1,
|
||||
_unused49_5 : 1,
|
||||
repeater_slot2 : 1,
|
||||
_unused49_7 : 1;
|
||||
|
||||
// Byte 50
|
||||
uint8_t dcdm : 1,
|
||||
_unused50_1 : 4,
|
||||
non_ste_frequency : 1,
|
||||
_unused50_6 : 2;
|
||||
|
||||
// Byte 51
|
||||
uint8_t squelch : 1,
|
||||
bandwidth : 1,
|
||||
rx_only : 1,
|
||||
talkaround : 1,
|
||||
_unused51_4 : 2,
|
||||
vox : 1,
|
||||
power : 1;
|
||||
|
||||
// Bytes 52-55
|
||||
uint8_t _unused52[4];
|
||||
}
|
||||
gdxChannel_t;
|
||||
#include "nvmData_GDx.h"
|
||||
|
||||
#if defined(PLATFORM_GD77)
|
||||
static const uint32_t UHF_CAL_BASE = 0x8F000;
|
||||
|
|
@ -121,6 +36,14 @@ static const uint32_t VHF_CAL_BASE = 0x6F070;
|
|||
#warning GDx calibration: platform not supported
|
||||
#endif
|
||||
|
||||
//const uint32_t zoneBaseAddr = 0x149e0; /**< Base address of zones */
|
||||
const uint32_t channelBaseAddrEEPROM = 0x03790; /**< Base address of channel data */
|
||||
const uint32_t channelBaseAddrFlash = 0x7b1c0; /**< Base address of channel data */
|
||||
const uint32_t contactBaseAddr = 0x87620; /**< Base address of contacts */
|
||||
const uint32_t maxNumChannels = 1024; /**< Maximum number of channels in memory */
|
||||
const uint32_t maxNumZones = 68; /**< Maximum number of zones in memory */
|
||||
const uint32_t maxNumContacts = 1024; /**< Maximum number of contacts in memory */
|
||||
|
||||
/**
|
||||
* \internal Utility function to convert 4 byte BCD values into a 32-bit
|
||||
* unsigned integer ones.
|
||||
|
|
@ -247,9 +170,120 @@ int nvm_readVFOChannelData(channel_t *channel)
|
|||
|
||||
int nvm_readChannelData(channel_t *channel, uint16_t pos)
|
||||
{
|
||||
(void) channel;
|
||||
(void) pos;
|
||||
return -1;
|
||||
if((pos <= 0) || (pos > maxNumChannels))
|
||||
return -1;
|
||||
|
||||
// Channels are organized in 128-channel banks
|
||||
uint8_t bank_num = (pos - 1) / 128;
|
||||
// Note: pos is 1-based because an empty slot in a zone contains index 0
|
||||
uint8_t bank_channel = (pos - 1) % 128;
|
||||
|
||||
// ### Read channel bank bitmap ###
|
||||
uint8_t bitmap[16];
|
||||
// First channel bank (128 channels) is saved in EEPROM
|
||||
if(pos <= 128)
|
||||
{
|
||||
uint32_t readAddr = channelBaseAddrEEPROM + bank_num * sizeof(gdxChannelBank_t);
|
||||
AT24Cx_readData(readAddr, ((uint8_t *) &bitmap), sizeof(bitmap));
|
||||
}
|
||||
// Remaining 7 channel banks (896 channels) are saved in SPI Flash
|
||||
else
|
||||
{
|
||||
W25Qx_wakeup();
|
||||
delayUs(5);
|
||||
uint32_t readAddr = channelBaseAddrFlash + (bank_num - 1) * sizeof(gdxChannelBank_t);
|
||||
W25Qx_readData(readAddr, ((uint8_t *) &bitmap), sizeof(bitmap));
|
||||
W25Qx_sleep();
|
||||
}
|
||||
uint8_t bitmap_byte = bank_channel / 8;
|
||||
uint8_t bitmap_bit = bank_channel % 8;
|
||||
gdxChannelBank_t chBank;
|
||||
// The channel is marked not valid in the bitmap
|
||||
if(!(bitmap[bitmap_byte] & (1 >> bitmap_bit)))
|
||||
return -1;
|
||||
// The channel is marked valid in the bitmap
|
||||
else
|
||||
// ### Read full channel bank ###
|
||||
{
|
||||
// First channel bank (128 channels) is saved in EEPROM
|
||||
if(pos <= 128)
|
||||
{
|
||||
uint32_t readAddr = channelBaseAddrEEPROM + bank_num * sizeof(gdxChannelBank_t);
|
||||
AT24Cx_readData(readAddr, ((uint8_t *) &chBank), sizeof(gdxChannelBank_t));
|
||||
}
|
||||
// Remaining 7 channel banks (896 channels) are saved in SPI Flash
|
||||
else
|
||||
{
|
||||
W25Qx_wakeup();
|
||||
delayUs(5);
|
||||
uint32_t readAddr = channelBaseAddrFlash + (bank_num - 1) * sizeof(gdxChannelBank_t);
|
||||
W25Qx_readData(readAddr, ((uint8_t *) &chBank), sizeof(gdxChannelBank_t));
|
||||
W25Qx_sleep();
|
||||
}
|
||||
}
|
||||
gdxChannel_t chData = chBank.chan[bank_channel];
|
||||
// Copy data to OpenRTX channel_t
|
||||
channel->mode = chData.channel_mode - 1;
|
||||
channel->bandwidth = chData.bandwidth;
|
||||
channel->admit_criteria = chData.admit_criteria;
|
||||
channel->squelch = chData.squelch;
|
||||
channel->rx_only = chData.rx_only;
|
||||
channel->vox = chData.vox;
|
||||
channel->power = ((chData.power == 1) ? 5.0f : 1.0f);
|
||||
channel->rx_frequency = _bcd2bin(chData.rx_frequency) * 10;
|
||||
channel->tx_frequency = _bcd2bin(chData.tx_frequency) * 10;
|
||||
channel->tot = chData.tot;
|
||||
channel->tot_rekey_delay = chData.tot_rekey_delay;
|
||||
channel->emSys_index = chData.emergency_system_index;
|
||||
channel->scanList_index = chData.scan_list_index;
|
||||
channel->groupList_index = chData.group_list_index;
|
||||
memcpy(channel->name, chData.name, sizeof(chData.name));
|
||||
|
||||
/* Load mode-specific parameters */
|
||||
if(channel->mode == FM)
|
||||
{
|
||||
channel->fm.txToneEn = 0;
|
||||
channel->fm.rxToneEn = 0;
|
||||
uint16_t rx_css = chData.ctcss_dcs_receive;
|
||||
uint16_t tx_css = chData.ctcss_dcs_transmit;
|
||||
|
||||
// TODO: Implement binary search to speed up this lookup
|
||||
if((rx_css != 0) && (rx_css != 0xFFFF))
|
||||
{
|
||||
for(int i = 0; i < MAX_TONE_INDEX; i++)
|
||||
{
|
||||
if(ctcss_tone[i] == ((uint16_t) _bcd2bin(rx_css)))
|
||||
{
|
||||
channel->fm.rxTone = i;
|
||||
channel->fm.rxToneEn = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((tx_css != 0) && (tx_css != 0xFFFF))
|
||||
{
|
||||
for(int i = 0; i < MAX_TONE_INDEX; i++)
|
||||
{
|
||||
if(ctcss_tone[i] == ((uint16_t) _bcd2bin(tx_css)))
|
||||
{
|
||||
channel->fm.txTone = i;
|
||||
channel->fm.txToneEn = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Implement warning screen if tone was not found
|
||||
}
|
||||
else if(channel->mode == DMR)
|
||||
{
|
||||
channel->dmr.contactName_index = chData.contact_name_index;
|
||||
channel->dmr.dmr_timeslot = chData.repeater_slot;
|
||||
channel->dmr.rxColorCode = chData.colorcode_rx;
|
||||
channel->dmr.txColorCode = chData.colorcode_tx;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nvm_readZoneData(zone_t *zone, uint16_t pos)
|
||||
|
|
|
|||
Loading…
Reference in New Issue