Process message receive
This commit is contained in:
parent
c19d05c64e
commit
59cce635c7
|
@ -777,26 +777,17 @@ void handle_message(const unsigned char source_mac[6], const unsigned char *data
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char mac[18];
|
// Type of event: Received a message
|
||||||
format_mac(source_mac, mac);
|
writeallx(1, "m", 1);
|
||||||
|
|
||||||
if (printf("%s (%" PRIu16 "): ", mac, msgid) == -1) {
|
// MAC
|
||||||
err(1, "printf");
|
writeallx(1, source_mac, 6);
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < message_length; i++) {
|
// Message length
|
||||||
if (putchar(message[i]) == EOF) {
|
writeallx_u16(1, message_length);
|
||||||
err(1, "putchar");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (putchar('\n') == EOF) {
|
// Message
|
||||||
err(1, "putchar");
|
writeallx(1, message, message_length);
|
||||||
}
|
|
||||||
|
|
||||||
if (fflush(stdout) == EOF) {
|
|
||||||
err(1, "fflush");
|
|
||||||
}
|
|
||||||
|
|
||||||
send_ack(source_mac, msgid);
|
send_ack(source_mac, msgid);
|
||||||
}
|
}
|
||||||
|
|
17
ethermess.py
17
ethermess.py
|
@ -19,6 +19,10 @@ def readall(f, length):
|
||||||
read.extend(data)
|
read.extend(data)
|
||||||
return bytes(read)
|
return bytes(read)
|
||||||
|
|
||||||
|
def readall_u16(f):
|
||||||
|
u16_bytes = readall(f, 2)
|
||||||
|
return (u16_bytes[1] << 8) | u16_bytes[0]
|
||||||
|
|
||||||
def parse_mac(text):
|
def parse_mac(text):
|
||||||
parts = text.split(':')
|
parts = text.split(':')
|
||||||
if len(parts) != 6:
|
if len(parts) != 6:
|
||||||
|
@ -88,9 +92,16 @@ def eventloop(proc):
|
||||||
|
|
||||||
elif event_type == b'i':
|
elif event_type == b'i':
|
||||||
# Msgid for message
|
# Msgid for message
|
||||||
msgid_bytes = readall(proc.stdout, 2)
|
msgid = readall_u16(proc.stdout);
|
||||||
msgid = (msgid_bytes[1] << 8) | msgid_bytes[0]
|
print('(msgid: %i)' % msgid) #debg
|
||||||
print('Msgid: %i' % msgid)
|
|
||||||
|
elif event_type == b'm':
|
||||||
|
# Message received
|
||||||
|
source_mac = readall(proc.stdout, 6)
|
||||||
|
message_length = readall_u16(proc.stdout)
|
||||||
|
message = readall(proc.stdout, message_length)
|
||||||
|
|
||||||
|
print('<%s> %s' % (format_mac(source_mac), message.decode('utf-8')))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Not sth we handle yet
|
# Not sth we handle yet
|
||||||
|
|
Loading…
Reference in New Issue