Add ACK address to protocol, implement in obus_can

This commit is contained in:
redfast00 2020-09-11 21:10:47 +02:00
parent 2c994f2c60
commit b7fd5b404a
No known key found for this signature in database
GPG key ID: 5946E0E34FD0553C
3 changed files with 22 additions and 2 deletions

View file

@ -38,8 +38,10 @@ Types for controller:
- 0 acknowledge valid message
[ X B B B B B B B ]
--------------
reserved
- - ----------
| ↓ reserved
↓ module ID
type
- 1 hello
[ X B B B B B B B ]

View file

@ -36,6 +36,7 @@ uint8_t payload_type(uint8_t module_type, uint8_t module_id, uint8_t msg_type) {
if (module_type == OBUS_TYPE_CONTROLLER && module_id == OBUS_CONTROLLER_ID) {
switch (msg_type) {
case OBUS_MSGTYPE_C_ACK:
return OBUS_PAYLDTYPE_MODULEADDR;
case OBUS_MSGTYPE_C_HELLO:
return OBUS_PAYLDTYPE_EMPTY;
@ -140,6 +141,16 @@ bool receive(struct message *msg) {
msg->infomessage.len = data_len;
}
break;
case OBUS_PAYLDTYPE_MODULEADDR:
{
if (receive_frame.can_dlc < 3) {
Serial.println(F("W Received illegal count msg: payload <3"));
return false;
}
msg->payload_address.type = receive_frame.data[1];
msg->payload_address.id = receive_frame.data[2];
}
break;
default:
Serial.println(F("W Couldn't determine payload type"));
return false;
@ -194,6 +205,11 @@ void send(struct message *msg) {
length = msg->infomessage.len + 1;
break;
case OBUS_PAYLDTYPE_MODULEADDR:
send_frame.data[1] = msg->payload_address.type;
send_frame.data[2] = msg->payload_address.id;
break;
default:
Serial.print(F("E Unknown payload type "));
Serial.println(pyld_type);

View file

@ -35,6 +35,7 @@
#define OBUS_PAYLDTYPE_GAMESTATUS 1
#define OBUS_PAYLDTYPE_COUNT 2
#define OBUS_PAYLDTYPE_INFO 3
#define OBUS_PAYLDTYPE_MODULEADDR 4
#define OBUS_PAYLD_INFO_MAXLEN (OBUS_MSG_LENGTH - 1)
@ -66,6 +67,7 @@ struct message {
struct payld_gamestatus gamestatus;
uint8_t count;
struct payld_infomessage infomessage;
struct module payload_address;
};
};