| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package main
- import (
- "time"
- "hnyfkj.com.cn/rtu/linux/utils/shell"
- )
- var (
- rpc_ping = "executor.ping"
- rpc_exec = "executor.exec"
- rpc_stop = "executor.interrupt"
- rpc_quit = "executor.close"
- )
- func (c *MQTTCoupler) needSerialize(method string) bool {
- if method == rpc_ping || method == rpc_stop {
- return false
- }
- return true
- }
- func (c *MQTTCoupler) needTimeoutEnd(method string) bool {
- if method == rpc_ping || method == rpc_stop || method == rpc_quit {
- return true
- }
- return false
- }
- // 心跳检测
- func (c *MQTTCoupler) Ping() (shell.ExecuteResult, error) {
- params := struct {
- ClientID string `json:"client_id"`
- }{
- ClientID: c.clientID,
- }
- return c.doCmd(rpc_ping, params)
- }
- // 执行命令
- func (c *MQTTCoupler) Exec(
- cmd string) (shell.ExecuteResult, error) {
- params := struct {
- ClientID string `json:"client_id"`
- shell.ExecuteParams
- }{
- ClientID: c.clientID,
- ExecuteParams: shell.ExecuteParams{
- Cmd: cmd,
- Timeout: int(shell.DefaultTimeout / time.Second),
- },
- }
- timeout := getCmdTimeoutByPrefix(cmd)
- if timeout > 0 {
- params.Timeout = timeout
- }
- return c.doCmd(rpc_exec, params)
- }
- // 中断执行
- func (c *MQTTCoupler) Stop() (shell.ExecuteResult, error) {
- params := struct {
- ClientID string `json:"client_id"`
- }{
- ClientID: c.clientID,
- }
- return c.doCmd(rpc_stop, params)
- }
- // 关闭退出
- func (c *MQTTCoupler) Quit() (shell.ExecuteResult, error) {
- params := struct {
- ClientID string `json:"client_id"`
- }{
- ClientID: c.clientID,
- }
- return c.doCmd(rpc_quit, params)
- }
|