Skip to content

Commit

Permalink
make main fields private
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Beegan committed Apr 11, 2024
1 parent 7fb1fc1 commit 6ea2d22
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 48 deletions.
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,35 @@ A simple dart library that transforms the reverse beacon telnet CW and DIGI serv
import 'dart:io';
import 'package:reverse_beacon/reverse_beacon.dart';
import 'package:reverse_beacon/src/band.dart';
import 'package:reverse_beacon/src/cw_spot.dart';
import 'package:reverse_beacon/src/exceptions.dart';
import 'package:reverse_beacon/src/mode.dart';
void main() async{
void main() async {
var rb = ReverseBeacon();
try{
try {
await rb.connect(callsign: 'n1bri');
}
on TelnetCommunicationException catch(_){
} on TelnetCommunicationException catch (_) {
print('Telnet Communication Exception');
exit(-1);
}
on InvalidCallsignException catch(_){
} on InvalidCallsignException catch (_) {
print('Invalid callsign');
exit(-1);
}
catch(ex){
} catch (ex) {
print('unknown issue');
exit(-1);
}
rb.controller.stream.listen((spot) {
int spotCount = 0;
rb.listen((spot) {
//filter
if(spot.band == Band.meters20 && spot.mode == Mode.cw){
if ((spot as CWSpot).wpm == 15){
if (spot.band == Band.meters20 && spot.mode == Mode.cw) {
if ((spot as CWSpot).wpm >= 15) {
print(spot);
spotCount++;
}
}
if (spotCount == 5) {
rb.close();
}
});
}
```
28 changes: 13 additions & 15 deletions example/reverse_beacon_example.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
import 'dart:io';

import 'package:reverse_beacon/reverse_beacon.dart';
import 'package:reverse_beacon/src/band.dart';
import 'package:reverse_beacon/src/cw_spot.dart';
import 'package:reverse_beacon/src/exceptions.dart';
import 'package:reverse_beacon/src/mode.dart';

void main() async{
void main() async {
var rb = ReverseBeacon();
try{
try {
await rb.connect(callsign: 'n1bri');
}
on TelnetCommunicationException catch(_){
} on TelnetCommunicationException catch (_) {
print('Telnet Communication Exception');
exit(-1);
}
on InvalidCallsignException catch(_){
} on InvalidCallsignException catch (_) {
print('Invalid callsign');
exit(-1);
}
catch(ex){
} catch (ex) {
print('unknown issue');
exit(-1);
}
rb.controller.stream.listen((spot) {
int spotCount = 0;
rb.listen((spot) {
//filter
if(spot.band == Band.meters20 && spot.mode == Mode.cw){
if ((spot as CWSpot).wpm == 15){
if (spot.band == Band.meters20 && spot.mode == Mode.cw) {
if ((spot as CWSpot).wpm >= 15) {
print(spot);
spotCount++;
}
}
if (spotCount == 5) {
rb.close();
}
});
}
11 changes: 6 additions & 5 deletions lib/reverse_beacon.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/// Support for doing something awesome.
///
/// More dartdocs go here.

library;

export 'src/reverse_beacon_base.dart';

// TODO: Export any libraries intended for clients of this package.
export 'src/cw_spot.dart';
export 'package:reverse_beacon/reverse_beacon.dart';
export 'package:reverse_beacon/src/band.dart';
export 'package:reverse_beacon/src/exceptions.dart';
export 'package:reverse_beacon/src/mode.dart';
33 changes: 22 additions & 11 deletions lib/src/reverse_beacon_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ const int digiPort = 7001;
const int timeout = 25;

class ReverseBeacon {
Socket? cwSocket;
Socket? digiSocket;
StreamController<Spot> controller = StreamController.broadcast();
Socket? _cwSocket;
Socket? _digiSocket;
final StreamController<Spot> _controller = StreamController.broadcast();

Future<void> connect({required callsign}) async {
if (!isValidCallsign(callsign)) {
throw InvalidCallsignException();
}
cwSocket = await Socket.connect(host, cwPort,
_cwSocket = await Socket.connect(host, cwPort,
timeout: const Duration(seconds: timeout));
digiSocket = await Socket.connect(host, digiPort,
_digiSocket = await Socket.connect(host, digiPort,
timeout: const Duration(seconds: timeout));

cwSocket?.listen(onError: (error) => throw TelnetCommunicationException(),
_cwSocket?.listen(onError: (error) => throw TelnetCommunicationException(),
(event) {
var spots = utf8
.decode(event)
Expand All @@ -37,16 +37,16 @@ class ReverseBeacon {
.toList();

if (spots[0] == "Please enter your call: ") {
cwSocket?.add(utf8.encode('$callsign\r\n'));
_cwSocket?.add(utf8.encode('$callsign\r\n'));
} else {
spots = spots.where((e) => e.startsWith('DX')).toList();
for (int i = 0; i < spots.length; i++) {
controller.add(CWSpot.fromTelnetText(spots[i]));
_controller.add(CWSpot.fromTelnetText(spots[i]));
}
}
});

digiSocket?.listen(onError: (error) => throw TelnetCommunicationException(),
_digiSocket?.listen(onError: (error) => throw TelnetCommunicationException(),
(event) {
var spots = utf8
.decode(event)
Expand All @@ -55,13 +55,24 @@ class ReverseBeacon {
.toList();

if (spots[0] == "Please enter your call: ") {
digiSocket?.add(utf8.encode('$callsign\r\n'));
_digiSocket?.add(utf8.encode('$callsign\r\n'));
} else {
spots = spots.where((e) => e.startsWith('DX')).toList();
for (int i = 0; i < spots.length; i++) {
controller.add(DigiSpot.fromTelnetText(spots[i]));
_controller.add(DigiSpot.fromTelnetText(spots[i]));
}
}
});
}

void listen(Function(Spot spot) onListen){
_controller.stream.listen(onListen);
}

void close() async{
await _cwSocket?.close();
await _digiSocket?.close();
_controller.close();
}

}
5 changes: 3 additions & 2 deletions test/reverse_beacon_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:reverse_beacon/reverse_beacon.dart';
import 'package:reverse_beacon/src/exceptions.dart';
import 'package:reverse_beacon/src/spot.dart';
import 'package:test/test.dart';

Expand All @@ -12,6 +11,8 @@ void main(){
test('valid call should emit spots', () async{
var tRb = ReverseBeacon();
await tRb.connect(callsign: 'n1bri');
await expectLater(tRb.controller?.stream, emits(TypeMatcher<Spot>()));
tRb.listen((spot) {
expect(spot, emits(TypeMatcher<Spot>()));
});
});
}

0 comments on commit 6ea2d22

Please sign in to comment.