Merge pull request #15 from ZeusWPI/ack-address

Ack address
This commit is contained in:
redfast00 2021-01-30 14:26:19 +01:00 committed by GitHub
commit 98e8c39ad8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 10 deletions

View file

@ -42,8 +42,9 @@ class Message:
def sender_id(self):
return (self.received_from >> 0) & 0b1111_1111
def human_readable_type(self):
return [('controller' if self.sender_id() == 0 else 'info'), 'puzzle', 'needy', 'RESERVED TYPE'][self.sender_type()]
@staticmethod
def human_readable_type(sender_type, sender_id):
return [('controller' if sender_id == 0 else 'info'), 'puzzle', 'needy', 'RESERVED TYPE'][sender_type]
def _parse_state_update(self):
timeleft = self.payload[1] << 0x18 | self.payload[2] << 0x10 | self.payload[3] << 0x08 | self.payload[4]
@ -58,7 +59,7 @@ class Message:
try:
if sender_type == 0b00 and self.sender_id() == 0: # controller
if message_type == 0:
return "ACK"
return f"ACK {Message.human_readable_type(self.payload[1], self.payload[2])} {self.payload[2]}"
elif message_type == 1:
return "HELLO"
elif message_type == 2:
@ -99,7 +100,7 @@ class Message:
'parsed': self.parse_message(),
'pretty_raw_sender_id': f'{self.priority_bit():01b} {self.sender_type():02b} {self.sender_id():08b}',
'raw_message': f"{self.payload.hex(' ')}",
'human_readable_type': self.human_readable_type(),
'human_readable_type': Message.human_readable_type(self.sender_type(), self.sender_id()),
'sender_id': self.sender_id(),
'internal_id': self.internal_id
}

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 ]
@ -64,10 +66,10 @@ Types for controller:
end time ↓ ↓ reserved
#strikes #max strikes
- 7 info start
- 7 info start
[ X B B B B B B B ]
--------------
reserved
reserved
- 8-255 reserved

View file

@ -37,6 +37,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;
@ -137,6 +138,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;
@ -188,6 +199,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;
};
};
@ -140,9 +142,10 @@ inline void _send_payld_gamestatus(
/**
* Send a controller "ACK" OBUS message
*/
inline void send_c_ack(struct module from) {
inline void send_c_ack(struct module from, struct module payload_address) {
assert(from.type == OBUS_TYPE_CONTROLLER);
struct message msg = _msg(from, false, OBUS_MSGTYPE_C_ACK);
msg.payload_address = payload_address;
send(&msg);
}
@ -200,6 +203,15 @@ inline void send_c_timeout(
from, false, OBUS_MSGTYPE_C_TIMEOUT, time_left, strikes, max_strikes);
}
/**
* Send a controller "info start" OBUS message
*/
inline void send_c_infostart(struct module from) {
assert(from.type == OBUS_TYPE_CONTROLLER);
struct message msg = _msg(from, false, OBUS_MSGTYPE_C_INFOSTART);
send(&msg);
}
/**
* Send a controller "strikeout" OBUS message
*/

View file

@ -157,7 +157,7 @@ void receive_hello() {
Serial.println(F("W Max # modules reached"));
}
obus_can::send_c_ack(this_module);
obus_can::send_c_ack(this_module, msg.from);
Serial.println(" ACK");
}