Skip to content

Commit

Permalink
Merge pull request #123 from kamilsss655/rc20.5
Browse files Browse the repository at this point in the history
Rc20.5
  • Loading branch information
kamilsss655 authored Feb 3, 2024
2 parents 5fbb556 + 340497b commit b655393
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 64 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ ENABLE_SPECTRUM_SHOW_CHANNEL_NAME := 1
ENABLE_SPECTRUM_CHANNEL_SCAN := 1
ENABLE_MESSENGER := 1
ENABLE_MESSENGER_DELIVERY_NOTIFICATION := 1
ENABLE_MESSENGER_FSK_MUTE := 1
ENABLE_MESSENGER_NOTIFICATION := 1
ENABLE_MESSENGER_UART := 0
ENABLE_ENCRYPTION := 1
Expand Down Expand Up @@ -370,6 +371,9 @@ endif
ifeq ($(ENABLE_MESSENGER_DELIVERY_NOTIFICATION),1)
CFLAGS += -DENABLE_MESSENGER_DELIVERY_NOTIFICATION
endif
ifeq ($(ENABLE_MESSENGER_FSK_MUTE),1)
CFLAGS += -DENABLE_MESSENGER_FSK_MUTE
endif
ifeq ($(ENABLE_MESSENGER_NOTIFICATION),1)
CFLAGS += -DENABLE_MESSENGER_NOTIFICATION
endif
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ ENABLE_SPECTRUM_SHOW_CHANNEL_NAME := 1 shows channel number and channel n
ENABLE_ADJUSTABLE_RX_GAIN_SETTINGS := 1 keeps the rx gain settings set in spectrum mode after exit (otherwise these are always overwritten to default value), this makes much more sense considering that we have a radio with user adjustable gain so why not use it to adjust to current radio conditions, maximum gain allows to greatly increase reception in scan memory channels mode (in this configuration default gain settings are only set at boot and when exiting AM modulation mode to set it to sane value after am fix)
ENABLE_SPECTRUM_CHANNEL_SCAN := 1 this enables spectrum channel scan mode (enter by going into memory mode and press F+5, this allows SUPER fast channel scanning (4.5x faster than regular scanning), regular scan of 200 memory channels takes roughly 18 seconds, spectrum memory scan takes roughly 4 seconds, if you have less channels stored i.e 50 - the spectrum memory scan will take only **1 second**
ENABLE_MESSENGER := 1 enable messenger
ENABLE_MESSENGER_FSK_MUTE := 1 mutes speaker once it detects fsk sync word (might cause unintentional mutes during ctcss rx)
ENABLE_MESSENGER_NOTIFICATION := 1 enable messenger delivery notification
ENABLE_MESSENGER_UART := 0 enable sending messages via serial with SMS:content command (unreliable)
ENABLE_ENCRYPTION := 1 enable ChaCha20 256 bit encryption for messenger
Expand Down
54 changes: 53 additions & 1 deletion app/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,24 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax)
case MENU_500TX:
case MENU_350EN:
case MENU_SCREN:
#ifdef ENABLE_ENCRYPTION
case MENU_MSG_ENC:
#endif
#ifdef ENABLE_MESSENGER
case MENU_MSG_RX:
case MENU_MSG_ACK:
#endif
*pMin = 0;
*pMax = ARRAY_SIZE(gSubMenu_OFF_ON) - 1;
break;

#ifdef ENABLE_MESSENGER
case MENU_MSG_MODULATION:
*pMin = 0;
*pMax = ARRAY_SIZE(gSubMenu_MSG_MODULATION) - 1;
break;
#endif

case MENU_AM:
*pMin = 0;
*pMax = ARRAY_SIZE(gModulationStr) - 1;
Expand Down Expand Up @@ -483,10 +497,28 @@ void MENU_AcceptSetting(void)
#ifdef ENABLE_ENCRYPTION
case MENU_ENC_KEY:
memset(gEeprom.ENC_KEY, 0, sizeof(gEeprom.ENC_KEY));
memmove(gEeprom.ENC_KEY, edit, sizeof(edit));
memmove(gEeprom.ENC_KEY, edit, sizeof(gEeprom.ENC_KEY));
memset(edit, 0, sizeof(edit));
gUpdateStatus = true;
break;

case MENU_MSG_ENC:
gEeprom.MESSENGER_CONFIG.data.encrypt = gSubMenuSelection;
break;
#endif

#ifdef ENABLE_MESSENGER
case MENU_MSG_RX:
gEeprom.MESSENGER_CONFIG.data.receive = gSubMenuSelection;
break;

case MENU_MSG_ACK:
gEeprom.MESSENGER_CONFIG.data.ack = gSubMenuSelection;
break;

case MENU_MSG_MODULATION:
gEeprom.MESSENGER_CONFIG.data.modulation = gSubMenuSelection;
break;
#endif

case MENU_W_N:
Expand Down Expand Up @@ -916,6 +948,26 @@ void MENU_ShowCurrentSetting(void)
gSubMenuSelection = gEeprom.RX_OFFSET;
break;

#ifdef ENABLE_ENCRYPTION
case MENU_MSG_ENC:
gSubMenuSelection = gEeprom.MESSENGER_CONFIG.data.encrypt;
break;
#endif

#ifdef ENABLE_MESSENGER
case MENU_MSG_RX:
gSubMenuSelection = gEeprom.MESSENGER_CONFIG.data.receive;
break;

case MENU_MSG_ACK:
gSubMenuSelection = gEeprom.MESSENGER_CONFIG.data.ack;
break;

case MENU_MSG_MODULATION:
gSubMenuSelection = gEeprom.MESSENGER_CONFIG.data.modulation;
break;
#endif

#ifdef ENABLE_PWRON_PASSWORD
case MENU_PASSWORD:
gSubMenuSelection = gEeprom.POWER_ON_PASSWORD;
Expand Down
196 changes: 137 additions & 59 deletions app/messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const uint8_t MSG_BUTTON_EVENT_LONG = MSG_BUTTON_STATE_HELD;

const uint8_t MAX_MSG_LENGTH = PAYLOAD_LENGTH - 1;

const uint16_t TONE2_FREQ = 0x3065; // 0x2854
uint16_t TONE2_FREQ;

#define NEXT_CHAR_DELAY 100 // 10ms tick

Expand Down Expand Up @@ -72,13 +72,14 @@ void MSG_FSKSendData() {
uint16_t deviation;
switch (gEeprom.VfoInfo[gEeprom.TX_VFO].CHANNEL_BANDWIDTH)
{
case BK4819_FILTER_BW_WIDE: deviation = 1350; break; // 20k // measurements by kamilsss655
case BK4819_FILTER_BW_WIDE: deviation = 1300; break; // 20k // measurements by kamilsss655
case BK4819_FILTER_BW_NARROW: deviation = 1200; break; // 10k
// case BK4819_FILTER_BW_NARROWAVIATION: deviation = 850; break; // 5k
// case BK4819_FILTER_BW_NARROWER: deviation = 850; break; // 5k
// case BK4819_FILTER_BW_NARROWEST: deviation = 850; break; // 5k
default: deviation = 850; break; // 5k
}

//BK4819_WriteRegister(0x40, (3u << 12) | (deviation & 0xfff));
BK4819_WriteRegister(BK4819_REG_40, (dev_val & 0xf000) | (deviation & 0xfff));
}
Expand Down Expand Up @@ -152,7 +153,9 @@ void MSG_EnableRX(const bool enable) {

if (enable) {
MSG_ConfigureFSK(true);
BK4819_FskEnableRx();

if(gEeprom.MESSENGER_CONFIG.data.receive)
BK4819_FskEnableRx();
} else {
BK4819_WriteRegister(BK4819_REG_70, 0);
BK4819_WriteRegister(BK4819_REG_58, 0);
Expand Down Expand Up @@ -266,9 +269,12 @@ void MSG_StorePacket(const uint16_t interrupt_bits) {
//UART_printf("\nMSG : S%i, F%i, E%i | %i", rx_sync, rx_fifo_almost_full, rx_finished, interrupt_bits);

if (rx_sync) {
// prevent listening to fsk data and squelch (kamilsss655)
AUDIO_AudioPathOff();

#ifdef ENABLE_MESSENGER_FSK_MUTE
// prevent listening to fsk data and squelch (kamilsss655)
// CTCSS codes seem to false trigger the rx_sync
if(gCurrentCodeType == CODE_TYPE_OFF)
AUDIO_AudioPathOff();
#endif
gFSKWriteIndex = 0;
MSG_ClearPacketBuffer();
msgStatus = RECEIVING;
Expand Down Expand Up @@ -382,7 +388,9 @@ void MSG_HandleReceive(){
{
// wait so the correspondent radio can properly receive it
SYSTEM_DelayMs(700);
MSG_SendAck();

if(gEeprom.MESSENGER_CONFIG.data.ack)
MSG_SendAck();
}
}

Expand Down Expand Up @@ -519,7 +527,14 @@ void MSG_ClearPacketBuffer()
void MSG_Send(const char *cMessage){
MSG_ClearPacketBuffer();
#ifdef ENABLE_ENCRYPTION
dataPacket.data.header=ENCRYPTED_MESSAGE_PACKET;
if(gEeprom.MESSENGER_CONFIG.data.encrypt)
{
dataPacket.data.header=ENCRYPTED_MESSAGE_PACKET;
}
else
{
dataPacket.data.header=MESSAGE_PACKET;
}
#else
dataPacket.data.header=MESSAGE_PACKET;
#endif
Expand Down Expand Up @@ -551,59 +566,122 @@ void MSG_ConfigureFSK(bool rx)
( 1u << 7) | // 1
(96u << 0)); // 96

// Tone2 baudrate 1200
BK4819_WriteRegister(BK4819_REG_72, TONE2_FREQ);
// Tone2 = FSK baudrate // kamilsss655 2024
switch(gEeprom.MESSENGER_CONFIG.data.modulation)
{
case MOD_AFSK_1200:
TONE2_FREQ = 12389u;
break;
case MOD_FSK_700:
TONE2_FREQ = 7227u;
break;
case MOD_FSK_450:
TONE2_FREQ = 4646u;
break;
}

BK4819_WriteRegister(BK4819_REG_72, TONE2_FREQ);


BK4819_WriteRegister(BK4819_REG_58,
(1u << 13) | // 1 FSK TX mode selection
// 0 = FSK 1.2K and FSK 2.4K TX .. no tones, direct FM
// 1 = FFSK 1200 / 1800 TX
// 2 = ???
// 3 = FFSK 1200 / 2400 TX
// 4 = ???
// 5 = NOAA SAME TX
// 6 = ???
// 7 = ???
//
(7u << 10) | // 0 FSK RX mode selection
// 0 = FSK 1.2K, FSK 2.4K RX and NOAA SAME RX .. no tones, direct FM
// 1 = ???
// 2 = ???
// 3 = ???
// 4 = FFSK 1200 / 2400 RX
// 5 = ???
// 6 = ???
// 7 = FFSK 1200 / 1800 RX
//
(3u << 8) | // 0 FSK RX gain
// 0 ~ 3
//
(0u << 6) | // 0 ???
// 0 ~ 3
//
(0u << 4) | // 0 FSK preamble type selection
// 0 = 0xAA or 0x55 due to the MSB of FSK sync byte 0
// 1 = ???
// 2 = 0x55
// 3 = 0xAA
//
(1u << 1) | // 1 FSK RX bandwidth setting
// 0 = FSK 1.2K .. no tones, direct FM
// 1 = FFSK 1200 / 1800
// 2 = NOAA SAME RX
// 3 = ???
// 4 = FSK 2.4K and FFSK 1200 / 2400
// 5 = ???
// 6 = ???
// 7 = ???
//
(1u << 0)); // 1 FSK enable
// 0 = disable
// 1 = enable


switch(gEeprom.MESSENGER_CONFIG.data.modulation)
{
case MOD_FSK_700:
case MOD_FSK_450:
BK4819_WriteRegister(BK4819_REG_58,
(0u << 13) | // 1 FSK TX mode selection
// 0 = FSK 1.2K and FSK 2.4K TX .. no tones, direct FM
// 1 = FFSK 1200 / 1800 TX
// 2 = ???
// 3 = FFSK 1200 / 2400 TX
// 4 = ???
// 5 = NOAA SAME TX
// 6 = ???
// 7 = ???
//
(0u << 10) | // 0 FSK RX mode selection
// 0 = FSK 1.2K, FSK 2.4K RX and NOAA SAME RX .. no tones, direct FM
// 1 = ???
// 2 = ???
// 3 = ???
// 4 = FFSK 1200 / 2400 RX
// 5 = ???
// 6 = ???
// 7 = FFSK 1200 / 1800 RX
//
(3u << 8) | // 0 FSK RX gain
// 0 ~ 3
//
(0u << 6) | // 0 ???
// 0 ~ 3
//
(0u << 4) | // 0 FSK preamble type selection
// 0 = 0xAA or 0x55 due to the MSB of FSK sync byte 0
// 1 = ???
// 2 = 0x55
// 3 = 0xAA
//
(0u << 1) | // 1 FSK RX bandwidth setting
// 0 = FSK 1.2K .. no tones, direct FM
// 1 = FFSK 1200 / 1800
// 2 = NOAA SAME RX
// 3 = ???
// 4 = FSK 2.4K and FFSK 1200 / 2400
// 5 = ???
// 6 = ???
// 7 = ???
//
(1u << 0)); // 1 FSK enable
// 0 = disable
// 1 = enable
break;
case MOD_AFSK_1200:
BK4819_WriteRegister(BK4819_REG_58,
(1u << 13) | // 1 FSK TX mode selection
// 0 = FSK 1.2K and FSK 2.4K TX .. no tones, direct FM
// 1 = FFSK 1200 / 1800 TX
// 2 = ???
// 3 = FFSK 1200 / 2400 TX
// 4 = ???
// 5 = NOAA SAME TX
// 6 = ???
// 7 = ???
//
(7u << 10) | // 0 FSK RX mode selection
// 0 = FSK 1.2K, FSK 2.4K RX and NOAA SAME RX .. no tones, direct FM
// 1 = ???
// 2 = ???
// 3 = ???
// 4 = FFSK 1200 / 2400 RX
// 5 = ???
// 6 = ???
// 7 = FFSK 1200 / 1800 RX
//
(3u << 8) | // 0 FSK RX gain
// 0 ~ 3
//
(0u << 6) | // 0 ???
// 0 ~ 3
//
(0u << 4) | // 0 FSK preamble type selection
// 0 = 0xAA or 0x55 due to the MSB of FSK sync byte 0
// 1 = ???
// 2 = 0x55
// 3 = 0xAA
//
(1u << 1) | // 1 FSK RX bandwidth setting
// 0 = FSK 1.2K .. no tones, direct FM
// 1 = FFSK 1200 / 1800
// 2 = NOAA SAME RX
// 3 = ???
// 4 = FSK 2.4K and FFSK 1200 / 2400
// 5 = ???
// 6 = ???
// 7 = ???
//
(1u << 0)); // 1 FSK enable
// 0 = disable
// 1 = enable
break;
}

// REG_5A .. bytes 0 & 1 sync pattern
//
Expand Down
20 changes: 20 additions & 0 deletions app/messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ typedef enum PacketType {
INVALID_PACKET
} PacketType;

// Modem Modulation // 2024 kamilsss655
typedef enum ModemModulation {
MOD_FSK_450, // for bad conditions
MOD_FSK_700, // for medium conditions
MOD_AFSK_1200 // for good conditions
} ModemModulation;

// Data Packet definition // 2024 kamilsss655
union DataPacket
{
Expand All @@ -53,6 +60,19 @@ union DataPacket
uint8_t serializedArray[1+PAYLOAD_LENGTH+NONCE_LENGTH];
};

// MessengerConfig // 2024 kamilsss655
typedef union {
struct {
uint8_t
receive :1, // determines whether fsk modem will listen for new messages
ack :1, // determines whether the radio will automatically respond to messages with ACK
encrypt :1, // determines whether outgoing messages will be encrypted
unused :1,
modulation :2, // determines FSK modulation type
unused2 :2;
} data;
uint8_t __val;
} MessengerConfig;

void MSG_EnableRX(const bool enable);
void MSG_StorePacket(const uint16_t interrupt_bits);
Expand Down
Loading

0 comments on commit b655393

Please sign in to comment.