]> git.argeo.org Git - gpl/argeo-slc.git/blob - GpsBabelCall.java
4b0db1fd9ebaa80efc899a3d6d136135809e097a
[gpl/argeo-slc.git] / GpsBabelCall.java
1 package org.argeo.slc.gpsbabel;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.argeo.slc.SlcException;
7 import org.argeo.slc.core.execution.tasks.SystemCall;
8 import org.springframework.beans.factory.InitializingBean;
9
10 public class GpsBabelCall extends SystemCall implements InitializingBean {
11 private String executable = "/usr/bin/gpsbabel";
12 private String inputFormat;
13 private String inputFile;
14 private String outputFormat;
15 private String outputFile;
16
17 public GpsBabelCall() {
18 super();
19 }
20
21 public GpsBabelCall(String inputFormat, String inputFile,
22 String outputFormat, String outputFile) {
23 super();
24 this.inputFormat = inputFormat;
25 this.inputFile = inputFile;
26 this.outputFormat = outputFormat;
27 this.outputFile = outputFile;
28 try {
29 afterPropertiesSet();
30 } catch (Exception e) {
31 throw new SlcException("Cannot configure gpsbabel call", e);
32 }
33 }
34
35 public void afterPropertiesSet() throws Exception {
36 List<Object> command = new ArrayList<Object>();
37 command.add(executable);
38 command.add("-i");
39 command.add(inputFormat);
40 command.add("-f");
41 command.add(inputFile);
42 command.add("-o");
43 command.add(outputFormat);
44 command.add("-F");
45 command.add(outputFile);
46 setCommand(command);
47
48 setStdOutLogLevel(LOG_STDOUT);
49 }
50
51 public final static void main(String[] args) {
52 String output = new GpsBabelCall("garmin,get_posn", "usb:", "csv", "-")
53 .function();
54 System.out.println("output='" + output + "'");
55 }
56 }