More organization - need to use the new flow for probing
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package packets
|
||||
|
||||
import "esdi/peripheral/communication/constvar"
|
||||
|
||||
type AckPacket struct {
|
||||
StartMarker byte
|
||||
AckByte byte
|
||||
EndMarker byte
|
||||
}
|
||||
|
||||
func (pkt *AckPacket) Validate() bool {
|
||||
if pkt.StartMarker != constvar.StartOfText ||
|
||||
pkt.EndMarker != constvar.EndOfText {
|
||||
return false
|
||||
}
|
||||
|
||||
if pkt.AckByte != constvar.ACK {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package packets
|
||||
|
||||
import (
|
||||
"esdi/peripheral/communication/constvar"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type IdentificationPacket struct {
|
||||
StartMarker byte
|
||||
DeviceID uint8
|
||||
PktType PacketType
|
||||
Name [32]byte
|
||||
EndMarker byte
|
||||
}
|
||||
|
||||
func (pkt *IdentificationPacket) Validate() bool {
|
||||
fmt.Println("↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓")
|
||||
fmt.Println(pkt.StartMarker)
|
||||
fmt.Println(pkt.PktType.String())
|
||||
fmt.Println(string(pkt.Name[:]))
|
||||
fmt.Println(pkt.EndMarker)
|
||||
fmt.Println("↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑")
|
||||
|
||||
// Change this to return an error and add a validation against available
|
||||
// device ids
|
||||
|
||||
if pkt.StartMarker != constvar.StartOfText ||
|
||||
pkt.EndMarker != constvar.EndOfText {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Package packets will define the available packets we have
|
||||
package packets
|
||||
|
||||
type Packet interface {
|
||||
Validate() bool
|
||||
}
|
||||
|
||||
type PacketType uint8
|
||||
|
||||
const (
|
||||
identificationPacket PacketType = iota
|
||||
)
|
||||
|
||||
const (
|
||||
identificationPacketStr = "identificationPacket"
|
||||
unknownPacketStr = "unknownPacket"
|
||||
)
|
||||
|
||||
func (p PacketType) String() string {
|
||||
switch p {
|
||||
case identificationPacket:
|
||||
return identificationPacketStr
|
||||
default:
|
||||
return unknownPacketStr
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user