Skip to content

Commit 61d29a5

Browse files
New 'receive' example + bug fixes
1 parent bb2fde9 commit 61d29a5

File tree

2 files changed

+83
-34
lines changed

2 files changed

+83
-34
lines changed

src/AprsLibrary.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2020
#
2121

22-
2322
from robot.api.deco import library, keyword
2423
from robot.api.logger import librarylogger as logger
2524
import aprslib
@@ -31,7 +30,7 @@
3130
)
3231
logger = logging.getLogger(__name__)
3332

34-
__version__ = "0.3.3"
33+
__version__ = "0.4.0"
3534
__author__ = "Joerg Schultze-Lutter"
3635

3736

@@ -463,11 +462,14 @@ def get_msgno(self, aprs_packet):
463462
# find out if a field exists or not.
464463
@keyword("Get Value From APRS Packet")
465464
def get_value_from_aprs_packet(self, aprs_packet, field_name):
466-
valid_message_types = [type(dict), type(str), type(byte)]
467-
if type(aprs_packet) not in valid_message_types:
468-
raise TypeError("This does not look like a valid APRS message type")
465+
t_str = type("")
466+
t_dict = type({})
467+
t_bytes = type(b'')
469468

470-
if type(aprs_packet) == t_str or type(aprs_packet) == t_byte:
469+
if type(aprs_packet) not in [t_str, t_dict, t_bytes]:
470+
raise TypeError(f"This packet does not look like a valid APRS message type: {type(aprs_packet)}")
471+
472+
if type(aprs_packet) == t_str or type(aprs_packet) == t_bytes:
471473
packet = self.parse_aprs_packet(aprs_packet=aprs_packet)
472474
if type(packet) == t_dict:
473475
if field_name in packet:
@@ -545,11 +547,14 @@ def check_packet_msgno(self, aprs_packet):
545547
# raw format (str or bytes) OR decoded.
546548
@keyword("Check If APRS Packet Contains")
547549
def check_if_field_exists_in_packet(self, aprs_packet, field_name):
548-
valid_message_types = [type(dict), type(str), type(byte)]
549-
if type(aprs_packet) not in valid_message_types:
550+
t_str = type("")
551+
t_dict = type({})
552+
t_bytes = type(b'')
553+
554+
if type(aprs_packet) not in [t_str, t_dict, t_bytes]:
550555
raise TypeError("This does not look like a valid APRS message type")
551556

552-
if type(aprs_packet) == t_str or type(aprs_packet) == t_byte:
557+
if type(aprs_packet) == t_str or type(aprs_packet) == t_bytes:
553558
packet = self.parse_aprs_packet(aprs_packet=aprs_packet)
554559
if type(packet) == t_dict:
555560
return True if field_name in packet else False

src/receive_and_send_single_packet.robot

Lines changed: 69 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,43 @@ ${filter} g/${callsign}*
2323
*** Test Cases ***
2424
Simple Receive-and-Respond Test Case
2525
[Documentation] Our 'master receiver' task
26-
# The current Robot Framework does not support WHILE loops. This is a still a
26+
# Robot Framework 4.x does not support WHILE loops. This is a still a
2727
# finite loop but as our goal is only to receive a single message, this
28-
# crude approach will do.
29-
Wait Until Keyword Succeeds 50x 0sec Receive Packet From APRS-IS
28+
# crude approach will do. Keep in mind that by default, the APRSLib is
29+
# queried in "blocked" mode, meaning that we don't need any retries etc.
30+
#
31+
# The current setup will accept up to 10 messages, confirm them whereas
32+
# necessary and send a pesonalized response. After processing these 10
33+
# messages, the test will stop its execution
34+
Wait Until Keyword Succeeds 10x 0sec Receive Packet From APRS-IS
3035

3136
*** Keywords ***
3237

3338
Receive packet from APRS-IS
3439
[Documentation] VERY simplified ack-and-respond-to-message test case. Sends ack & msg to user, then terminates the test
40+
41+
# Get the packet from APRS-IS
3542
Log Receive message from APRS-IS
3643
${packet} = Receive APRS Packet
3744

45+
Log To Console Receive complete
46+
47+
# check what we have received so far
3848
${format_string}= Get Format Value From APRS Packet ${packet}
39-
Run Keyword If '${format_string}' != 'message' Fail msg=Packet format is not 'message'; start new loop
40-
41-
${from_string}= Get From Value From APRS Packet ${packet}
42-
${adresse_string}= Get Adresse Value From APRS Packet ${packet}
43-
${msgtext_string}= Get Message Text Value From APRS Packet ${packet}
4449

45-
# The msgno might not be present for unconfirmed messsages. A failure to extract the msgno
46-
# simply triggers a new WUKS loop. After all, this is a VERY very simplified library demo.
47-
#
48-
# Therefore, I don't care about this case and simply expect to receive a message with a
49-
# msgno present. Additionally, keep in mind that alphanumeric message number qualifiers
50-
# are currently not parsed by the aprslib library.
51-
${msgno_string}= Get Message Number Value From APRS Packet ${packet}
50+
# and handle response/message formats
51+
Run Keyword If '${format_string}' == 'response' Process APRS Response MYPACKET=${packet}
52+
Run Keyword If '${format_string}' == 'message' Process APRS Message MYPACKET=${packet}
5253

53-
# If we have received an ack or a rej, we simply ignore the message and start anew
54-
Run Keyword If '${msgtext_string}' == 'ack' Fail msg=Ignoring ack, start new loop
55-
Run Keyword If '${msgtext_string}' == 'rej' Fail msg=Ignoring rej, start new loop
54+
Log To Console And we're done
5655

57-
# show the user what we have received
58-
Log To Console I have received '${msgtext_string}'
56+
Send Acknowledgment
57+
[Documentation] Send an acknowledgement in case the incoming message
58+
[Arguments] ${MYPACKET}
59+
60+
${from_string}= Get From Value From APRS Packet ${MYPACKET}
61+
${adresse_string}= Get Adresse Value From APRS Packet ${MYPACKET}
62+
${msgno_string}= Get Message Number Value From APRS Packet ${MYPACKET}
5963

6064
# Send the ack
6165
# build the ack based on the incoming message number
@@ -65,21 +69,61 @@ Receive packet from APRS-IS
6569
Send Packet to APRS-IS ${ackmsg}
6670

6771
# do not flood the APRS-IS network
68-
Sleep 2sec
72+
Log To Console Sleep 5 secs
73+
Sleep 5sec
74+
75+
Process APRS Message
76+
[Documentation] Process an APRS Message (format type: 'messsage')
77+
[Arguments] ${MYPACKET}
78+
79+
Log To Console Processing an APRS 'message' packet
80+
81+
# show the user what we have received
82+
Log To Console I have received '${MYPACKET}' from APRS-IS
6983

70-
# Send the actual message
84+
# Send an acknowledgment in case we have received a message containing a message number
85+
${msgno_present}= Check If APRS Packet Contains Message Number ${MYPACKET}
86+
Log To Console Message contains a message number: ${msgno_present}
87+
88+
Run Keyword If '${msgno_present}' == '${True}' Send Acknowledgment MYPACKET=${MYPACKET}
89+
90+
# Extract some fields from the original message
91+
${from_string}= Get From Value From APRS Packet ${MYPACKET}
92+
${adresse_string}= Get Adresse Value From APRS Packet ${MYPACKET}
93+
94+
# Send the response message
7195
# Get a message number from the library
7296
${mymsgno}= Get APRS MsgNo As Alphanumeric Value
97+
7398
# Increment the library's message number (not really necessary here as we only deal with one message)
7499
Increment APRS MsgNo
100+
75101
# build the final string
76102
${msg}= Format String {}>APRS::{:9}:{} {}{} ${adresse_string} ${from_string} Hello ${from_string} , your Robot Overlords send greetings!
77-
${msg}= Catenate SEPARATOR= ${msg} { ${mymsgno}
103+
104+
# our response will always contain a message number, even though the incoming message had none
105+
# Remember that this is just a simple demo script
106+
${msg}= Catenate SEPARATOR= ${msg} { ${mymsgno}
107+
78108
# and send the message to APRS-IS
79-
Log To Console Sending actual message '${msg}'
109+
Log To Console Sending response message '${msg}' to APRS-IS
80110
Send Packet to APRS-IS ${msg}
81111

82-
Log To Console And we're done
112+
# Since we do not intentionally fail this command sequence, we will automatically break free from the encapsulating WUKS
113+
Log To Console Process APRS Message complete.
114+
115+
Process APRS Response
116+
[Documentation] Process an APRS Response (format type: 'response'). Causes a desired fail (thus causing another WUKS loop) in case an ack/rej has been received
117+
[Arguments] ${MYPACKET}
118+
119+
# At this point, we already know that there is a response present. Normally, this can only be an ack or a rej
120+
# but let's be sure about that and check the value
121+
${response_string} Get Response Value from APRS Packet ${MYPACKET}
122+
123+
# If we have received an ack or a rej, we simply ignore the message and start anew
124+
Run Keyword If '${response_string}' == 'ack' Fail msg=Ignoring ack, start new loop
125+
Run Keyword If '${response_string}' == 'rej' Fail msg=Ignoring rej, start new loop
126+
83127

84128
Send Packet to APRS-IS
85129
[Documentation] Send packet to APRS-IS

0 commit comments

Comments
 (0)