UartBus source documentation
UartbusCliTools.java
1 package eu.javaexperience.electronic.uartbus.rpc;
2 
3 import java.io.IOException;
4 import java.util.List;
5 import java.util.Map;
6 
7 import eu.javaexperience.cli.CliEntry;
9 
10 public class UartbusCliTools
11 {
12  private UartbusCliTools()
13  {}
14 
15  public static final CliEntry<Integer> SERIAL_BAUD = CliEntry.createFirstArgParserEntry
16  (
17  (e)->Integer.parseInt(e),
18  "Serial baud rate",
19  "b", "-baud"
20  );
21 
22  public static final CliEntry<String> RPC_HOST = CliEntry.createFirstArgParserEntry
23  (
24  (e)->e,
25  "Rpc server IP",
26  "h", "-host"
27  );
28 
29  public static final CliEntry<Integer> RPC_PORT = CliEntry.createFirstArgParserEntry
30  (
31  (e)->Integer.parseInt(e),
32  "Rpc port",
33  "p", "-port"
34  );
35 
36  public static final CliEntry<Integer> FROM = CliEntry.createFirstArgParserEntry
37  (
38  (e)->Integer.parseInt(e),
39  "Uartbus from address",
40  "f", "-from"
41  );
42 
43  public static final CliEntry<Boolean> LOOPBACK = CliEntry.createFirstArgParserEntry
44  (
45  (e)->true,
46  "Show sent packet",
47  "x", "-loopback-sent"
48  );
49 
50  public static final CliEntry<String> OPTIONS = CliEntry.createFirstArgParserEntry
51  (
52  (e)->e,
53  "Other options",
54  "o", "-options"
55  );
56 
57 
58  public static final int DEFAULT_FROM_ADDRESS = 63;
59  public static int parseFrom(Map<String, List<String>> args)
60  {
61  return FROM.tryParseOrDefault(args, DEFAULT_FROM_ADDRESS);
62  }
63 
64  public static final CliEntry<Integer> TO = CliEntry.createFirstArgParserEntry
65  (
66  (e)->Integer.parseInt(e),
67  "Uartbus to address",
68  "t", "-to"
69  );
70 
71  public static final CliEntry<String> WORK_DIR = CliEntry.createFirstArgParserEntry
72  (
73  (e) -> e,
74  "Working directory",
75  "d", "-working-directory"
76  );
77 
78  public static final CliEntry<Boolean> LOG_TIME = CliEntry.createFirstArgParserEntry
79  (
80  (e) -> true,
81  "Log times",
82  "l", "-log-times"
83  );
84 
85  public static final CliEntry<Boolean> RECONNECT = CliEntry.createFirstArgParserEntry
86  (
87  (e) -> true,
88  "Reconnect",
89  "r", "-reconnect"
90  );
91 
92  public static final CliEntry<String> DECODE_PACKET = CliEntry.createFirstArgParserEntry
93  (
94  (e)->e,
95  "Decode packet",
96  "D", "-decode-packet"
97  );
98 
99 
100  public static UartBus cliBusConnect(Map<String, List<String>> cliArgs) throws IOException
101  {
102  return UartBus.fromTcp
103  (
104  RPC_HOST.tryParseOrDefault(cliArgs, "127.0.0.1"),
105  RPC_PORT.tryParseOrDefault(cliArgs, 2112),
106  UartbusCliTools.parseFrom(cliArgs)
107  );
108  }
109 
110 }