Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JG1VPP opened this issue Jul 30, 2023 · 3 comments
Open

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

JG1VPP opened this issue Jul 30, 2023 · 3 comments
Assignees
Labels
CW CW decoder & encoder enhancement New feature or request

Comments

@JG1VPP
Copy link
Member

JG1VPP commented Jul 30, 2023

問題意識

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 JG1VPP added enhancement New feature or request CW CW decoder & encoder labels Jul 30, 2023
@JG1VPP
Copy link
Member Author

JG1VPP commented Aug 3, 2023

波形の可視化

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

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

@JG1VPP
Copy link
Member Author

JG1VPP commented Aug 6, 2023

プロセスの起動

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

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

@JG1VPP
Copy link
Member Author

JG1VPP commented Aug 6, 2023

パイプ

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がモールス信号を解読するたびに、その内容が共有される。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CW CW decoder & encoder enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants