123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package main
- import (
- "testing"
- )
- /////-------
- import (
- "encoding/hex"
- "fmt"
- "strings"
- )
- /*
- 设备->平台
- */
- func T(t string, b []byte) string {
- return string(b)
- }
- /*
- 平台->设备
- */
- func R(sn string, b string) (string, []byte) {
- t := sn
- return t, []byte(b)
- }
- var Data_hex = true
- var Topic = "/topic/snxxx1"
- var T_string = "A456"
- var R_string = "495051"
- /////-------
- func main() {
- // -------------------------------设备->平台
- T_byte := []byte(T_string)
- if Data_hex {
- T_byte, _ = hex.DecodeString(T_string)
- }
- // 设备->平台(发送)
- if len(T_string) != 0 {
- data_ := T(Topic, T_byte)
- fmt.Print("|-=&" + data_)
- } else {
- fmt.Print("|-=&" + "无参数")
- }
- // 平台->设备(接收):
- if len(R_string) != 0 {
- topic_, data_ := R(Topic, R_string)
- fmt.Print("|-=&" + topic_)
- if Data_hex {
- fmt.Print("|-=&" + strings.ToUpper(hex.EncodeToString(data_)))
- } else {
- fmt.Print("|-=&" + string(data_))
- }
- } else {
- fmt.Print("|-=&" + "无参数")
- fmt.Print("|-=&" + "无参数")
- }
- // 返回数据: 1、 设备发送数据解析到平台json 2、topic 3、平台处理后返回给设备数据
- }
- func Test_Runcode(t *testing.T) {
- main()
- }
|