mirror of
https://github.com/nonoo/kappanhang.git
synced 2025-12-31 22:09:58 +01:00
Implement all request/replies
This commit is contained in:
parent
80f490871a
commit
cc7f1159c7
42
main.go
42
main.go
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net"
|
||||
|
|
@ -94,6 +95,7 @@ func main() {
|
|||
var receivedSeq bool
|
||||
var lastPingAt time.Time
|
||||
var errCount int
|
||||
var randID [4]byte
|
||||
for {
|
||||
r, err := read()
|
||||
if err != nil {
|
||||
|
|
@ -112,32 +114,38 @@ func main() {
|
|||
log.Print("auth ok")
|
||||
}
|
||||
}
|
||||
if bytes.Equal(r[:6], []byte{0x00, 0x00, 0x00, 0x00, 0x07, 0x00}) {
|
||||
if len(r) == 21 && bytes.Equal(r[1:6], []byte{0x00, 0x00, 0x00, 0x07, 0x00}) {
|
||||
gotSeq := r[6]
|
||||
if receivedSeq && lastReceivedSeq+1 != gotSeq {
|
||||
log.Error("packet loss detected")
|
||||
}
|
||||
lastReceivedSeq = gotSeq
|
||||
receivedSeq = true
|
||||
|
||||
// Replying to the radio.
|
||||
// Example request from radio: 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x1c, 0x0e, 0xe4, 0x35, 0xdd, 0x72, 0xbe, 0xd9, 0xf2, 0x63, 0x00, 0x57, 0x2b, 0x12, 0x00
|
||||
// Example answer from PC: 0x15, 0x00, 0x00, 0x00, 0x07, 0x00, 0x1c, 0x0e, 0xbe, 0xd9, 0xf2, 0x63, 0xe4, 0x35, 0xdd, 0x72, 0x01, 0x57, 0x2b, 0x12, 0x00
|
||||
send([]byte{0x15, 0x00, 0x00, 0x00, 0x07, 0x00, gotSeq, r[7], byte(remoteSID >> 24), byte(remoteSID >> 16), byte(remoteSID >> 8), byte(remoteSID), byte(localSID >> 24), byte(localSID >> 16), byte(localSID >> 8), byte(localSID), 0x01,
|
||||
r[17], r[18], r[19], r[20]})
|
||||
}
|
||||
if len(r) == 16 && bytes.Equal(r[:6], []byte{0x10, 0x00, 0x00, 0x00, 0x00, 0x00}) {
|
||||
// Replying to the radio.
|
||||
// Example receive: 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0xe4, 0x35, 0xdd, 0x72, 0xbe, 0xd9, 0xf2, 0x63
|
||||
// Example answer: 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0xbe, 0xd9, 0xf2, 0x63, 0xe4, 0x35, 0xdd, 0x72
|
||||
gotSeq := r[6]
|
||||
send([]byte{0x10, 0x00, 0x00, 0x00, 0x00, 0x00, gotSeq, 0x00, byte(remoteSID >> 24), byte(remoteSID >> 16), byte(remoteSID >> 8), byte(remoteSID), byte(localSID >> 24), byte(localSID >> 16), byte(localSID >> 8), byte(localSID)})
|
||||
}
|
||||
|
||||
if time.Since(lastPingAt) >= time.Second {
|
||||
// 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0xf0, 0xa4, 0xf5, 0x9d, 0xad, 0x89, 0x2b, 0x14
|
||||
// 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0xf0, 0xa4, 0xf5, 0x9d, 0xad, 0x89, 0x2b, 0x14
|
||||
send([]byte{0x10, 0x00, 0x00, 0x00, 0x00, 0x00, sendSeq, 0x00, byte(remoteSID >> 24), byte(remoteSID >> 16), byte(remoteSID >> 8), byte(remoteSID), byte(localSID >> 24), byte(localSID >> 16), byte(localSID >> 8), byte(localSID)})
|
||||
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x86, 0x08, 0xf0, 0xa4, 0xf5, 0x9d, 0xad, 0x89, 0x2b, 0x14, 0x00, 0x08, 0xdf, 0x10, 0x00
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x87, 0x08, 0xf0, 0xa4, 0xf5, 0x9d, 0xad, 0x89, 0x2b, 0x14, 0x00, 0x6c, 0xdf, 0x10, 0x00
|
||||
send([]byte{0x00, 0x00, 0x00, 0x00, 0x07, 0x00, sendSeq, 0x08, byte(remoteSID >> 24), byte(remoteSID >> 16), byte(remoteSID >> 8), byte(remoteSID), byte(localSID >> 24), byte(localSID >> 16), byte(localSID >> 8), byte(localSID), 0x00, 0xd0, 0xdf, 0x10, 0x00})
|
||||
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x1c, 0x00, 0xf0, 0xa4, 0xf5, 0x9d, 0xad, 0x89, 0x2b, 0x14, 0x01, 0xb2, 0x48, 0x10, 0x00
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x1d, 0x00, 0xf0, 0xa4, 0xf5, 0x9d, 0xad, 0x89, 0x2b, 0x14, 0x01, 0x17, 0x49, 0x10, 0x00
|
||||
// 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x1e, 0x00, 0xf0, 0xa4, 0xf5, 0x9d, 0xad, 0x89, 0x2b, 0x14, 0x01, 0x7c, 0x49, 0x10, 0x00
|
||||
send([]byte{0x00, 0x00, 0x00, 0x00, 0x07, 0x00, sendSeq, 0x00, byte(remoteSID >> 24), byte(remoteSID >> 16), byte(remoteSID >> 8), byte(remoteSID), byte(localSID >> 24), byte(localSID >> 16), byte(localSID >> 8), byte(localSID), 0x01, 0xe1, 0x49, 0x10, 0x00})
|
||||
|
||||
if time.Since(lastPingAt) >= 100*time.Millisecond {
|
||||
// Example request from PC: 0x15, 0x00, 0x00, 0x00, 0x07, 0x00, 0x09, 0x00, 0xbe, 0xd9, 0xf2, 0x63, 0xe4, 0x35, 0xdd, 0x72, 0x00, 0x78, 0x40, 0xf6, 0x02
|
||||
// Example reply from radio: 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x09, 0x00, 0xe4, 0x35, 0xdd, 0x72, 0xbe, 0xd9, 0xf2, 0x63, 0x01, 0x78, 0x40, 0xf6, 0x02
|
||||
_, err = rand.Read(randID[:])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
send([]byte{0x15, 0x00, 0x00, 0x00, 0x07, 0x00, sendSeq, 0x00, byte(remoteSID >> 24), byte(remoteSID >> 16), byte(remoteSID >> 8), byte(remoteSID), byte(localSID >> 24), byte(localSID >> 16), byte(localSID >> 8), byte(localSID), 0x01,
|
||||
randID[0], randID[1], randID[2], randID[3]})
|
||||
sendSeq++
|
||||
|
||||
//send([]byte{0x10, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, byte(localSID >> 24), byte(localSID >> 16), byte(localSID >> 8), byte(localSID), byte(remoteSID >> 24), byte(remoteSID >> 16), byte(remoteSID >> 8), byte(remoteSID)})
|
||||
lastPingAt = time.Now()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue