NMT: Fixed traffic area (Y1Y2) digit conversion

pull/1/head
Andreas Eversberg 4 years ago
parent 1321f66456
commit e4fcc080df
  1. 4
      src/nmt/countries.c
  2. 25
      src/nmt/frame.c
  3. 1
      src/nmt/frame.h
  4. 15
      src/nmt/main.c
  5. 2
      src/nmt/nmt.c

@ -147,7 +147,7 @@ static struct nmt_country {
{ 900, 1, 2, 1,9, "SE", "Sweden", "Telia Mobitel", frq_900_scandinavia },
{ 900, 1, 3, 1,9, "NO", "Norway", "Telenor Mobil", frq_900_scandinavia },
{ 900, 1, 4, 1,9, "FI", "Finland", "Telecom Finland", frq_900_scandinavia },
{ 900, 1,10, 1,9, "F0", "France (Group 0)", "France Telecom", frq_900_f },
{ 900, 1, 0, 1,9, "F0", "France (Group 0)", "France Telecom", frq_900_f },
{ 900, 1, 1, 1,9, "F1", "France (Group 1)", "France Telecom", frq_900_f },
{ 900, 1, 2, 1,9, "F2", "France (Group 2)", "France Telecom", frq_900_f },
{ 900, 1, 3, 1,9, "F3", "France (Group 3)", "France Telecom", frq_900_f },
@ -174,7 +174,7 @@ void nmt_country_list(int nmt_system)
int ch_from = 0, ch_to = 0;
char ch_string[256];
printf("TA from\tTA to\tYY Code\tChannels\t\t\tShort\tCountry (Provider)\n");
printf("TA from\tTA to\tYY Code\tChannels\t\t\tCountry (Provider)\n");
printf("--------------------------------------------------------------------------------------------------------\n");
for (i = 0; nmt_country[i].short_name; i++) {
if (nmt_system != nmt_country[i].system)

@ -147,7 +147,7 @@ void nmt_value2digits(uint64_t value, char *digits, int num)
if (digit == 10)
digits[i] = '0';
else if (digit == 0)
digits[i] = 'N';
digits[i] = 'a';
else if (digit > 10)
digits[i] = digit - 10 + 'a';
else
@ -167,9 +167,9 @@ uint64_t nmt_digits2value(const char *digits, int num)
value |= digit - '0';
else if (digit == '0')
value |= 10;
else if (digit >= 'a' && digit <= 'f')
else if (digit >= 'b' && digit <= 'f')
value |= digit - 'a' + 10;
else if (digit >= 'A' && digit <= 'F')
else if (digit >= 'B' && digit <= 'F')
value |= digit - 'A' + 10;
else
value |= 0;
@ -178,6 +178,14 @@ uint64_t nmt_digits2value(const char *digits, int num)
return value;
}
uint8_t nmt_flip_ten(uint8_t v)
{
if (!(v % 10))
v ^= 10;
return v;
}
char nmt_value2digit(uint64_t value)
{
return "D1234567890*#ABC"[value & 0x0000f];
@ -481,18 +489,13 @@ static const char *param_ta_450(uint64_t value, int ndigits, enum nmt_direction
return result;
}
static const char *param_ta_900(uint64_t value, int ndigits, enum nmt_direction __attribute__((unused)) direction)
static const char *param_ta_900(uint64_t value, int __attribute__((unused)) ndigits, enum nmt_direction __attribute__((unused)) direction)
{
static char result[64];
if ((value & 0x80)) {
nmt_value2digits(value & 0x7f, result, ndigits);
result[ndigits] = '\0';
sprintf(result, "%02" PRIx64, value & 0x7f);
if ((value & 0x80))
strcat(result, " (Channel No. + 1024)");
} else {
nmt_value2digits(value, result, ndigits);
result[ndigits] = '\0';
}
return result;
}

@ -90,6 +90,7 @@ uint64_t nmt_encode_traffic_area(int nmt_system, int channel, uint8_t traffic_ar
void nmt_value2digits(uint64_t value, char *digits, int num);
uint64_t nmt_digits2value(const char *digits, int num);
char nmt_value2digit(uint64_t value);
uint8_t nmt_flip_ten(uint8_t v);
uint16_t nmt_encode_area_no(uint8_t area_no);
int nmt_encode_a_number(frame_t *frame, int index, enum number_type type, const char *number, int nmt_system, int channel, int power, uint8_t traffic_area);

@ -48,7 +48,8 @@ int num_chan_type = 0;
enum nmt_chan_type chan_type[MAX_SENDER] = { CHAN_TYPE_CC_TC };
int ms_power = 1; /* 0..3 */
char country[16] = "";
char traffic_area[3] = "";
uint8_t traffic_area;
int traffic_area_given = 0;
char area_no = 0;
int compandor = 1;
int num_supervisory = 0;
@ -172,14 +173,16 @@ error_ta:
fprintf(stderr, "Invalid traffic area '%s', use '-Y list' for a list of valid areas\n", argv[argi]);
return -EINVAL;
}
traffic_area[0] = rc + '0';
traffic_area = rc << 4;
if (p[strlen(p) - 1] != '!') {
rc = nmt_ta_by_short_name(nmt_system, country, atoi(p));
if (rc < 0)
goto error_ta;
}
nmt_value2digits(atoi(p), traffic_area + 1, 1);
traffic_area[2] = '\0';
if (atoi(p) < 0 || atoi(p) > 15)
goto error_ta;
traffic_area |= (nmt_system == 450) ? nmt_flip_ten(atoi(p)) : atoi(p);
traffic_area_given = 1;
break;
case 'A':
area_no = argv[argi][0] - '0';
@ -354,7 +357,7 @@ int main(int argc, char *argv[])
}
}
if (!traffic_area[0]) {
if (!traffic_area_given) {
printf("No traffic area is specified, I suggest to use Sweden (-Y SE,1) and set the phone's roaming to 'SE' also.\n\n");
mandatory = 1;
}
@ -398,7 +401,7 @@ int main(int argc, char *argv[])
/* create transceiver instance */
for (i = 0; i < num_kanal; i++) {
rc = nmt_create(nmt_system, country, kanal[i], chan_type[i], audiodev[i], use_sdr, samplerate, rx_gain, do_pre_emphasis, do_de_emphasis, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, ms_power, nmt_digits2value(traffic_area, 2), area_no, compandor, supervisory[i], smsc_number, send_callerid, loopback);
rc = nmt_create(nmt_system, country, kanal[i], chan_type[i], audiodev[i], use_sdr, samplerate, rx_gain, do_pre_emphasis, do_de_emphasis, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, ms_power, traffic_area, area_no, compandor, supervisory[i], smsc_number, send_callerid, loopback);
if (rc < 0) {
fprintf(stderr, "Failed to create transceiver instance. Quitting!\n");
goto fail;

@ -347,7 +347,7 @@ int nmt_create(int nmt_system, const char *country, int channel, enum nmt_chan_t
PDEBUG(DNMT, DEBUG_NOTICE, "Created channel #%d of type '%s' = %s\n", channel, chan_type_short_name(nmt_system, chan_type), chan_type_long_name(nmt_system, chan_type));
if (nmt_long_name_by_short_name(nmt_system, country))
PDEBUG(DNMT, DEBUG_NOTICE, " -> Using country '%s'\n", nmt_long_name_by_short_name(nmt_system, country));
PDEBUG(DNMT, DEBUG_NOTICE, " -> Using traffic area %d,%d and area no %d\n", traffic_area >> 4, traffic_area & 0xf, area_no);
PDEBUG(DNMT, DEBUG_NOTICE, " -> Using traffic area %d,%d and area no %d\n", traffic_area >> 4, (nmt_system == 450) ? nmt_flip_ten((traffic_area & 0xf)) : (traffic_area & 0xf), area_no);
if (nmt->supervisory)
PDEBUG(DNMT, DEBUG_NOTICE, " -> Using supervisory signal %d\n", supervisory);
else

Loading…
Cancel
Save