File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 using System ;
55 using System . ComponentModel ;
66 using System . Windows . Forms ;
7+ using System . Linq ;
78
89 public partial class PocsagControl : UserControl
910 {
@@ -52,6 +53,12 @@ private void MessageReceived(Pocsag.Message message)
5253 new Action < Pocsag . Message > (
5354 ( message ) =>
5455 {
56+ // skip duplicate messages
57+ if ( this . bindingList . Any ( x => x . Hash == message . Hash ) )
58+ {
59+ return ;
60+ }
61+
5562 int firstDisplayed = this . dataGridView1 . FirstDisplayedScrollingRowIndex ;
5663 int displayed = this . dataGridView1 . DisplayedRowCount ( true ) ;
5764 int lastVisible = ( firstDisplayed + displayed ) - 1 ;
Original file line number Diff line number Diff line change 11namespace Pocsag
22{
33 using System ;
4- using System . Linq ;
5- using System . Collections . Generic ;
64 using System . Collections ;
7- using System . Text ;
5+ using System . Collections . Generic ;
6+ using System . Linq ;
87
98 public class Message
109 {
@@ -36,6 +35,8 @@ public class Message
3635
3736 public bool IsValid => ! this . HasBchError && ! this . HasParityError ;
3837
38+ public string Hash { get ; private set ; }
39+
3940 public Message ( int baud )
4041 {
4142 try
@@ -215,6 +216,26 @@ public void ProcessPayload()
215216 }
216217
217218 this . Payload = result ;
219+
220+ var textToHash = this . Payload ;
221+
222+ // skip first 9 characters, typically contains time / date + another number which will mess up duplicate detection
223+
224+ if ( textToHash . Length > 9 )
225+ {
226+ textToHash = textToHash . Substring ( 8 ) ;
227+ }
228+
229+ var bytesToHash = System . Text . Encoding . ASCII . GetBytes ( textToHash ) ;
230+
231+ var sha256 = new System . Security . Cryptography . SHA256Managed ( ) ;
232+
233+ var hashBytes = sha256 . ComputeHash ( bytesToHash ) ;
234+
235+ sha256 . Dispose ( ) ;
236+ sha256 = null ;
237+
238+ this . Hash = BitConverter . ToString ( hashBytes ) . Replace ( "-" , "" ) ;
218239 }
219240 catch ( Exception exception )
220241 {
You can’t perform that action at this time.
0 commit comments