-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1914 corrections to assembled talker alias for logging.
- Loading branch information
Dennis Sheirer
committed
May 11, 2024
1 parent
9e64996
commit c0c8368
Showing
7 changed files
with
286 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
...module/decode/p25/phase2/message/mac/structure/motorola/MotorolaTalkerAliasAssembler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* ***************************************************************************** | ||
* Copyright (C) 2014-2024 Dennis Sheirer | ||
* | ||
* 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 3 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, see <http://www.gnu.org/licenses/> | ||
* **************************************************************************** | ||
*/ | ||
|
||
package io.github.dsheirer.module.decode.p25.phase2.message.mac.structure.motorola; | ||
|
||
import io.github.dsheirer.bits.CorrectedBinaryMessage; | ||
import io.github.dsheirer.module.decode.p25.phase1.message.lc.motorola.LCMotorolaTalkerAliasComplete; | ||
import io.github.dsheirer.module.decode.p25.phase2.message.mac.structure.MacStructure; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Reassembles a P25 Motorola talker alias from a Header and Data Blocks. | ||
* | ||
* This is used for traffic channels and monitors: | ||
* - Phase 2: mac messaging | ||
*/ | ||
public class MotorolaTalkerAliasAssembler | ||
{ | ||
private static final int DATA_BLOCK_FRAGMENT_LENGTH = 44; | ||
private MotorolaTalkerAliasHeader mHeader; | ||
private Map<Integer, MotorolaTalkerAliasDataBlock> mDataBlocks = new HashMap<>(); | ||
private int mSequence = -1; | ||
private long mMostRecentTimestamp; | ||
|
||
/** | ||
* Constructs an instance | ||
*/ | ||
public MotorolaTalkerAliasAssembler() | ||
{ | ||
} | ||
|
||
/** | ||
* Link control word to process. | ||
* @param mac to add | ||
* @return true if we can (now) assemble a complete talker alias from the header and data blocks. | ||
*/ | ||
public boolean add(MacStructure mac, long timestamp) | ||
{ | ||
if(mac instanceof MotorolaTalkerAliasHeader header) | ||
{ | ||
mMostRecentTimestamp = timestamp; | ||
|
||
if(mSequence != header.getSequence()) | ||
{ | ||
mDataBlocks.clear(); | ||
mSequence = header.getSequence(); | ||
} | ||
|
||
mHeader = header; | ||
} | ||
else if(mac instanceof MotorolaTalkerAliasDataBlock block) | ||
{ | ||
mMostRecentTimestamp = timestamp; | ||
|
||
if(block.getSequence() != mSequence) | ||
{ | ||
mHeader = null; | ||
mDataBlocks.clear(); | ||
mSequence = block.getSequence(); | ||
} | ||
|
||
mDataBlocks.put(block.getBlockNumber(), block); | ||
} | ||
else | ||
{ | ||
return false; //For all lcw's that are not headers or data blocks | ||
} | ||
|
||
return isComplete(); | ||
} | ||
|
||
/** | ||
* Indicates if the assembler has a header and the correct number of data blocks to reassemble an alias. | ||
*/ | ||
private boolean isComplete() | ||
{ | ||
if(mHeader != null) | ||
{ | ||
int dataBlockCount = mHeader.getBlockCount(); | ||
|
||
for(int x = 1; x <= dataBlockCount; x++) | ||
{ | ||
if(!mDataBlocks.containsKey(x)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Assembles the talker alias once the header and data blocks have been collected. | ||
* | ||
* Note: do not invoke unless the add() methods indicate that the assembler is complete. | ||
* @return assembled talker alias | ||
* @throws IllegalStateException if the assembler can't assemble the alias. | ||
*/ | ||
public LCMotorolaTalkerAliasComplete assemble() throws IllegalStateException | ||
{ | ||
if(!isComplete()) | ||
{ | ||
throw new IllegalStateException("Can't assemble talker alias - missing header or data block(s)"); | ||
} | ||
|
||
int dataBlockCount = mHeader.getBlockCount(); | ||
CorrectedBinaryMessage reassembled = new CorrectedBinaryMessage(dataBlockCount * DATA_BLOCK_FRAGMENT_LENGTH); | ||
|
||
int offset = 0; | ||
|
||
for(int x = 1; x <= dataBlockCount; x++) | ||
{ | ||
MotorolaTalkerAliasDataBlock block = mDataBlocks.get(x); | ||
reassembled.load(offset, block.getFragment()); | ||
offset += DATA_BLOCK_FRAGMENT_LENGTH; | ||
} | ||
|
||
LCMotorolaTalkerAliasComplete complete = new LCMotorolaTalkerAliasComplete(reassembled, mHeader.getTalkgroup(), | ||
dataBlockCount, mHeader.getSequence(), mMostRecentTimestamp); | ||
|
||
mHeader = null; | ||
mDataBlocks.clear(); | ||
|
||
System.out.println(complete); | ||
return complete; | ||
} | ||
} |
Oops, something went wrong.