2016-01-14 18:45:04 +00:00
/*
2018-01-12 07:06:38 +00:00
* Copyright ( C ) 2015 , 2016 , 2017 , 2018 Jonathan Naylor , G4KLX
2016-01-14 18:45:04 +00:00
*
* 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 ; version 2 of the License .
*
* 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 .
*/
2017-01-05 19:15:10 +00:00
# include "DMRAccessControl.h"
2017-05-21 10:52:26 +00:00
# include "DMRDataHeader.h"
2016-02-15 18:45:57 +00:00
# include "DMRSlotType.h"
# include "DMRShortLC.h"
2016-07-07 19:23:30 +00:00
# include "DMRTrellis.h"
2016-02-15 18:45:57 +00:00
# include "DMRFullLC.h"
2016-02-24 07:37:58 +00:00
# include "BPTC19696.h"
2016-01-14 18:45:04 +00:00
# include "DMRSlot.h"
2016-02-15 18:45:57 +00:00
# include "DMRCSBK.h"
2017-01-05 19:15:10 +00:00
# include "DMREMB.h"
2016-01-14 18:45:04 +00:00
# include "Utils.h"
2016-02-15 18:45:57 +00:00
# include "Sync.h"
2016-01-14 18:45:04 +00:00
# include "CRC.h"
# include "Log.h"
# include <cassert>
# include <ctime>
2016-04-06 16:24:14 +00:00
# include <algorithm>
2017-11-26 17:56:20 +00:00
# include <cstdint>
2018-02-09 17:49:18 +00:00
# include <cmath>
2016-01-14 18:45:04 +00:00
2016-02-15 18:45:57 +00:00
unsigned int CDMRSlot : : m_colorCode = 0U ;
2016-07-10 20:37:11 +00:00
2017-01-16 12:10:23 +00:00
bool CDMRSlot : : m_embeddedLCOnly = false ;
2017-02-27 20:17:55 +00:00
bool CDMRSlot : : m_dumpTAData = true ;
2017-01-16 12:10:23 +00:00
2016-02-15 18:45:57 +00:00
CModem * CDMRSlot : : m_modem = NULL ;
2016-09-14 06:41:37 +00:00
CDMRNetwork * CDMRSlot : : m_network = NULL ;
2016-05-09 17:14:27 +00:00
CDisplay * CDMRSlot : : m_display = NULL ;
2016-02-15 18:45:57 +00:00
bool CDMRSlot : : m_duplex = true ;
2016-04-12 17:26:13 +00:00
CDMRLookup * CDMRSlot : : m_lookup = NULL ;
2016-06-16 20:40:05 +00:00
unsigned int CDMRSlot : : m_hangCount = 3U * 17U ;
2016-01-14 18:45:04 +00:00
2016-12-21 19:58:46 +00:00
CRSSIInterpolator * CDMRSlot : : m_rssiMapper = NULL ;
2016-08-08 20:26:18 +00:00
2018-02-09 17:32:52 +00:00
unsigned int CDMRSlot : : m_jitterTime = 360U ;
unsigned int CDMRSlot : : m_jitterSlots = 6U ;
2018-02-08 20:25:03 +00:00
2016-02-15 18:45:57 +00:00
unsigned char * CDMRSlot : : m_idle = NULL ;
2016-01-14 18:45:04 +00:00
2016-02-15 18:45:57 +00:00
FLCO CDMRSlot : : m_flco1 ;
unsigned char CDMRSlot : : m_id1 = 0U ;
2017-10-04 10:20:37 +00:00
ACTIVITY_TYPE CDMRSlot : : m_activity1 = ACTIVITY_NONE ;
2016-02-15 18:45:57 +00:00
FLCO CDMRSlot : : m_flco2 ;
unsigned char CDMRSlot : : m_id2 = 0U ;
2017-10-04 10:20:37 +00:00
ACTIVITY_TYPE CDMRSlot : : m_activity2 = ACTIVITY_NONE ;
2016-01-14 18:45:04 +00:00
2017-02-12 18:37:00 +00:00
const unsigned char TALKER_ID_NONE = 0x00U ;
const unsigned char TALKER_ID_HEADER = 0x01U ;
const unsigned char TALKER_ID_BLOCK1 = 0x02U ;
const unsigned char TALKER_ID_BLOCK2 = 0x04U ;
const unsigned char TALKER_ID_BLOCK3 = 0x08U ;
2017-04-02 12:39:28 +00:00
const unsigned int NO_HEADERS_SIMPLEX = 8U ;
const unsigned int NO_HEADERS_DUPLEX = 3U ;
2016-01-14 18:45:04 +00:00
// #define DUMP_DMR
CDMRSlot : : CDMRSlot ( unsigned int slotNo , unsigned int timeout ) :
m_slotNo ( slotNo ) ,
2016-05-10 17:54:35 +00:00
m_queue ( 5000U , " DMR Slot " ) ,
2016-02-25 19:54:18 +00:00
m_rfState ( RS_RF_LISTENING ) ,
m_netState ( RS_NET_IDLE ) ,
2017-01-10 19:27:12 +00:00
m_rfEmbeddedLC ( ) ,
m_rfEmbeddedData ( NULL ) ,
m_rfEmbeddedReadN ( 0U ) ,
m_rfEmbeddedWriteN ( 1U ) ,
2017-02-12 18:37:00 +00:00
m_rfTalkerId ( TALKER_ID_NONE ) ,
2017-11-13 20:48:47 +00:00
m_rfTalkerAlias ( NULL ) ,
2017-01-10 19:27:12 +00:00
m_netEmbeddedLC ( ) ,
m_netEmbeddedData ( NULL ) ,
m_netEmbeddedReadN ( 0U ) ,
m_netEmbeddedWriteN ( 1U ) ,
2017-02-12 18:37:00 +00:00
m_netTalkerId ( TALKER_ID_NONE ) ,
2016-02-25 19:54:18 +00:00
m_rfLC ( NULL ) ,
m_netLC ( NULL ) ,
2016-02-28 17:40:15 +00:00
m_rfSeqNo ( 0U ) ,
2016-02-28 17:18:13 +00:00
m_rfN ( 0U ) ,
m_netN ( 0U ) ,
2016-01-21 18:38:45 +00:00
m_networkWatchdog ( 1000U , 0U , 1500U ) ,
2016-02-25 19:54:18 +00:00
m_rfTimeoutTimer ( 1000U , timeout ) ,
m_netTimeoutTimer ( 1000U , timeout ) ,
2018-02-08 20:25:03 +00:00
m_packetTimer ( 1000U , 0U , 50U ) ,
2016-03-14 20:55:15 +00:00
m_interval ( ) ,
2018-02-08 20:25:03 +00:00
m_elapsed ( ) ,
2016-02-25 19:54:18 +00:00
m_rfFrames ( 0U ) ,
m_netFrames ( 0U ) ,
m_netLost ( 0U ) ,
2016-01-19 20:13:20 +00:00
m_fec ( ) ,
2016-07-21 16:46:37 +00:00
m_rfBits ( 1U ) ,
m_netBits ( 1U ) ,
2016-02-25 19:54:18 +00:00
m_rfErrs ( 0U ) ,
m_netErrs ( 0U ) ,
2017-03-12 19:06:47 +00:00
m_rfTimeout ( false ) ,
m_netTimeout ( false ) ,
2018-02-08 20:25:03 +00:00
m_lastFrame ( NULL ) ,
m_lastFrameValid ( false ) ,
2016-08-11 16:28:47 +00:00
m_rssi ( 0U ) ,
2017-01-05 19:15:10 +00:00
m_maxRSSI ( 0U ) ,
m_minRSSI ( 0U ) ,
m_aveRSSI ( 0U ) ,
m_rssiCount ( 0U ) ,
2016-01-14 18:45:04 +00:00
m_fp ( NULL )
{
2017-11-13 20:48:47 +00:00
m_rfTalkerAlias = new unsigned char [ 32U ] ;
2016-03-14 20:55:15 +00:00
2018-02-08 20:25:03 +00:00
m_lastFrame = new unsigned char [ DMR_FRAME_LENGTH_BYTES + 2U ] ;
2017-01-10 19:27:12 +00:00
m_rfEmbeddedData = new CDMREmbeddedData [ 2U ] ;
m_netEmbeddedData = new CDMREmbeddedData [ 2U ] ;
2016-03-14 20:55:15 +00:00
m_interval . start ( ) ;
2016-01-14 18:45:04 +00:00
}
CDMRSlot : : ~ CDMRSlot ( )
{
2017-01-10 19:27:12 +00:00
delete [ ] m_rfEmbeddedData ;
delete [ ] m_netEmbeddedData ;
2018-02-08 20:25:03 +00:00
delete [ ] m_lastFrame ;
2017-11-15 10:47:56 +00:00
delete [ ] m_rfTalkerAlias ;
2016-01-14 18:45:04 +00:00
}
2017-03-12 19:06:47 +00:00
bool CDMRSlot : : writeModem ( unsigned char * data , unsigned int len )
2016-01-14 18:45:04 +00:00
{
2016-03-07 20:21:55 +00:00
assert ( data ! = NULL ) ;
2016-02-25 19:54:18 +00:00
if ( data [ 0U ] = = TAG_LOST & & m_rfState = = RS_RF_AUDIO ) {
2017-01-07 12:25:03 +00:00
if ( m_rssi ! = 0U )
LogMessage ( " DMR Slot %u, RF voice transmission lost, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm " , m_slotNo , float ( m_rfFrames ) / 16.667F , float ( m_rfErrs * 100U ) / float ( m_rfBits ) , m_minRSSI , m_maxRSSI , m_aveRSSI / m_rssiCount ) ;
else
LogMessage ( " DMR Slot %u, RF voice transmission lost, %.1f seconds, BER: %.1f%% " , m_slotNo , float ( m_rfFrames ) / 16.667F , float ( m_rfErrs * 100U ) / float ( m_rfBits ) ) ;
2017-03-12 19:25:01 +00:00
if ( m_rfTimeout ) {
writeEndRF ( ) ;
return false ;
} else {
writeEndRF ( true ) ;
return true ;
}
2016-01-20 07:12:28 +00:00
}
2016-02-25 19:54:18 +00:00
if ( data [ 0U ] = = TAG_LOST & & m_rfState = = RS_RF_DATA ) {
2017-01-05 19:15:10 +00:00
LogMessage ( " DMR Slot %u, RF data transmission lost " , m_slotNo ) ;
2016-02-25 19:54:18 +00:00
writeEndRF ( ) ;
2017-03-13 08:28:38 +00:00
return false ;
2016-01-14 18:45:04 +00:00
}
2016-02-02 18:17:36 +00:00
if ( data [ 0U ] = = TAG_LOST ) {
2016-02-25 19:54:18 +00:00
m_rfState = RS_RF_LISTENING ;
2017-03-12 19:06:47 +00:00
return false ;
2016-01-14 18:45:04 +00:00
}
2016-08-08 20:26:18 +00:00
// Have we got RSSI bytes on the end?
2016-12-21 19:58:46 +00:00
if ( len = = ( DMR_FRAME_LENGTH_BYTES + 4U ) ) {
2016-08-11 16:28:47 +00:00
uint16_t raw = 0U ;
raw | = ( data [ 35U ] < < 8 ) & 0xFF00U ;
raw | = ( data [ 36U ] < < 0 ) & 0x00FFU ;
2016-12-22 11:10:08 +00:00
// Convert the raw RSSI to dBm
2016-12-21 19:58:46 +00:00
int rssi = m_rssiMapper - > interpolate ( raw ) ;
2018-03-06 20:12:29 +00:00
if ( rssi ! = 0 )
LogDebug ( " DMR Slot %u, raw RSSI: %u, reported RSSI: %d dBm " , m_slotNo , raw , rssi ) ;
2016-12-22 11:10:08 +00:00
// RSSI is always reported as positive
2016-08-11 16:28:47 +00:00
m_rssi = ( rssi > = 0 ) ? rssi : - rssi ;
2017-01-05 19:15:10 +00:00
if ( m_rssi > m_minRSSI )
m_minRSSI = m_rssi ;
if ( m_rssi < m_maxRSSI )
m_maxRSSI = m_rssi ;
m_aveRSSI + = m_rssi ;
m_rssiCount + + ;
2016-08-08 20:26:18 +00:00
}
2016-01-14 18:45:04 +00:00
bool dataSync = ( data [ 1U ] & DMR_SYNC_DATA ) = = DMR_SYNC_DATA ;
bool audioSync = ( data [ 1U ] & DMR_SYNC_AUDIO ) = = DMR_SYNC_AUDIO ;
if ( dataSync ) {
2016-12-21 08:55:30 +00:00
// Get the type from the packet metadata
unsigned char dataType = data [ 1U ] & 0x0FU ;
2016-01-14 18:45:04 +00:00
2016-12-21 08:55:30 +00:00
CDMRSlotType slotType ;
slotType . setColorCode ( m_colorCode ) ;
slotType . setDataType ( dataType ) ;
2016-01-14 18:45:04 +00:00
if ( dataType = = DT_VOICE_LC_HEADER ) {
2016-02-25 19:54:18 +00:00
if ( m_rfState = = RS_RF_AUDIO )
2017-03-12 19:06:47 +00:00
return true ;
2016-01-14 18:45:04 +00:00
2016-02-15 18:45:57 +00:00
CDMRFullLC fullLC ;
2016-04-04 16:40:05 +00:00
CDMRLC * lc = fullLC . decode ( data + 2U , DT_VOICE_LC_HEADER ) ;
2016-04-28 08:58:45 +00:00
if ( lc = = NULL )
2017-03-12 19:06:47 +00:00
return false ;
2016-01-14 18:45:04 +00:00
2016-11-01 08:00:13 +00:00
unsigned int srcId = lc - > getSrcId ( ) ;
unsigned int dstId = lc - > getDstId ( ) ;
2017-01-05 19:15:10 +00:00
FLCO flco = lc - > getFLCO ( ) ;
2016-10-10 18:27:08 +00:00
2017-01-05 19:15:10 +00:00
if ( ! CDMRAccessControl : : validateSrcId ( srcId ) ) {
2016-12-21 19:06:29 +00:00
LogMessage ( " DMR Slot %u, RF user %u rejected " , m_slotNo , srcId ) ;
2016-07-10 17:35:23 +00:00
delete lc ;
2017-03-12 19:06:47 +00:00
return false ;
2016-06-07 14:34:16 +00:00
}
2016-10-10 18:27:08 +00:00
2017-01-05 19:15:10 +00:00
if ( ! CDMRAccessControl : : validateTGId ( m_slotNo , flco = = FLCO_GROUP , dstId ) ) {
LogMessage ( " DMR Slot %u, RF user %u rejected for using TG %u " , m_slotNo , srcId , dstId ) ;
delete lc ;
2017-03-12 19:06:47 +00:00
return false ;
2017-01-05 19:15:10 +00:00
}
2016-04-04 16:40:05 +00:00
m_rfLC = lc ;
2017-01-10 19:27:12 +00:00
// The standby LC data
m_rfEmbeddedLC . setLC ( * m_rfLC ) ;
m_rfEmbeddedData [ 0U ] . setLC ( * m_rfLC ) ;
m_rfEmbeddedData [ 1U ] . setLC ( * m_rfLC ) ;
2016-02-22 18:12:24 +00:00
// Regenerate the LC data
2016-02-25 19:54:18 +00:00
fullLC . encode ( * m_rfLC , data + 2U , DT_VOICE_LC_HEADER ) ;
2016-02-22 18:12:24 +00:00
2016-01-18 18:36:14 +00:00
// Regenerate the Slot Type
slotType . getData ( data + 2U ) ;
2016-01-14 18:45:04 +00:00
2016-09-05 17:03:23 +00:00
// Convert the Data Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-01-14 18:45:04 +00:00
2016-01-18 18:36:14 +00:00
data [ 0U ] = TAG_DATA ;
data [ 1U ] = 0x00U ;
2016-01-14 18:45:04 +00:00
2016-02-25 19:54:18 +00:00
m_rfTimeoutTimer . start ( ) ;
2017-03-12 19:06:47 +00:00
m_rfTimeout = false ;
2016-01-14 18:45:04 +00:00
2016-02-25 19:54:18 +00:00
m_rfFrames = 0U ;
2016-02-28 17:40:15 +00:00
m_rfSeqNo = 0U ;
2016-02-25 19:54:18 +00:00
m_rfBits = 1U ;
m_rfErrs = 0U ;
2017-02-12 18:37:00 +00:00
2017-01-10 19:27:12 +00:00
m_rfEmbeddedReadN = 0U ;
m_rfEmbeddedWriteN = 1U ;
2017-02-12 18:37:00 +00:00
m_rfTalkerId = TALKER_ID_NONE ;
2016-01-19 20:13:20 +00:00
2017-01-05 19:15:10 +00:00
m_minRSSI = m_rssi ;
m_maxRSSI = m_rssi ;
m_aveRSSI = m_rssi ;
m_rssiCount = 1U ;
2016-02-15 18:01:21 +00:00
if ( m_duplex ) {
2016-06-20 09:01:09 +00:00
m_queue . clear ( ) ;
m_modem - > writeDMRAbort ( m_slotNo ) ;
2017-04-02 12:39:28 +00:00
for ( unsigned int i = 0U ; i < NO_HEADERS_DUPLEX ; i + + )
writeQueueRF ( data ) ;
2016-01-18 18:36:14 +00:00
}
2016-01-14 18:45:04 +00:00
2016-02-28 17:40:15 +00:00
writeNetworkRF ( data , DT_VOICE_LC_HEADER ) ;
2016-02-15 18:01:21 +00:00
2016-02-25 19:54:18 +00:00
m_rfState = RS_RF_AUDIO ;
2016-01-26 18:28:39 +00:00
2016-11-01 08:00:13 +00:00
std : : string src = m_lookup - > find ( srcId ) ;
std : : string dst = m_lookup - > find ( dstId ) ;
2016-04-12 17:26:13 +00:00
2016-02-25 19:54:18 +00:00
if ( m_netState = = RS_NET_IDLE ) {
2017-10-03 09:03:13 +00:00
setShortLC ( m_slotNo , dstId , flco , ACTIVITY_VOICE ) ;
2017-01-05 19:15:10 +00:00
m_display - > writeDMR ( m_slotNo , src , flco = = FLCO_GROUP , dst , " R " ) ;
2017-01-05 19:44:52 +00:00
m_display - > writeDMRRSSI ( m_slotNo , m_rssi ) ;
2016-02-25 19:54:18 +00:00
}
2016-01-18 18:36:14 +00:00
2017-01-05 19:15:10 +00:00
LogMessage ( " DMR Slot %u, received RF voice header from %s to %s%s " , m_slotNo , src . c_str ( ) , flco = = FLCO_GROUP ? " TG " : " " , dst . c_str ( ) ) ;
2017-03-12 19:06:47 +00:00
return true ;
2016-01-14 18:45:04 +00:00
} else if ( dataType = = DT_VOICE_PI_HEADER ) {
2016-02-25 19:54:18 +00:00
if ( m_rfState ! = RS_RF_AUDIO )
2017-03-12 19:06:47 +00:00
return false ;
2016-01-14 18:45:04 +00:00
2016-01-18 18:36:14 +00:00
// Regenerate the Slot Type
slotType . getData ( data + 2U ) ;
2016-01-14 18:45:04 +00:00
2016-09-05 17:03:23 +00:00
// Convert the Data Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-01-14 18:45:04 +00:00
2016-02-25 19:59:09 +00:00
// Regenerate the payload
CBPTC19696 bptc ;
unsigned char payload [ 12U ] ;
bptc . decode ( data + 2U , payload ) ;
bptc . encode ( payload , data + 2U ) ;
2016-01-18 18:36:14 +00:00
data [ 0U ] = TAG_DATA ;
data [ 1U ] = 0x00U ;
2016-01-14 18:45:04 +00:00
2016-02-15 18:01:21 +00:00
if ( m_duplex )
2016-02-25 19:54:18 +00:00
writeQueueRF ( data ) ;
2016-02-15 18:01:21 +00:00
2016-02-25 19:54:18 +00:00
writeNetworkRF ( data , DT_VOICE_PI_HEADER ) ;
2017-03-12 19:06:47 +00:00
return true ;
2016-01-18 18:36:14 +00:00
} else if ( dataType = = DT_TERMINATOR_WITH_LC ) {
2016-02-25 19:54:18 +00:00
if ( m_rfState ! = RS_RF_AUDIO )
2017-03-12 19:06:47 +00:00
return false ;
2016-01-14 18:45:04 +00:00
2016-02-22 18:12:24 +00:00
// Regenerate the LC data
CDMRFullLC fullLC ;
2016-02-25 19:54:18 +00:00
fullLC . encode ( * m_rfLC , data + 2U , DT_TERMINATOR_WITH_LC ) ;
2016-02-22 18:12:24 +00:00
2016-01-18 18:36:14 +00:00
// Regenerate the Slot Type
slotType . getData ( data + 2U ) ;
2016-01-14 18:45:04 +00:00
2016-09-05 17:03:23 +00:00
// Convert the Data Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-01-18 18:36:14 +00:00
2017-03-12 19:06:47 +00:00
if ( ! m_rfTimeout ) {
data [ 0U ] = TAG_EOT ;
data [ 1U ] = 0x00U ;
2016-01-14 18:45:04 +00:00
2017-03-12 19:06:47 +00:00
writeNetworkRF ( data , DT_TERMINATOR_WITH_LC ) ;
writeNetworkRF ( data , DT_TERMINATOR_WITH_LC ) ;
2016-01-14 18:45:04 +00:00
2017-03-12 19:06:47 +00:00
if ( m_duplex ) {
for ( unsigned int i = 0U ; i < m_hangCount ; i + + )
writeQueueRF ( data ) ;
}
2016-02-15 18:01:21 +00:00
}
2016-01-21 18:38:45 +00:00
2017-01-07 12:25:03 +00:00
if ( m_rssi ! = 0U )
LogMessage ( " DMR Slot %u, received RF end of voice transmission, %.1f seconds, BER: %.1f%%, RSSI: -%u/-%u/-%u dBm " , m_slotNo , float ( m_rfFrames ) / 16.667F , float ( m_rfErrs * 100U ) / float ( m_rfBits ) , m_minRSSI , m_maxRSSI , m_aveRSSI / m_rssiCount ) ;
else
LogMessage ( " DMR Slot %u, received RF end of voice transmission, %.1f seconds, BER: %.1f%% " , m_slotNo , float ( m_rfFrames ) / 16.667F , float ( m_rfErrs * 100U ) / float ( m_rfBits ) ) ;
2017-11-15 10:47:56 +00:00
m_display - > writeDMRTA ( m_slotNo , NULL , " " ) ;
2017-03-12 19:25:01 +00:00
if ( m_rfTimeout ) {
writeEndRF ( ) ;
return false ;
} else {
writeEndRF ( ) ;
return true ;
}
2016-01-18 18:36:14 +00:00
} else if ( dataType = = DT_DATA_HEADER ) {
2016-04-26 17:22:47 +00:00
if ( m_rfState = = RS_RF_DATA )
2017-03-12 19:06:47 +00:00
return true ;
2016-04-26 17:22:47 +00:00
2016-02-22 18:12:24 +00:00
CDMRDataHeader dataHeader ;
bool valid = dataHeader . put ( data + 2U ) ;
2016-04-28 08:58:45 +00:00
if ( ! valid )
2017-03-12 19:06:47 +00:00
return false ;
2016-01-26 18:06:31 +00:00
2016-04-04 16:40:05 +00:00
bool gi = dataHeader . getGI ( ) ;
unsigned int srcId = dataHeader . getSrcId ( ) ;
unsigned int dstId = dataHeader . getDstId ( ) ;
2016-11-01 08:00:13 +00:00
2017-01-05 19:15:10 +00:00
if ( ! CDMRAccessControl : : validateSrcId ( srcId ) ) {
2016-12-21 19:06:29 +00:00
LogMessage ( " DMR Slot %u, RF user %u rejected " , m_slotNo , srcId ) ;
2017-03-12 19:06:47 +00:00
return false ;
2016-12-21 19:06:29 +00:00
}
2016-04-04 16:40:05 +00:00
2017-01-05 19:15:10 +00:00
if ( ! CDMRAccessControl : : validateTGId ( m_slotNo , gi , dstId ) ) {
LogMessage ( " DMR Slot %u, RF user %u rejected for using TG %u " , m_slotNo , srcId , dstId ) ;
2017-03-12 19:06:47 +00:00
return false ;
2017-01-05 19:15:10 +00:00
}
2016-03-15 22:46:36 +00:00
m_rfFrames = dataHeader . getBlocks ( ) ;
2016-02-25 19:54:18 +00:00
m_rfLC = new CDMRLC ( gi ? FLCO_GROUP : FLCO_USER_USER , srcId , dstId ) ;
2016-01-26 18:06:31 +00:00
2016-02-22 18:12:24 +00:00
// Regenerate the data header
2016-03-14 17:33:05 +00:00
dataHeader . get ( data + 2U ) ;
2016-02-22 18:12:24 +00:00
2016-01-18 18:36:14 +00:00
// Regenerate the Slot Type
slotType . getData ( data + 2U ) ;
2016-09-05 17:03:23 +00:00
// Convert the Data Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-01-18 18:36:14 +00:00
2016-04-26 17:22:47 +00:00
data [ 0U ] = m_rfFrames = = 0U ? TAG_EOT : TAG_DATA ;
2016-01-18 18:36:14 +00:00
data [ 1U ] = 0x00U ;
2016-03-11 06:50:06 +00:00
if ( m_duplex )
writeQueueRF ( data ) ;
2016-01-14 18:45:04 +00:00
2016-02-28 17:40:15 +00:00
writeNetworkRF ( data , DT_DATA_HEADER ) ;
2016-01-18 18:36:14 +00:00
2016-02-25 19:54:18 +00:00
m_rfState = RS_RF_DATA ;
2016-01-26 18:06:31 +00:00
2016-04-12 17:26:13 +00:00
std : : string src = m_lookup - > find ( srcId ) ;
2016-04-15 13:24:57 +00:00
std : : string dst = m_lookup - > find ( dstId ) ;
2016-04-12 17:26:13 +00:00
2016-02-25 19:54:18 +00:00
if ( m_netState = = RS_NET_IDLE ) {
2017-10-03 09:03:13 +00:00
setShortLC ( m_slotNo , dstId , gi ? FLCO_GROUP : FLCO_USER_USER , ACTIVITY_DATA ) ;
2016-04-21 12:01:53 +00:00
m_display - > writeDMR ( m_slotNo , src , gi , dst , " R " ) ;
2017-01-05 19:44:52 +00:00
m_display - > writeDMRRSSI ( m_slotNo , m_rssi ) ;
2016-02-25 19:54:18 +00:00
}
2016-01-18 18:36:14 +00:00
2016-04-15 13:24:57 +00:00
LogMessage ( " DMR Slot %u, received RF data header from %s to %s%s, %u blocks " , m_slotNo , src . c_str ( ) , gi ? " TG " : " " , dst . c_str ( ) , m_rfFrames ) ;
2016-04-26 17:22:47 +00:00
2017-03-05 19:33:03 +00:00
if ( m_rfFrames = = 0U ) {
LogMessage ( " DMR Slot %u, ended RF data transmission " , m_slotNo ) ;
writeEndRF ( ) ;
}
2017-03-12 19:06:47 +00:00
return true ;
2016-01-25 21:56:57 +00:00
} else if ( dataType = = DT_CSBK ) {
2016-02-22 18:12:24 +00:00
CDMRCSBK csbk ;
bool valid = csbk . put ( data + 2U ) ;
2016-04-28 08:58:45 +00:00
if ( ! valid )
2017-03-12 19:06:47 +00:00
return false ;
2016-01-25 21:56:57 +00:00
CSBKO csbko = csbk . getCSBKO ( ) ;
2016-03-14 17:33:05 +00:00
if ( csbko = = CSBKO_BSDWNACT )
2017-03-12 19:06:47 +00:00
return false ;
2016-01-25 21:56:57 +00:00
2016-03-14 21:22:09 +00:00
bool gi = csbk . getGI ( ) ;
unsigned int srcId = csbk . getSrcId ( ) ;
unsigned int dstId = csbk . getDstId ( ) ;
2016-11-01 08:00:13 +00:00
2016-11-11 07:20:45 +00:00
if ( srcId ! = 0U | | dstId ! = 0U ) {
2017-01-05 19:15:10 +00:00
if ( ! CDMRAccessControl : : validateSrcId ( srcId ) ) {
2016-12-21 19:06:29 +00:00
LogMessage ( " DMR Slot %u, RF user %u rejected " , m_slotNo , srcId ) ;
2017-03-12 19:06:47 +00:00
return false ;
2016-12-21 19:06:29 +00:00
}
2017-01-05 19:15:10 +00:00
if ( ! CDMRAccessControl : : validateTGId ( m_slotNo , gi , dstId ) ) {
LogMessage ( " DMR Slot %u, RF user %u rejected for using TG %u " , m_slotNo , srcId , dstId ) ;
2017-03-12 19:06:47 +00:00
return false ;
2017-01-05 19:15:10 +00:00
}
2016-11-11 07:20:45 +00:00
}
2016-09-11 12:01:05 +00:00
2016-03-14 17:33:05 +00:00
// Regenerate the CSBK data
csbk . get ( data + 2U ) ;
2016-02-22 18:12:24 +00:00
2016-03-14 17:33:05 +00:00
// Regenerate the Slot Type
slotType . getData ( data + 2U ) ;
2016-01-26 18:06:31 +00:00
2016-09-05 17:03:23 +00:00
// Convert the Data Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-01-25 21:56:57 +00:00
2016-03-14 17:33:05 +00:00
data [ 0U ] = TAG_DATA ;
data [ 1U ] = 0x00U ;
2016-01-25 21:56:57 +00:00
2016-03-14 17:33:05 +00:00
if ( m_duplex )
writeQueueRF ( data ) ;
2016-02-15 18:01:21 +00:00
2016-03-14 21:22:09 +00:00
writeNetworkRF ( data , DT_CSBK , gi ? FLCO_GROUP : FLCO_USER_USER , srcId , dstId ) ;
2016-01-25 22:36:16 +00:00
2016-04-28 09:32:11 +00:00
std : : string src = m_lookup - > find ( srcId ) ;
std : : string dst = m_lookup - > find ( dstId ) ;
2016-03-14 17:33:05 +00:00
switch ( csbko ) {
case CSBKO_UUVREQ :
2016-04-28 09:32:11 +00:00
LogMessage ( " DMR Slot %u, received RF Unit to Unit Voice Service Request CSBK from %s to %s%s " , m_slotNo , src . c_str ( ) , gi ? " TG " : " " , dst . c_str ( ) ) ;
2016-03-14 17:33:05 +00:00
break ;
case CSBKO_UUANSRSP :
2016-04-28 09:32:11 +00:00
LogMessage ( " DMR Slot %u, received RF Unit to Unit Voice Service Answer Response CSBK from %s to %s%s " , m_slotNo , src . c_str ( ) , gi ? " TG " : " " , dst . c_str ( ) ) ;
2016-03-14 17:33:05 +00:00
break ;
case CSBKO_NACKRSP :
2016-04-28 09:32:11 +00:00
LogMessage ( " DMR Slot %u, received RF Negative Acknowledgment Response CSBK from %s to %s%s " , m_slotNo , src . c_str ( ) , gi ? " TG " : " " , dst . c_str ( ) ) ;
2016-03-14 17:33:05 +00:00
break ;
case CSBKO_PRECCSBK :
2016-12-11 16:01:30 +00:00
LogMessage ( " DMR Slot %u, received RF %s Preamble CSBK (%u to follow) from %s to %s%s " , m_slotNo , csbk . getDataContent ( ) ? " Data " : " CSBK " , csbk . getCBF ( ) , src . c_str ( ) , gi ? " TG " : " " , dst . c_str ( ) ) ;
2016-01-25 21:56:57 +00:00
break ;
default :
2016-01-25 22:36:16 +00:00
LogWarning ( " DMR Slot %u, unhandled RF CSBK type - 0x%02X " , m_slotNo , csbko ) ;
2016-01-25 21:56:57 +00:00
break ;
}
2017-03-12 19:06:47 +00:00
2017-10-04 20:56:40 +00:00
// If data preamble, signal its existence
if ( m_netState = = RS_NET_IDLE & & csbko = = CSBKO_PRECCSBK & & csbk . getDataContent ( ) ) {
setShortLC ( m_slotNo , dstId , gi ? FLCO_GROUP : FLCO_USER_USER , ACTIVITY_DATA ) ;
m_display - > writeDMR ( m_slotNo , src , gi , dst , " R " ) ;
m_display - > writeDMRRSSI ( m_slotNo , m_rssi ) ;
}
2017-10-03 09:03:13 +00:00
return true ;
2016-01-26 18:06:31 +00:00
} else if ( dataType = = DT_RATE_12_DATA | | dataType = = DT_RATE_34_DATA | | dataType = = DT_RATE_1_DATA ) {
2016-03-14 21:22:09 +00:00
if ( m_rfState ! = RS_RF_DATA | | m_rfFrames = = 0U )
2017-03-12 19:06:47 +00:00
return false ;
2016-01-26 18:06:31 +00:00
2016-04-19 18:46:16 +00:00
// Regenerate the rate 1/2 payload
2016-03-10 17:18:40 +00:00
if ( dataType = = DT_RATE_12_DATA ) {
CBPTC19696 bptc ;
unsigned char payload [ 12U ] ;
bptc . decode ( data + 2U , payload ) ;
bptc . encode ( payload , data + 2U ) ;
2016-07-07 13:05:38 +00:00
} else if ( dataType = = DT_RATE_34_DATA ) {
2016-07-07 19:23:30 +00:00
CDMRTrellis trellis ;
unsigned char payload [ 18U ] ;
2016-07-14 17:58:03 +00:00
bool ret = trellis . decode ( data + 2U , payload ) ;
2016-08-08 17:05:14 +00:00
if ( ret ) {
2016-07-14 17:58:03 +00:00
trellis . encode ( payload , data + 2U ) ;
2016-08-08 17:05:14 +00:00
} else {
2017-02-13 08:50:23 +00:00
LogMessage ( " DMR Slot %u, unfixable RF rate 3/4 data " , m_slotNo ) ;
2016-08-08 17:05:14 +00:00
CUtils : : dump ( 1U , " Data " , data + 2U , DMR_FRAME_LENGTH_BYTES ) ;
}
2016-03-10 17:18:40 +00:00
}
2016-01-14 18:45:04 +00:00
// Regenerate the Slot Type
slotType . getData ( data + 2U ) ;
2016-09-05 17:03:23 +00:00
// Convert the Data Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-01-14 18:45:04 +00:00
2016-02-25 19:54:18 +00:00
m_rfFrames - - ;
2016-01-26 18:06:31 +00:00
2016-02-25 19:54:18 +00:00
data [ 0U ] = m_rfFrames = = 0U ? TAG_EOT : TAG_DATA ;
2016-01-14 18:45:04 +00:00
data [ 1U ] = 0x00U ;
2016-02-15 18:01:21 +00:00
if ( m_duplex )
2016-02-25 19:54:18 +00:00
writeQueueRF ( data ) ;
2016-02-15 18:01:21 +00:00
2016-02-25 19:54:18 +00:00
writeNetworkRF ( data , dataType ) ;
2016-01-26 18:06:31 +00:00
2017-03-05 19:33:03 +00:00
if ( m_rfFrames = = 0U ) {
LogMessage ( " DMR Slot %u, ended RF data transmission " , m_slotNo ) ;
writeEndRF ( ) ;
}
2017-03-12 19:06:47 +00:00
return true ;
2016-01-14 18:45:04 +00:00
}
} else if ( audioSync ) {
2016-02-25 19:54:18 +00:00
if ( m_rfState = = RS_RF_AUDIO ) {
2016-09-05 17:03:23 +00:00
// Convert the Audio Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRAudioSync ( data + 2U , m_duplex ) ;
2016-01-14 18:45:04 +00:00
2016-03-23 17:30:06 +00:00
unsigned int errors = 0U ;
2016-02-25 19:54:18 +00:00
unsigned char fid = m_rfLC - > getFID ( ) ;
2016-02-18 18:18:37 +00:00
if ( fid = = FID_ETSI | | fid = = FID_DMRA ) {
2016-03-23 17:30:06 +00:00
errors = m_fec . regenerateDMR ( data + 2U ) ;
2017-02-12 18:37:00 +00:00
LogDebug ( " DMR Slot %u, audio sequence no. 0, errs: %u/141 (%.1f%%) " , m_slotNo , errors , float ( errors ) / 1.41F ) ;
m_display - > writeDMRBER ( m_slotNo , float ( errors ) / 1.41F ) ;
2016-02-25 19:54:18 +00:00
m_rfErrs + = errors ;
2016-02-18 18:18:37 +00:00
}
2016-02-25 19:54:18 +00:00
m_rfBits + = 141U ;
2016-04-26 18:10:45 +00:00
m_rfFrames + + ;
2017-01-10 19:27:12 +00:00
m_rfEmbeddedReadN = ( m_rfEmbeddedReadN + 1U ) % 2U ;
m_rfEmbeddedWriteN = ( m_rfEmbeddedWriteN + 1U ) % 2U ;
m_rfEmbeddedData [ m_rfEmbeddedWriteN ] . reset ( ) ;
2017-01-05 19:00:01 +00:00
2017-03-12 19:25:01 +00:00
m_display - > writeDMRRSSI ( m_slotNo , m_rssi ) ;
2017-03-12 19:06:47 +00:00
if ( ! m_rfTimeout ) {
data [ 0U ] = TAG_DATA ;
data [ 1U ] = 0x00U ;
2016-02-15 18:01:21 +00:00
2017-03-12 19:06:47 +00:00
if ( m_duplex )
writeQueueRF ( data ) ;
writeNetworkRF ( data , DT_VOICE_SYNC , errors ) ;
2017-01-05 19:44:52 +00:00
2017-03-12 19:25:01 +00:00
return true ;
}
2017-03-12 19:06:47 +00:00
2017-03-12 19:25:01 +00:00
return false ;
2016-02-25 19:54:18 +00:00
} else if ( m_rfState = = RS_RF_LISTENING ) {
2017-01-05 19:00:01 +00:00
m_rfEmbeddedLC . reset ( ) ;
2016-02-25 19:54:18 +00:00
m_rfState = RS_RF_LATE_ENTRY ;
2017-03-12 19:06:47 +00:00
return false ;
2016-01-14 18:45:04 +00:00
}
} else {
2016-02-29 06:41:19 +00:00
if ( m_rfState = = RS_RF_AUDIO ) {
2016-02-29 06:51:34 +00:00
m_rfN = data [ 1U ] & 0x0FU ;
2018-02-08 20:34:18 +00:00
if ( m_rfN > 5U )
2018-02-04 17:46:09 +00:00
return false ;
2016-03-23 17:30:06 +00:00
unsigned int errors = 0U ;
2016-02-25 19:54:18 +00:00
unsigned char fid = m_rfLC - > getFID ( ) ;
2016-02-18 18:18:37 +00:00
if ( fid = = FID_ETSI | | fid = = FID_DMRA ) {
2016-03-23 17:30:06 +00:00
errors = m_fec . regenerateDMR ( data + 2U ) ;
2017-02-12 18:37:00 +00:00
LogDebug ( " DMR Slot %u, audio sequence no. %u, errs: %u/141 (%.1f%%) " , m_slotNo , m_rfN , errors , float ( errors ) / 1.41F ) ;
m_display - > writeDMRBER ( m_slotNo , float ( errors ) / 1.41F ) ;
2016-02-25 19:54:18 +00:00
m_rfErrs + = errors ;
2016-02-18 18:18:37 +00:00
}
2016-02-25 19:54:18 +00:00
m_rfBits + = 141U ;
2016-04-26 18:10:45 +00:00
m_rfFrames + + ;
2017-01-10 19:27:12 +00:00
// Get the LCSS from the EMB
CDMREMB emb ;
emb . putData ( data + 2U ) ;
unsigned char lcss = emb . getLCSS ( ) ;
// Dump any interesting Embedded Data
bool ret = m_rfEmbeddedData [ m_rfEmbeddedWriteN ] . addData ( data + 2U , lcss ) ;
if ( ret ) {
FLCO flco = m_rfEmbeddedData [ m_rfEmbeddedWriteN ] . getFLCO ( ) ;
2017-10-24 20:55:58 +00:00
2017-01-10 19:27:12 +00:00
unsigned char data [ 9U ] ;
m_rfEmbeddedData [ m_rfEmbeddedWriteN ] . getRawData ( data ) ;
char text [ 80U ] ;
switch ( flco ) {
case FLCO_GROUP :
case FLCO_USER_USER :
// ::sprintf(text, "DMR Slot %u, Embedded LC", m_slotNo);
// CUtils::dump(1U, text, data, 9U);
break ;
2017-05-18 11:58:56 +00:00
2017-01-10 19:27:12 +00:00
case FLCO_GPS_INFO :
2017-02-27 20:17:55 +00:00
if ( m_dumpTAData ) {
: : sprintf ( text , " DMR Slot %u, Embedded GPS Info " , m_slotNo ) ;
CUtils : : dump ( 2U , text , data , 9U ) ;
2017-11-26 17:56:20 +00:00
logGPSPosition ( data ) ;
2017-02-27 20:17:55 +00:00
}
2017-05-17 17:16:08 +00:00
if ( m_network ! = NULL )
m_network - > writePosition ( m_rfLC - > getSrcId ( ) , data ) ;
2017-01-10 19:27:12 +00:00
break ;
2017-05-18 11:58:56 +00:00
2017-01-10 19:27:12 +00:00
case FLCO_TALKER_ALIAS_HEADER :
2017-05-18 11:58:56 +00:00
if ( m_network ! = NULL )
m_network - > writeTalkerAlias ( m_rfLC - > getSrcId ( ) , 0U , data ) ;
2017-02-12 18:37:00 +00:00
if ( ! ( m_rfTalkerId & TALKER_ID_HEADER ) ) {
2017-11-15 10:47:56 +00:00
if ( m_rfTalkerId = = TALKER_ID_NONE )
: : memset ( m_rfTalkerAlias , ' \0 ' , 32U ) ;
2017-11-13 20:48:47 +00:00
: : memcpy ( m_rfTalkerAlias , data , 6U ) ;
2017-11-15 10:47:56 +00:00
m_display - > writeDMRTA ( m_slotNo , m_rfTalkerAlias , " R " ) ;
2017-02-27 20:17:55 +00:00
if ( m_dumpTAData ) {
: : sprintf ( text , " DMR Slot %u, Embedded Talker Alias Header " , m_slotNo ) ;
CUtils : : dump ( 2U , text , data , 9U ) ;
}
2017-02-28 08:27:56 +00:00
m_rfTalkerId | = TALKER_ID_HEADER ;
2017-02-12 18:37:00 +00:00
}
2017-01-10 19:27:12 +00:00
break ;
2017-05-18 11:58:56 +00:00
2017-01-10 19:27:12 +00:00
case FLCO_TALKER_ALIAS_BLOCK1 :
2017-05-18 11:58:56 +00:00
if ( m_network ! = NULL )
m_network - > writeTalkerAlias ( m_rfLC - > getSrcId ( ) , 1U , data ) ;
2017-02-12 18:37:00 +00:00
if ( ! ( m_rfTalkerId & TALKER_ID_BLOCK1 ) ) {
2017-11-15 10:47:56 +00:00
if ( m_rfTalkerId = = TALKER_ID_NONE )
: : memset ( m_rfTalkerAlias , ' \0 ' , 32U ) ;
: : memcpy ( m_rfTalkerAlias + 6U , data , 7U ) ;
m_display - > writeDMRTA ( m_slotNo , m_rfTalkerAlias , " R " ) ;
2017-02-27 20:17:55 +00:00
if ( m_dumpTAData ) {
: : sprintf ( text , " DMR Slot %u, Embedded Talker Alias Block 1 " , m_slotNo ) ;
CUtils : : dump ( 2U , text , data , 9U ) ;
}
2017-02-28 08:27:56 +00:00
m_rfTalkerId | = TALKER_ID_BLOCK1 ;
2017-02-12 18:37:00 +00:00
}
2017-01-10 19:27:12 +00:00
break ;
2017-05-18 11:58:56 +00:00
2017-01-10 19:27:12 +00:00
case FLCO_TALKER_ALIAS_BLOCK2 :
2017-05-18 11:58:56 +00:00
if ( m_network ! = NULL )
m_network - > writeTalkerAlias ( m_rfLC - > getSrcId ( ) , 2U , data ) ;
2017-02-12 18:37:00 +00:00
if ( ! ( m_rfTalkerId & TALKER_ID_BLOCK2 ) ) {
2017-11-15 10:47:56 +00:00
if ( m_rfTalkerId = = TALKER_ID_NONE )
: : memset ( m_rfTalkerAlias , 0 , 32U ) ;
: : memcpy ( m_rfTalkerAlias + 6U + 7U , data , 7U ) ;
m_display - > writeDMRTA ( m_slotNo , m_rfTalkerAlias , " R " ) ;
2017-02-27 20:17:55 +00:00
if ( m_dumpTAData ) {
: : sprintf ( text , " DMR Slot %u, Embedded Talker Alias Block 2 " , m_slotNo ) ;
CUtils : : dump ( 2U , text , data , 9U ) ;
}
2017-02-28 08:27:56 +00:00
2017-10-24 20:55:58 +00:00
m_rfTalkerId | = TALKER_ID_BLOCK2 ;
2017-02-12 18:37:00 +00:00
}
2017-01-10 19:27:12 +00:00
break ;
2017-05-18 11:58:56 +00:00
2017-01-10 19:27:12 +00:00
case FLCO_TALKER_ALIAS_BLOCK3 :
2017-05-18 11:58:56 +00:00
if ( m_network ! = NULL )
m_network - > writeTalkerAlias ( m_rfLC - > getSrcId ( ) , 3U , data ) ;
2017-02-12 18:37:00 +00:00
if ( ! ( m_rfTalkerId & TALKER_ID_BLOCK3 ) ) {
2017-11-15 10:47:56 +00:00
if ( m_rfTalkerId = = TALKER_ID_NONE )
: : memset ( m_rfTalkerAlias , ' \0 ' , 32U ) ;
: : memcpy ( m_rfTalkerAlias + 6U + 7U + 7U , data , 7U ) ;
m_display - > writeDMRTA ( m_slotNo , m_rfTalkerAlias , " R " ) ;
2017-02-27 20:17:55 +00:00
if ( m_dumpTAData ) {
: : sprintf ( text , " DMR Slot %u, Embedded Talker Alias Block 3 " , m_slotNo ) ;
CUtils : : dump ( 2U , text , data , 9U ) ;
}
2017-02-28 08:27:56 +00:00
m_rfTalkerId | = TALKER_ID_BLOCK3 ;
2017-02-12 18:37:00 +00:00
}
2017-01-10 19:27:12 +00:00
break ;
2017-05-18 11:58:56 +00:00
2017-01-10 19:27:12 +00:00
default :
: : sprintf ( text , " DMR Slot %u, Unknown Embedded Data " , m_slotNo ) ;
CUtils : : dump ( 1U , text , data , 9U ) ;
break ;
}
}
// Regenerate the previous super blocks Embedded Data or substitude the LC for it
if ( m_rfEmbeddedData [ m_rfEmbeddedReadN ] . isValid ( ) )
lcss = m_rfEmbeddedData [ m_rfEmbeddedReadN ] . getData ( data + 2U , m_rfN ) ;
else
lcss = m_rfEmbeddedLC . getData ( data + 2U , m_rfN ) ;
// Regenerate the EMB
emb . setColorCode ( m_colorCode ) ;
emb . setLCSS ( lcss ) ;
emb . getData ( data + 2U ) ;
2017-03-12 19:25:01 +00:00
if ( ! m_rfTimeout ) {
data [ 0U ] = TAG_DATA ;
data [ 1U ] = 0x00U ;
2016-01-18 18:36:14 +00:00
2017-03-12 19:06:47 +00:00
writeNetworkRF ( data , DT_VOICE , errors ) ;
2017-01-16 12:10:23 +00:00
2017-03-12 19:25:01 +00:00
if ( m_embeddedLCOnly ) {
// Only send the previously received LC
lcss = m_rfEmbeddedLC . getData ( data + 2U , m_rfN ) ;
2017-01-16 12:10:23 +00:00
2017-03-12 19:25:01 +00:00
// Regenerate the EMB
emb . setColorCode ( m_colorCode ) ;
emb . setLCSS ( lcss ) ;
emb . getData ( data + 2U ) ;
}
2017-01-16 12:10:23 +00:00
2017-03-12 19:06:47 +00:00
if ( m_duplex )
writeQueueRF ( data ) ;
2017-03-12 19:25:01 +00:00
return true ;
2017-03-12 19:06:47 +00:00
}
2017-03-12 19:25:01 +00:00
return false ;
2016-02-25 19:54:18 +00:00
} else if ( m_rfState = = RS_RF_LATE_ENTRY ) {
2016-02-23 21:01:14 +00:00
CDMREMB emb ;
emb . putData ( data + 2U ) ;
2016-01-14 18:45:04 +00:00
// If we haven't received an LC yet, then be strict on the color code
unsigned char colorCode = emb . getColorCode ( ) ;
if ( colorCode ! = m_colorCode )
2017-03-12 19:06:47 +00:00
return false ;
2016-01-14 18:45:04 +00:00
2017-01-05 19:00:01 +00:00
m_rfEmbeddedLC . addData ( data + 2U , emb . getLCSS ( ) ) ;
CDMRLC * lc = m_rfEmbeddedLC . getLC ( ) ;
2016-04-04 16:40:05 +00:00
if ( lc ! = NULL ) {
2016-11-01 08:00:13 +00:00
unsigned int srcId = lc - > getSrcId ( ) ;
unsigned int dstId = lc - > getDstId ( ) ;
2017-01-05 19:15:10 +00:00
FLCO flco = lc - > getFLCO ( ) ;
2016-10-10 18:27:08 +00:00
2017-01-05 19:15:10 +00:00
if ( ! CDMRAccessControl : : validateSrcId ( srcId ) ) {
2016-12-21 19:06:29 +00:00
LogMessage ( " DMR Slot %u, RF user %u rejected " , m_slotNo , srcId ) ;
delete lc ;
2017-03-12 19:06:47 +00:00
return false ;
2016-06-16 20:40:05 +00:00
}
2016-10-10 18:27:08 +00:00
2017-01-05 19:15:10 +00:00
if ( ! CDMRAccessControl : : validateTGId ( m_slotNo , flco = = FLCO_GROUP , dstId ) ) {
LogMessage ( " DMR Slot %u, RF user %u rejected for using TG %u " , m_slotNo , srcId , dstId ) ;
delete lc ;
2017-03-12 19:06:47 +00:00
return false ;
2017-01-05 19:15:10 +00:00
}
2016-04-04 16:40:05 +00:00
m_rfLC = lc ;
2017-01-10 19:27:12 +00:00
// The standby LC data
m_rfEmbeddedLC . setLC ( * m_rfLC ) ;
m_rfEmbeddedData [ 0U ] . setLC ( * m_rfLC ) ;
m_rfEmbeddedData [ 1U ] . setLC ( * m_rfLC ) ;
2016-01-14 18:45:04 +00:00
// Create a dummy start frame to replace the received frame
unsigned char start [ DMR_FRAME_LENGTH_BYTES + 2U ] ;
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( start + 2U , m_duplex ) ;
2016-01-14 18:45:04 +00:00
2016-02-15 18:45:57 +00:00
CDMRFullLC fullLC ;
2016-02-25 19:54:18 +00:00
fullLC . encode ( * m_rfLC , start + 2U , DT_VOICE_LC_HEADER ) ;
2016-01-14 18:45:04 +00:00
2016-02-15 18:45:57 +00:00
CDMRSlotType slotType ;
2016-01-14 18:45:04 +00:00
slotType . setColorCode ( m_colorCode ) ;
slotType . setDataType ( DT_VOICE_LC_HEADER ) ;
slotType . getData ( start + 2U ) ;
start [ 0U ] = TAG_DATA ;
start [ 1U ] = 0x00U ;
2016-02-25 19:54:18 +00:00
m_rfTimeoutTimer . start ( ) ;
2017-03-12 19:06:47 +00:00
m_rfTimeout = false ;
2016-01-14 18:45:04 +00:00
2016-02-25 19:54:18 +00:00
m_rfFrames = 0U ;
2016-02-28 17:40:15 +00:00
m_rfSeqNo = 0U ;
m_rfBits = 1U ;
m_rfErrs = 0U ;
2017-02-12 18:37:00 +00:00
2017-01-10 19:27:12 +00:00
m_rfEmbeddedReadN = 0U ;
m_rfEmbeddedWriteN = 1U ;
2017-02-12 18:37:00 +00:00
m_rfTalkerId = TALKER_ID_NONE ;
2016-01-19 20:13:20 +00:00
2017-01-05 19:15:10 +00:00
m_minRSSI = m_rssi ;
m_maxRSSI = m_rssi ;
m_aveRSSI = m_rssi ;
m_rssiCount = 1U ;
2016-02-15 18:01:21 +00:00
if ( m_duplex ) {
2016-06-20 09:01:09 +00:00
m_queue . clear ( ) ;
m_modem - > writeDMRAbort ( m_slotNo ) ;
2017-04-02 12:39:28 +00:00
for ( unsigned int i = 0U ; i < NO_HEADERS_DUPLEX ; i + + )
writeQueueRF ( start ) ;
2016-01-14 18:45:04 +00:00
}
2016-02-28 17:40:15 +00:00
writeNetworkRF ( start , DT_VOICE_LC_HEADER ) ;
2016-02-15 18:01:21 +00:00
2016-02-29 06:51:34 +00:00
m_rfN = data [ 1U ] & 0x0FU ;
2018-02-08 20:34:18 +00:00
if ( m_rfN > 5U )
2018-02-04 17:46:09 +00:00
return false ;
2016-01-19 17:43:33 +00:00
// Regenerate the EMB
emb . getData ( data + 2U ) ;
2016-01-14 18:45:04 +00:00
// Send the original audio frame out
2016-03-23 17:30:06 +00:00
unsigned int errors = 0U ;
2016-02-25 19:54:18 +00:00
unsigned char fid = m_rfLC - > getFID ( ) ;
2016-02-18 18:18:37 +00:00
if ( fid = = FID_ETSI | | fid = = FID_DMRA ) {
2016-03-23 17:30:06 +00:00
errors = m_fec . regenerateDMR ( data + 2U ) ;
2017-02-12 18:37:00 +00:00
LogDebug ( " DMR Slot %u, audio sequence no. %u, errs: %u/141 (%.1f%%) " , m_slotNo , m_rfN , errors , float ( errors ) / 1.41F ) ;
2016-02-25 19:54:18 +00:00
m_rfErrs + = errors ;
2016-02-18 18:18:37 +00:00
}
2016-02-25 19:54:18 +00:00
m_rfBits + = 141U ;
2016-04-26 18:10:45 +00:00
m_rfFrames + + ;
2016-01-14 18:45:04 +00:00
data [ 0U ] = TAG_DATA ;
data [ 1U ] = 0x00U ;
2016-01-18 18:36:14 +00:00
2016-02-15 18:01:21 +00:00
if ( m_duplex )
2016-02-25 19:54:18 +00:00
writeQueueRF ( data ) ;
2016-01-14 18:45:04 +00:00
2016-03-23 17:30:06 +00:00
writeNetworkRF ( data , DT_VOICE , errors ) ;
2016-01-14 18:45:04 +00:00
2016-02-25 19:54:18 +00:00
m_rfState = RS_RF_AUDIO ;
2016-01-14 18:45:04 +00:00
2016-11-01 08:00:13 +00:00
std : : string src = m_lookup - > find ( srcId ) ;
std : : string dst = m_lookup - > find ( dstId ) ;
2016-04-12 17:26:13 +00:00
2016-02-25 19:54:18 +00:00
if ( m_netState = = RS_NET_IDLE ) {
2017-10-03 09:03:13 +00:00
setShortLC ( m_slotNo , dstId , flco , ACTIVITY_VOICE ) ;
2017-01-05 19:15:10 +00:00
m_display - > writeDMR ( m_slotNo , src , flco = = FLCO_GROUP , dst , " R " ) ;
2017-01-05 19:44:52 +00:00
m_display - > writeDMRRSSI ( m_slotNo , m_rssi ) ;
2017-02-12 18:37:00 +00:00
m_display - > writeDMRBER ( m_slotNo , float ( errors ) / 1.41F ) ;
2016-02-25 19:54:18 +00:00
}
2016-01-14 18:45:04 +00:00
2017-01-05 19:15:10 +00:00
LogMessage ( " DMR Slot %u, received RF late entry from %s to %s%s " , m_slotNo , src . c_str ( ) , flco = = FLCO_GROUP ? " TG " : " " , dst . c_str ( ) ) ;
2017-03-12 19:06:47 +00:00
return true ;
2016-01-14 18:45:04 +00:00
}
}
}
2017-03-12 19:06:47 +00:00
return false ;
2016-01-14 18:45:04 +00:00
}
unsigned int CDMRSlot : : readModem ( unsigned char * data )
{
2016-03-07 20:21:55 +00:00
assert ( data ! = NULL ) ;
2016-03-07 18:08:50 +00:00
if ( m_queue . isEmpty ( ) )
2016-01-14 18:45:04 +00:00
return 0U ;
unsigned char len = 0U ;
2016-03-07 18:08:50 +00:00
m_queue . getData ( & len , 1U ) ;
2016-01-14 18:45:04 +00:00
2016-03-07 18:08:50 +00:00
m_queue . getData ( data , len ) ;
2016-01-14 18:45:04 +00:00
return len ;
}
2016-02-25 19:54:18 +00:00
void CDMRSlot : : writeEndRF ( bool writeEnd )
2016-01-14 18:45:04 +00:00
{
2016-02-25 19:54:18 +00:00
m_rfState = RS_RF_LISTENING ;
2016-01-14 18:45:04 +00:00
2016-02-25 19:54:18 +00:00
if ( m_netState = = RS_NET_IDLE ) {
setShortLC ( m_slotNo , 0U ) ;
m_display - > clearDMR ( m_slotNo ) ;
}
2016-01-14 18:45:04 +00:00
2016-02-07 20:12:24 +00:00
if ( writeEnd ) {
2017-03-12 19:06:47 +00:00
if ( m_netState = = RS_NET_IDLE & & m_duplex & & ! m_rfTimeout ) {
2016-02-15 18:01:21 +00:00
// Create a dummy start end frame
unsigned char data [ DMR_FRAME_LENGTH_BYTES + 2U ] ;
2016-02-07 20:12:24 +00:00
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-02-07 20:12:24 +00:00
2016-02-15 18:45:57 +00:00
CDMRFullLC fullLC ;
2016-02-25 19:54:18 +00:00
fullLC . encode ( * m_rfLC , data + 2U , DT_TERMINATOR_WITH_LC ) ;
2016-02-07 20:12:24 +00:00
2016-02-15 18:45:57 +00:00
CDMRSlotType slotType ;
2016-02-15 18:01:21 +00:00
slotType . setColorCode ( m_colorCode ) ;
slotType . setDataType ( DT_TERMINATOR_WITH_LC ) ;
slotType . getData ( data + 2U ) ;
2016-02-07 20:12:24 +00:00
2016-05-03 20:18:44 +00:00
data [ 0U ] = TAG_EOT ;
2016-02-15 18:01:21 +00:00
data [ 1U ] = 0x00U ;
2016-10-10 18:27:08 +00:00
2016-06-16 20:40:05 +00:00
for ( unsigned int i = 0U ; i < m_hangCount ; i + + )
writeQueueRF ( data ) ;
2016-02-15 18:01:21 +00:00
}
2016-02-07 20:12:24 +00:00
}
2017-03-12 19:06:47 +00:00
m_rfTimeoutTimer . stop ( ) ;
m_rfTimeout = false ;
m_rfFrames = 0U ;
m_rfErrs = 0U ;
m_rfBits = 1U ;
2018-01-11 21:17:25 +00:00
m_rfSeqNo = 0U ;
m_rfN = 0U ;
2016-02-25 19:54:18 +00:00
delete m_rfLC ;
m_rfLC = NULL ;
}
void CDMRSlot : : writeEndNet ( bool writeEnd )
{
m_netState = RS_NET_IDLE ;
setShortLC ( m_slotNo , 0U ) ;
m_display - > clearDMR ( m_slotNo ) ;
2018-02-08 20:25:03 +00:00
m_lastFrameValid = false ;
2017-03-12 19:06:47 +00:00
if ( writeEnd & & ! m_netTimeout ) {
2016-02-25 19:54:18 +00:00
// Create a dummy start end frame
unsigned char data [ DMR_FRAME_LENGTH_BYTES + 2U ] ;
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-02-25 19:54:18 +00:00
CDMRFullLC fullLC ;
fullLC . encode ( * m_netLC , data + 2U , DT_TERMINATOR_WITH_LC ) ;
CDMRSlotType slotType ;
slotType . setColorCode ( m_colorCode ) ;
slotType . setDataType ( DT_TERMINATOR_WITH_LC ) ;
slotType . getData ( data + 2U ) ;
2016-05-03 20:18:44 +00:00
data [ 0U ] = TAG_EOT ;
2016-02-25 19:54:18 +00:00
data [ 1U ] = 0x00U ;
2016-06-20 09:01:09 +00:00
if ( m_duplex ) {
for ( unsigned int i = 0U ; i < m_hangCount ; i + + )
writeQueueNet ( data ) ;
} else {
for ( unsigned int i = 0U ; i < 3U ; i + + )
writeQueueNet ( data ) ;
}
2016-02-25 19:54:18 +00:00
}
2017-03-12 19:06:47 +00:00
m_networkWatchdog . stop ( ) ;
m_netTimeoutTimer . stop ( ) ;
2018-02-08 20:25:03 +00:00
m_packetTimer . stop ( ) ;
2017-03-12 19:06:47 +00:00
m_netTimeout = false ;
m_netFrames = 0U ;
m_netLost = 0U ;
m_netErrs = 0U ;
m_netBits = 1U ;
2018-01-11 21:17:25 +00:00
m_netN = 0U ;
2016-02-25 19:54:18 +00:00
delete m_netLC ;
m_netLC = NULL ;
2016-01-19 17:43:33 +00:00
# if defined(DUMP_DMR)
closeFile ( ) ;
# endif
2016-01-14 18:45:04 +00:00
}
2016-06-16 20:40:05 +00:00
void CDMRSlot : : writeNetwork ( const CDMRData & dmrData )
2016-01-14 18:45:04 +00:00
{
2016-02-25 19:54:18 +00:00
if ( m_rfState ! = RS_RF_LISTENING & & m_netState = = RS_NET_IDLE )
2016-01-14 18:45:04 +00:00
return ;
2018-02-08 20:25:03 +00:00
m_networkWatchdog . start ( ) ;
2017-11-28 10:09:29 +00:00
2018-02-08 20:25:03 +00:00
unsigned char dataType = dmrData . getDataType ( ) ;
2018-01-10 19:05:59 +00:00
2018-02-08 20:25:03 +00:00
unsigned char data [ DMR_FRAME_LENGTH_BYTES + 2U ] ;
dmrData . getData ( data + 2U ) ;
2018-01-10 19:05:59 +00:00
2016-01-14 18:45:04 +00:00
if ( dataType = = DT_VOICE_LC_HEADER ) {
2016-08-09 06:28:10 +00:00
if ( m_netState = = RS_NET_AUDIO )
2016-01-18 18:36:14 +00:00
return ;
2016-01-14 18:45:04 +00:00
2016-02-15 18:45:57 +00:00
CDMRFullLC fullLC ;
2016-11-01 08:00:13 +00:00
CDMRLC * lc = fullLC . decode ( data + 2U , DT_VOICE_LC_HEADER ) ;
if ( lc = = NULL ) {
2016-10-31 17:55:38 +00:00
LogMessage ( " DMR Slot %u, bad LC received from the network, replacing " , m_slotNo ) ;
2016-11-01 08:00:13 +00:00
lc = new CDMRLC ( dmrData . getFLCO ( ) , dmrData . getSrcId ( ) , dmrData . getDstId ( ) ) ;
2016-01-18 18:36:14 +00:00
}
2016-01-14 18:45:04 +00:00
2016-11-01 08:00:13 +00:00
unsigned int dstId = lc - > getDstId ( ) ;
unsigned int srcId = lc - > getSrcId ( ) ;
2017-05-12 08:26:34 +00:00
FLCO flco = lc - > getFLCO ( ) ;
if ( dstId ! = dmrData . getDstId ( ) | | srcId ! = dmrData . getSrcId ( ) | | flco ! = dmrData . getFLCO ( ) )
LogWarning ( " DMR Slot %u, DMRD header doesn't match the DMR RF header: %u->%s%u %u->%s%u " , m_slotNo ,
dmrData . getSrcId ( ) , dmrData . getFLCO ( ) = = FLCO_GROUP ? " TG " : " " , dmrData . getDstId ( ) ,
srcId , flco = = FLCO_GROUP ? " TG " : " " , dstId ) ;
2016-10-10 18:27:08 +00:00
2016-11-01 08:00:13 +00:00
m_netLC = lc ;
2016-10-10 18:27:08 +00:00
2017-01-10 19:27:12 +00:00
// The standby LC data
m_netEmbeddedLC . setLC ( * m_netLC ) ;
m_netEmbeddedData [ 0U ] . setLC ( * m_netLC ) ;
m_netEmbeddedData [ 1U ] . setLC ( * m_netLC ) ;
2016-02-22 18:12:24 +00:00
// Regenerate the LC data
2016-02-25 19:54:18 +00:00
fullLC . encode ( * m_netLC , data + 2U , DT_VOICE_LC_HEADER ) ;
2016-06-16 20:40:05 +00:00
2016-01-18 18:36:14 +00:00
// Regenerate the Slot Type
2016-02-15 18:45:57 +00:00
CDMRSlotType slotType ;
2016-01-18 18:36:14 +00:00
slotType . setColorCode ( m_colorCode ) ;
slotType . setDataType ( DT_VOICE_LC_HEADER ) ;
slotType . getData ( data + 2U ) ;
2016-01-14 18:45:04 +00:00
2016-09-05 17:03:23 +00:00
// Convert the Data Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-01-14 18:45:04 +00:00
2016-01-18 18:36:14 +00:00
data [ 0U ] = TAG_DATA ;
data [ 1U ] = 0x00U ;
2016-01-14 18:45:04 +00:00
2018-02-08 20:25:03 +00:00
m_lastFrameValid = false ;
2016-02-25 19:54:18 +00:00
m_netTimeoutTimer . start ( ) ;
2017-03-12 19:06:47 +00:00
m_netTimeout = false ;
2016-01-14 18:45:04 +00:00
2016-02-25 19:54:18 +00:00
m_netFrames = 0U ;
m_netLost = 0U ;
m_netBits = 1U ;
m_netErrs = 0U ;
2017-02-12 18:37:00 +00:00
2017-01-10 19:27:12 +00:00
m_netEmbeddedReadN = 0U ;
m_netEmbeddedWriteN = 1U ;
2017-02-12 18:37:00 +00:00
m_netTalkerId = TALKER_ID_NONE ;
2016-01-20 07:12:28 +00:00
2016-06-20 09:01:09 +00:00
if ( m_duplex ) {
m_queue . clear ( ) ;
m_modem - > writeDMRAbort ( m_slotNo ) ;
}
2018-02-08 20:25:03 +00:00
for ( unsigned int i = 0U ; i < m_jitterSlots ; i + + )
writeQueueNet ( m_idle ) ;
2017-04-02 12:39:28 +00:00
if ( m_duplex ) {
for ( unsigned int i = 0U ; i < NO_HEADERS_DUPLEX ; i + + )
writeQueueNet ( data ) ;
} else {
for ( unsigned int i = 0U ; i < NO_HEADERS_SIMPLEX ; i + + )
writeQueueNet ( data ) ;
}
2016-01-14 18:45:04 +00:00
2016-02-25 19:54:18 +00:00
m_netState = RS_NET_AUDIO ;
2016-01-14 18:45:04 +00:00
2017-10-03 09:03:13 +00:00
setShortLC ( m_slotNo , dstId , flco , ACTIVITY_VOICE ) ;
2016-11-01 08:00:13 +00:00
std : : string src = m_lookup - > find ( srcId ) ;
std : : string dst = m_lookup - > find ( dstId ) ;
2018-04-10 22:08:48 +00:00
std : : string cn = m_lookup - > findwithname ( srcId ) ;
m_display - > writeDMR ( m_slotNo , cn , flco = = FLCO_GROUP , dst , " N " ) ;
2016-01-14 18:45:04 +00:00
# if defined(DUMP_DMR)
2016-01-18 18:36:14 +00:00
openFile ( ) ;
writeFile ( data ) ;
2016-01-14 18:45:04 +00:00
# endif
2018-04-10 22:08:48 +00:00
2017-05-12 08:26:34 +00:00
LogMessage ( " DMR Slot %u, received network voice header from %s to %s%s " , m_slotNo , src . c_str ( ) , flco = = FLCO_GROUP ? " TG " : " " , dst . c_str ( ) ) ;
2016-01-14 18:45:04 +00:00
} else if ( dataType = = DT_VOICE_PI_HEADER ) {
2016-11-01 18:07:10 +00:00
if ( m_netState ! = RS_NET_AUDIO ) {
CDMRLC * lc = new CDMRLC ( dmrData . getFLCO ( ) , dmrData . getSrcId ( ) , dmrData . getDstId ( ) ) ;
unsigned int dstId = lc - > getDstId ( ) ;
unsigned int srcId = lc - > getSrcId ( ) ;
m_netLC = lc ;
2018-02-08 20:25:03 +00:00
m_lastFrameValid = false ;
2016-11-01 18:07:10 +00:00
m_netTimeoutTimer . start ( ) ;
2017-03-12 19:06:47 +00:00
m_netTimeout = false ;
2016-11-01 18:07:10 +00:00
if ( m_duplex ) {
m_queue . clear ( ) ;
m_modem - > writeDMRAbort ( m_slotNo ) ;
}
2018-02-08 20:25:03 +00:00
for ( unsigned int i = 0U ; i < m_jitterSlots ; i + + )
writeQueueNet ( m_idle ) ;
2016-11-01 18:07:10 +00:00
// Create a dummy start frame
unsigned char start [ DMR_FRAME_LENGTH_BYTES + 2U ] ;
CSync : : addDMRDataSync ( start + 2U , m_duplex ) ;
CDMRFullLC fullLC ;
fullLC . encode ( * m_netLC , start + 2U , DT_VOICE_LC_HEADER ) ;
CDMRSlotType slotType ;
slotType . setColorCode ( m_colorCode ) ;
slotType . setDataType ( DT_VOICE_LC_HEADER ) ;
slotType . getData ( start + 2U ) ;
start [ 0U ] = TAG_DATA ;
start [ 1U ] = 0x00U ;
2017-04-02 12:39:28 +00:00
if ( m_duplex ) {
for ( unsigned int i = 0U ; i < NO_HEADERS_DUPLEX ; i + + )
writeQueueRF ( start ) ;
} else {
for ( unsigned int i = 0U ; i < NO_HEADERS_SIMPLEX ; i + + )
writeQueueRF ( start ) ;
}
2016-11-01 18:07:10 +00:00
# if defined(DUMP_DMR)
openFile ( ) ;
# endif
m_netFrames = 0U ;
m_netLost = 0U ;
m_netBits = 1U ;
m_netErrs = 0U ;
m_netState = RS_NET_AUDIO ;
2017-10-03 09:03:13 +00:00
setShortLC ( m_slotNo , dstId , m_netLC - > getFLCO ( ) , ACTIVITY_VOICE ) ;
2016-11-01 18:07:10 +00:00
std : : string src = m_lookup - > find ( srcId ) ;
std : : string dst = m_lookup - > find ( dstId ) ;
m_display - > writeDMR ( m_slotNo , src , m_netLC - > getFLCO ( ) = = FLCO_GROUP , dst , " N " ) ;
LogMessage ( " DMR Slot %u, received network late entry from %s to %s%s " , m_slotNo , src . c_str ( ) , m_netLC - > getFLCO ( ) = = FLCO_GROUP ? " TG " : " " , dst . c_str ( ) ) ;
}
2016-01-14 18:45:04 +00:00
// Regenerate the Slot Type
2016-02-15 18:45:57 +00:00
CDMRSlotType slotType ;
2016-01-14 18:45:04 +00:00
slotType . setColorCode ( m_colorCode ) ;
slotType . setDataType ( DT_VOICE_PI_HEADER ) ;
slotType . getData ( data + 2U ) ;
2016-09-05 17:03:23 +00:00
// Convert the Data Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-01-14 18:45:04 +00:00
2016-02-25 19:59:09 +00:00
// Regenerate the payload
CBPTC19696 bptc ;
unsigned char payload [ 12U ] ;
bptc . decode ( data + 2U , payload ) ;
bptc . encode ( payload , data + 2U ) ;
2016-01-14 18:45:04 +00:00
data [ 0U ] = TAG_DATA ;
data [ 1U ] = 0x00U ;
2016-06-16 20:40:05 +00:00
2016-02-25 19:54:18 +00:00
writeQueueNet ( data ) ;
2016-01-14 18:45:04 +00:00
# if defined(DUMP_DMR)
writeFile ( data ) ;
# endif
} else if ( dataType = = DT_TERMINATOR_WITH_LC ) {
2016-02-25 19:54:18 +00:00
if ( m_netState ! = RS_NET_AUDIO )
2016-01-14 18:45:04 +00:00
return ;
2016-06-17 06:05:37 +00:00
// Regenerate the LC data
CDMRFullLC fullLC ;
fullLC . encode ( * m_netLC , data + 2U , DT_TERMINATOR_WITH_LC ) ;
2016-01-14 18:45:04 +00:00
// Regenerate the Slot Type
2016-02-15 18:45:57 +00:00
CDMRSlotType slotType ;
2016-01-14 18:45:04 +00:00
slotType . setColorCode ( m_colorCode ) ;
slotType . setDataType ( DT_TERMINATOR_WITH_LC ) ;
slotType . getData ( data + 2U ) ;
2016-09-05 17:03:23 +00:00
// Convert the Data Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-01-14 18:45:04 +00:00
2017-03-12 19:06:47 +00:00
if ( ! m_netTimeout ) {
data [ 0U ] = TAG_EOT ;
data [ 1U ] = 0x00U ;
2016-06-20 09:01:09 +00:00
2017-03-12 19:06:47 +00:00
if ( m_duplex ) {
for ( unsigned int i = 0U ; i < m_hangCount ; i + + )
writeQueueNet ( data ) ;
2017-04-02 12:39:28 +00:00
} else {
2017-03-12 19:06:47 +00:00
for ( unsigned int i = 0U ; i < 3U ; i + + )
writeQueueNet ( data ) ;
}
2016-06-20 09:01:09 +00:00
}
2016-01-21 18:38:45 +00:00
2016-01-14 18:45:04 +00:00
# if defined(DUMP_DMR)
writeFile ( data ) ;
closeFile ( ) ;
# endif
2016-01-19 19:34:49 +00:00
// We've received the voice header and terminator haven't we?
2016-02-25 19:54:18 +00:00
m_netFrames + = 2U ;
LogMessage ( " DMR Slot %u, received network end of voice transmission, %.1f seconds, %u%% packet loss, BER: %.1f%% " , m_slotNo , float ( m_netFrames ) / 16.667F , ( m_netLost * 100U ) / m_netFrames , float ( m_netErrs * 100U ) / float ( m_netBits ) ) ;
2017-11-15 10:47:56 +00:00
m_display - > writeDMRTA ( m_slotNo , NULL , " " ) ;
2016-04-26 18:10:45 +00:00
writeEndNet ( ) ;
2016-01-18 18:36:14 +00:00
} else if ( dataType = = DT_DATA_HEADER ) {
2016-04-26 17:22:47 +00:00
if ( m_netState = = RS_NET_DATA )
return ;
2016-02-22 18:12:24 +00:00
CDMRDataHeader dataHeader ;
bool valid = dataHeader . put ( data + 2U ) ;
if ( ! valid ) {
2016-03-14 21:22:09 +00:00
LogMessage ( " DMR Slot %u, unable to decode the network data header " , m_slotNo ) ;
2016-02-18 21:56:26 +00:00
return ;
}
2016-01-26 18:06:31 +00:00
bool gi = dataHeader . getGI ( ) ;
unsigned int srcId = dataHeader . getSrcId ( ) ;
unsigned int dstId = dataHeader . getDstId ( ) ;
2016-11-01 08:00:13 +00:00
2016-06-17 06:05:37 +00:00
m_netFrames = dataHeader . getBlocks ( ) ;
2016-02-22 18:12:24 +00:00
// Regenerate the data header
2016-03-14 17:33:05 +00:00
dataHeader . get ( data + 2U ) ;
2016-02-22 18:12:24 +00:00
2016-01-18 18:36:14 +00:00
// Regenerate the Slot Type
2016-02-15 18:45:57 +00:00
CDMRSlotType slotType ;
2016-01-18 18:36:14 +00:00
slotType . setColorCode ( m_colorCode ) ;
slotType . setDataType ( DT_DATA_HEADER ) ;
slotType . getData ( data + 2U ) ;
2016-09-05 17:03:23 +00:00
// Convert the Data Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-01-18 18:36:14 +00:00
2016-04-26 17:22:47 +00:00
data [ 0U ] = m_netFrames = = 0U ? TAG_EOT : TAG_DATA ;
2016-01-18 18:36:14 +00:00
data [ 1U ] = 0x00U ;
2018-02-08 20:25:03 +00:00
// Put a small delay into starting transmission
writeQueueNet ( m_idle ) ;
writeQueueNet ( m_idle ) ;
2016-03-11 06:50:06 +00:00
writeQueueNet ( data ) ;
2016-01-18 18:36:14 +00:00
2016-02-25 19:54:18 +00:00
m_netState = RS_NET_DATA ;
2016-01-19 19:34:49 +00:00
2017-10-03 09:03:13 +00:00
setShortLC ( m_slotNo , dstId , gi ? FLCO_GROUP : FLCO_USER_USER , ACTIVITY_DATA ) ;
2016-01-18 18:36:14 +00:00
2016-04-19 18:46:16 +00:00
std : : string src = m_lookup - > find ( srcId ) ;
std : : string dst = m_lookup - > find ( dstId ) ;
2016-04-12 17:26:13 +00:00
2016-04-21 14:21:39 +00:00
m_display - > writeDMR ( m_slotNo , src , gi , dst , " N " ) ;
2016-01-18 18:36:14 +00:00
2016-04-15 13:24:57 +00:00
LogMessage ( " DMR Slot %u, received network data header from %s to %s%s, %u blocks " , m_slotNo , src . c_str ( ) , gi ? " TG " : " " , dst . c_str ( ) , m_netFrames ) ;
2016-04-26 17:22:47 +00:00
2017-03-05 19:33:03 +00:00
if ( m_netFrames = = 0U ) {
LogMessage ( " DMR Slot %u, ended network data transmission " , m_slotNo ) ;
writeEndNet ( ) ;
}
2016-01-14 18:45:04 +00:00
} else if ( dataType = = DT_VOICE_SYNC ) {
2016-02-25 19:54:18 +00:00
if ( m_netState = = RS_NET_IDLE ) {
2016-11-01 08:00:13 +00:00
CDMRLC * lc = new CDMRLC ( dmrData . getFLCO ( ) , dmrData . getSrcId ( ) , dmrData . getDstId ( ) ) ;
unsigned int dstId = lc - > getDstId ( ) ;
unsigned int srcId = lc - > getSrcId ( ) ;
m_netLC = lc ;
2017-01-10 19:27:12 +00:00
// The standby LC data
m_netEmbeddedLC . setLC ( * m_netLC ) ;
m_netEmbeddedData [ 0U ] . setLC ( * m_netLC ) ;
m_netEmbeddedData [ 1U ] . setLC ( * m_netLC ) ;
2018-02-08 20:25:03 +00:00
m_lastFrameValid = false ;
2016-02-25 19:54:18 +00:00
m_netTimeoutTimer . start ( ) ;
2017-03-12 19:06:47 +00:00
m_netTimeout = false ;
2016-01-14 18:45:04 +00:00
2016-06-20 09:01:09 +00:00
if ( m_duplex ) {
m_queue . clear ( ) ;
m_modem - > writeDMRAbort ( m_slotNo ) ;
}
2018-02-08 20:25:03 +00:00
for ( unsigned int i = 0U ; i < m_jitterSlots ; i + + )
writeQueueNet ( m_idle ) ;
2016-05-03 20:18:44 +00:00
// Create a dummy start frame
unsigned char start [ DMR_FRAME_LENGTH_BYTES + 2U ] ;
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( start + 2U , m_duplex ) ;
2016-05-03 20:18:44 +00:00
CDMRFullLC fullLC ;
fullLC . encode ( * m_netLC , start + 2U , DT_VOICE_LC_HEADER ) ;
CDMRSlotType slotType ;
slotType . setColorCode ( m_colorCode ) ;
slotType . setDataType ( DT_VOICE_LC_HEADER ) ;
slotType . getData ( start + 2U ) ;
start [ 0U ] = TAG_DATA ;
start [ 1U ] = 0x00U ;
2017-04-02 12:39:28 +00:00
if ( m_duplex ) {
for ( unsigned int i = 0U ; i < NO_HEADERS_DUPLEX ; i + + )
writeQueueRF ( start ) ;
} else {
for ( unsigned int i = 0U ; i < NO_HEADERS_SIMPLEX ; i + + )
writeQueueRF ( start ) ;
}
2016-01-21 21:08:10 +00:00
2016-01-22 06:43:08 +00:00
# if defined(DUMP_DMR)
openFile ( ) ;
# endif
2016-02-25 19:54:18 +00:00
m_netFrames = 0U ;
m_netLost = 0U ;
m_netBits = 1U ;
m_netErrs = 0U ;
2017-02-12 18:37:00 +00:00
2017-01-10 19:27:12 +00:00
m_netEmbeddedReadN = 0U ;
m_netEmbeddedWriteN = 1U ;
2017-02-12 18:37:00 +00:00
m_netTalkerId = TALKER_ID_NONE ;
2016-01-21 21:08:10 +00:00
2016-02-25 19:54:18 +00:00
m_netState = RS_NET_AUDIO ;
2016-01-21 21:08:10 +00:00
2017-10-03 09:03:13 +00:00
setShortLC ( m_slotNo , dstId , m_netLC - > getFLCO ( ) , ACTIVITY_VOICE ) ;
2016-06-09 18:33:00 +00:00
2016-11-01 08:00:13 +00:00
std : : string src = m_lookup - > find ( srcId ) ;
std : : string dst = m_lookup - > find ( dstId ) ;
2016-04-12 17:26:13 +00:00
2016-04-21 14:21:39 +00:00
m_display - > writeDMR ( m_slotNo , src , m_netLC - > getFLCO ( ) = = FLCO_GROUP , dst , " N " ) ;
2016-01-22 06:43:08 +00:00
2016-04-15 13:24:57 +00:00
LogMessage ( " DMR Slot %u, received network late entry from %s to %s%s " , m_slotNo , src . c_str ( ) , m_netLC - > getFLCO ( ) = = FLCO_GROUP ? " TG " : " " , dst . c_str ( ) ) ;
2016-01-19 19:34:49 +00:00
}
2016-02-25 19:54:18 +00:00
if ( m_netState = = RS_NET_AUDIO ) {
unsigned char fid = m_netLC - > getFID ( ) ;
2016-06-01 08:43:39 +00:00
if ( fid = = FID_ETSI | | fid = = FID_DMRA )
m_netErrs + = m_fec . regenerateDMR ( data + 2U ) ;
2016-02-25 19:54:18 +00:00
m_netBits + = 141U ;
2016-01-25 21:56:57 +00:00
data [ 0U ] = TAG_DATA ;
data [ 1U ] = 0x00U ;
2016-09-05 17:03:23 +00:00
// Convert the Audio Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRAudioSync ( data + 2U , m_duplex ) ;
2016-01-22 06:43:08 +00:00
2018-02-08 20:25:03 +00:00
// Initialise the lost packet data
if ( m_netFrames = = 0U ) {
: : memcpy ( m_lastFrame , data , DMR_FRAME_LENGTH_BYTES + 2U ) ;
m_lastFrameValid = true ;
2018-02-09 17:32:52 +00:00
m_netN = 5U ;
2018-02-08 20:25:03 +00:00
m_netLost = 0U ;
}
2018-02-09 20:30:53 +00:00
if ( insertSilence ( data , dmrData . getN ( ) ) ) {
if ( ! m_netTimeout )
writeQueueNet ( data ) ;
}
2016-01-21 21:08:10 +00:00
2017-01-10 19:27:12 +00:00
m_netEmbeddedReadN = ( m_netEmbeddedReadN + 1U ) % 2U ;
m_netEmbeddedWriteN = ( m_netEmbeddedWriteN + 1U ) % 2U ;
m_netEmbeddedData [ m_netEmbeddedWriteN ] . reset ( ) ;
2018-02-08 20:25:03 +00:00
m_packetTimer . start ( ) ;
m_elapsed . start ( ) ;
2017-11-28 10:09:29 +00:00
2016-02-25 19:54:18 +00:00
m_netFrames + + ;
2016-01-19 19:34:49 +00:00
2018-02-08 20:25:03 +00:00
// Save details in case we need to infill data
m_netN = dmrData . getN ( ) ;
2016-01-14 18:45:04 +00:00
# if defined(DUMP_DMR)
2016-01-21 21:08:10 +00:00
writeFile ( data ) ;
2016-01-14 18:45:04 +00:00
# endif
2016-01-22 06:43:08 +00:00
}
} else if ( dataType = = DT_VOICE ) {
2016-02-25 19:54:18 +00:00
if ( m_netState ! = RS_NET_AUDIO )
2016-01-22 06:43:08 +00:00
return ;
2016-06-16 20:40:05 +00:00
2016-02-25 19:54:18 +00:00
unsigned char fid = m_netLC - > getFID ( ) ;
2016-06-01 08:43:39 +00:00
if ( fid = = FID_ETSI | | fid = = FID_DMRA )
m_netErrs + = m_fec . regenerateDMR ( data + 2U ) ;
2016-02-25 19:54:18 +00:00
m_netBits + = 141U ;
2016-01-25 21:56:57 +00:00
2017-01-10 19:27:12 +00:00
// Get the LCSS from the EMB
2017-01-05 19:15:10 +00:00
CDMREMB emb ;
emb . putData ( data + 2U ) ;
2017-01-10 19:27:12 +00:00
unsigned char lcss = emb . getLCSS ( ) ;
// Dump any interesting Embedded Data
bool ret = m_netEmbeddedData [ m_netEmbeddedWriteN ] . addData ( data + 2U , lcss ) ;
if ( ret ) {
FLCO flco = m_netEmbeddedData [ m_netEmbeddedWriteN ] . getFLCO ( ) ;
unsigned char data [ 9U ] ;
m_netEmbeddedData [ m_netEmbeddedWriteN ] . getRawData ( data ) ;
char text [ 80U ] ;
switch ( flco ) {
case FLCO_GROUP :
case FLCO_USER_USER :
// ::sprintf(text, "DMR Slot %u, Embedded LC", m_slotNo);
// CUtils::dump(1U, text, data, 9U);
break ;
case FLCO_GPS_INFO :
2017-02-27 20:17:55 +00:00
if ( m_dumpTAData ) {
: : sprintf ( text , " DMR Slot %u, Embedded GPS Info " , m_slotNo ) ;
CUtils : : dump ( 2U , text , data , 9U ) ;
2017-11-26 17:56:20 +00:00
logGPSPosition ( data ) ;
2017-02-27 20:17:55 +00:00
}
2017-01-10 19:27:12 +00:00
break ;
case FLCO_TALKER_ALIAS_HEADER :
2017-02-12 18:37:00 +00:00
if ( ! ( m_netTalkerId & TALKER_ID_HEADER ) ) {
2017-11-15 10:47:56 +00:00
if ( ! m_netTalkerId )
: : memset ( m_rfTalkerAlias , ' \0 ' , 32U ) ;
: : memcpy ( m_rfTalkerAlias , data + 2U , 7U ) ;
m_display - > writeDMRTA ( m_slotNo , m_rfTalkerAlias , " N " ) ;
2017-02-27 20:17:55 +00:00
if ( m_dumpTAData ) {
: : sprintf ( text , " DMR Slot %u, Embedded Talker Alias Header " , m_slotNo ) ;
CUtils : : dump ( 2U , text , data , 9U ) ;
}
2017-02-28 08:27:56 +00:00
m_netTalkerId | = TALKER_ID_HEADER ;
2017-02-12 18:37:00 +00:00
}
2017-01-10 19:27:12 +00:00
break ;
case FLCO_TALKER_ALIAS_BLOCK1 :
2017-02-12 18:37:00 +00:00
if ( ! ( m_netTalkerId & TALKER_ID_BLOCK1 ) ) {
2017-11-15 10:47:56 +00:00
if ( ! m_netTalkerId )
: : memset ( m_rfTalkerAlias , ' \0 ' , 32U ) ;
: : memcpy ( m_rfTalkerAlias + 7U , data + 2U , 7U ) ;
m_display - > writeDMRTA ( m_slotNo , m_rfTalkerAlias , " N " ) ;
2017-02-27 20:17:55 +00:00
if ( m_dumpTAData ) {
: : sprintf ( text , " DMR Slot %u, Embedded Talker Alias Block 1 " , m_slotNo ) ;
CUtils : : dump ( 2U , text , data , 9U ) ;
}
2017-02-28 08:27:56 +00:00
m_netTalkerId | = TALKER_ID_BLOCK1 ;
2017-02-12 18:37:00 +00:00
}
2017-01-10 19:27:12 +00:00
break ;
case FLCO_TALKER_ALIAS_BLOCK2 :
2017-02-12 18:37:00 +00:00
if ( ! ( m_netTalkerId & TALKER_ID_BLOCK2 ) ) {
2017-11-15 10:47:56 +00:00
if ( ! m_netTalkerId )
: : memset ( m_rfTalkerAlias , ' \0 ' , 32U ) ;
: : memcpy ( m_rfTalkerAlias + 7U + 7U , data + 2U , 7U ) ;
m_display - > writeDMRTA ( m_slotNo , m_rfTalkerAlias , " N " ) ;
2017-02-27 20:17:55 +00:00
if ( m_dumpTAData ) {
: : sprintf ( text , " DMR Slot %u, Embedded Talker Alias Block 2 " , m_slotNo ) ;
CUtils : : dump ( 2U , text , data , 9U ) ;
}
2017-02-28 08:27:56 +00:00
m_netTalkerId | = TALKER_ID_BLOCK2 ;
2017-02-12 18:37:00 +00:00
}
2017-01-10 19:27:12 +00:00
break ;
case FLCO_TALKER_ALIAS_BLOCK3 :
2017-02-12 18:37:00 +00:00
if ( ! ( m_netTalkerId & TALKER_ID_BLOCK3 ) ) {
2017-11-15 10:47:56 +00:00
if ( ! m_netTalkerId )
: : memset ( m_rfTalkerAlias , ' \0 ' , 32U ) ;
: : memcpy ( m_rfTalkerAlias + 7U + 7U + 7U , data + 2U , 7U ) ;
m_display - > writeDMRTA ( m_slotNo , m_rfTalkerAlias , " N " ) ;
2017-02-27 20:17:55 +00:00
if ( m_dumpTAData ) {
: : sprintf ( text , " DMR Slot %u, Embedded Talker Alias Block 3 " , m_slotNo ) ;
CUtils : : dump ( 2U , text , data , 9U ) ;
}
2017-02-28 08:27:56 +00:00
m_netTalkerId | = TALKER_ID_BLOCK3 ;
2017-02-12 18:37:00 +00:00
}
2017-01-10 19:27:12 +00:00
break ;
default :
: : sprintf ( text , " DMR Slot %u, Unknown Embedded Data " , m_slotNo ) ;
CUtils : : dump ( 1U , text , data , 9U ) ;
break ;
}
}
2017-01-16 12:10:23 +00:00
if ( m_embeddedLCOnly ) {
// Only send the previously received LC
2017-01-10 19:27:12 +00:00
lcss = m_netEmbeddedLC . getData ( data + 2U , dmrData . getN ( ) ) ;
2017-01-16 12:10:23 +00:00
} else {
// Regenerate the previous super blocks Embedded Data or substitude the LC for it
if ( m_netEmbeddedData [ m_netEmbeddedReadN ] . isValid ( ) )
lcss = m_netEmbeddedData [ m_netEmbeddedReadN ] . getData ( data + 2U , dmrData . getN ( ) ) ;
else
lcss = m_netEmbeddedLC . getData ( data + 2U , dmrData . getN ( ) ) ;
}
2017-01-10 19:27:12 +00:00
// Regenerate the EMB
2017-01-05 19:15:10 +00:00
emb . setColorCode ( m_colorCode ) ;
2017-01-10 19:27:12 +00:00
emb . setLCSS ( lcss ) ;
2017-01-05 19:15:10 +00:00
emb . getData ( data + 2U ) ;
2016-01-25 21:56:57 +00:00
data [ 0U ] = TAG_DATA ;
data [ 1U ] = 0x00U ;
2018-02-08 20:25:03 +00:00
// Initialise the lost packet data
if ( m_netFrames = = 0U ) {
: : memcpy ( m_lastFrame , data , DMR_FRAME_LENGTH_BYTES + 2U ) ;
m_lastFrameValid = true ;
2018-02-09 17:32:52 +00:00
m_netN = 5U ;
2018-02-08 20:25:03 +00:00
m_netLost = 0U ;
}
2018-02-09 20:30:53 +00:00
if ( insertSilence ( data , dmrData . getN ( ) ) ) {
if ( ! m_netTimeout )
writeQueueNet ( data ) ;
}
2016-01-21 21:08:10 +00:00
2018-02-08 20:25:03 +00:00
m_packetTimer . start ( ) ;
m_elapsed . start ( ) ;
2017-11-28 10:09:29 +00:00
2016-02-25 19:54:18 +00:00
m_netFrames + + ;
2016-01-21 21:08:10 +00:00
2018-02-08 20:25:03 +00:00
// Save details in case we need to infill data
m_netN = dmrData . getN ( ) ;
2016-01-21 21:08:10 +00:00
# if defined(DUMP_DMR)
2016-01-22 06:43:08 +00:00
writeFile ( data ) ;
2016-01-21 21:08:10 +00:00
# endif
2016-01-26 18:06:31 +00:00
} else if ( dataType = = DT_CSBK ) {
2016-02-22 18:12:24 +00:00
CDMRCSBK csbk ;
bool valid = csbk . put ( data + 2U ) ;
if ( ! valid ) {
2016-03-14 21:22:09 +00:00
LogMessage ( " DMR Slot %u, unable to decode the network CSBK " , m_slotNo ) ;
2016-02-18 21:56:26 +00:00
return ;
}
2016-01-26 18:06:31 +00:00
CSBKO csbko = csbk . getCSBKO ( ) ;
2016-03-14 17:33:05 +00:00
if ( csbko = = CSBKO_BSDWNACT )
2016-01-26 18:06:31 +00:00
return ;
2016-03-14 21:22:09 +00:00
bool gi = csbk . getGI ( ) ;
unsigned int srcId = csbk . getSrcId ( ) ;
unsigned int dstId = csbk . getDstId ( ) ;
2016-11-01 08:00:13 +00:00
2016-03-14 17:33:05 +00:00
// Regenerate the CSBK data
csbk . get ( data + 2U ) ;
2016-02-22 18:12:24 +00:00
2016-03-14 17:33:05 +00:00
// Regenerate the Slot Type
CDMRSlotType slotType ;
slotType . putData ( data + 2U ) ;
slotType . setColorCode ( m_colorCode ) ;
slotType . getData ( data + 2U ) ;
2016-01-26 18:06:31 +00:00
2016-09-05 17:03:23 +00:00
// Convert the Data Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-01-26 18:06:31 +00:00
2016-03-14 17:33:05 +00:00
data [ 0U ] = TAG_DATA ;
data [ 1U ] = 0x00U ;
2016-01-26 18:06:31 +00:00
2016-03-14 17:33:05 +00:00
writeQueueNet ( data ) ;
2016-01-26 18:06:31 +00:00
# if defined(DUMP_DMR)
2016-03-14 17:33:05 +00:00
openFile ( ) ;
writeFile ( data ) ;
closeFile ( ) ;
2016-01-26 18:06:31 +00:00
# endif
2016-04-28 09:32:11 +00:00
std : : string src = m_lookup - > find ( srcId ) ;
std : : string dst = m_lookup - > find ( dstId ) ;
2016-03-14 17:33:05 +00:00
switch ( csbko ) {
case CSBKO_UUVREQ :
2016-04-28 09:32:11 +00:00
LogMessage ( " DMR Slot %u, received network Unit to Unit Voice Service Request CSBK from %s to %s%s " , m_slotNo , src . c_str ( ) , gi ? " TG " : " " , dst . c_str ( ) ) ;
2016-03-14 17:33:05 +00:00
break ;
case CSBKO_UUANSRSP :
2016-04-28 09:32:11 +00:00
LogMessage ( " DMR Slot %u, received network Unit to Unit Voice Service Answer Response CSBK from %s to %s%s " , m_slotNo , src . c_str ( ) , gi ? " TG " : " " , dst . c_str ( ) ) ;
2016-03-14 17:33:05 +00:00
break ;
case CSBKO_NACKRSP :
2016-04-28 09:32:11 +00:00
LogMessage ( " DMR Slot %u, received network Negative Acknowledgment Response CSBK from %s to %s%s " , m_slotNo , src . c_str ( ) , gi ? " TG " : " " , dst . c_str ( ) ) ;
2016-03-14 17:33:05 +00:00
break ;
case CSBKO_PRECCSBK :
2016-12-11 16:01:30 +00:00
LogMessage ( " DMR Slot %u, received network %s Preamble CSBK (%u to follow) from %s to %s%s " , m_slotNo , csbk . getDataContent ( ) ? " Data " : " CSBK " , csbk . getCBF ( ) , src . c_str ( ) , gi ? " TG " : " " , dst . c_str ( ) ) ;
2016-03-14 17:33:05 +00:00
break ;
2016-01-26 18:06:31 +00:00
default :
LogWarning ( " DMR Slot %u, unhandled network CSBK type - 0x%02X " , m_slotNo , csbko ) ;
break ;
}
2017-10-03 09:03:13 +00:00
2017-10-04 20:56:40 +00:00
// If data preamble, signal its existence
if ( csbko = = CSBKO_PRECCSBK & & csbk . getDataContent ( ) ) {
setShortLC ( m_slotNo , dstId , gi ? FLCO_GROUP : FLCO_USER_USER , ACTIVITY_DATA ) ;
m_display - > writeDMR ( m_slotNo , src , gi , dst , " N " ) ;
}
2017-10-03 09:03:13 +00:00
} else if ( dataType = = DT_RATE_12_DATA | | dataType = = DT_RATE_34_DATA | | dataType = = DT_RATE_1_DATA ) {
2018-02-03 14:07:13 +00:00
if ( m_netState ! = RS_NET_DATA | | m_netFrames = = 0U ) {
writeEndNet ( ) ;
2016-01-26 18:06:31 +00:00
return ;
2018-02-03 14:07:13 +00:00
}
2016-01-26 18:06:31 +00:00
2016-04-19 18:46:16 +00:00
// Regenerate the rate 1/2 payload
2016-03-10 17:18:40 +00:00
if ( dataType = = DT_RATE_12_DATA ) {
CBPTC19696 bptc ;
unsigned char payload [ 12U ] ;
bptc . decode ( data + 2U , payload ) ;
bptc . encode ( payload , data + 2U ) ;
2016-07-07 13:05:38 +00:00
} else if ( dataType = = DT_RATE_34_DATA ) {
2016-07-07 19:23:30 +00:00
CDMRTrellis trellis ;
unsigned char payload [ 18U ] ;
2016-07-14 17:58:03 +00:00
bool ret = trellis . decode ( data + 2U , payload ) ;
2017-02-13 08:50:23 +00:00
if ( ret ) {
2016-07-14 17:58:03 +00:00
trellis . encode ( payload , data + 2U ) ;
2017-02-13 08:50:23 +00:00
} else {
LogMessage ( " DMR Slot %u, unfixable network rate 3/4 data " , m_slotNo ) ;
CUtils : : dump ( 1U , " Data " , data + 2U , DMR_FRAME_LENGTH_BYTES ) ;
}
2016-03-10 17:18:40 +00:00
}
2016-01-26 18:06:31 +00:00
// Regenerate the Slot Type
2016-02-15 18:45:57 +00:00
CDMRSlotType slotType ;
2016-01-14 18:45:04 +00:00
slotType . putData ( data + 2U ) ;
slotType . setColorCode ( m_colorCode ) ;
slotType . getData ( data + 2U ) ;
2016-09-05 17:03:23 +00:00
// Convert the Data Sync to be from the BS or MS as needed
2016-09-06 07:06:19 +00:00
CSync : : addDMRDataSync ( data + 2U , m_duplex ) ;
2016-01-14 18:45:04 +00:00
2016-02-25 19:54:18 +00:00
m_netFrames - - ;
2016-01-14 18:45:04 +00:00
2016-02-25 19:54:18 +00:00
data [ 0U ] = m_netFrames = = 0U ? TAG_EOT : TAG_DATA ;
2016-01-26 18:06:31 +00:00
data [ 1U ] = 0x00U ;
2016-01-14 18:45:04 +00:00
# if defined(DUMP_DMR)
writeFile ( data ) ;
# endif
2016-02-25 19:54:18 +00:00
writeQueueNet ( data ) ;
2016-01-26 18:06:31 +00:00
2017-03-05 19:33:03 +00:00
if ( m_netFrames = = 0U ) {
LogMessage ( " DMR Slot %u, ended network data transmission " , m_slotNo ) ;
writeEndNet ( ) ;
}
2016-01-26 18:06:31 +00:00
} else {
// Unhandled data type
LogWarning ( " DMR Slot %u, unhandled network data type - 0x%02X " , m_slotNo , dataType ) ;
2016-01-14 18:45:04 +00:00
}
}
2017-11-26 17:56:20 +00:00
void CDMRSlot : : logGPSPosition ( const unsigned char * data )
2017-11-13 20:48:47 +00:00
{
2017-11-15 10:47:56 +00:00
unsigned int errorI = ( data [ 2U ] & 0x0E ) > > 1U ;
2017-11-13 20:48:47 +00:00
2017-11-28 21:35:25 +00:00
const char * error ;
2017-11-28 13:45:22 +00:00
switch ( errorI ) {
2017-11-15 10:47:56 +00:00
case 0U :
2017-11-28 13:45:22 +00:00
error = " < 2m " ;
2017-11-15 10:47:56 +00:00
break ;
case 1U :
2017-11-28 13:45:22 +00:00
error = " < 20m " ;
2017-11-15 10:47:56 +00:00
break ;
case 2U :
2017-11-28 13:45:22 +00:00
error = " < 200m " ;
2017-11-15 10:47:56 +00:00
break ;
case 3U :
2017-11-28 13:45:22 +00:00
error = " < 2km " ;
2017-11-15 10:47:56 +00:00
break ;
case 4U :
2017-11-28 13:45:22 +00:00
error = " < 20km " ;
2017-11-15 10:47:56 +00:00
break ;
case 5U :
2017-11-28 13:45:22 +00:00
error = " < 200km " ;
2017-11-15 10:47:56 +00:00
break ;
case 6U :
2017-11-28 13:45:22 +00:00
error = " > 200km " ;
2017-11-15 10:47:56 +00:00
break ;
default :
2017-11-28 21:35:25 +00:00
error = " not known " ;
break ;
2017-11-28 13:45:22 +00:00
}
2017-11-13 20:48:47 +00:00
2017-11-26 17:56:20 +00:00
int32_t longitudeI = ( ( data [ 2U ] & 0x01U ) < < 31 ) | ( data [ 3U ] < < 23 ) | ( data [ 4U ] < < 15 ) | ( data [ 5U ] < < 7 ) ;
longitudeI > > = 7 ;
2017-11-15 10:47:56 +00:00
2017-11-26 17:56:20 +00:00
int32_t latitudeI = ( data [ 6U ] < < 24 ) | ( data [ 7U ] < < 16 ) | ( data [ 8U ] < < 8 ) ;
latitudeI > > = 8 ;
2017-11-13 20:48:47 +00:00
2017-11-15 10:47:56 +00:00
float longitude = 360.0F / 33554432.0F ; // 360/2^25 steps
float latitude = 180.0F / 16777216.0F ; // 180/2^24 steps
2017-11-13 20:48:47 +00:00
2017-11-26 17:56:20 +00:00
longitude * = float ( longitudeI ) ;
latitude * = float ( latitudeI ) ;
2017-11-13 20:48:47 +00:00
2017-11-28 13:45:22 +00:00
LogMessage ( " GPS position [%f,%f] (Position error %s) " , latitude , longitude , error ) ;
2017-11-13 20:48:47 +00:00
}
2016-03-14 20:55:15 +00:00
void CDMRSlot : : clock ( )
2016-01-14 18:45:04 +00:00
{
2016-03-14 20:55:15 +00:00
unsigned int ms = m_interval . elapsed ( ) ;
m_interval . start ( ) ;
2016-02-25 19:54:18 +00:00
m_rfTimeoutTimer . clock ( ms ) ;
2017-03-12 19:06:47 +00:00
if ( m_rfTimeoutTimer . isRunning ( ) & & m_rfTimeoutTimer . hasExpired ( ) ) {
if ( ! m_rfTimeout ) {
LogMessage ( " DMR Slot %u, RF user has timed out " , m_slotNo ) ;
m_rfTimeout = true ;
}
}
2016-02-25 19:54:18 +00:00
m_netTimeoutTimer . clock ( ms ) ;
2017-03-12 19:06:47 +00:00
if ( m_netTimeoutTimer . isRunning ( ) & & m_netTimeoutTimer . hasExpired ( ) ) {
if ( ! m_netTimeout ) {
LogMessage ( " DMR Slot %u, network user has timed out " , m_slotNo ) ;
m_netTimeout = true ;
}
}
2016-01-14 18:45:04 +00:00
2016-02-25 19:54:18 +00:00
if ( m_netState = = RS_NET_AUDIO | | m_netState = = RS_NET_DATA ) {
2016-01-14 18:45:04 +00:00
m_networkWatchdog . clock ( ms ) ;
if ( m_networkWatchdog . hasExpired ( ) ) {
2016-02-25 19:54:18 +00:00
if ( m_netState = = RS_NET_AUDIO ) {
2016-01-21 18:38:45 +00:00
// We've received the voice header haven't we?
2016-02-25 19:54:18 +00:00
m_netFrames + = 1U ;
LogMessage ( " DMR Slot %u, network watchdog has expired, %.1f seconds, %u%% packet loss, BER: %.1f%% " , m_slotNo , float ( m_netFrames ) / 16.667F , ( m_netLost * 100U ) / m_netFrames , float ( m_netErrs * 100U ) / float ( m_netBits ) ) ;
writeEndNet ( true ) ;
2016-01-21 21:08:10 +00:00
# if defined(DUMP_DMR)
closeFile ( ) ;
# endif
2016-01-22 06:43:08 +00:00
} else {
2016-01-20 07:12:28 +00:00
LogMessage ( " DMR Slot %u, network watchdog has expired " , m_slotNo ) ;
2016-02-25 19:54:18 +00:00
writeEndNet ( ) ;
2016-01-14 18:45:04 +00:00
# if defined(DUMP_DMR)
2016-01-21 21:08:10 +00:00
closeFile ( ) ;
2016-01-14 18:45:04 +00:00
# endif
2016-01-21 21:08:10 +00:00
}
2016-01-14 18:45:04 +00:00
}
}
2018-02-08 20:25:03 +00:00
if ( m_netState = = RS_NET_AUDIO ) {
m_packetTimer . clock ( ms ) ;
if ( m_packetTimer . isRunning ( ) & & m_packetTimer . hasExpired ( ) ) {
unsigned int elapsed = m_elapsed . elapsed ( ) ;
if ( elapsed > = m_jitterTime ) {
LogDebug ( " DMR Slot %u, lost audio for %ums filling in " , m_slotNo , elapsed ) ;
insertSilence ( m_jitterSlots ) ;
m_elapsed . start ( ) ;
}
m_packetTimer . start ( ) ;
}
}
2016-01-14 18:45:04 +00:00
}
2016-02-25 19:54:18 +00:00
void CDMRSlot : : writeQueueRF ( const unsigned char * data )
2016-01-14 18:45:04 +00:00
{
2016-03-07 20:21:55 +00:00
assert ( data ! = NULL ) ;
2016-02-25 19:54:18 +00:00
if ( m_netState ! = RS_NET_IDLE )
return ;
2016-01-14 18:45:04 +00:00
unsigned char len = DMR_FRAME_LENGTH_BYTES + 2U ;
2016-03-07 18:08:50 +00:00
unsigned int space = m_queue . freeSpace ( ) ;
if ( space < ( len + 1U ) ) {
LogError ( " DMR Slot %u, overflow in the DMR slot RF queue " , m_slotNo ) ;
return ;
}
m_queue . addData ( & len , 1U ) ;
2017-03-12 19:06:47 +00:00
m_queue . addData ( data , len ) ;
2016-01-14 18:45:04 +00:00
}
2016-03-23 17:30:06 +00:00
void CDMRSlot : : writeNetworkRF ( const unsigned char * data , unsigned char dataType , FLCO flco , unsigned int srcId , unsigned int dstId , unsigned char errors )
2016-01-14 18:45:04 +00:00
{
2016-01-25 21:56:57 +00:00
assert ( data ! = NULL ) ;
2016-01-14 18:45:04 +00:00
2016-02-25 19:54:18 +00:00
if ( m_netState ! = RS_NET_IDLE )
return ;
2016-01-14 18:45:04 +00:00
if ( m_network = = NULL )
return ;
CDMRData dmrData ;
dmrData . setSlotNo ( m_slotNo ) ;
dmrData . setDataType ( dataType ) ;
2016-01-25 21:56:57 +00:00
dmrData . setSrcId ( srcId ) ;
dmrData . setDstId ( dstId ) ;
dmrData . setFLCO ( flco ) ;
2016-02-28 17:40:15 +00:00
dmrData . setN ( m_rfN ) ;
dmrData . setSeqNo ( m_rfSeqNo ) ;
2016-03-23 17:30:06 +00:00
dmrData . setBER ( errors ) ;
2016-08-08 20:26:18 +00:00
dmrData . setRSSI ( m_rssi ) ;
2016-01-14 18:45:04 +00:00
2016-02-28 17:40:15 +00:00
m_rfSeqNo + + ;
2016-01-14 18:45:04 +00:00
dmrData . setData ( data + 2U ) ;
m_network - > write ( dmrData ) ;
}
2016-03-23 17:30:06 +00:00
void CDMRSlot : : writeNetworkRF ( const unsigned char * data , unsigned char dataType , unsigned char errors )
2016-01-25 21:56:57 +00:00
{
assert ( data ! = NULL ) ;
2016-02-25 19:54:18 +00:00
assert ( m_rfLC ! = NULL ) ;
2016-03-23 17:30:06 +00:00
writeNetworkRF ( data , dataType , m_rfLC - > getFLCO ( ) , m_rfLC - > getSrcId ( ) , m_rfLC - > getDstId ( ) , errors ) ;
2016-02-25 19:54:18 +00:00
}
2016-01-25 21:56:57 +00:00
2016-02-25 19:54:18 +00:00
void CDMRSlot : : writeQueueNet ( const unsigned char * data )
{
2016-03-07 20:21:55 +00:00
assert ( data ! = NULL ) ;
2016-02-25 19:54:18 +00:00
unsigned char len = DMR_FRAME_LENGTH_BYTES + 2U ;
2016-03-07 18:08:50 +00:00
unsigned int space = m_queue . freeSpace ( ) ;
if ( space < ( len + 1U ) ) {
LogError ( " DMR Slot %u, overflow in the DMR slot RF queue " , m_slotNo ) ;
return ;
}
m_queue . addData ( & len , 1U ) ;
2017-03-12 19:06:47 +00:00
m_queue . addData ( data , len ) ;
2016-01-25 21:56:57 +00:00
}
2018-02-08 20:25:03 +00:00
void CDMRSlot : : init ( unsigned int colorCode , bool embeddedLCOnly , bool dumpTAData , unsigned int callHang , CModem * modem , CDMRNetwork * network , CDisplay * display , bool duplex , CDMRLookup * lookup , CRSSIInterpolator * rssiMapper , unsigned int jitter )
2016-01-14 18:45:04 +00:00
{
assert ( modem ! = NULL ) ;
assert ( display ! = NULL ) ;
2016-04-12 17:26:13 +00:00
assert ( lookup ! = NULL ) ;
2016-12-21 19:58:46 +00:00
assert ( rssiMapper ! = NULL ) ;
2016-01-14 18:45:04 +00:00
2017-01-16 12:10:23 +00:00
m_colorCode = colorCode ;
m_embeddedLCOnly = embeddedLCOnly ;
2017-02-27 20:17:55 +00:00
m_dumpTAData = dumpTAData ;
2017-01-16 12:10:23 +00:00
m_modem = modem ;
m_network = network ;
m_display = display ;
m_duplex = duplex ;
m_lookup = lookup ;
m_hangCount = callHang * 17U ;
2016-08-08 20:26:18 +00:00
2017-01-16 12:10:23 +00:00
m_rssiMapper = rssiMapper ;
2016-01-14 18:45:04 +00:00
2018-02-08 20:25:03 +00:00
m_jitterTime = jitter ;
2018-02-09 17:49:18 +00:00
float jitter_tmp = float ( jitter ) / 360.0F ;
m_jitterSlots = ( unsigned int ) ( std : : ceil ( jitter_tmp ) * 6.0F ) ;
2018-02-08 20:25:03 +00:00
2016-09-06 18:42:15 +00:00
m_idle = new unsigned char [ DMR_FRAME_LENGTH_BYTES + 2U ] ;
2016-01-25 21:56:57 +00:00
: : memcpy ( m_idle , DMR_IDLE_DATA , DMR_FRAME_LENGTH_BYTES + 2U ) ;
2016-01-21 18:38:45 +00:00
// Generate the Slot Type for the Idle frame
2016-02-15 18:45:57 +00:00
CDMRSlotType slotType ;
2016-01-14 18:45:04 +00:00
slotType . setColorCode ( colorCode ) ;
slotType . setDataType ( DT_IDLE ) ;
slotType . getData ( m_idle + 2U ) ;
2016-04-04 18:03:38 +00:00
}
2016-06-07 14:34:16 +00:00
2017-10-04 10:20:37 +00:00
void CDMRSlot : : setShortLC ( unsigned int slotNo , unsigned int id , FLCO flco , ACTIVITY_TYPE type )
2016-01-14 18:45:04 +00:00
{
assert ( m_modem ! = NULL ) ;
switch ( slotNo ) {
case 1U :
2017-10-03 09:03:13 +00:00
m_id1 = 0U ;
m_flco1 = flco ;
m_activity1 = type ;
2016-01-14 18:45:04 +00:00
if ( id ! = 0U ) {
unsigned char buffer [ 3U ] ;
buffer [ 0U ] = ( id < < 16 ) & 0xFFU ;
buffer [ 1U ] = ( id < < 8 ) & 0xFFU ;
buffer [ 2U ] = ( id < < 0 ) & 0xFFU ;
m_id1 = CCRC : : crc8 ( buffer , 3U ) ;
}
break ;
case 2U :
2017-10-03 09:03:13 +00:00
m_id2 = 0U ;
m_flco2 = flco ;
m_activity2 = type ;
2016-01-14 18:45:04 +00:00
if ( id ! = 0U ) {
unsigned char buffer [ 3U ] ;
buffer [ 0U ] = ( id < < 16 ) & 0xFFU ;
buffer [ 1U ] = ( id < < 8 ) & 0xFFU ;
buffer [ 2U ] = ( id < < 0 ) & 0xFFU ;
m_id2 = CCRC : : crc8 ( buffer , 3U ) ;
}
break ;
default :
LogError ( " Invalid slot number passed to setShortLC - %u " , slotNo ) ;
return ;
}
2016-06-20 17:33:04 +00:00
// If we have no activity to report, let the modem send the null Short LC when it's ready
if ( m_id1 = = 0U & & m_id2 = = 0U )
return ;
2016-01-14 18:45:04 +00:00
unsigned char lc [ 5U ] ;
lc [ 0U ] = 0x01U ;
lc [ 1U ] = 0x00U ;
lc [ 2U ] = 0x00U ;
lc [ 3U ] = 0x00U ;
if ( m_id1 ! = 0U ) {
2017-10-04 10:20:37 +00:00
lc [ 2U ] = m_id1 ;
2017-10-04 20:56:40 +00:00
if ( m_activity1 = = ACTIVITY_VOICE & & m_flco1 = = FLCO_GROUP )
lc [ 1U ] | = 0x08U ;
else if ( m_activity1 = = ACTIVITY_VOICE & & m_flco1 = = FLCO_USER_USER )
lc [ 1U ] | = 0x09U ;
else if ( m_activity1 = = ACTIVITY_DATA & & m_flco1 = = FLCO_GROUP )
lc [ 1U ] | = 0x0BU ;
else if ( m_activity1 = = ACTIVITY_DATA & & m_flco1 = = FLCO_USER_USER )
lc [ 1U ] | = 0x0AU ;
else if ( m_activity1 = = ACTIVITY_CSBK & & m_flco1 = = FLCO_GROUP )
lc [ 1U ] | = 0x02U ;
else if ( m_activity1 = = ACTIVITY_CSBK & & m_flco1 = = FLCO_USER_USER )
lc [ 1U ] | = 0x03U ;
else if ( m_activity1 = = ACTIVITY_EMERG & & m_flco1 = = FLCO_GROUP )
lc [ 1U ] | = 0x0CU ;
else if ( m_activity1 = = ACTIVITY_EMERG & & m_flco1 = = FLCO_USER_USER )
lc [ 1U ] | = 0x0DU ;
}
if ( m_id2 ! = 0U ) {
lc [ 3U ] = m_id2 ;
if ( m_activity2 = = ACTIVITY_VOICE & & m_flco2 = = FLCO_GROUP )
lc [ 1U ] | = 0x80U ;
else if ( m_activity2 = = ACTIVITY_VOICE & & m_flco2 = = FLCO_USER_USER )
lc [ 1U ] | = 0x90U ;
else if ( m_activity2 = = ACTIVITY_DATA & & m_flco2 = = FLCO_GROUP )
lc [ 1U ] | = 0xB0U ;
else if ( m_activity2 = = ACTIVITY_DATA & & m_flco2 = = FLCO_USER_USER )
lc [ 1U ] | = 0xA0U ;
else if ( m_activity2 = = ACTIVITY_CSBK & & m_flco2 = = FLCO_GROUP )
lc [ 1U ] | = 0x20U ;
else if ( m_activity2 = = ACTIVITY_CSBK & & m_flco2 = = FLCO_USER_USER )
lc [ 1U ] | = 0x30U ;
else if ( m_activity2 = = ACTIVITY_EMERG & & m_flco2 = = FLCO_GROUP )
lc [ 1U ] | = 0xC0U ;
else if ( m_activity2 = = ACTIVITY_EMERG & & m_flco2 = = FLCO_USER_USER )
lc [ 1U ] | = 0xD0U ;
}
lc [ 4U ] = CCRC : : crc8 ( lc , 4U ) ;
2016-01-14 18:45:04 +00:00
unsigned char sLC [ 9U ] ;
2016-02-15 18:45:57 +00:00
CDMRShortLC shortLC ;
2016-01-14 18:45:04 +00:00
shortLC . encode ( lc , sLC ) ;
m_modem - > writeDMRShortLC ( sLC ) ;
}
bool CDMRSlot : : openFile ( )
{
if ( m_fp ! = NULL )
return true ;
time_t t ;
: : time ( & t ) ;
struct tm * tm = : : localtime ( & t ) ;
char name [ 100U ] ;
: : sprintf ( name , " DMR_%u_%04d%02d%02d_%02d%02d%02d.ambe " , m_slotNo , tm - > tm_year + 1900 , tm - > tm_mon + 1 , tm - > tm_mday , tm - > tm_hour , tm - > tm_min , tm - > tm_sec ) ;
m_fp = : : fopen ( name , " wb " ) ;
if ( m_fp = = NULL )
return false ;
: : fwrite ( " DMR " , 1U , 3U , m_fp ) ;
return true ;
}
bool CDMRSlot : : writeFile ( const unsigned char * data )
{
if ( m_fp = = NULL )
return false ;
: : fwrite ( data , 1U , DMR_FRAME_LENGTH_BYTES + 2U , m_fp ) ;
return true ;
}
void CDMRSlot : : closeFile ( )
{
if ( m_fp ! = NULL ) {
: : fclose ( m_fp ) ;
m_fp = NULL ;
}
}
2016-01-19 19:34:49 +00:00
2018-02-08 20:25:03 +00:00
bool CDMRSlot : : insertSilence ( const unsigned char * data , unsigned char seqNo )
2017-11-28 10:09:29 +00:00
{
2018-02-08 20:25:03 +00:00
assert ( data ! = NULL ) ;
2018-02-09 20:30:53 +00:00
// Do not send duplicate
if ( seqNo = = m_netN )
return false ;
2018-02-08 20:25:03 +00:00
// Check to see if we have any spaces to fill?
2018-02-09 17:32:52 +00:00
unsigned char seq = ( m_netN + 1U ) % 6U ;
2018-02-08 20:25:03 +00:00
if ( seq = = seqNo ) {
// Just copy the data, nothing else to do here
: : memcpy ( m_lastFrame , data , DMR_FRAME_LENGTH_BYTES + 2U ) ;
m_lastFrameValid = true ;
return true ;
2017-11-28 10:09:29 +00:00
}
2016-01-19 19:34:49 +00:00
2018-02-09 17:32:52 +00:00
unsigned int count = ( seqNo - seq + 6U ) % 6U ;
2018-02-08 20:25:03 +00:00
insertSilence ( count ) ;
: : memcpy ( m_lastFrame , data , DMR_FRAME_LENGTH_BYTES + 2U ) ;
m_lastFrameValid = true ;
return true ;
}
void CDMRSlot : : insertSilence ( unsigned int count )
{
unsigned char data [ DMR_FRAME_LENGTH_BYTES + 2U ] ;
2017-11-28 10:09:29 +00:00
2018-02-08 20:25:03 +00:00
if ( m_lastFrameValid ) {
: : memcpy ( data , m_lastFrame , 2U ) ; // The control data
: : memcpy ( data + 2U , m_lastFrame + 24U + 2U , 9U ) ; // Copy the last audio block to the first
: : memcpy ( data + 24U + 2U , data + 2U , 9U ) ; // Copy the last audio block to the last
: : memcpy ( data + 9U + 2U , data + 2U , 5U ) ; // Copy the last audio block to the middle (1/2)
: : memcpy ( data + 19U + 2U , data + 4U + 2U , 5U ) ; // Copy the last audio block to the middle (2/2)
2018-01-10 19:05:59 +00:00
} else {
2018-02-08 20:25:03 +00:00
// Not sure what to do if this isn't AMBE audio
: : memcpy ( data , DMR_SILENCE_DATA , DMR_FRAME_LENGTH_BYTES + 2U ) ;
}
2017-11-28 10:09:29 +00:00
2018-02-08 20:25:03 +00:00
unsigned char n = ( m_netN + 1U ) % 6U ;
unsigned char fid = m_netLC - > getFID ( ) ;
CDMREMB emb ;
emb . setColorCode ( m_colorCode ) ;
2017-11-28 10:09:29 +00:00
2018-02-08 20:25:03 +00:00
for ( unsigned int i = 0U ; i < count ; i + + ) {
// Only use our silence frame if its AMBE audio data
if ( fid = = FID_ETSI | | fid = = FID_DMRA ) {
if ( i > 0U ) {
: : memcpy ( data , DMR_SILENCE_DATA , DMR_FRAME_LENGTH_BYTES + 2U ) ;
m_lastFrameValid = false ;
}
}
if ( n = = 0U ) {
CSync : : addDMRAudioSync ( data + 2U , m_duplex ) ;
} else {
2018-02-09 20:43:26 +00:00
unsigned char lcss = m_netEmbeddedLC . getData ( data + 2U , n ) ;
emb . setLCSS ( lcss ) ;
2018-02-08 20:25:03 +00:00
emb . getData ( data + 2U ) ;
}
writeQueueNet ( data ) ;
m_netN = n ;
m_netFrames + + ;
m_netLost + + ;
2017-11-28 10:09:29 +00:00
2018-02-08 20:25:03 +00:00
n = ( n + 1U ) % 6U ;
2016-01-19 19:34:49 +00:00
}
}