Notify frotend of Speak version packets
This commit is contained in:
parent
9a2efcce2e
commit
bd23f43cfa
|
@ -646,6 +646,29 @@ bool check_utf8(const unsigned char *data, size_t data_length, bool newline_tab_
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handle_speak_version(const unsigned char source_mac[6], const unsigned char *data, size_t data_length) {
|
||||||
|
if (data_length < 1) {
|
||||||
|
// Too short
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char version = data[0];
|
||||||
|
|
||||||
|
if (!check_padding(data, 1, data_length)) {
|
||||||
|
// Malformed padding
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type of event: Speak version
|
||||||
|
writeallx(1, "v", 1);
|
||||||
|
|
||||||
|
// MAC
|
||||||
|
writeallx(1, source_mac, 6);
|
||||||
|
|
||||||
|
// Version
|
||||||
|
writeallx(1, &version, 1);
|
||||||
|
}
|
||||||
|
|
||||||
void handle_status(const unsigned char source_mac[6], const unsigned char *data, size_t data_length) {
|
void handle_status(const unsigned char source_mac[6], const unsigned char *data, size_t data_length) {
|
||||||
if (data_length < 2) {
|
if (data_length < 2) {
|
||||||
// Too short
|
// Too short
|
||||||
|
@ -885,6 +908,10 @@ void process_frame(void) {
|
||||||
// Process the packet based on the version and packet type
|
// Process the packet based on the version and packet type
|
||||||
if (version == 0) {
|
if (version == 0) {
|
||||||
switch (packet_type) {
|
switch (packet_type) {
|
||||||
|
case EMT_SPEAK_VERSION:
|
||||||
|
handle_speak_version(source_mac, &frame[16], packet_length - 16);
|
||||||
|
break;
|
||||||
|
|
||||||
case EMT_STATUS_REQUEST:
|
case EMT_STATUS_REQUEST:
|
||||||
if (check_padding(&frame[16], 0, packet_length - 16)) {
|
if (check_padding(&frame[16], 0, packet_length - 16)) {
|
||||||
send_status(source_mac);
|
send_status(source_mac);
|
||||||
|
|
|
@ -435,7 +435,14 @@ def eventloop(proc):
|
||||||
for fd, event in poll.poll(wait):
|
for fd, event in poll.poll(wait):
|
||||||
if fd == proc.stdout.fileno() and event & select.POLLIN:
|
if fd == proc.stdout.fileno() and event & select.POLLIN:
|
||||||
event_type = readall(proc.stdout, 1)
|
event_type = readall(proc.stdout, 1)
|
||||||
if event_type == b's':
|
if event_type == b'v':
|
||||||
|
# Speak version
|
||||||
|
source_mac = readall(proc.stdout, 6)
|
||||||
|
version, = readall(proc.stdout, 1)
|
||||||
|
|
||||||
|
print('--- Speak version %s %i' % (format_mac(source_mac), version)) #debg
|
||||||
|
|
||||||
|
elif event_type == b's':
|
||||||
# Status
|
# Status
|
||||||
source_mac = readall(proc.stdout, 6)
|
source_mac = readall(proc.stdout, 6)
|
||||||
status, = readall(proc.stdout, 1)
|
status, = readall(proc.stdout, 1)
|
||||||
|
|
|
@ -70,6 +70,12 @@ Events
|
||||||
|
|
||||||
Frontend receives events from the backend.
|
Frontend receives events from the backend.
|
||||||
|
|
||||||
|
### Speak version
|
||||||
|
Format: 'v' + MAC + version (u8)
|
||||||
|
|
||||||
|
Generated when an EtherMess Speak version packet is received by the
|
||||||
|
backend.
|
||||||
|
|
||||||
### Status
|
### Status
|
||||||
Format: 's' + MAC + status + nick length in bytes (u8) + nick
|
Format: 's' + MAC + status + nick length in bytes (u8) + nick
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue