package adl400TtyApi

import (
	"github.com/gogf/gf/v2/util/gconv"
	"github.com/towgo/towgo/towgo"
	"strings"
)

func setMsgAddress(rpc towgo.JsonRpcConnection) {
	var p struct {
		CommUid string `json:"comm_uid"`
		MsgAddr string `json:"msg_addr"`
	}
	rpc.ReadParams(&p)

	oldAddr := getMeterAddr(p.CommUid)
	newAddr := gconv.Byte(strings.TrimPrefix(p.MsgAddr, "0x"))
	err := getMc().WriteMsgAddr(p.CommUid, oldAddr, newAddr)
	if err != nil {
		panic(err)
	}
	rpc.WriteResult("ok")
}
