Skip to content

Commit 1e045ee

Browse files
Removal of SimulateSend & Code/Doc cleanup
1 parent 85ac631 commit 1e045ee

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ You can either specify all parameters during the initial setup of the library or
163163
|``Parse APRS Packet``|Parses the given APRS packet. In case the packet is either invalid or its format is unknown, an exception will be triggered|``aprs_packet``|
164164
|``Connect to APRS-IS``|Establishes a socket connection to the APRS-IS network| |
165165
|``Disconnect from APRS-IS``|Disconnects from the APRS-IS network| |
166-
|``Send APRS Packet``|Sends a raw APRS packet to APRS-IS in case an open connection to the APRS-IS network has been established|``packet`` and ``simulate_send`` (bool)|
166+
|``Send APRS Packet``|Sends a raw APRS packet to APRS-IS in case an open connection to the APRS-IS network has been established|``packet`` (string)|
167167
|``Receive APRS Packet``|Receives an APRS packet to APRS-IS in case an open connection to the APRS-IS network has been established. The default setting uses the parameter values ``immortal`` = ``True`` and ``raw``= ``False``, meaning that aprslib will try to re-establish the connection in case it is lost and will also auto-decode APRS packets when received|``immortal`` and ``raw`` (both boolean params)|
168168
|``Get <field name> Value from APRS Packet``|various wrappers; e.g. ``Get Message Text Value From APRS Packet`` will return the decoded message string if it is present in the message|``aprs_packet``. If you specify a field that does not exit in the packet, this keyword will cause an error. Both raw and decoded messages are supported.|
169169
|``Get Value From APRS Packet``|called by the aporementioned ``Get <field name> Value fron APRS Packet`` functions |``aprs_packet`` and ``field_name``. If you specify a field that does not exit in the packet, this keyword will cause an error. Both raw and decoded messages are supported.|

src/AprsLibrary.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,15 @@ def connect_aprsis(self):
334334
# Finally, connect to APRS-IS
335335
self.ais.connect(blocking=True)
336336

337+
# Are we connected? If not, then properly destroy what we
338+
# may have gathered as data and raise an error
337339
if not self.ais._connected:
338340
disconnect_aprsis(self)
339341
raise ConnectionError(
340342
f"Cannot connect to APRS-IS with server {self.aprsis_server} port {self.aprsis_port} callsign {self.aprsis_callsign}"
341343
)
344+
345+
# Yay - we made it. Return the object to the user.
342346
logger.debug(msg="Successfully connected to APRS-IS")
343347
return self.ais
344348

@@ -364,24 +368,25 @@ def get_aprs_configuration(self):
364368
}
365369
return myvalues
366370

371+
# Send an APRS-packet to APRS-IS. There is no sanity check
372+
# on the data provided to this function - everything
373+
# is sent 'as is'
367374
@keyword("Send APRS Packet")
368-
def send_aprs_packet(self, packet: str, simulate_send: bool = False):
369-
if not simulate_send:
370-
# Are we connected?
371-
if not self.ais:
372-
raise ConnectionError("Not connected to APRS-IS; cannot send packet")
373-
logger.debug(msg=f"Sending message '{packet}' to APRS-IS")
374-
375-
# Try to send data to the socket
376-
try:
377-
self.ais.sendall(packet)
378-
except:
379-
raise ConnectionError(
380-
f"Error while sending message '{packet}' to APRS-IS"
381-
)
382-
else:
383-
# just pretend that we send something to the socket
384-
logger.debug(msg=f"Simulate message 'Send' of message '{packet}'")
375+
def send_aprs_packet(self, packet: str):
376+
# Are we connected?
377+
if not self.ais:
378+
raise ConnectionError("Not connected to APRS-IS; cannot send packet")
379+
380+
# We seem to be connected
381+
logger.debug(msg=f"Sending message '{packet}' to APRS-IS")
382+
383+
# Try to send data to the socket
384+
try:
385+
self.ais.sendall(packet)
386+
except:
387+
raise ConnectionError(
388+
f"Error while sending message '{packet}' to APRS-IS"
389+
)
385390

386391
@keyword("Receive APRS Packet")
387392
def receive_aprs_packet(self, immortal: bool = True, raw: bool = False):
@@ -454,6 +459,12 @@ def get_msgno(self, aprs_packet):
454459
aprs_packet=aprs_packet, field_name="msgNo"
455460
)
456461

462+
# This is the core function which will extract the requested
463+
# field name from our packet(s). The packet can either be in
464+
# raw format (str or bytes) OR decoded. If you try to access
465+
# a field that does not exist, this function will raise
466+
# an exception. Use the "check ..." methods if you want to
467+
# find out if a field exists or not.
457468
@keyword("Get Value From APRS Packet")
458469
def get_value_from_aprs_packet(self, aprs_packet, field_name):
459470
t_dict = type(dict())
@@ -537,6 +548,9 @@ def check_packet_msgno(self, aprs_packet):
537548
aprs_packet=aprs_packet, field_name="msgNo"
538549
)
539550

551+
# This is the core function which will check if a field exists
552+
# in our packet(s). The packet can either be in
553+
# raw format (str or bytes) OR decoded.
540554
@keyword("APRS Message should contain")
541555
def check_if_field_exists_in_packet(self, aprs_packet, field_name):
542556
t_dict = type(dict())
@@ -556,10 +570,8 @@ def check_if_field_exists_in_packet(self, aprs_packet, field_name):
556570

557571

558572
#
559-
# Internal functions that are not to be called by Robot keywords
573+
# Internal functions that are not to be called as Robot keywords
560574
#
561-
562-
563575
def get_alphanumeric_counter_value(numeric_counter: int):
564576
"""
565577
Calculates the alphanumeric two-character APRS-IS message counter

0 commit comments

Comments
 (0)