-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add instructions and mockup code how to create a custom convert-mode
Signed-off-by: Malte Muench <[email protected]>
- Loading branch information
Malte Muench
committed
Jun 18, 2024
1 parent
4b99e4d
commit 07071a6
Showing
3 changed files
with
83 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package convertfunctions | ||
|
||
import ( | ||
"errors" | ||
"github.com/brutella/can" | ||
) | ||
|
||
const mockErr string = "I am just mockup-code and not supposed to be actually used, implement something useful here" | ||
|
||
func YourModeToCan(input []byte) (can.Frame, error) { | ||
/* | ||
This is your area to create your convertMode (Receive MQTT, convert to CAN). | ||
You can find the payload of the received MQTT-Message | ||
in the []byte input. You can craft your returning can-Frame here. It does not make sense to set the ID, | ||
it will be overwritten. You can also return an error, the Frame is not sent in that case. | ||
As an example you could use the following code to implement the "none" convert-Mode. | ||
var returner [8]byte | ||
var i uint8 = 0 | ||
for ; int(i) < len(input) && i < 8; i++ { | ||
returner[i] = input[i] | ||
} | ||
return can.Frame{Length: i, Data: returner}, nil | ||
*/ | ||
return can.Frame{}, errors.New(mockErr) | ||
} | ||
|
||
func YourModeToMqtt(input can.Frame) ([]byte, error) { | ||
/* | ||
This is your area to create your convertMode (Receive CAN, convert to MQTT). | ||
You can find the received CAN-Frame in the can.Frame input. You can craft your returning MQTT-Payload here. | ||
You can also return an error, the MQTT-Message is not sent in that case. | ||
As an example you could use the following code to implement the "none" convert-Mode. | ||
return input.Data[:input.Length], nil | ||
*/ | ||
return []byte{}, errors.New(mockErr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters