4
Fork 0
AutoPatch/CallCapture/BrandMeisterBridge.cpp
2016-03-23 20:08:20 +03:00

90 lines
2 KiB
C++

// Copyright 2015 by Artem Prilutskiy
#include "BrandMeisterBridge.h"
#include <string.h>
#include <stdlib.h>
#include <syslog.h>
#include <stdio.h>
#define ECHOLINK_DEFAULT_USER_NUMBER 1
#define ECHOLINK_DEFAULT_CORD_NUMBER 10
#define REGISTRY_CONFIGURATION_FILE "/opt/BrandMeister/Registry.cnf"
BrandMeisterBridge::BrandMeisterBridge() :
proxy(ECHOLINK_DEFAULT_CORD_NUMBER),
store(REGISTRY_CONFIGURATION_FILE),
talker(NULL)
{
}
BrandMeisterBridge::~BrandMeisterBridge()
{
free(talker);
}
// Interface methods for ModuleEchoLink
const char* BrandMeisterBridge::getTalker()
{
free(talker);
uint32_t number = proxy.getTalkerID();
char call[LONG_CALLSIGN_LENGTH];
char text[SLOW_DATA_TEXT_LENGTH];
if ((number != 0) &&
(store.getCredentialsForID(number, call, text)))
{
asprintf(&talker, "%s %s", call, text);
return talker;
}
asprintf(&talker, "DMR ID: %d", number);
return talker;
}
void BrandMeisterBridge::setTalker(const char* call, const char* name)
{
if (*call == '*')
{
// Do not process conference call-sign
return;
}
const char* delimiter = strpbrk(call, " -\n");
if (delimiter != NULL)
{
// Remove characters after call-sign
size_t length = delimiter - call;
char* buffer = (char*)alloca(length + 1);
strncpy(buffer, call, length);
call = buffer;
}
uint32_t number = store.getPrivateIDForCall(call);
if (number == 0)
{
syslog(LOG_INFO, "DMR ID for call-sign %s not found", call);
number = ECHOLINK_DEFAULT_USER_NUMBER;
}
syslog(LOG_DEBUG, "Set talker DMR ID to %d", number);
proxy.setTalkerID(number);
}
void BrandMeisterBridge::handleChatMessage(const char* text)
{
// CONF Russian Reflector, Open 24/7, Contacts: rv3dhc.link@qip.ru * Call CQ / Use pauses 2sec * [28/500]
// R3ABM-L *DSTAR.SU DMR Bridge*
// UB3AMO Moscow T I N A O
// ->UA0LQE-L USSURIISK
const char* delimiter;
if ((strncmp(text, "CONF ", 5) == 0) &&
((delimiter = strstr(text, "\n->")) != NULL))
{
const char* call = delimiter + 3;
setTalker(call, NULL);
}
}