129 lines
3.1 KiB
Go
129 lines
3.1 KiB
Go
package proto
|
|
|
|
type (
|
|
clientID uint16
|
|
flag uint8
|
|
state uint8
|
|
version uint8
|
|
)
|
|
|
|
/*
|
|
0 - AUTH REQUEST
|
|
1 - AUTH RESPONSE
|
|
2 - CLIENT DATA
|
|
254 - ACK
|
|
255 - NAK
|
|
*/
|
|
const (
|
|
AUTH_REQUEST flag = iota
|
|
AUTH_RESPONSE
|
|
CLIENT_DATA
|
|
ACK flag = 254
|
|
NAK flag = 255
|
|
)
|
|
|
|
const (
|
|
NOT_CONNECTED state = iota
|
|
SENT_AUTH
|
|
AUTH_TOT
|
|
AUTHENTICATED
|
|
CONNECTED
|
|
SENT_DATA
|
|
RECEIVED_ACK
|
|
RECEIVED_NAK
|
|
)
|
|
|
|
const (
|
|
VERSION version = 1
|
|
)
|
|
|
|
/*
|
|
===================================================
|
|
| VERSION 1 byte | FLAG 1 byte | CLIENT ID 2 byte |
|
|
===================================================
|
|
| LEN OF DATA 4 bytes |
|
|
===================================================
|
|
*/
|
|
type Header struct {
|
|
Version version
|
|
Flag flag
|
|
ClientID clientID
|
|
DataLen uint32
|
|
}
|
|
|
|
/*
|
|
AUTH DATA (REQUEST)
|
|
===================================================
|
|
| AUTH KEY 0 4 bytes |
|
|
===================================================
|
|
*/
|
|
|
|
type Request struct {
|
|
Akey_0 uint64
|
|
}
|
|
|
|
/*
|
|
AUTH DATA (RESPONSE)
|
|
===================================================
|
|
| CLIENT KEY 0 4 bytes |
|
|
===================================================
|
|
===================================================
|
|
| CLIENT KEY 1 4 bytes |
|
|
===================================================
|
|
===================================================
|
|
| CLIENT KEY 2 4 bytes |
|
|
===================================================
|
|
===================================================
|
|
| CLIENT KEY 3 4 bytes |
|
|
===================================================
|
|
*/
|
|
type Response struct {
|
|
CKey_0 uint32
|
|
Ckey_1 uint32
|
|
Ckey_2 uint32
|
|
Ckey_3 uint32
|
|
}
|
|
|
|
/*
|
|
CLIENT DATA
|
|
===================================================
|
|
| CLIENT KEY 0 4 bytes |
|
|
===================================================
|
|
===================================================
|
|
| CLIENT KEY 1 4 bytes |
|
|
===================================================
|
|
===================================================
|
|
| CLIENT KEY 2 4 bytes |
|
|
===================================================
|
|
===================================================
|
|
| CLIENT KEY 3 4 bytes |
|
|
===================================================
|
|
===================================================
|
|
| NOW 4 bytes |
|
|
===================================================
|
|
===================================================
|
|
| DAY 4 bytes |
|
|
===================================================
|
|
===================================================
|
|
| EXPORT 4 bytes |
|
|
===================================================
|
|
===================================================
|
|
| GAS 4 bytes |
|
|
===================================================
|
|
*/
|
|
type Energy struct {
|
|
CKey Response
|
|
Now float32
|
|
Day float32
|
|
Export float32
|
|
Gas float32
|
|
}
|
|
|
|
type Session struct {
|
|
CKey_p1 uint64
|
|
Ckey_p2 uint64
|
|
Header Header
|
|
Mpan uint64
|
|
State state
|
|
}
|