Skip to content

Commit

Permalink
Decode TMC country code from LTCC and LTECC (fixes #80)
Browse files Browse the repository at this point in the history
This finishes the LTCC, LTECC support - they are now combined in the
TMC system info and a two-letter country code is printed.
  • Loading branch information
windytan committed Jun 9, 2023
1 parent 58f52de commit b34fd7c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/groups.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void Station::decodeType1(const Group& group) {

if (ecc_ != 0x00) {
has_country_ = true;
json_["country"] = getCountryString(pi_, ecc_);
json_["country"] = getCountryString(cc_, ecc_);
}
break;

Expand Down
8 changes: 3 additions & 5 deletions src/tables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::string getPTYNameStringRBDS(uint16_t pty) {
// 2-letter country codes
// EN 50067:1998, Annex D, Table D.1 (p. 71)
// RDS Forum R08/008_7, Table D.2 (p. 75)
std::string getCountryString(uint16_t pi, uint16_t ecc) {
std::string getCountryString(uint16_t cc, uint16_t ecc) {
static const std::map<uint16_t, std::vector<std::string>> country_codes({
{0xA0, {"us", "us", "us", "us", "us", "us", "us", "us",
"us", "us", "us", "--", "us", "us", "--"}},
Expand Down Expand Up @@ -104,10 +104,8 @@ std::string getCountryString(uint16_t pi, uint16_t ecc) {

std::string result("--");

uint16_t pi_cc = pi >> 12;

if (country_codes.find(ecc) != country_codes.end() && pi_cc > 0) {
result = country_codes.at(ecc).at(pi_cc-1);
if (country_codes.find(ecc) != country_codes.end() && cc > 0) {
result = country_codes.at(ecc).at(cc - 1);
}

return result;
Expand Down
13 changes: 9 additions & 4 deletions src/tmc/tmc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <json/json.h>

#include "src/common.h"
#include "src/tables.h"
#include "src/tmc/event_list.h"
#include "src/tmc/locationdb.h"
#include "src/util.h"
Expand Down Expand Up @@ -507,13 +508,17 @@ void TMCService::receiveSystemGroup(uint16_t message, Json::Value* jsonroot) {
static const int gap_values[4] = {3, 5, 8, 11};
(*jsonroot)["tmc"]["system_info"]["gap"] = gap_values[g];

int ltcc = getBits<4>(message, 0);
if (ltcc)
(*jsonroot)["tmc"]["system_info"]["ltcc"] = ltcc;
ltcc_ = getBits<4>(message, 0);
if (ltcc_ > 0)
(*jsonroot)["tmc"]["system_info"]["ltcc"] = ltcc_;
} else if (variant == 2) {
int ltecc = getBits<8>(message, 0);
if (ltecc)
if (ltecc > 0) {
(*jsonroot)["tmc"]["system_info"]["ltecc"] = ltecc;
if (ltcc_ > 0) {
(*jsonroot)["tmc"]["system_info"]["country"] = getCountryString(ltcc_, ltecc);
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/tmc/tmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class TMCService {
uint16_t ltn_ { 0 };
uint16_t sid_ { 0 };
uint16_t encid_ { 0 };
int ltcc_ { -1 };
Message message_;
std::map<uint16_t, ServiceKey> service_key_table_;
RDSString ps_;
Expand Down

0 comments on commit b34fd7c

Please sign in to comment.