#9 It works ! Still need to figure out interleaved data and acks
parent
761fca2a46
commit
da924acb7c
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2022 by Geoffrey Merck F4FXL / KC3FRA
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "APRStoDPRS.h"
|
||||
#include "Log.h"
|
||||
#include "RSMS1AMessageBuilder.h"
|
||||
|
||||
bool CAPRSToDPRS::aprsToDPRS(std::string& dprs, CHeaderData& header, CAPRSFrame& frame)
|
||||
{
|
||||
dprs.clear();
|
||||
switch (frame.getType())
|
||||
{
|
||||
case APFT_MESSAGE :
|
||||
return messageToDPRS(dprs, header, frame);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CAPRSToDPRS::messageToDPRS(std::string& dprs, CHeaderData& header, CAPRSFrame& frame)
|
||||
{
|
||||
auto frameBody = frame.getBody();
|
||||
if(frameBody.length() < 11 || frameBody[0] != ':' || frameBody[10] != ':') {
|
||||
CLog::logDebug("Invalid APRS message body : %s", frameBody.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// extract recipient
|
||||
auto recipient = boost::trim_copy(frameBody.substr(1, 9));
|
||||
if(recipient.length() == 0U) {
|
||||
CLog::logDebug("APRS message has no recipient");
|
||||
return false;
|
||||
}
|
||||
auto dashPos = recipient.find_first_of('-');
|
||||
if(dashPos != std::string::npos)
|
||||
recipient = recipient.substr(0, dashPos);
|
||||
|
||||
|
||||
auto messageBody = boost::trim_copy(frameBody.substr(11));
|
||||
|
||||
header.setId(header.createId());
|
||||
header.setMyCall1(frame.getSource());
|
||||
header.setMyCall2("MSG");
|
||||
header.setYourCall(recipient);
|
||||
|
||||
CRSMS1AMessageBuilder::buildMessage(dprs, frame.getSource(), recipient, messageBody);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2022 by Geoffrey Merck F4FXL / KC3FRA
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "HeaderData.h"
|
||||
#include "APRSFrame.h"
|
||||
|
||||
class CAPRSToDPRS
|
||||
{
|
||||
public:
|
||||
static bool aprsToDPRS(std::string& dprs, CHeaderData& header, CAPRSFrame& frame);
|
||||
|
||||
private:
|
||||
static bool messageToDPRS(std::string& drps, CHeaderData& header, CAPRSFrame& frame);
|
||||
};
|
||||
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 by Geoffrey Merck F4FXL / KC3FRA
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../../APRStoDPRS.h"
|
||||
|
||||
namespace APRStoDPRSTests
|
||||
{
|
||||
class APRStoDPRS_aprsToDPRS : public ::testing::Test {
|
||||
|
||||
};
|
||||
|
||||
TEST_F(APRStoDPRS_aprsToDPRS, validMessage)
|
||||
{
|
||||
CAPRSFrame frame("KC3FRA", "APRS", {"WIDE1-1", "WIDE2-2"}, ":F4FXL :Salut, comment vas tu?", APFT_MESSAGE);
|
||||
|
||||
std::string dprs;
|
||||
CHeaderData header;
|
||||
bool ret = CAPRSToDPRS::aprsToDPRS(dprs, header, frame);
|
||||
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_STREQ(dprs.c_str(), "$$Msg,KC3FRA,F4FXL,001118Saluto, comment vas tu?z\r");
|
||||
}
|
||||
|
||||
TEST_F(APRStoDPRS_aprsToDPRS, validMessageRecipientWithSSID)
|
||||
{
|
||||
CAPRSFrame frame("KC3FRA", "APRS", {"WIDE1-1", "WIDE2-2"}, ":F4FXL-7 :Salut, comment vas tu?", APFT_MESSAGE);
|
||||
|
||||
std::string dprs;
|
||||
CHeaderData header;
|
||||
bool ret = CAPRSToDPRS::aprsToDPRS(dprs, header, frame);
|
||||
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_STREQ(dprs.c_str(), "$$Msg,KC3FRA,F4FXL,001118Saluto, comment vas tu?z\r");
|
||||
}
|
||||
|
||||
TEST_F(APRStoDPRS_aprsToDPRS, emptyRecipient)
|
||||
{
|
||||
CAPRSFrame frame("KC3FRA", "APRS", {"WIDE1-1", "WIDE2-2"}, ": :Salut, comment vas tu?", APFT_MESSAGE);
|
||||
|
||||
std::string dprs;
|
||||
CHeaderData header;
|
||||
bool ret = CAPRSToDPRS::aprsToDPRS(dprs, header, frame);
|
||||
|
||||
EXPECT_FALSE(ret);
|
||||
EXPECT_STREQ(dprs.c_str(), "");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue