speed complete
This commit is contained in:
parent
9ca099ead4
commit
7d1069cf2c
30
speed.go
30
speed.go
@ -167,24 +167,26 @@ type Car struct {
|
|||||||
|
|
||||||
func (c *Car) hasTicket(one uint32, two uint32) bool {
|
func (c *Car) hasTicket(one uint32, two uint32) bool {
|
||||||
|
|
||||||
for i := one ; i <= two; i += 86400 {
|
start := uint32(float64(one) / 86400)
|
||||||
day := uint32(i / 86400)
|
stop := uint32(float64(two) / 86400)
|
||||||
_, ok := c.ticketDays[day]
|
for i := start; i <= stop; i+=1 {
|
||||||
|
_, ok := c.ticketDays[i]
|
||||||
if ok {
|
if ok {
|
||||||
fmt.Printf("ticket on %d for %s\n", day, c.plate)
|
fmt.Printf("ticket on %d for %s\n", i, c.plate)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
fmt.Printf("no ticket on %d for %s\n", day, c.plate)
|
fmt.Printf("no ticket on %d for %s\n", i, c.plate)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Car) markTicket(one uint32, two uint32) {
|
func (c *Car) markTicket(one uint32, two uint32) {
|
||||||
for i := one ; i <= two; i += 86400 {
|
start := uint32(float64(one) / 86400)
|
||||||
day := uint32(i / 86400)
|
stop := uint32(float64(two) / 86400)
|
||||||
fmt.Printf("setting ticket on %d for %s\n", day, c.plate)
|
for i := start; i <= stop; i+=1 {
|
||||||
c.ticketDays[day] = true
|
fmt.Printf("setting ticket on %d for %s\n", i, c.plate)
|
||||||
|
c.ticketDays[i] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,6 +368,10 @@ func (c *SpeedClient) receiver() {
|
|||||||
if err != nil { break }
|
if err != nil { break }
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
m := ErrorMessage{err.Error()}
|
||||||
|
c.q <- m
|
||||||
|
}
|
||||||
fmt.Printf("Client %d error %s\n", c.clientId, err)
|
fmt.Printf("Client %d error %s\n", c.clientId, err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Client %d closing\n", c.clientId)
|
fmt.Printf("Client %d closing\n", c.clientId)
|
||||||
@ -394,6 +400,9 @@ func (c *SpeedClient) hdlWantHeartbeat() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *SpeedClient) hdlIAmCamera() error {
|
func (c *SpeedClient) hdlIAmCamera() error {
|
||||||
|
if c.ctype != 0 {
|
||||||
|
return fmt.Errorf("wrong state")
|
||||||
|
}
|
||||||
c.ctype = 1
|
c.ctype = 1
|
||||||
var err error
|
var err error
|
||||||
c.camRoad, err = readU16(c.con)
|
c.camRoad, err = readU16(c.con)
|
||||||
@ -407,6 +416,9 @@ func (c *SpeedClient) hdlIAmCamera() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *SpeedClient) hdlIAmDispatch() error {
|
func (c *SpeedClient) hdlIAmDispatch() error {
|
||||||
|
if c.ctype != 0 {
|
||||||
|
return fmt.Errorf("wrong state")
|
||||||
|
}
|
||||||
c.ctype = 2
|
c.ctype = 2
|
||||||
numRoads, err := readU8(c.con)
|
numRoads, err := readU8(c.con)
|
||||||
if err != nil { return err }
|
if err != nil { return err }
|
||||||
|
@ -16,6 +16,11 @@ def heartbeat(s):
|
|||||||
dur = time() - start
|
dur = time() - start
|
||||||
print(f"heartbeat {dur:.2f}")
|
print(f"heartbeat {dur:.2f}")
|
||||||
|
|
||||||
|
|
||||||
|
def doublecam(s):
|
||||||
|
s.sendall(pack(">BHHH", 0x80,1,0,80))
|
||||||
|
s.sendall(pack(">BHHH", 0x80,1,0,80))
|
||||||
|
print("Dc", s.recv(1024))
|
||||||
def camera(s):
|
def camera(s):
|
||||||
s.sendall(pack(">BHHH", 0x80,1,0,80))
|
s.sendall(pack(">BHHH", 0x80,1,0,80))
|
||||||
s.sendall(b"\x20\x05snack" +pack(">I", 100000))
|
s.sendall(b"\x20\x05snack" +pack(">I", 100000))
|
||||||
@ -36,6 +41,7 @@ def readTicket(d):
|
|||||||
|
|
||||||
|
|
||||||
heartbeat(sock())
|
heartbeat(sock())
|
||||||
|
doublecam(sock())
|
||||||
camera(sock())
|
camera(sock())
|
||||||
camera2(sock())
|
camera2(sock())
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user