Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

55
LINES

< > BotCompany Repo | #1027258 // Run Vector SDK

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (6765L/34K).

1  
!7
2  
3  
cmodule RunVectorSDK > DynPrintLogAndEnabled {
4  
  transient Process process;
5  
  transient PrintStream out;
6  
  S toSay;
7  
  
8  
  start-thread {
9  
    dm_reloadOnFieldChange enabled();
10  
    if (!enabled) ret;
11  
    //File script = userDir("vector-sdk/cam-stream-to-stdout.py");
12  
    File script = userDir("vector-sdk/control-from-java.py");
13  
    assertFileExists(script);
14  
    makeExecutable(script);
15  
16  
    print("Calling " + script);
17  
    process = Runtime.getRuntime().exec(platformQuoteOpt(script));
18  
    print("SDK process started");
19  
    print("PID: " + getOpt(process, "pid"));
20  
  
21  
    drainErrorStreamToConsole(process, line -> enabled, lambda0 enter);
22  
    out = new PrintStream(process.getOutputStream());
23  
    
24  
    DataInputStream in = new(process.getInputStream());
25  
    S line;
26  
    while ((line = in.readLine()) != null) {
27  
      if (enabled)
28  
        print("Got line: " + takeFirst(100, line));
29  
    }
30  
  }
31  
32  
  void cleanMeUp_process {
33  
    if (process != null) {
34  
      print("Stopping SDK process");
35  
      process.destroy/*Forcibly*/();
36  
      print("Stopped SDK process, hopefully");
37  
    }
38  
  }
39  
  
40  
  visual centerAndSouthWithMargin(super, withMargin(
41  
    dm_textFieldAndSubmit_q toSay(r { say(toSay) }, buttonText := "Say")));
42  
43  
  // API
44  
45  
  // returns true if (probably) successful
46  
  bool say(S s) {
47  
    if (out == null) false;
48  
    s = newLinesToSpaces_trim(s);
49  
    if (empty(s)) true;
50  
    print("Making Vector say: " + s);
51  
    out.println(s);
52  
    out.flush();
53  
    true;
54  
  }
55  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027258
Snippet name: Run Vector SDK
Eternal ID of this version: #1027258/22
Text MD5: b04a5db1cb074e9d968e9e84b7926911
Transpilation MD5: 47f4cb2af5185a25a692278aeae8b92a
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-28 12:39:38
Source code size: 1515 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 149 / 473
Version history: 21 change(s)
Referenced in: [show references]