Skip to content

Commit

Permalink
Added AIRCOPY_SendMessage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dual Tachyon authored and Dual Tachyon committed Aug 26, 2023
1 parent 69b4c86 commit 30acd10
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
29 changes: 29 additions & 0 deletions aircopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,38 @@
*/

#include "aircopy.h"
#include "driver/bk4819.h"
#include "driver/crc.h"
#include "driver/eeprom.h"
#include "misc.h"
#include "radio.h"

static const uint16_t Obfuscation[8] = { 0x6C16, 0xE614, 0x912E, 0x400D, 0x3521, 0x40D5, 0x0313, 0x80E9 };

AIRCOPY_State_t gAircopyState;
uint16_t gAirCopyBlockNumber;
uint16_t gErrorsDuringAirCopy;
uint8_t gAirCopyIsSendMode;

uint16_t g_FSK_Buffer[36];

void AIRCOPY_SendMessage(void)
{
uint8_t i;

g_FSK_Buffer[1] = (gAirCopyBlockNumber & 0x3FF) << 6;
EEPROM_ReadBuffer(g_FSK_Buffer[1], &g_FSK_Buffer[2], 64);
g_FSK_Buffer[34] = CRC_Calculate(&g_FSK_Buffer[1], 2 + 64);
for (i = 0; i < 34; i++) {
g_FSK_Buffer[i + 1] ^= Obfuscation[i % 8];
}
if (++gAirCopyBlockNumber >= 0x78) {
gAircopyState = AIRCOPY_COMPLETE;
}
RADIO_PrepareTransmit();
BK4819_SendFSKData(g_FSK_Buffer);
BK4819_SetupPowerAmplifier(0, 0);
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1, false);
gAircopySendCountdown = 0x1e;
}

6 changes: 5 additions & 1 deletion aircopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
enum AIRCOPY_State_t {
AIRCOPY_READY = 0U,
AIRCOPY_TRANSFER = 1U,
AIRCOPY_CMP = 2U,
AIRCOPY_COMPLETE = 2U,
};

typedef enum AIRCOPY_State_t AIRCOPY_State_t;
Expand All @@ -32,5 +32,9 @@ extern uint16_t gAirCopyBlockNumber;
extern uint16_t gErrorsDuringAirCopy;
extern uint8_t gAirCopyIsSendMode;

extern uint16_t g_FSK_Buffer[36];

void AIRCOPY_SendMessage(void);

#endif

2 changes: 1 addition & 1 deletion app.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ void APP_TimeSlice10ms(void)
if (gAircopySendCountdown != 0) {
gAircopySendCountdown--;
if (gAircopySendCountdown == 0) {
//FSK_SendMessage();
AIRCOPY_SendMessage();
GUI_DisplayScreen();
}
}
Expand Down
34 changes: 34 additions & 0 deletions driver/bk4819.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,3 +819,37 @@ uint8_t BK4819_GetCTCSSPhaseShift(void)
return (BK4819_GetRegister(BK4819_REG_0C) >> 14) & 3;
}

void BK4819_SendFSKData(uint16_t *pData)
{
uint8_t i;
uint8_t Timeout;

Timeout = 200;

SYSTEM_DelayMs(20);

BK4819_WriteRegister(BK4819_REG_3F, BK4819_REG_3F_FSK_TX_FINISHED);
BK4819_WriteRegister(BK4819_REG_59, 0x8068);
BK4819_WriteRegister(BK4819_REG_59, 0x0068);

for (i = 0; i < 36; i++) {
BK4819_WriteRegister(BK4819_REG_5F, pData[i]);
}

SYSTEM_DelayMs(20);

BK4819_WriteRegister(BK4819_REG_59,0x2868);

while (Timeout) {
if (BK4819_GetRegister(BK4819_REG_0C) & 1U) {
break;
}
SYSTEM_DelayMs(5);
Timeout--;
}

BK4819_WriteRegister(BK4819_REG_02, 0);
SYSTEM_DelayMs(20);
BK4819_ResetFSK();
}

2 changes: 2 additions & 0 deletions driver/bk4819.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,7 @@ uint8_t BK4819_GetDTMF_5TONE_Code(void);
uint8_t BK4819_CheckCDCSSCodeReceived(void);
uint8_t BK4819_GetCTCSSPhaseShift(void);

void BK4819_SendFSKData(uint16_t *pData);

#endif

0 comments on commit 30acd10

Please sign in to comment.