Skip to content

Commit

Permalink
KDC
Browse files Browse the repository at this point in the history
  • Loading branch information
losehu committed Nov 21, 2024
1 parent c543e68 commit 9196dc9
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ full:

test:
$(RM) *.bin
$(MAKE) build ENABLE_CHINESE_FULL=0 ENABLE_MDC1200=0 ENABLE_MDC1200_EDIT=0 ENABLE_MDC1200_CONTACT=0 ENABLE_FMRADIO=0 ENABLE_MESSENGER=1 ENABLE_MESSENGER_DELIVERY_NOTIFICATION=1 ENABLE_MESSENGER_NOTIFICATION=1
$(MAKE) build ENABLE_CHINESE_FULL=0 ENABLE_MDC1200=1 ENABLE_MDC1200_EDIT=0 ENABLE_MDC1200_CONTACT=1 ENABLE_FMRADIO=0 ENABLE_MESSENGER=0 ENABLE_MESSENGER_DELIVERY_NOTIFICATION=0 ENABLE_MESSENGER_NOTIFICATION=0



Expand Down
70 changes: 62 additions & 8 deletions app/mdc1200.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include "misc.h"
#include <string.h>
#include "driver/eeprom.h"
char ham[7]={0};
uint8_t ham_flag=0;


uint8_t new_mdc_switch = 1;
const uint8_t mdc1200_pre_amble[] = {0x00, 0x00, 0x00};
const uint8_t mdc1200_sync[5] = {0x07, 0x09, 0x2a, 0x44, 0x6f};

Expand Down Expand Up @@ -215,6 +217,41 @@ uint8_t *encode_data(void *data) {
return data8 + (MDC1200_FEC_K * 2);
}

uint32_t get_bits_at_position(uint32_t b, uint8_t n, uint8_t k) {
uint32_t mask = ((1U << k) - 1) << n;
return (b & mask) >> n;
}

void set_bit_at_position(uint32_t *b, uint32_t a, uint8_t n) {
*b &= ~(1U << n);
*b |= (a << n);
}

uint8_t change_mat[6] = {24, 19, 15, 10, 5, 0};

uint32_t HamToCode(char *ham) //呼号转uint32_t编码
{
uint32_t result = 0xa0000000;
for (int i = 0; i < 6; ++i) {
uint8_t tmp;
if (i == 2)tmp = ham[i] - '0';
else if (ham[i] == ' ') tmp = 26;
else tmp = ham[i] - 'A';
set_bit_at_position(&result, tmp, change_mat[i]);
}
return result;
}

void CodeToHam(char *ham, uint32_t code) {
for (int i = 0; i < 6; ++i) {
uint16_t tmp;
tmp = get_bits_at_position(code, change_mat[i], i == 2 ? 4 : 5);
if (i == 2)ham[i] = tmp + '0';
else if (tmp == 26) ham[i] = ' ';
else ham[i] = tmp + 'A';
}
}

unsigned int MDC1200_encode_single_packet(void *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id) {
unsigned int size;
uint16_t crc;
Expand All @@ -225,10 +262,20 @@ unsigned int MDC1200_encode_single_packet(void *data, const uint8_t op, const ui
memcpy(p, mdc1200_sync, sizeof(mdc1200_sync));
p += sizeof(mdc1200_sync);

p[0] = op;
p[1] = arg;
p[2] = (unit_id >> 8) & 0x00ff;
p[3] = (unit_id >> 0) & 0x00ff;
if (new_mdc_switch) {
char name[6] = {'B', 'G', '2', 'F', 'Z', 'V'};
uint32_t code = HamToCode(name);
p[0] = code >> 24;
p[1] = 0xff & (code >> 16);
p[2] = 0xff & (code >> 8);
p[3] = 0xff & (code);
} else {
p[0] = op;
p[1] = arg;
p[2] = (unit_id >> 8) & 0x00ff;
p[3] = (unit_id >> 0) & 0x00ff;
}
new_mdc_switch=1-new_mdc_switch;
crc = compute_crc(p, 4);
p[4] = (crc >> 0) & 0x00ff;
p[5] = (crc >> 8) & 0x00ff;
Expand Down Expand Up @@ -351,11 +398,18 @@ bool MDC1200_process_rx_data(
}

// extract the info from the packet
*op = rx.data[0];
*arg = rx.data[1];
*unit_id = ((uint16_t) rx.data[2] << 8) | (rx.data[3] << 0);

if((rx.data[0]&0xa0)==0xa0) {
CodeToHam(ham, (rx.data[0] << 24) | (rx.data[1] << 16) | (rx.data[2] << 8) | (rx.data[3]));
ham_flag=1;
}else
{
*op = rx.data[0];
*arg = rx.data[1];
*unit_id = ((uint16_t) rx.data[2] << 8) | (rx.data[3] << 0);
ham_flag=0;

}
// reset the detector
MDC1200_reset_rx();

Expand Down
2 changes: 2 additions & 0 deletions app/mdc1200.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,7 @@ uint16_t extractHex(const char *str);
#define MDC_NUM_ADD 0X1FFF
#define MAX_CONTACT_NUM 21
extern uint8_t contact_num;
extern char ham[7];
extern uint8_t ham_flag;

#endif
2 changes: 1 addition & 1 deletion app/messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string.h>
#include "driver/keyboard.h"

#define ENABLE_MESSENGER

#ifdef ENABLE_MESSENGER


Expand Down
10 changes: 7 additions & 3 deletions ui/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,12 @@ void UI_DisplayMain(void) {
if (mdc1200_rx_ready_tick_500ms > 0) {
char mdc1200_contact[14];
center_line = CENTER_LINE_MDC1200;
uint8_t print_col = 0;
uint8_t print_col = 30;
if(ham_flag==1)
{
sprintf(String, "HAM %s", ham);
}
else{
#ifdef ENABLE_MDC1200_CONTACT

if (mdc1200_contact_find(mdc1200_unit_id, mdc1200_contact))//
Expand All @@ -891,11 +896,10 @@ void UI_DisplayMain(void) {
} else {
#endif
sprintf(String, "ID %04X", mdc1200_unit_id);
print_col = 40;
#ifdef ENABLE_MDC1200_CONTACT
}
#endif

}

//#ifdef ENABLE_MDC1200_SHOW_OP_ARG
// sprintf(String, "MDC1200 %02X %02X %04X", mdc1200_op, mdc1200_arg, mdc1200_unit_id);
Expand Down
2 changes: 1 addition & 1 deletion ui/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ void UI_DisplayMenu(void) {

Contact[11] = 0;
memcpy(&gDTMF_ID, Contact + 8, 4);
sprintf(String, "ID:%4s", gDTMF_ID);
sprintf(String, "MDC:%4s", gDTMF_ID);
UI_PrintStringSmall(String, menu_item_x1, menu_item_x2, 5);
}
#endif
Expand Down

0 comments on commit 9196dc9

Please sign in to comment.