View Javadoc
1   package fr.ifremer.tutti.ichtyometer.tool;
2   
3   /*
4    * #%L
5    * Tutti :: Ichtyometer API
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import com.google.common.collect.Lists;
26  import fr.ifremer.tutti.ichtyometer.IchtyometerClient;
27  import fr.ifremer.tutti.ichtyometer.RemoteDeviceChooser;
28  import fr.ifremer.tutti.ichtyometer.feed.IchtyometerFeedReader;
29  import fr.ifremer.tutti.ichtyometer.feed.event.IchtyometerFeedReaderListener;
30  
31  import java.io.Console;
32  import java.io.IOException;
33  import java.io.PrintWriter;
34  import java.util.List;
35  
36  /**
37   * Created on 1/30/14.
38   *
39   * @author Tony Chemit - chemit@codelutin.com
40   * @since 3.2
41   */
42  public class FeedReaderTool {
43  
44      public static void main(String... args) throws IOException {
45  
46          final PrintWriter writer = System.console().writer();
47          writer.println("FeedReaderTool: to display record in feed mode v1.0");
48  
49          RemoteDeviceChooser remoteDeviceChooser = remoteDeviceNames -> {
50              List<String> remoteDeviceNameList = Lists.newArrayList(remoteDeviceNames);
51              Console console = System.console();
52              writer.println("Choose you device");
53              int i = 0;
54              for (String remoteDeviceName : remoteDeviceNameList) {
55                  writer.println(i++ + " for device " + remoteDeviceName);
56              }
57              writer.println("q (to quit)");
58              writer.print("Your choice: ");
59              writer.flush();
60  
61              String command = console.readLine();
62  
63              if ("q".equals(command)) {
64                  System.exit(0);
65              }
66              return remoteDeviceNameList.get(Integer.valueOf(command));
67          };
68  
69          IchtyometerClient client = new IchtyometerClient(2);
70  
71          client.open(remoteDeviceChooser, true);
72  
73          IchtyometerFeedReader reader = new IchtyometerFeedReader();
74  
75          writer.println("client " + client + " is open and listen the board");
76  
77          IchtyometerFeedReaderListener listener = event -> writer.println("New record: " + event.getRecord());
78  
79          reader.addFeedModeReaderListener(listener);
80          reader.start(client);
81  
82          while (true) {
83  
84          }
85      }
86  }