From daa6def2ad95d915b75083e29f8cdf8481b2e27a Mon Sep 17 00:00:00 2001 From: Tom Early Date: Fri, 6 Apr 2018 07:04:14 -0700 Subject: [PATCH] still building --- g2_typedefs.h | 45 +++++++++++++++++++++++++++++++++++-- mmdvm_modem.cpp | 59 ++++++++++++++++++++++++++++++++++++++++--------- mmdvm_modem.h | 11 ++++++--- 3 files changed, 100 insertions(+), 15 deletions(-) diff --git a/g2_typedefs.h b/g2_typedefs.h index b81b0c6..b5fc0db 100644 --- a/g2_typedefs.h +++ b/g2_typedefs.h @@ -1,6 +1,6 @@ #pragma once /* - * Copyright 2017 by Thomas Early, N7TAE + * Copyright 2017,2018 by Thomas Early, N7TAE * * 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 @@ -47,6 +47,15 @@ typedef struct pkt_tag { unsigned char sfx[4]; // 52 unsigned char pfcs[2]; // 56 } hdr; // total 58 + struct { + unsigned char flag[3]; // 17 + unsigned char rpt2[8]; // 20 + unsigned char rpt1[8]; // 28 + unsigned char urcall[8];// 36 + unsigned char mycall[8];// 44 + unsigned char sfx[4]; // 52 + unsigned char pfcs[2]; // 56 + } hdrr; // total 58 union { struct { unsigned char voice[9]; // 17 @@ -69,7 +78,7 @@ typedef struct dsvt_tag { unsigned char title[4]; // 0 "DSVT" unsigned char config; // 4 0x10 is hdr 0x20 is vasd unsigned char flaga[3]; // 5 zeros - unsigned char id; // 8 0x20 + unsigned char id; // 8 0x20 unsigned char flagb[3]; // 9 0x0 0x1 0x1 unsigned short streamid;// 12 unsigned char counter; // 14 hdr: 0x80 vsad: framecounter (mod 21) @@ -90,3 +99,35 @@ typedef struct dsvt_tag { }; } SDSVT; #pragma pack(pop) + +#pragma pack(push, 1) +typedef struct mmdvm_tag { // offset size + unsigned char title[4]; // "DSRP" 0 + unsigned char tag; // Poll : 0xA 4 + // Header : busy ? 0x22 : 0x20 + // Voice : busy ? 0x23 : 0x21 + union { + unsigned char msg[59]; // space for text (release version) 5 64 + struct { + unsigned short id; // random id number 5 + unsigned char seq; // 0x0 7 + unsigned char flag[3]; // 0x80 Dstar Data 8 + // 0x40 Dstar Repeater + // 0x01 Dstar Relay Unavailable + unsigned char r2[8]; // Repeater 2 11 + unsigned char r1[8]; // Repeater 1 19 + unsigned char yr[8]; // Your Call 27 + unsigned char my[8]; // My Call 35 + unsigned char nm[4]; // Name 43 + unsigned short pcfs; // 47 49 + } header; + struct { + unsigned short id; // random id number 5 + unsigned char seq; // sequence from 0 to 0x14 7 + // if end then sequence |= 0x40 + unsigned char err; // # of errors? 8 + unsigned char ambe[12]; // voice + slow data 9 21 + } voice; + }; +} SMMDVMPKT; +#pragma pack(pop) diff --git a/mmdvm_modem.cpp b/mmdvm_modem.cpp index cbd9752..3a7fba0 100644 --- a/mmdvm_modem.cpp +++ b/mmdvm_modem.cpp @@ -26,6 +26,7 @@ #include "versions.h" #include "mmdvm_modem.h" #include "UDPSocket.h" +#include "g2_typedefs.h" std::atomic CMMDVMModem::keep_running(true); @@ -66,7 +67,7 @@ void CMMDVMModem::Run(const char *cfgfile) if (Initialize(cfgfile)) return; - CUDPSocket GatewaySock(G2_INTERNAL_IP, G2_PORT); + CUDPSocket GatewaySock(G2_INTERNAL_IP, G2_INTERNAL_PORT); if (GatewaySock.open()) return; @@ -80,22 +81,58 @@ void CMMDVMModem::Run(const char *cfgfile) while (keep_running) { - ProcessMMDVM(); - ProcessGateway(); + ProcessMMDVM(GatewaySock, MMDVMSock); + if (keep_running) + ProcessGateway(GatewaySock, MMDVMSock); } MMDVMSock.close(); GatewaySock.close(); } -void CMMDVMModem::ProcessGateway() +void CMMDVMModem::ProcessGateway(CUDPSocket &gsock, CUDPSocket &msock) { + SPKT buf; + unsigned int port; + // read from gateway + int len = gsock.read(buf.pkt_id, 58, g2_internal_addr, port); + + if (0 == len) + return; + + if (0 > len) { + printf("ERROR: ProcessGateway: Can't read gateway data\n"); + keep_running = false; + return; + } // if there is data, translate it and send it to the MMDVM Modem + if (29==len || 58==len) { //here is dstar data + SMMDVMPKT pkt; + memcpy(pkt.title, "DSRP", 4); + if (29 == len) { // write an AMBE packet + pkt.tag = 0x21U; + pkt.voice.id = buf.vpkt.streamid; + + if (false == msock.write(pkt.title, 21, mmdvm_addr, MMDVM_PORT)) { + printf("ERROR: ProcessGateway: Could not write AMBE data packet to MMDVMHost\n"); + keep_running = false; + return; + } + } else { // write a Header packet + pkt.tag = 0x20U; + pkt.header.id = buf.vpkt.streamid; + + if (false == msock.write(pkt.title, 49, mmdvm_addr, MMDVM_PORT)) { + printf("ERROR: ProcessGateway: Could not write Header data packet to MMDVMHost\n"); + keep_running = false; + } + } + } } -void CMMDVMModem::ProcessMMDVM() +void CMMDVMModem::ProcessMMDVM(CUDPSocket &gsock, CUDPSocket &msock) { // read from the MMDVM modem @@ -218,21 +255,23 @@ bool CMMDVMModem::ReadConfig(const char *cfgFile) return true; } - if (GetValue(cfg, std::string(mmdvm_path+".internal_ip").c_str(), value, 7, IP_SIZE, "0.0.0.0")) + if (GetValue(cfg, std::string(mmdvm_path+".internal_ip").c_str(), value, 7, IP_SIZE, "0.0.0.0")) { MMDVM_IP = value; - else + inet_aton(MMDVM_IP.c_str(), &mmdvm_addr); + } else return true; GetValue(cfg, std::string(mmdvm_path+".port").c_str(), i, 10000, 65535, 20010); MMDVM_PORT = (unsigned short)i; - if (GetValue(cfg, "gateway.ip", value, 7, IP_SIZE, "127.0.0.1")) + if (GetValue(cfg, "gateway.ip", value, 7, IP_SIZE, "127.0.0.1")) { G2_INTERNAL_IP = value; - else + inet_aton(G2_INTERNAL_IP.c_str(), &g2_internal_addr); + } else return true; GetValue(cfg, "gateway.internal.port", i, 10000, 65535, 20010); - G2_PORT = (unsigned short)i; + G2_INTERNAL_PORT = (unsigned short)i; GetValue(cfg, "timing.play.delay", DELAY_BETWEEN, 9, 25, 19); diff --git a/mmdvm_modem.h b/mmdvm_modem.h index 38d8916..38c06de 100644 --- a/mmdvm_modem.h +++ b/mmdvm_modem.h @@ -22,6 +22,10 @@ #include #include +#include + +#include "UDPSocket.h" + using namespace libconfig; #define CALL_SIZE 8 @@ -42,8 +46,8 @@ private: // functions bool Initialize(const char *cfgfile); static void SignalCatch(int signum); - void ProcessGateway(); - void ProcessMMDVM(); + void ProcessGateway(CUDPSocket &gsock, CUDPSocket &msock); + void ProcessMMDVM(CUDPSocket &gsock, CUDPSocket &msock); // read configuration file bool ReadConfig(const char *); @@ -57,7 +61,8 @@ private: char RPTR[CALL_SIZE + 1]; char OWNER[CALL_SIZE + 1]; std::string MMDVM_IP, G2_INTERNAL_IP; - unsigned short MMDVM_PORT, G2_PORT; + in_addr mmdvm_addr, g2_internal_addr; + unsigned short MMDVM_PORT, G2_INTERNAL_PORT; int WAIT_FOR_PACKETS, DELAY_BEFORE, DELAY_BETWEEN; bool RPTR_ACK;