This commit is contained in:
fish 2019-03-21 11:52:09 +08:00
parent b10aace99b
commit 1bcc46f458
6 changed files with 443 additions and 444 deletions

View File

@ -4,10 +4,10 @@ import (
"database/sql" "database/sql"
"encoding/json" "encoding/json"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"os"
"time"
"strconv"
"log" "log"
"os"
"strconv"
"time"
) )
type Traffic struct { type Traffic struct {
@ -64,7 +64,6 @@ var conf Conf
var DEVICEDATAS Devicedatas var DEVICEDATAS Devicedatas
var demoDevice Device var demoDevice Device
var db, _ = sql.Open("sqlite3", "./db/gateway.db") var db, _ = sql.Open("sqlite3", "./db/gateway.db")
// 加载配置文件 // 加载配置文件
@ -87,7 +86,6 @@ func init() {
} }
DEVICEDATAS.Unlock() DEVICEDATAS.Unlock()
demoDevice.ID = "deb03e28-ddcb-4e5d-aa31-d870a1f0f09b" demoDevice.ID = "deb03e28-ddcb-4e5d-aa31-d870a1f0f09b"
demoDevice.VERSION = "yunhorn_kgl_c8_v1" demoDevice.VERSION = "yunhorn_kgl_c8_v1"
demoDevice.DATA = make(map[string]interface{}) demoDevice.DATA = make(map[string]interface{})
@ -97,7 +95,6 @@ func init() {
demoDevice.ONLINE = true demoDevice.ONLINE = true
log.Println("init demoDevice success:", demoDevice) log.Println("init demoDevice success:", demoDevice)
dbdata_init() dbdata_init()
} }

View File

@ -3,8 +3,8 @@ package main
import ( import (
"github.com/robfig/cron" "github.com/robfig/cron"
"log" "log"
"os"
"net" "net"
"os"
) )
var err error var err error

View File

@ -11,7 +11,6 @@ import (
// "go-study/socket/config" // "go-study/socket/config"
) )
func handleConn(conn net.Conn) { func handleConn(conn net.Conn) {
defer conn.Close() defer conn.Close()

View File

@ -4,9 +4,9 @@ import (
"encoding/binary" "encoding/binary"
"github.com/tarm/serial" "github.com/tarm/serial"
"log" "log"
"math/rand"
"strconv" "strconv"
"sync" "sync"
"math/rand"
) )
type Devicedatas struct { type Devicedatas struct {
@ -14,7 +14,6 @@ type Devicedatas struct {
DATA map[string]Device DATA map[string]Device
} }
type Device struct { type Device struct {
sync.RWMutex sync.RWMutex
ID string `json:"id"` ID string `json:"id"`
@ -34,10 +33,14 @@ func yunhorn_ys_l_v1(data_buf []byte){
// log.Println(binary.BigEndian.Uint16(append([]byte{0x00}, k)) // log.Println(binary.BigEndian.Uint16(append([]byte{0x00}, k))
// } // }
log.Println("ys_l_v1_data:",data_buf) // log.Println("ys_l_v1_data:",data_buf)
data_int := Bytes2Bits(data_buf[3:4]) data_int := Bytes2Bits(data_buf[3:4])
data_int0 := Bytes2Bits(data_buf[0:1])
data_int1 := Bytes2Bits(data_buf[1:2])
data_int2 := Bytes2Bits(data_buf[2:3])
log.Println("data_int:", data_int[0]) log.Println("data_int:", data_int[0])
log.Printf("ADRH:%d,ADRL:%d,dataType:%d,", data_int0[0], data_int1[0], data_int2[0])
var device Device var device Device
device.ID = demoDevice.ID device.ID = demoDevice.ID
device.VERSION = demoDevice.VERSION device.VERSION = demoDevice.VERSION