Skip to content

Commit

Permalink
1128-water00
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaokeke committed Nov 28, 2017
1 parent 8513f2d commit 0a7d325
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 57 deletions.
64 changes: 42 additions & 22 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/main/config/conf6018.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"port":"6019",
"meterids":[
[
[254,254,254,104,53,113,16,97,1,0,104,1,2,67,195,241,22],
[254,254,254,104,51,113,16,97,1,0,104,1,2,67,195,239,22],
[254,254,254,104,82,113,16,97,1,0,104,1,2,67,195,14,22],
[254,254,254,104,1,112,129,96,1,0,104,1,2,67,195,44,22],
[254,254,254,104,88,113,16,97,1,0,104,1,2,67,195,20,22],
[254,254,254,104,72,113,16,97,1,0,104,1,2,67,195,4,22],
[254,254,254,104,128,113,16,97,1,0,104,1,2,67,195,60,22]
]
]
}
68 changes: 34 additions & 34 deletions src/main/water6018.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func ParseWaterId(bytes []byte) string{
str := ""
for i:=5;i>=0;i--{
hexs := strconv.FormatInt(int64((bytes[i])&0xff),16)
if hexs=="0"{
hexs="00"
if len(hexs)==1{
str+="0"
}
str += hexs
}
Expand Down Expand Up @@ -183,41 +183,41 @@ func handleWrite(conn net.Conn) {
func handleRead(conn net.Conn) {
defer conn.Close()
for{
recvBytes := make([]byte,0,100)
tmp := make([]byte,100)
n,err := conn.Read(tmp)
if err!=nil{
fmt.Println(err)
break
}
if n<=0{
continue
}
fmt.Printf("% X\n",tmp[0:n])

if bytes.HasPrefix(tmp,[]byte{0x68}){
recvBytes = append(recvBytes,tmp[:n]...)
if n < 18{
for{
i,err := conn.Read(tmp)
if err!=nil{
fmt.Println(err)
break
}
if i<=0{
continue
}
fmt.Printf("% X\n",tmp[0:i])
recvBytes = append(recvBytes,tmp[:i]...)
n +=i
if n>=18{
break
}
recvBytes := make([]byte,0,100)
tmp := make([]byte,100)
n,err := conn.Read(tmp)
if err!=nil{
fmt.Println(err)
break
}
if n<=0{
continue
}
fmt.Printf("% X\n",tmp[0:n])

if bytes.HasPrefix(tmp,[]byte{0x68}){
recvBytes = append(recvBytes,tmp[:n]...)
if n < 18{
for{
i,err := conn.Read(tmp)
if err!=nil{
fmt.Println(err)
break
}
if i<=0{
continue
}
fmt.Printf("% X\n",tmp[0:i])
recvBytes = append(recvBytes,tmp[:i]...)
n +=i
if n>=18{
break
}
}
fmt.Printf("% X\n",recvBytes)
go HandData(recvBytes)
}
fmt.Printf("% X\n",recvBytes)
go HandData(recvBytes)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/water6019.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func ParseWaterId(bytes []byte) string{
for i:=5;i>=0;i--{
hexs := strconv.FormatInt(int64((bytes[i])&0xff),16)
if len(hexs)==1{
hexs+="0"
str+="0"
}
str += hexs
}
Expand Down

0 comments on commit 0a7d325

Please sign in to comment.