nextzlog / todo

ToDo lists for ATS-4, CW4ISR, QxSL, ZyLO.
https://nextzlog.dev
1 stars 0 forks source link

スクリプトで操作できる範囲の強化 #185

Open JG1VPP opened 1 year ago

JG1VPP commented 1 year ago

問題意識

CW4ISRはJavaScript (ES5)でイベントハンドラを定義可能だが、現時点では、読み取ったメッセージの編集ができる程度。

decoder.Program = function(message) {
  message.Text = message.Text.replace('5NN', '599');
  message.Text = message.Text.replace('ENN', '599');
  return message;
}

もっとCW4ISRの設定を細かく調節したり、デバッグ・可視化機能やRPCによる外部連携を強化したい。

解決方法

Goの構造体・メソッドの形式で、JavaScriptから呼び出し可能なライブラリを充実させる。それらは、以下のように渡される。

vm := goja.New()
vm.Set("RPC", RPC{})
JG1VPP commented 1 year ago

波形の可視化

以下のcw4i.jsで、振幅の時系列を描画してSVGファイルに保存できる。デバッグに最適。

decoder.Program = function(message) {
  if (message.Miss == decoder.MaxMiss) {
    plot(message.Text.replace(/ /g, '') + '.svg', message);
  }
  return message;
}
JG1VPP commented 1 year ago

プロセスの起動

以下は、適当なプロセスを起動するサンプル。

decoder.Program = function(message) {
  call('cowsay', message.Text);
  return message;
}
JG1VPP commented 1 year ago

パイプ

Windowsで他のプロセスにパイプ経由でメッセージを送信するサンプル。まず、以下をclient.exeとしてビルドする。

package main

import (
  "github.com/Microsoft/go-winio"
  "os"
)

const PIPE = `\\.\pipe\zlog-pipe`

func main() {
  conn, err := winio.DialPipe(PIPE, nil)
  if err == nil {
    defer conn.Close()
    conn.Write([]byte(os.Args[0]))
  }
}

同様に、以下をserver.exeとしてビルドする。

package main

import (
  "fmt"
  "github.com/Microsoft/go-winio"
  "io/ioutil"
)

const PIPE = `\\.\pipe\zlog-pipe`

func main() {
  listener, _ := winio.ListenPipe(PIPE, &winio.PipeConfig{
    SecurityDescriptor: "S:(ML;;NW;;;LW)D:(A;;0x12019f;;;WD)",
    InputBufferSize:    4096,
    OutputBufferSize:   4096,
  })
  defer listener.Close()
  for {
    conn, _ := listener.Accept()
    defer conn.Close()
    bytes, _ := ioutil.ReadAll(conn)
    fmt.Println(string(bytes))
  }
}

client.exeをCW4ISRと同じディレクトリに配置して、以下のcw4i.jsでCW4ISRを起動する。

decoder.Program = function(message) {
  call('./pipe.exe', message.Text);
  return message;
}

server.exeも起動しておく。CW4ISRがモールス信号を解読するたびに、その内容が共有される。