Open JG1VPP opened 1 year ago
以下のcw4i.js
で、振幅の時系列を描画してSVGファイルに保存できる。デバッグに最適。
decoder.Program = function(message) {
if (message.Miss == decoder.MaxMiss) {
plot(message.Text.replace(/ /g, '') + '.svg', message);
}
return message;
}
以下は、適当なプロセスを起動するサンプル。
decoder.Program = function(message) {
call('cowsay', message.Text);
return message;
}
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がモールス信号を解読するたびに、その内容が共有される。
問題意識
CW4ISRはJavaScript (ES5)でイベントハンドラを定義可能だが、現時点では、読み取ったメッセージの編集ができる程度。
もっとCW4ISRの設定を細かく調節したり、デバッグ・可視化機能やRPCによる外部連携を強化したい。
解決方法
Goの構造体・メソッドの形式で、JavaScriptから呼び出し可能なライブラリを充実させる。それらは、以下のように渡される。