Skip records with FFs.

This commit is contained in:
Serge Vakulenko 2018-08-27 13:34:21 -07:00
parent 3c0685190c
commit 89b6b50f5f
3 changed files with 392 additions and 411 deletions

View File

@ -1,7 +1,8 @@
CC = gcc
VERSION = 1.0
CFLAGS = -g -O -Wall -Werror -DVERSION='"$(VERSION)"'
VERSION = 0.1
GITCOUNT = $(shell git rev-list HEAD --count)
CFLAGS = -g -O -Wall -Werror -DVERSION='"$(VERSION).$(GITCOUNT)"'
LDFLAGS = -g
OBJS = main.o util.o radio.o dfu.o uv380.o md380.o

115
md380.c
View File

@ -56,9 +56,7 @@
// Channel data.
//
typedef struct {
//
// Byte 0
//
uint8_t channel_mode : 2, // Mode: Analog or Digital
#define MODE_ANALOG 1
#define MODE_DIGITAL 2
@ -76,17 +74,13 @@ typedef struct {
_unused1 : 1, // 1
lone_worker : 1; // Lone Worker
//
// Byte 1
//
uint8_t talkaround : 1, // Allow Talkaround
rx_only : 1, // RX Only Enable
repeater_slot : 2, // Repeater Slot: 1 or 2
colorcode : 4; // Color Code: 1...15
//
// Byte 2
//
uint8_t privacy_no : 4, // Privacy No. (+1): 1...16
privacy : 2, // Privacy: None, Basic or Enhanced
#define PRIV_NONE 0
@ -96,9 +90,7 @@ typedef struct {
private_call_conf : 1, // Private Call Confirmed
data_call_conf : 1; // Data Call Confirmed
//
// Byte 3
//
uint8_t rx_ref_frequency : 2, // RX Ref Frequency: Low, Medium or High
#define REF_LOW 0
#define REF_MEDIUM 1
@ -110,9 +102,7 @@ typedef struct {
uncompressed_udp : 1, // Compressed UDP Data header (0) Enable, (1) Disable
display_pttid_dis : 1; // Display PTT ID (inverted)
//
// Byte 4
//
uint8_t tx_ref_frequency : 2, // RX Ref Frequency: Low, Medium or High
_unused4 : 2, // 0b01
vox : 1, // VOX Enable
@ -125,9 +115,7 @@ typedef struct {
#define ADMIT_CH_FREE 1
#define ADMIT_TONE 2
//
// Byte 5
//
uint8_t _unused5 : 4, // 0
in_call_criteria : 2, // In Call Criteria: Always, Follow Admit Criteria or TX Interrupt
#define INCALL_ALWAYS 0
@ -135,62 +123,42 @@ typedef struct {
_unused6 : 2; // 0b11
//
// Bytes 6-7
//
uint16_t contact_name_index; // Contact Name: Contact1...
//
// Bytes 8-9
//
uint8_t tot; // TOT x 15sec: 0-Infinite, 1=15s... 37=255s
uint8_t tot_rekey_delay; // TOT Rekey Delay: 0s...255s
//
// Bytes 10-11
//
uint8_t emergency_system_index; // Emergency System: None, System1...32
uint8_t scan_list_index; // Scan List: None, ScanList1...250
//
// Bytes 12-13
//
uint8_t group_list_index; // Group List: None, GroupList1...250
uint8_t _unused7; // 0
//
// Bytes 14-15
//
uint8_t _unused8; // 0
uint8_t _unused9; // 0xff
//
// Bytes 16-23
//
uint32_t rx_frequency; // RX Frequency: 8 digits BCD
uint32_t tx_frequency; // TX Frequency: 8 digits BCD
//
// Bytes 24-27
//
uint16_t ctcss_dcs_decode; // CTCSS/DCS Dec: 4 digits BCD
uint16_t ctcss_dcs_encode; // CTCSS/DCS Enc: 4 digits BCD
//
// Bytes 28-29
//
uint8_t rx_signaling_syst; // Rx Signaling System: Off, DTMF-1...4
uint8_t tx_signaling_syst; // Tx Signaling System: Off, DTMF-1...4
//
// Bytes 30-31
//
uint8_t _unused10; // 0xff
uint8_t _unused11; // 0xff
//
// Bytes 32-63
//
uint16_t name[16]; // Channel Name (Unicode)
} channel_t;
@ -198,14 +166,10 @@ typedef struct {
// Contact data.
//
typedef struct {
//
// Bytes 0-2
//
uint32_t id : 24; // Call ID: 1...16777215
//
// Byte 3
//
uint8_t type : 2, // Call Type: Group Call, Private Call or All Call
#define CALL_GROUP 1
#define CALL_PRIVATE 2
@ -215,9 +179,7 @@ typedef struct {
receive_tone : 1, // Call Receive Tone: No or yes
_unused2 : 2; // 0b11
//
// Bytes 4-19
//
uint16_t name[16]; // Contact Name (Unicode)
} contact_t;
@ -225,14 +187,10 @@ typedef struct {
// Zone data.
//
typedef struct {
//
// Bytes 0-31
//
uint16_t name[16]; // Zone Name (Unicode)
//
// Bytes 32-63
//
uint16_t member[16]; // Member: channels 1...16
} zone_t;
@ -240,14 +198,10 @@ typedef struct {
// Group list data.
//
typedef struct {
//
// Bytes 0-31
//
uint16_t name[16]; // Group List Name (Unicode)
//
// Bytes 32-95
//
uint16_t member[32]; // Contacts
} grouplist_t;
@ -255,29 +209,21 @@ typedef struct {
// Scan list data.
//
typedef struct {
//
// Bytes 0-31
//
uint16_t name[16]; // Scan List Name (Unicode)
//
// Bytes 32-37
//
uint16_t priority_ch1; // Priority Channel 1 or ffff
uint16_t priority_ch2; // Priority Channel 2 or ffff
uint16_t tx_designated_ch; // Tx Designated Channel or ffff
//
// Bytes 38-41
//
uint8_t _unused1; // 0xf1
uint8_t sign_hold_time; // Signaling Hold Time (x25 = msec)
uint8_t prio_sample_time; // Priority Sample Time (x250 = msec)
uint8_t _unused2; // 0xff
//
// Bytes 42-103
//
uint16_t member[31]; // Channels
} scanlist_t;
@ -542,13 +488,14 @@ static void print_id(FILE *out)
fprintf(out, "Radio: TYT MD-380\n");
fprintf(out, "Name: ");
if (radio_mem[OFFSET_NAME] != 0) {
if (radio_mem[OFFSET_NAME] != 0 && *(uint16_t*)&radio_mem[OFFSET_NAME] != 0xffff) {
print_unicode(out, (uint16_t*) &radio_mem[OFFSET_NAME], 16, 0);
} else {
fprintf(out, "-");
}
fprintf(out, "\nID: %d\n", *(uint32_t*) &radio_mem[OFFSET_ID]);
fprintf(out, "\nID: %u\n", *(uint32_t*) &radio_mem[OFFSET_ID] & 0xffffff);
if (*data != 0xff) {
fprintf(out, "Last Programmed Date: %d%d%d%d-%d%d-%d%d",
data[0] >> 4, data[0] & 15, data[1] >> 4, data[1] & 15,
data[2] >> 4, data[2] & 15, data[3] >> 4, data[3] & 15);
@ -557,6 +504,7 @@ static void print_id(FILE *out)
data[6] >> 4, data[6] & 15);
fprintf(out, "CPS Software Version: V%x%x.%x%x\n",
data[7], data[8], data[9], data[10]);
}
}
//
@ -799,6 +747,41 @@ static void print_analog_channels(FILE *out, int verbose)
}
}
static int have_zones()
{
zone_t *z = (zone_t*) &radio_mem[OFFSET_ZONES];
return z->name[0] != 0 && z->name[0] != 0xffff;
}
static int have_scanlists()
{
scanlist_t *sl = (scanlist_t*) &radio_mem[OFFSET_SCANL];
return sl->name[0] != 0 && sl->name[0] != 0xffff;
}
static int have_contacts()
{
contact_t *ct = (contact_t*) &radio_mem[OFFSET_CONTACTS];
return ct->name[0] != 0 && ct->name[0] != 0xffff;
}
static int have_grouplists()
{
grouplist_t *gl = (grouplist_t*) &radio_mem[OFFSET_GLISTS];
return gl->name[0] != 0 && gl->name[0] != 0xffff;
}
static int have_messages()
{
uint16_t *msg = (uint16_t*) &radio_mem[OFFSET_MSG];
return msg[0] != 0 && msg[0] != 0xffff;
}
//
// Print full information about the device configuration.
//
@ -823,6 +806,7 @@ static void md380_print_config(FILE *out, int verbose)
//
// Zones.
//
if (have_zones()) {
fprintf(out, "\n");
if (verbose) {
fprintf(out, "# Table of channel zones.\n");
@ -835,7 +819,7 @@ static void md380_print_config(FILE *out, int verbose)
for (i=0; i<NZONES; i++) {
zone_t *z = (zone_t*) &radio_mem[OFFSET_ZONES + i*64];
if (z->name[0] == 0) {
if (z->name[0] == 0 || z->name[0] == 0xffff) {
// Zone is disabled.
continue;
}
@ -850,10 +834,12 @@ static void md380_print_config(FILE *out, int verbose)
}
fprintf(out, "\n");
}
}
//
// Scan lists.
//
if (have_scanlists()) {
fprintf(out, "\n");
if (verbose) {
fprintf(out, "# Table of scan lists.\n");
@ -866,7 +852,7 @@ static void md380_print_config(FILE *out, int verbose)
for (i=0; i<NSCANL; i++) {
scanlist_t *sl = (scanlist_t*) &radio_mem[OFFSET_SCANL + i*104];
if (sl->name[0] == 0) {
if (sl->name[0] == 0 || sl->name[0] == 0xffff) {
// Scan list is disabled.
continue;
}
@ -903,10 +889,12 @@ static void md380_print_config(FILE *out, int verbose)
}
fprintf(out, "\n");
}
}
//
// Contacts.
//
if (have_contacts()) {
fprintf(out, "\n");
if (verbose) {
fprintf(out, "# Table of contacts.\n");
@ -921,7 +909,7 @@ static void md380_print_config(FILE *out, int verbose)
for (i=0; i<NCONTACTS; i++) {
contact_t *ct = (contact_t*) &radio_mem[OFFSET_CONTACTS + i*36];
if (ct->name[0] == 0) {
if (ct->name[0] == 0 || ct->name[0] == 0xffff) {
// Contact is disabled
continue;
}
@ -931,10 +919,12 @@ static void md380_print_config(FILE *out, int verbose)
fprintf(out, " %-7s %-8d %s\n",
CONTACT_TYPE[ct->type], ct->id, ct->receive_tone ? "Yes" : "-");
}
}
//
// Group lists.
//
if (have_grouplists()) {
fprintf(out, "\n");
if (verbose) {
fprintf(out, "# Table of group lists.\n");
@ -946,7 +936,7 @@ static void md380_print_config(FILE *out, int verbose)
for (i=0; i<NGLISTS; i++) {
grouplist_t *gl = (grouplist_t*) &radio_mem[OFFSET_GLISTS + i*96];
if (gl->name[0] == 0) {
if (gl->name[0] == 0 || gl->name[0] == 0xffff) {
// Group list is disabled.
continue;
}
@ -959,10 +949,12 @@ static void md380_print_config(FILE *out, int verbose)
}
fprintf(out, "\n");
}
}
//
// Text messages.
//
if (have_messages()) {
fprintf(out, "\n");
if (verbose) {
fprintf(out, "# Table of text messages.\n");
@ -974,7 +966,7 @@ static void md380_print_config(FILE *out, int verbose)
for (i=0; i<NMESSAGES; i++) {
uint16_t *msg = (uint16_t*) &radio_mem[OFFSET_MSG + i*288];
if (msg[0] == 0) {
if (msg[0] == 0 || msg[0] == 0xffff) {
// Message is disabled
continue;
}
@ -983,6 +975,7 @@ static void md380_print_config(FILE *out, int verbose)
print_unicode(out, msg, 144, 0);
fprintf(out, "\n");
}
}
}
//

121
uv380.c
View File

@ -57,9 +57,7 @@
// Channel data.
//
typedef struct {
//
// Byte 0
//
uint8_t channel_mode : 2, // Mode: Analog or Digital
#define MODE_ANALOG 1
#define MODE_DIGITAL 2
@ -73,17 +71,13 @@ typedef struct {
_unused1 : 2, // 0b11
lone_worker : 1; // Lone Worker
//
// Byte 1
//
uint8_t _unused2 : 1, // 0
rx_only : 1, // RX Only Enable
repeater_slot : 2, // Repeater Slot: 1 or 2
colorcode : 4; // Color Code: 1...15
//
// Byte 2
//
uint8_t privacy_no : 4, // Privacy No. (+1): 1...16
privacy : 2, // Privacy: None, Basic or Enhanced
#define PRIV_NONE 0
@ -93,9 +87,7 @@ typedef struct {
private_call_conf : 1, // Private Call Confirmed
data_call_conf : 1; // Data Call Confirmed
//
// Byte 3
//
uint8_t rx_ref_frequency : 2, // RX Ref Frequency: Low, Medium or High
#define REF_LOW 0
#define REF_MEDIUM 1
@ -106,9 +98,7 @@ typedef struct {
_unused4 : 3, // 0b110
display_pttid_dis : 1; // Display PTT ID (inverted)
//
// Byte 4
//
uint8_t tx_ref_frequency : 2, // RX Ref Frequency: Low, Medium or High
_unused5 : 2, // 0b01
vox : 1, // VOX Enable
@ -118,9 +108,7 @@ typedef struct {
#define ADMIT_CH_FREE 1
#define ADMIT_TONE 2
//
// Byte 5
//
uint8_t _unused7 : 4, // 0
in_call_criteria : 2, // In Call Criteria: Always, Follow Admit Criteria or TX Interrupt
#define INCALL_ALWAYS 0
@ -132,56 +120,38 @@ typedef struct {
#define TURNOFF_259_2HZ 0
#define TURNOFF_55_2HZ 1
//
// Bytes 6-7
//
uint16_t contact_name_index; // Contact Name: Contact1...
//
// Bytes 8-9
//
uint8_t tot; // TOT x 15sec: 0-Infinite, 1=15s... 37=255s
uint8_t tot_rekey_delay; // TOT Rekey Delay: 0s...255s
//
// Bytes 10-11
//
uint8_t emergency_system_index; // Emergency System: None, System1...32
uint8_t scan_list_index; // Scan List: None, ScanList1...250
//
// Bytes 12-13
//
uint8_t group_list_index; // Group List: None, GroupList1...250
uint8_t _unused8; // 0
//
// Bytes 14-15
//
uint8_t _unused9; // 0
uint8_t squelch; // Squelch: 0...9
//
// Bytes 16-23
//
uint32_t rx_frequency; // RX Frequency: 8 digits BCD
uint32_t tx_frequency; // TX Frequency: 8 digits BCD
//
// Bytes 24-27
//
uint16_t ctcss_dcs_decode; // CTCSS/DCS Dec: 4 digits BCD
uint16_t ctcss_dcs_encode; // CTCSS/DCS Enc: 4 digits BCD
//
// Bytes 28-29
//
uint8_t rx_signaling_syst; // Rx Signaling System: Off, DTMF-1...4
uint8_t tx_signaling_syst; // Tx Signaling System: Off, DTMF-1...4
//
// Byte 30
//
uint8_t power : 2, // Power: Low, Middle, High
#define POWER_HIGH 3
#define POWER_LOW 0
@ -189,9 +159,7 @@ typedef struct {
_unused10 : 6; // 0b111111
//
// Byte 31
//
uint8_t _unused11 : 3, // 0b111
dcdm_switch_dis : 1, // DCDM switch (inverted)
leader_ms : 1, // Leader/MS: Leader or MS
@ -200,9 +168,7 @@ typedef struct {
_unused12 : 3; // 0b111
//
// Bytes 32-63
//
uint16_t name[16]; // Channel Name (Unicode)
} channel_t;
@ -210,14 +176,10 @@ typedef struct {
// Contact data.
//
typedef struct {
//
// Bytes 0-2
//
uint32_t id : 24; // Call ID: 1...16777215
//
// Byte 3
//
uint8_t type : 2, // Call Type: Group Call, Private Call or All Call
#define CALL_GROUP 1
#define CALL_PRIVATE 2
@ -227,9 +189,7 @@ typedef struct {
receive_tone : 1, // Call Receive Tone: No or yes
_unused2 : 2; // 0b11
//
// Bytes 4-19
//
uint16_t name[16]; // Contact Name (Unicode)
} contact_t;
@ -237,26 +197,18 @@ typedef struct {
// Zone data.
//
typedef struct {
//
// Bytes 0-31
//
uint16_t name[16]; // Zone Name (Unicode)
//
// Bytes 32-63
//
uint16_t member_a[16]; // Member A: channels 1...16
} zone_t;
typedef struct {
//
// Bytes 0-95
//
uint16_t ext_a[48]; // Member A: channels 17...64
//
// Bytes 96-223
//
uint16_t member_b[64]; // Member B: channels 1...64
} zone_ext_t;
@ -264,14 +216,10 @@ typedef struct {
// Group list data.
//
typedef struct {
//
// Bytes 0-31
//
uint16_t name[16]; // Group List Name (Unicode)
//
// Bytes 32-95
//
uint16_t member[32]; // Contacts
} grouplist_t;
@ -279,29 +227,21 @@ typedef struct {
// Scan list data.
//
typedef struct {
//
// Bytes 0-31
//
uint16_t name[16]; // Scan List Name (Unicode)
//
// Bytes 32-37
//
uint16_t priority_ch1; // Priority Channel 1 or ffff
uint16_t priority_ch2; // Priority Channel 2 or ffff
uint16_t tx_designated_ch; // Tx Designated Channel or ffff
//
// Bytes 38-41
//
uint8_t _unused1; // 0xf1
uint8_t sign_hold_time; // Signaling Hold Time (x25 = msec)
uint8_t prio_sample_time; // Priority Sample Time (x250 = msec)
uint8_t _unused2; // 0xff
//
// Bytes 42-103
//
uint16_t member[31]; // Channels
} scanlist_t;
@ -564,13 +504,14 @@ static void print_id(FILE *out)
fprintf(out, "Radio: TYT MD-UV380\n");
fprintf(out, "Name: ");
if (radio_mem[OFFSET_NAME] != 0) {
if (radio_mem[OFFSET_NAME] != 0 && *(uint16_t*)&radio_mem[OFFSET_NAME] != 0xffff) {
print_unicode(out, (uint16_t*) &radio_mem[OFFSET_NAME], 16, 0);
} else {
fprintf(out, "-");
}
fprintf(out, "\nID: %d\n", *(uint32_t*) &radio_mem[OFFSET_ID]);
fprintf(out, "\nID: %u\n", *(uint32_t*) &radio_mem[OFFSET_ID] & 0xffffff);
if (*data != 0xff) {
fprintf(out, "Last Programmed Date: %d%d%d%d-%d%d-%d%d",
data[0] >> 4, data[0] & 15, data[1] >> 4, data[1] & 15,
data[2] >> 4, data[2] & 15, data[3] >> 4, data[3] & 15);
@ -579,6 +520,7 @@ static void print_id(FILE *out)
data[6] >> 4, data[6] & 15);
fprintf(out, "CPS Software Version: V%x%x.%x%x\n",
data[7], data[8], data[9], data[10]);
}
}
//
@ -825,6 +767,41 @@ static void print_analog_channels(FILE *out, int verbose)
}
}
static int have_zones()
{
zone_t *z = (zone_t*) &radio_mem[OFFSET_ZONES];
return z->name[0] != 0 && z->name[0] != 0xffff;
}
static int have_scanlists()
{
scanlist_t *sl = (scanlist_t*) &radio_mem[OFFSET_SCANL];
return sl->name[0] != 0 && sl->name[0] != 0xffff;
}
static int have_contacts()
{
contact_t *ct = (contact_t*) &radio_mem[OFFSET_CONTACTS];
return ct->name[0] != 0 && ct->name[0] != 0xffff;
}
static int have_grouplists()
{
grouplist_t *gl = (grouplist_t*) &radio_mem[OFFSET_GLISTS];
return gl->name[0] != 0 && gl->name[0] != 0xffff;
}
static int have_messages()
{
uint16_t *msg = (uint16_t*) &radio_mem[OFFSET_MSG];
return msg[0] != 0 && msg[0] != 0xffff;
}
//
// Print full information about the device configuration.
//
@ -849,6 +826,7 @@ static void uv380_print_config(FILE *out, int verbose)
//
// Zones.
//
if (have_zones()) {
fprintf(out, "\n");
if (verbose) {
fprintf(out, "# Table of channel zones.\n");
@ -862,7 +840,7 @@ static void uv380_print_config(FILE *out, int verbose)
zone_t *z = (zone_t*) &radio_mem[OFFSET_ZONES + i*64];
zone_ext_t *zext = (zone_ext_t*) &radio_mem[OFFSET_ZONEXT + i*224];
if (z->name[0] == 0) {
if (z->name[0] == 0 || z->name[0] == 0xffff) {
// Zone is disabled.
continue;
}
@ -889,10 +867,12 @@ static void uv380_print_config(FILE *out, int verbose)
}
fprintf(out, "\n");
}
}
//
// Scan lists.
//
if (have_scanlists()) {
fprintf(out, "\n");
if (verbose) {
fprintf(out, "# Table of scan lists.\n");
@ -905,7 +885,7 @@ static void uv380_print_config(FILE *out, int verbose)
for (i=0; i<NSCANL; i++) {
scanlist_t *sl = (scanlist_t*) &radio_mem[OFFSET_SCANL + i*104];
if (sl->name[0] == 0) {
if (sl->name[0] == 0 || sl->name[0] == 0xffff) {
// Scan list is disabled.
continue;
}
@ -942,10 +922,12 @@ static void uv380_print_config(FILE *out, int verbose)
}
fprintf(out, "\n");
}
}
//
// Contacts.
//
if (have_contacts()) {
fprintf(out, "\n");
if (verbose) {
fprintf(out, "# Table of contacts.\n");
@ -960,7 +942,7 @@ static void uv380_print_config(FILE *out, int verbose)
for (i=0; i<NCONTACTS; i++) {
contact_t *ct = (contact_t*) &radio_mem[OFFSET_CONTACTS + i*36];
if (ct->name[0] == 0) {
if (ct->name[0] == 0 || ct->name[0] == 0xffff) {
// Contact is disabled
continue;
}
@ -970,10 +952,12 @@ static void uv380_print_config(FILE *out, int verbose)
fprintf(out, " %-7s %-8d %s\n",
CONTACT_TYPE[ct->type], ct->id, ct->receive_tone ? "Yes" : "-");
}
}
//
// Group lists.
//
if (have_grouplists()) {
fprintf(out, "\n");
if (verbose) {
fprintf(out, "# Table of group lists.\n");
@ -985,7 +969,7 @@ static void uv380_print_config(FILE *out, int verbose)
for (i=0; i<NGLISTS; i++) {
grouplist_t *gl = (grouplist_t*) &radio_mem[OFFSET_GLISTS + i*96];
if (gl->name[0] == 0) {
if (gl->name[0] == 0 || gl->name[0] == 0xffff) {
// Group list is disabled.
continue;
}
@ -998,10 +982,12 @@ static void uv380_print_config(FILE *out, int verbose)
}
fprintf(out, "\n");
}
}
//
// Text messages.
//
if (have_messages()) {
fprintf(out, "\n");
if (verbose) {
fprintf(out, "# Table of text messages.\n");
@ -1013,7 +999,7 @@ static void uv380_print_config(FILE *out, int verbose)
for (i=0; i<NMESSAGES; i++) {
uint16_t *msg = (uint16_t*) &radio_mem[OFFSET_MSG + i*288];
if (msg[0] == 0) {
if (msg[0] == 0 || msg[0] == 0xffff) {
// Message is disabled
continue;
}
@ -1022,6 +1008,7 @@ static void uv380_print_config(FILE *out, int verbose)
print_unicode(out, msg, 144, 0);
fprintf(out, "\n");
}
}
}
//