Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys
- from time import sleep
- import spi
- import Adafruit_BBIO.GPIO as GPIO
- myDev = "/dev/spidev1.0"
- def main():
- init()
- try:
- # print_config()
- for n in range (0, 200):
- test_tx("test single...", n)
- sleep(.01)
- spi.closeSPI()
- # print_config()
- finally:
- spi.closeSPI()
- set_power_down()
- GPIO.cleanup()
- ## Functions:
- def init():
- sys.stdout.write("[*] Initializing radio... ")
- GPIO.setup("P9_11", GPIO.OUT) # PWR - Power up chip. Active high.
- GPIO.setup("P9_13", GPIO.OUT) # TXEN - Transmit mode. Low for Recieve mode.
- GPIO.setup("P9_15", GPIO.OUT) # CE - Enable transciever. Active high.
- GPIO.setup("P9_12", GPIO.IN) # CD - Carrier detect. High when carrier present on tuned freq at greater than -95dBm.
- GPIO.setup("P9_14", GPIO.IN) # AM - Address match. High when packet header address field matches transciever address.
- GPIO.setup("P9_16", GPIO.IN) # DR - Data ready. High when data packet is recieved
- GPIO.output("P9_11", GPIO.LOW)
- GPIO.output("P9_13", GPIO.LOW)
- GPIO.output("P9_15", GPIO.LOW)
- set_stand_by()
- try:
- spi.openSPI(device=myDev, speed=10000000, mode=0)
- spi.transfer((0b00000000, 0b00100000, 0b00001011, 0b01000100, 0b01000100, 0b00000100, 0xff, 0xff, 0xff, 0xff, 0b11100111))
- print "done.\n"
- except:
- print "Failsauce! ", sys.exc_info()[0]
- finally:
- spi.closeSPI()
- def set_config(addr, val1, val2, desc):
- try:
- sys.stdout.write("[*] Changing config register[s]... ")
- set_stand_by()
- spi.openSPI(device=myDev, speed=10000, mode=0)
- spi.transfer((0b00000000^addr, val1, val2))
- print "done.\n"
- except:
- print "Failmobile! Could not "+desc, sys.exc_info()[0]
- finally:
- spi.closeSPI()
- def test_tx(desc, iter):
- try:
- # sys.stdout.write("["+str(iter)+"] Trying send payload...")
- set_stand_by()
- # Writing address, payload and config:
- spi.openSPI(device=myDev, speed=10000, mode=0)
- spi.transfer((0b00100010, 0b11011110, 0b10101101, 0b10111110, 0b11101111))
- spi.closeSPI()
- spi.openSPI(device=myDev, speed=10000, mode=0)
- # spi.transfer((0b00100000, 0b10111010, 0b10101101, 0b11110000, 0b00001101))
- spi.transfer((0b00100000, iter, iter, iter, iter))
- spi.closeSPI()
- spi.openSPI(device=myDev, speed=10000, mode=0)
- spi.transfer((0b00000000, 0b00011111, 0b00111111, 0b01000100, 0b01000100, 0b00000100, 0xca, 0xfe, 0xca, 0xfe, 0b11011111))
- spi.closeSPI()
- set_tx()
- while (not GPIO.input("P9_16")):
- continue
- except:
- print "Failmobile! Could not "+desc, sys.exc_info()[0]
- # finally:
- # print " done.\n"
- def print_config():
- try:
- set_stand_by()
- spi.openSPI(device=myDev, speed=10000, mode=0)
- print "[*] Reading config registers:"
- for offset in range (0b0000, 0b1010):
- bytes = spi.transfer((0b00010000^offset, 0b00010000^offset))
- sys.stdout.write(str("\t"+hex(offset)+": "+ '{:08b}'.format(bytes[1]))+": "+hex(bytes[1])+" \n")
- except:
- print "Could not read byte"
- finally:
- spi.closeSPI()
- print "done.\n"
- def set_power_down():
- GPIO.setup("P9_11", GPIO.OUT)
- GPIO.output("P9_11", GPIO.LOW)
- GPIO.setup("P9_13", GPIO.IN)
- GPIO.setup("P9_15", GPIO.IN)
- def set_stand_by():
- GPIO.setup("P9_11", GPIO.OUT)
- GPIO.output("P9_11", GPIO.HIGH)
- GPIO.setup("P9_13", GPIO.IN)
- GPIO.setup("P9_15", GPIO.OUT)
- GPIO.output("P9_15", GPIO.LOW)
- def set_read_rx():
- GPIO.setup("P9_11", GPIO.OUT)
- GPIO.output("P9_11", GPIO.HIGH)
- GPIO.setup("P9_13", GPIO.OUT)
- GPIO.output("P9_13", GPIO.LOW)
- GPIO.setup("P9_15", GPIO.IN)
- def set_rx():
- GPIO.setup("P9_11", GPIO.OUT)
- GPIO.output("P9_11", GPIO.HIGH)
- GPIO.setup("P9_13", GPIO.OUT)
- GPIO.output("P9_13", GPIO.LOW)
- GPIO.setup("P9_15", GPIO.OUT)
- GPIO.output("P9_15", GPIO.HIGH)
- def set_tx():
- GPIO.setup("P9_11", GPIO.OUT)
- GPIO.output("P9_11", GPIO.HIGH)
- GPIO.setup("P9_13", GPIO.OUT)
- GPIO.output("P9_13", GPIO.HIGH)
- GPIO.setup("P9_15", GPIO.OUT)
- GPIO.output("P9_15", GPIO.HIGH)
- ############################
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment