Skip to content

Commit

Permalink
restructure convertfunctions (#52)
Browse files Browse the repository at this point in the history
* Restructure README.md

* convertmodes are now in a table
* first steps to restructure convertmodes to external files, a cleaner
  interface

Signed-off-by: Malte Muench <[email protected]>

* All convertmethods with none-function

Signed-off-by: Malte Muench <[email protected]>

* Tiny steps to use convertfunctions via an interface

Signed-off-by: Malte Muench <[email protected]>

* Some stuff that should have happened earlier...

* Changed the default type for CAN-IDs to uint32 in all places
* Changed the default type for MQTT Payload to []byte
* Completely removed convert2CAN and convert2MQTT functions

* New type for mqtt payload in test

* Removes mockup _test files

* Second convertmode in new interface format

Signed-off-by: Malte Muench <[email protected]>

* Remove convertfunctions.go and fix log message

* Implemented convertmode uint82ascii

* Generic implementation for all uint*2ascii convertmodes

* Enable uint*2ascii convertmodes

* Adds new interfaced convertmode 2uint322ascii

Placed hint for myself to use strings.Fields instead of split

* Implement all uint convertmodes

Signed-off-by: Malte Muench <[email protected]>

* Convert modes of uint and int now en par

Signed-off-by: Malte Muench <[email protected]>

* New convertmode in interfaced-form bytecolor2colorcode

Signed-off-by: Malte Muench <[email protected]>

* Last convertmode implemented

Signed-off-by: Malte Muench <[email protected]>

* Removes helpers.go

Signed-off-by: Malte Muench <[email protected]>

* Adds e2e test state

Signed-off-by: Malte Muench <[email protected]>

* Updates readme

Signed-off-by: Malte Muench <[email protected]>

---------

Signed-off-by: Malte Muench <[email protected]>
Co-authored-by: Malte Muench <[email protected]>
  • Loading branch information
mxmxchere and Malte Muench authored May 6, 2024
1 parent 6f8f707 commit 966136b
Show file tree
Hide file tree
Showing 13 changed files with 878 additions and 512 deletions.
45 changes: 25 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,28 @@ Explanation for the 1st Line: For example our Doorstatus is published on the CAN

## convert-modes
Here they are:
### none
does not convert anything. It just takes a bunch of bytes and hands it over to the other side. If you want to send strings, this will be your choice.
### 16bool2ascii
Interprets two bytes can-wise and publishes them as 16 boolean values to mqtt
### uint82ascii / uint162ascii / uint322ascii / uint642ascii
On the can2mqtt way it takes 1, 2, 4 or 8 byte and interprets it as an uint of that size and parses it to a human readable string for the mqtt side. The other way round this convert motde takes an int in a string representation and sends out an array of bytes representing that number (little-endian)
### 2uint322ascii
This one is a bit special but all it does is that it takes 8 bytes from the CAN-Bus and parses two uint32s out of it and sends them in a string representation to MQTT. The two numbers are seperated with a simple space(" "). MQTT2CAN-wise it takes two string representations of numbers and converts them to 8 bytes representing them as 2 uint32.
### 4uint162ascii
Interprets eight bytes can-wise and publishes them as 4 uint16 seperated by a space to the mqtt side
### 4int162ascii
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
This mode was designed to adress colorized pixels. MQTT-wise you can insert a string like "<0-255> #RRGGBB" wich will be converted to 4 byte on the CAN-BUS the first byte will be the number of the LED 0-255 and bytes 1, 2, 3 are the color of red, green and blue.

| convertmode | description |
|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `none` | does not convert anything. It just takes a bunch of bytes and hands it over to the other side. If you want to send strings, this will be your choice. If you have a mqtt payload that is longer than eight bytes, only the first eight bytes will be send via CAN. |
| `bytecolor2colorcode` | Converts an bytearray of 3 bytes to hexadecimal colorcode |
| `pixelbin2ascii` | This mode was designed to adress colorized pixels. MQTT-wise you can insert a string like "<0-255> #RRGGBB" wich will be converted to 4 byte on the CAN-BUS the first byte will be the number of the LED 0-255 and bytes 1, 2, 3 are the color of red, green and blue. |
| `16bool2ascii` | Interprets two bytes can-wise and publishes them as 16 boolean values to mqtt |
| *uint* | |
| `uint82ascii` | one uint8 in the CAN-Frame to one uint8 as string in the mqtt payload |
| `4uint82ascii` | four uint8 in the CAN-Frame to four uint8 as string seperated by spaces in the mqtt payload. |
| `8uint82ascii` | eight uint8 in the CAN-Frame to eight uint8 as string seperated by spaces in the mqtt payload. |
| `uint162ascii` | one uint16 in the CAN-Frame to one uint16 as string in the mqtt payload |
| `4uint162ascii` | four uint16 in the CAN-Frame to four uint16 as string seperated by spaces in the mqtt payload. |
| `uint322ascii` | one uint32 in the CAN-Frame to one uint32 as string in the mqtt payload |
| `2uint322ascii` | two uint32 in the CAN-Frame to two uint32 as string seperated by spaces in the mqtt payload. |
| `uint642ascii` | one uint64 in the CAN-Frame to one uint64 as string in the mqtt payload |
| *int* | |
| `int82ascii` | one int8 in the CAN-Frame to one int8 as string in the mqtt payload |
| `4int82ascii` | four int8 in the CAN-Frame to four int8 as string seperated by spaces in the mqtt payload. |
| `8int82ascii` | eight int8 in the CAN-Frame to eight int8 as string seperated by spaces in the mqtt payload. |
| `int162ascii` | one int16 in the CAN-Frame to one int16 as string in the mqtt payload |
| `4int162ascii` | four int16 in the CAN-Frame to four int16 as string seperated by spaces in the mqtt payload. |
| `int322ascii` | one int32 in the CAN-Frame to one int32 as string in the mqtt payload |
| `2int322ascii` | two int32 in the CAN-Frame to two int32 as string seperated by spaces in the mqtt payload. |
| `int642ascii` | one int64 in the CAN-Frame to one int64 as string in the mqtt payload |
14 changes: 7 additions & 7 deletions e2e-test/e2e.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# Build
go build -C ../src -o ../e2e-test/can2mqtt
go build -C ../src -o ../e2e-test/can2mqtt || exit

# Setup Virtual CAN Interface
# TODO find something that does not require root privileges
Expand Down Expand Up @@ -29,16 +29,16 @@ mosquitto_sub -h localhost -v -t 'e2e-test/#' > logs/mqtt 2>&1 &
# Publish MQTT-Tests
mosquitto_pub -h localhost -m "test" -t e2e-test/none
mosquitto_pub -h localhost -m "0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 1" -t e2e-test/16bool2ascii
mosquitto_pub -h localhost -m "test" -t e2e-test/uint82ascii
mosquitto_pub -h localhost -m "test" -t e2e-test/uint162ascii
mosquitto_pub -h localhost -m "test" -t e2e-test/uint322ascii
mosquitto_pub -h localhost -m "test" -t e2e-test/uint642ascii
mosquitto_pub -h localhost -m "75" -t e2e-test/uint82ascii
mosquitto_pub -h localhost -m "35000" -t e2e-test/uint162ascii
mosquitto_pub -h localhost -m "2000000001" -t e2e-test/uint322ascii
mosquitto_pub -h localhost -m "123470851232" -t e2e-test/uint642ascii
mosquitto_pub -h localhost -m "0 123441234" -t e2e-test/2uint322ascii
mosquitto_pub -h localhost -m "12 89 1234 4" -t e2e-test/4uint162ascii
mosquitto_pub -h localhost -m "-1234 42 1243 2" -t e2e-test/4int162ascii
mosquitto_pub -h localhost -m "12 2 21 2" -t e2e-test/4uint82ascii
mosquitto_pub -h localhost -m "1 2 3 4 5 6 7 8" -t e2e-test/8uint82ascii
mosquitto_pub -h localhost -m "test" -t e2e-test/bytecolor2colorcode
mosquitto_pub -h localhost -m "#00ff00" -t e2e-test/bytecolor2colorcode
mosquitto_pub -h localhost -m "12 #00ff00" -t e2e-test/pixelbin2ascii

# Send CAN-Tests
Expand All @@ -53,7 +53,7 @@ cansend vcan0 "06b#ABCD"
cansend vcan0 "06c#ABCD"
cansend vcan0 "06d#ABCD"
cansend vcan0 "06e#ABCD"
cansend vcan0 "06f#ABCD"
cansend vcan0 "06f#ABCDEF"
cansend vcan0 "070#ABCD"

#
Expand Down
Loading

0 comments on commit 966136b

Please sign in to comment.