diff --git a/conf/gateway.conf b/conf/gateway.conf index 8913a57..323e7ea 100644 --- a/conf/gateway.conf +++ b/conf/gateway.conf @@ -70,6 +70,7 @@ }, "devices_list": [ ["EC13C2D9-6A93-4894-BB5B-89BDAA786D8A", "port3", "yunhorn_kgl_c8_v1", "1"], + ["15394892-E8B0-4FF2-BC35-1BF380BD1B68", "port2", "yunhorn_xsy_c_v1", "1"], ["52A79B3D-D9D9-48AF-AEB4-7D456BA22B31", "port1", "yunhorn_db_c_v1", "1"], ["607E11C4-8986-4F8E-807E-FFA655A6F677", "port1", "yunhorn_sb_c_v1", "1"], ["066BB944-AFA2-4E5D-86FA-61D9080A97BB", "port2", "yunhorn_kq_c_v1", "1"], @@ -106,6 +107,13 @@ } }, "rs485devices": { + "15394892-E8B0-4FF2-BC35-1BF380BD1B68": { + "version": "yunhorn_xsy_c_v1", + "num": "1", + "command": [ + [8, 3, 0, 1, 0, 2, 149, 82] + ] + }, "EC13C2D9-6A93-4894-BB5B-89BDAA786D8A": { "version": "yunhorn_kgl_c8_v1", "num": "1", diff --git a/serial_init.go b/serial_init.go index c4c23f2..dfa8cdc 100644 --- a/serial_init.go +++ b/serial_init.go @@ -68,6 +68,8 @@ func run_port_device(port *serial.Port, the_same_port_devices [][]string) { yunhorn_kgl_c8_v1(port, i[0], conf.RS485DEVICES[i[0]].COMMAND, conf.RS485DEVICES[i[0]].NUM) case "yunhorn_kgl_c16_v1": yunhorn_kgl_c16_v1(port, i[0], conf.RS485DEVICES[i[0]].COMMAND, conf.RS485DEVICES[i[0]].NUM) + case "yunhorn_xsy_c_v1": + yunhorn_xsy_c_v1(port, i[0], conf.RS485DEVICES[i[0]].COMMAND, conf.RS485DEVICES[i[0]].NUM) } } } diff --git a/worker.go b/worker.go index a1ea283..c3783ab 100644 --- a/worker.go +++ b/worker.go @@ -60,6 +60,52 @@ func yunhorn_sb_c_v1(s *serial.Port, device_id string, command [][]byte, num str } } +func yunhorn_xsy_c_v1(s *serial.Port, device_id string, command [][]byte, num string) { + _, err = s.Write([]byte(command[0])) + check(err) + if conf.DEBUG { + log.Printf("命令:\t%x", []byte(command[0])) + } + buf := make([]byte, 128) + b_buf := make([]byte, 0) + var nn int + for { + n, err := s.Read(buf) + nn = n + nn + b_buf = append(b_buf, buf[:n]...) + if err != nil { + break + } + } + if nn != 9 { + return + } + data_buf := b_buf[3 : nn-4] + + DEVICEDATAS.RLock() + var olddata = DEVICEDATAS.DATA["yunhorn_xsy_c_v1_"+num] + DEVICEDATAS.RUnlock() + + var device Device + device.Lock() + device.ID = device_id + device.VERSION = "yunhorn_xsy_c_v1" + device.ONLINE = true + device.DATA = make(map[string]interface{}) + device.DATA["data"] = binary.BigEndian.Uint16(data_buf) + device.Unlock() + DEVICEDATAS.Lock() + DEVICEDATAS.DATA["yunhorn_xsy_c_v1_"+num] = device + DEVICEDATAS.Unlock() + + if device.DATA["data"] != olddata.DATA["data"] { + send_data(1005, device) + } + if conf.DEBUG { + log.Println(device) + } +} + func yunhorn_db_c_v1(s *serial.Port, device_id string, command [][]byte, num string) { _, err = s.Write([]byte(command[0])) check(err)