73 lines
1.2 KiB
Go
73 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
)
|
|
import "time"
|
|
|
|
const wiegand_a = 17
|
|
const wiegand_b = 18
|
|
const wiegand_bit_timeout = time.Millisecond * 8
|
|
const solenoid = 21
|
|
|
|
type card struct {
|
|
UidHash string `json:"uid_hash"`
|
|
}
|
|
|
|
type cardToken struct {
|
|
Token card `json:"token"`
|
|
}
|
|
|
|
type cardList struct {
|
|
AllowedUids []cardToken `json:"allowed_uids"`
|
|
}
|
|
|
|
type ValidUids map[string]bool // bool has no meaning
|
|
|
|
func main() {
|
|
|
|
wiegand := WiegandSetup(wiegand_a, wiegand_b, wiegand_bit_timeout, solenoid)
|
|
|
|
client := http.Client{}
|
|
req, err := http.NewRequest(http.MethodGet, "urlrul", nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
req.Header.Add("KEY", "keykey")
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
fmt.Printf("%v\n", resp)
|
|
|
|
var cl cardList
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
err = json.Unmarshal(body, &cl)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
validUids := make(ValidUids)
|
|
for i, val := range cl.AllowedUids {
|
|
fmt.Printf("%d: %+v\n", i, val.Token.UidHash)
|
|
validUids[val.Token.UidHash] = false
|
|
}
|
|
|
|
go wiegand.cardRunner(validUids)
|
|
|
|
fmt.Printf("Sleeping\n")
|
|
|
|
for {
|
|
time.Sleep(time.Second)
|
|
fmt.Printf(".")
|
|
}
|
|
}
|