-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from kendas/py3
Python 3 compatibility
- Loading branch information
Showing
20 changed files
with
472 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
*.pyc | ||
__pycache__ | ||
.idea | ||
.vscode | ||
dist | ||
moteconnection.egg-info | ||
*.egg-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: python | ||
python: | ||
# Python 2 | ||
- "2.7" | ||
# Python 3 | ||
- "3.5" | ||
- "3.6" | ||
- "3.7-dev" | ||
# - "3.7" | ||
# - "3.8-dev" | ||
install: | ||
- pip install -r requirements.txt | ||
script: | ||
- nosetests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Raido Pahtma <[email protected]> | ||
Kaarel Ratas <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# python-moteconnection | ||
|
||
Python library for using TinyOS inspired serial and tcp connections. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
""" | ||
This example sets up a connection and listens to all incoming packets. | ||
To run this example as a script, the following command: | ||
``` | ||
$ python -m example.sniffer sf@location:port | ||
``` | ||
""" | ||
from __future__ import print_function | ||
|
||
from argparse import ArgumentParser | ||
from functools import partial | ||
import logging | ||
import time | ||
|
||
from moteconnection.connection import Connection | ||
from moteconnection.message import MessageDispatcher | ||
|
||
|
||
def start_listen(connection_string): | ||
"""Begins listening for incoming packets.""" | ||
|
||
connection = construct_connection(connection_string) | ||
while 1: | ||
try: | ||
time.sleep(100) | ||
except (KeyboardInterrupt, SystemExit) as e: | ||
print("Received {!r}".format(e)) | ||
print("Shutting down") | ||
connection.disconnect() | ||
connection.join() | ||
break | ||
|
||
connection.disconnect() | ||
connection.join() | ||
|
||
|
||
def construct_connection(connection_string): | ||
""" | ||
Constructs the connection object and returns it. | ||
The connection string takes the form of protocol@location:port_or_baud | ||
Examples: sf@localhost:9002 | ||
serial@/dev/ttyUSB0 | ||
:param str connection string: A string in the form of protocol@location:port_or_baud | ||
:rtype: moteconnection.connection.Connection | ||
""" | ||
connection = Connection() | ||
connection.connect( | ||
connection_string, | ||
reconnect=10, | ||
connected=partial(print, "Connected to {}".format(connection_string)), | ||
disconnected=partial(print, "Disconnected from {}".format(connection_string)) | ||
) | ||
|
||
dispatcher = MessageDispatcher() | ||
# This example uses a callback function (print in this case). The callback function | ||
# _must_ take exactly 1 positional argument. That argument will be an instance of | ||
# `moteconnection.message.Message`. | ||
# The alternatice method to using a callback function is to pass an instance of | ||
# `queue.Queue` (python3) or `Queue.Queue` (python2) to these methoods. | ||
dispatcher.register_default_snooper(print) | ||
dispatcher.register_default_receiver(print) | ||
connection.register_dispatcher(dispatcher) | ||
return connection | ||
|
||
|
||
def get_args(): | ||
""" | ||
Parses the arguments and returns them. | ||
:rtype argparse.Namespace | ||
""" | ||
parser = ArgumentParser(description='An example moteconnection listening program.') | ||
parser.add_argument('connection', | ||
help="The connection string used to connect to the device. " | ||
"Can be a serial forwarder address or a serial device address.") | ||
parser.add_argument('--verbose', '-v', | ||
action='store_true', | ||
default=False, | ||
help='Verbose mode (displays moteconnection logs).') | ||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
"""Main entrypoint to the sniffer application.""" | ||
args = get_args() | ||
if args.verbose: | ||
logging.basicConfig(level=logging.DEBUG) | ||
start_listen(connection_string=args.connection) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
__license__ = "MIT" | ||
|
||
|
||
version = '0.1.7' | ||
version = '0.1.8' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.