Skip to content

Commit

Permalink
Adds new convertmode 8uint82ascii
Browse files Browse the repository at this point in the history
Signed-off-by: Malte Münch <[email protected]>
  • Loading branch information
mxmxchere authored and Malte Muench committed Dec 19, 2023
1 parent 664dd92 commit 28f3ece
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Interprets eight bytes can-wise and publishes them as 4 uint16 seperated by a sp
Interprets eight bytes can-wise and publishes them as 4 int16 seperated by a space to the mqtt side
### 4uint82ascii
Interprets four bytes (byte 0, 2, 4 and 6) can-wise and publishes them as 4 uint8 seperated by a space to the mqtt side
### 8uint82ascii
Interprets eight bytes (byte 0 to 7) can-wise and publishes them as eight uint8 seperated by a space to the mqtt side. The other way around it expects eight bytes seperated by a space and publishes them as eight bytes on the can-side.
### bytecolor2colorcode
Converts an bytearray of 3 bytes to hexadecimal colorcode
### pixelbin2ascii
Expand Down
22 changes: 22 additions & 0 deletions convertfunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,23 @@ func convert2CAN(topic, payload string) can.Frame {
data[6] = tmp
data[7] = 0
length = 8
} else if convertMethod == "8uint82ascii" {
if dbg {
fmt.Printf("convertfunctions: using convertmode ascii28uint8(reverse of %s)\n", convertMethod)
}
nums := strings.Split(payload, " ")
if len(nums) != 8 {
fmt.Printf("Error, wrong number of bytes provided for convertmode 8uint82ascii, expected 8 got %d\n", len(nums))
}
data[0] = ascii2uint8(nums[0])
data[1] = ascii2uint8(nums[1])
data[2] = ascii2uint8(nums[2])
data[3] = ascii2uint8(nums[3])
data[4] = ascii2uint8(nums[4])
data[5] = ascii2uint8(nums[5])
data[6] = ascii2uint8(nums[6])
data[7] = ascii2uint8(nums[7])
length = 8
} else if convertMethod == "bytecolor2colorcode" {
if dbg {
fmt.Printf("convertfunctions: using convertmode colorcode2bytecolor(reverse of %s)\n", convertMethod)
Expand Down Expand Up @@ -230,6 +247,11 @@ func convert2MQTT(id int, length int, payload [8]byte) string {
fmt.Printf("convertfunctions: using convertmode 4uint82ascii\n")
}
return uint82ascii(payload[0]) + " " + uint82ascii(payload[2]) + " " + uint82ascii(payload[4]) + " " + uint82ascii(payload[6])
} else if convertMethod == "8uint82ascii" {
if dbg {
fmt.Printf("convertfunctions: using convertmode 8uint82ascii\n")
}
return uint82ascii(payload[0]) + " " + uint82ascii(payload[1]) + " " + uint82ascii(payload[2]) + " " + uint82ascii(payload[3]) + " " + uint82ascii(payload[4]) + " " + uint82ascii(payload[5]) + " " + uint82ascii(payload[6]) + " " + uint82ascii(payload[7])
} else if convertMethod == "pixelbin2ascii" {
if dbg {
fmt.Printf("convertfunctions: using convertmode pixelbin2ascii\n")
Expand Down

0 comments on commit 28f3ece

Please sign in to comment.