mniak / bc108

@@ -1,3 +1,4 @@
Loading
1 +
import 'package:bc108/bc108.dart';
1 2
import 'package:bc108/src/layer2/operator.dart';
2 3
3 4
import 'mapper.dart';
@@ -16,16 +17,9 @@
Loading
16 17
    return RequestHandler(oper, mapper, mapper);
17 18
  }
18 19
19 -
  Future<PinpadResult<TResponse>> handleNonBlocking(TRequest request) async {
20 +
  Future<PinpadResult<TResponse>> handle(TRequest request) async {
20 21
    final command = _requestMapper.mapRequest(request);
21 -
    final result = await _operator.sendNonBlocking(command);
22 -
    final response = _responseMapper.mapResponse(result);
23 -
    return PinpadResult(result.status, response);
24 -
  }
25 -
26 -
  Future<PinpadResult<TResponse>> handleBlocking(TRequest request) async {
27 -
    final command = _requestMapper.mapRequest(request);
28 -
    final result = await _operator.sendBlocking(command);
22 +
    final result = await _operator.send(command);
29 23
    final response = _responseMapper.mapResponse(result);
30 24
    return PinpadResult(result.status, response);
31 25
  }

@@ -36,7 +36,7 @@
Loading
36 36
    }
37 37
  }
38 38
39 -
  Future<FrameResult> receiveData() async {
39 +
  Future<FrameResult> receive() async {
40 40
    try {
41 41
      final event = await _nextEvent(_responseTimeout);
42 42
      if (!event.isDataEvent) {
@@ -47,40 +47,4 @@
Loading
47 47
      return FrameResult.timeout();
48 48
    }
49 49
  }
50 -
51 -
  Future<FrameResult> receiveNonBlocking() async {
52 -
    final ack = await receiveAcknowledgement();
53 -
    if (ack.timeout) return FrameResult.timeout();
54 -
    if (ack.tryAgain) return FrameResult.tryAgain();
55 -
56 -
    try {
57 -
      final event = await _nextEvent(_responseTimeout);
58 -
      if (!event.isDataEvent) {
59 -
        throw ExpectingDataEventException(event);
60 -
      }
61 -
      return FrameResult.data(event.data);
62 -
    } on TimeoutException {
63 -
      return FrameResult.timeout();
64 -
    }
65 -
  }
66 -
67 -
  Stream<FrameResult> receiveBlocking() async* {
68 -
    // final controller = StreamController<FrameResult>();
69 -
    // // controller.sink.
70 -
    // Future.doWhile(() async {
71 -
    //    Stream.fromFuture(future)
72 -
    try {
73 -
      final event = await _nextEvent(_responseTimeout);
74 -
      if (!event.isDataEvent) {
75 -
        throw ExpectingDataEventException(event);
76 -
      }
77 -
78 -
      yield FrameResult.data(event.data);
79 -
    } on TimeoutException {
80 -
      yield FrameResult.timeout();
81 -
    }
82 -
    // return false;
83 -
    // });
84 -
    // return controller.stream;
85 -
  }
86 50
}

@@ -5,8 +5,6 @@
Loading
5 5
import 'package:bc108/src/layer2/read/command_result.dart';
6 6
import 'package:bc108/src/layer2/write/command.dart';
7 7
8 -
import '../log.dart';
9 -
10 8
class Operator {
11 9
  OperatorL1 _operatorL1;
12 10
  StreamController<String> _notificationController = StreamController<String>();
@@ -19,7 +17,6 @@
Loading
19 17
      : this(OperatorL1.fromStreamAndSink(stream, sink));
20 18
21 19
  // Future<CommandResult> _send(Command command) async {
22 -
  //   log("Command sent: '${command.payload}'");
23 20
  //   final result = await _operatorL1.send(command.payload);
24 21
  //   return CommandResult.fromAcknowledgementFrame(result);
25 22
  // }
@@ -37,8 +34,7 @@
Loading
37 34
    } while (true);
38 35
  }
39 36
40 -
  Future<CommandResult> sendNonBlocking(Command command) async {
41 -
    log("Command sent: '${command.payload}'");
37 +
  Future<CommandResult> send(Command command) async {
42 38
    final ackFrame = await _operatorL1.send(command.payload);
43 39
    if (ackFrame.tryAgain) return CommandResult.fromStatus(Status.PP_COMMERR);
44 40
    if (ackFrame.timeout) return CommandResult.fromStatus(Status.PP_COMMTOUT);
@@ -47,29 +43,6 @@
Loading
47 43
    return result;
48 44
  }
49 45
50 -
  Future<CommandResult> sendBlocking(Command command) async {
51 -
    log("Command sent: '${command.payload}'");
52 -
    final ackFrame = await _operatorL1.send(command.payload);
53 -
    if (ackFrame.tryAgain) return CommandResult.fromStatus(Status.PP_COMMERR);
54 -
    if (ackFrame.timeout) return CommandResult.fromStatus(Status.PP_COMMTOUT);
55 -
56 -
    final secondCommand = Command(command.code, []);
57 -
    await _operatorL1.send(secondCommand.payload);
58 -
    if (ackFrame.tryAgain) return CommandResult.fromStatus(Status.PP_COMMERR);
59 -
    if (ackFrame.timeout) return CommandResult.fromStatus(Status.PP_COMMTOUT);
60 -
61 -
    CommandResult result;
62 -
    bool first = true;
63 -
    do {
64 -
      if (first)
65 -
        first = false;
66 -
      else
67 -
        await Future.delayed(Duration(milliseconds: 100));
68 -
      result = await _receive();
69 -
    } while (result.status == Status.PP_PROCESSING);
70 -
    return result;
71 -
  }
72 -
73 46
  void close() {
74 47
    _operatorL1.close();
75 48
    _notificationController.close();

@@ -21,7 +21,6 @@
Loading
21 21
      sb.write(parameter.length.toString().padLeft(3, '0'));
22 22
      sb.write(parameter);
23 23
    });
24 -
    if (parameters.isEmpty) sb.write("000");
25 24
    final text = sb.toString();
26 25
    return text;
27 26
  }

@@ -19,30 +19,32 @@
Loading
19 19
20 20
  Stream<String> get notifications => _operator.notifications;
21 21
22 -
  Future<PinpadResult<void>> open() =>
23 -
      _factory.open(_operator).handleNonBlocking(null);
22 +
  Future<PinpadResult<void>> open() => _factory.open(_operator).handle(null);
24 23
  Future<PinpadResult<void>> close(CloseRequest request) =>
25 -
      _factory.close(_operator).handleNonBlocking(request);
24 +
      _factory.close(_operator).handle(request);
26 25
27 26
  Future<PinpadResult<GetInfo00Response>> getInfo00() =>
28 -
      _factory.getInfo(_operator).handleNonBlocking(null);
27 +
      _factory.getInfo(_operator).handle(null);
29 28
30 29
  Future<PinpadResult<void>> display(DisplayRequest request) =>
31 -
      _factory.display(_operator).handleNonBlocking(request);
30 +
      _factory.display(_operator).handle(request);
31 +
32 +
  Future<PinpadResult<void>> getKey() =>
33 +
      _factory.getKey(_operator).handle(null);
32 34
33 35
  Future<PinpadResult<void>> tableLoadInit(TableLoadInitRequest request) =>
34 -
      _factory.tableLoadInit(_operator).handleNonBlocking(request);
36 +
      _factory.tableLoadInit(_operator).handle(request);
35 37
36 38
  Future<PinpadResult<void>> tableLoadRec(TableLoadRecRequest request) =>
37 -
      _factory.tableLoadRec(_operator).handleNonBlocking(request);
39 +
      _factory.tableLoadRec(_operator).handle(request);
38 40
39 41
  Future<PinpadResult<void>> tableLoadEnd() =>
40 -
      _factory.tableLoadEnd(_operator).handleNonBlocking(null);
42 +
      _factory.tableLoadEnd(_operator).handle(null);
41 43
42 44
  Future<PinpadResult<GetTimestampResponse>> getTimestamp(
43 45
          GetTimestampRequest request) =>
44 -
      _factory.getTimestamp(_operator).handleNonBlocking(request);
46 +
      _factory.getTimestamp(_operator).handle(request);
45 47
46 48
  Future<PinpadResult<GetCardResponse>> getCard(GetCardRequest request) =>
47 -
      _factory.getCard(_operator).handleBlocking(request);
49 +
      _factory.getCard(_operator).handle(request);
48 50
}

@@ -2,6 +2,8 @@
Loading
2 2
import 'package:bc108/src/layer1/read/frame_acknowledgement.dart';
3 3
import 'package:bc108/src/layer1/read/frame_result.dart';
4 4
5 +
import '../log.dart';
6 +
5 7
class OperatorL1 {
6 8
  FrameReceiver _receiver;
7 9
  FrameSender _sender;
@@ -13,6 +15,8 @@
Loading
13 15
  Future<FrameAcknowledgement> send(String frame) async {
14 16
    var ackResult = FrameAcknowledgement.tryAgain();
15 17
18 +
    log("Frame sent: '$frame'");
19 +
16 20
    for (var remainingTries = 3;
17 21
        ackResult.tryAgain && remainingTries > 0;
18 22
        remainingTries--) {
@@ -23,7 +27,9 @@
Loading
23 27
  }
24 28
25 29
  Future<FrameResult> receive() async {
26 -
    return await _receiver.receiveData();
30 +
    final frame = await _receiver.receive();
31 +
    log("Data frame received: $frame");
32 +
    return frame;
27 33
  }
28 34
29 35
  void close() {

@@ -0,0 +1,24 @@
Loading
1 +
import 'package:bc108/bc108.dart';
2 +
import '../mapper.dart';
3 +
import '../handler.dart';
4 +
5 +
class GetKeyRequest {}
6 +
7 +
class GetKeyResponse {}
8 +
9 +
class Mapper extends RequestResponseMapper<void, void> {
10 +
  @override
11 +
  Command mapRequest(void request) {
12 +
    return Command("GKY", []);
13 +
  }
14 +
15 +
  @override
16 +
  void mapResponse(CommandResult result) {
17 +
    return null;
18 +
  }
19 +
}
20 +
21 +
class GetKeyFactory {
22 +
  RequestHandler<void, void> getKey(Operator o) =>
23 +
      RequestHandler.fromMapper(o, Mapper());
24 +
}
Files Coverage
lib/src 58.67%
Project Totals (40 files) 58.67%
Untitled

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading