Skip to content

Commit

Permalink
fixed size and mos for hep
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovikov committed Nov 7, 2024
1 parent 8ec6d59 commit 312a3a7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ type Packet struct {
Payload []byte
CID []byte
Vlan uint16
Mos uint16
TCPFlag uint8
IPTos uint8
}

// HEP chuncks
Expand Down
51 changes: 50 additions & 1 deletion publish/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const (
CID = 17 // Chunk 0x0011 Correlation ID
Vlan = 18 // Chunk 0x0012 VLAN
NodeName = 19 // Chunk 0x0013 NodeName
TCPFlag = 23 // Chunk 0x0017 TCP Flags
IPTos = 24 // Chunk 0x0018 IP TOS
Mos = 32 // Chunk 0x0020 MOS

)

// HepMsg represents a parsed HEP packet
Expand All @@ -50,6 +54,9 @@ type HepMsg struct {
CID []byte
Vlan uint16
NodeName string
Mos uint16
TCPFlag uint8
IPTos uint8
}

// EncodeHEP creates the HEP Packet which
Expand All @@ -72,6 +79,9 @@ func EncodeHEP(h *decoder.Packet) (hepMsg []byte, err error) {
CID: h.CID,
Vlan: h.Vlan,
NodeName: config.Cfg.HepNodeName,
Mos: h.Mos,
TCPFlag: h.TCPFlag,
IPTos: h.IPTos,
}
hepMsg, err = hep.Marshal()
} else {
Expand Down Expand Up @@ -201,6 +211,24 @@ func (h *HepMsg) MarshalTo(dAtA []byte) (int, error) {
i += copy(dAtA[i:], h.NodeName)
}

if h.TCPFlag > 0 {
i += copy(dAtA[i:], []byte{0x00, 0x00, 0x00, 0x17, 0x00, 0x07})
dAtA[i] = h.TCPFlag
i++
}

if h.IPTos > 0 {
i += copy(dAtA[i:], []byte{0x00, 0x00, 0x00, 0x18, 0x00, 0x07})
dAtA[i] = h.IPTos
i++
}

if h.Mos > 0 {
i += copy(dAtA[i:], []byte{0x00, 0x00, 0x00, 0x20, 0x00, 0x08})
binary.BigEndian.PutUint16(dAtA[i:], h.Mos)
i += 2
}

if h.Payload != nil {
i += copy(dAtA[i:], []byte{0x00, 0x00, 0x00, 0x0f})
binary.BigEndian.PutUint16(dAtA[i:], 6+uint16(len(h.Payload)))
Expand Down Expand Up @@ -239,6 +267,18 @@ func (h *HepMsg) Size() (n int) {
n += 4 + 2 + len(h.NodeName) // len(vendor) + len(chunk) + len(NodeName)
}

if h.TCPFlag > 0 {
n += 4 + 2 + 1 // len(vendor) + len(chunk) + len(TCPFlag)
}

if h.IPTos > 0 {
n += 4 + 2 + 1 // len(vendor) + len(chunk) + len(IPTos)
}

if h.Mos > 0 {
n += 4 + 2 + 2 // len(vendor) + len(chunk) + len(Mos)
}

if h.Payload != nil {
n += 4 + 2 + len(h.Payload) // len(vendor) + len(chunk) + len(Payload)
}
Expand Down Expand Up @@ -328,6 +368,12 @@ func (h *HepMsg) parseHEP(packet []byte) error {
h.CID = chunkBody
case Vlan:
h.Vlan = binary.BigEndian.Uint16(chunkBody)
case Mos:
h.Mos = binary.BigEndian.Uint16(chunkBody)
case TCPFlag:
h.TCPFlag = chunkBody[0]
case IPTos:
h.IPTos = chunkBody[0]
case NodeName:
h.NodeName = string(chunkBody)
default:
Expand All @@ -354,7 +400,10 @@ func (h *HepMsg) String() string {
`NodeID:` + fmt.Sprintf("%v", h.NodeID) + `,`,
`NodePW:` + fmt.Sprintf("%s", h.NodePW) + `,`,
`CID:` + fmt.Sprintf("%s", h.CID) + `,`,
`Vlan:` + fmt.Sprintf("%v", h.Vlan),
`Vlan:` + fmt.Sprintf("%v", h.Vlan) + `,`,
`Mos:` + fmt.Sprintf("%v", h.Mos) + `,`,
`IPTos:` + fmt.Sprintf("%v", h.IPTos) + `,`,
`TCPFlags:` + fmt.Sprintf("%v", h.TCPFlag),
`}`,
}, "")
return s + " with Payload:\n" + fmt.Sprintf("%s", string(h.Payload))
Expand Down

0 comments on commit 312a3a7

Please sign in to comment.