Skip to content

Commit

Permalink
add IoT-LAB A8-M3 nodes support
Browse files Browse the repository at this point in the history
  • Loading branch information
fsaintma committed Feb 2, 2016
1 parent e57fa70 commit 7bff11f
Showing 1 changed file with 39 additions and 52 deletions.
91 changes: 39 additions & 52 deletions projects/common/01bsp_radio_rx/01bsp_radio_rx.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import struct
import socket
Expand All @@ -17,71 +20,55 @@
banner = '\n'.join(banner)
print banner

DEFAULT_IOTLAB = True
DEFAULT_MOTENAME = 'wsn430-35'
DEFAULT_SERIALPORT = 'COM10'

#============================ configuration ===================================

iotlab = None
motename = None
serialport = None

# iotlab

t = raw_input('running IoT-lAB? (Y|N): '.format(DEFAULT_IOTLAB))
if not t.strip():
iotlab = DEFAULT_IOTLAB
elif t.strip() in ['1','yes','y','Y']:
iotlab = True
else:
iotlab = False

# motename

if iotlab:
t = raw_input('motename? (e.g. {0}): '.format(DEFAULT_MOTENAME))
if not t.strip():
motename = DEFAULT_MOTENAME
else:
motename = t.strip()

# serialport

if not iotlab:
t = raw_input('name of serial port (e.g. {0}): '.format(DEFAULT_SERIALPORT))
if not t.strip():
serialport = DEFAULT_SERIALPORT
else:
serialport = t.strip()

#============================ connect =========================================

if iotlab:
assert motename
def mote_connect(motename=None , serialport= None, baudrate='115200'):
try:
mote = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mote.connect((motename,20000))
if (motename):
mote = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mote.connect((motename,20000))
else:
mote = serial.Serial(serialport, baudrate)
return mote
except Exception as err:
print 'could not connect to {0}, reason: {1}'.format(motename,err)
print "{0}".format(err)
raw_input('Press Enter to close.')
sys.exit(1)


#============================ configuration and connection ===================================

iotlab_serialport = False
motename = 'wsn430-35'
serialport = 'COM10'
mote = None

t = raw_input('Are you running on IoT-LAB nodes ? (Y|N): ')
if (not t.strip() or t.strip() in ['1','yes','y','Y']):
t = raw_input('Enter mote name ? (e.g. {0}): '.format(motename))
if t.strip():
motename = t.strip()
archi = motename.split('-')
assert len(archi) == 2
assert archi[0] in ['wsn430', 'a8', 'm3']
if (archi[0] != 'a8'):
iotlab_serialport = True
mote = mote_connect(motename=motename)
else:
mote = mote_connect(serialport='/dev/ttyA8_M3', baudrate='500000')

else:
assert serialport
try:
mote = serial.Serial(serialport,115200)
except Exception as err:
print 'could not open {0}, reason: {1}'.format(serialport,err)
raw_input('Press Enter to close.')
sys.exit(1)
t = raw_input('Enter serial port name (e.g. {0}): '.format(serialport))
if t.strip():
serialport = t.strip()
mote = mote_connect(serialport=serialport)

#============================ read ============================================

rawFrame = []

while True:

if iotlab:
if iotlab_serialport:
bytes = mote.recv(1024)
rawFrame += [ord(b) for b in bytes]
else:
Expand Down

0 comments on commit 7bff11f

Please sign in to comment.