Skip to content

Automating new captures

Très Acton edited this page May 25, 2017 · 3 revisions

Preparation

This was designed with RFCat in mind, however, it can be used with anything that you externally configure to dump the resulting binary to file. Note that this should be the binary in its state prior to demodulation and decoding. For example, if the signal is PWM 66/33 then DSpectrumGUI expects:

  • This: 100110100110
  • NOT This: 0101

DSpectrumGUI will watch the file: <application_root>/tmp/test_change.tmp

Configure your external script to replace the test_change.tmp file with the appropriate binary. Note that the binary should start on the first line and should not end with a newline (\n).

DSpectrumGUI will then copy those changes, and create a new Capture with the binary.

Navigate to DSpectrumGUI in your browser and make sure that a "Device" and a "Unit" have been created for the new captures. Make note of their ID numbers. E.g. navigate to the device, click on the name of a unit. In the URL, the number following the unit is the Unit ID. The Device ID is displayed on the page.

Launching the DSpectrumGUI automation helper

Open a terminal, navigate to the root folder of the application, and type:

rails c

This will open up a rails console shell. Now type:

# Cons.live_capture_seed_file <deivce id> <unit id> <name of capture>
Cons.live_capture_seed_file 12 27 "unlock"

The application will associate each new capture with the unit and device supplied. The name will automatically increment using the supplied name parameter as a prefix, e.g. unlock_1, unlock_2.

Now you can launch your external script in a new terminal window, which should capture the transmissions and store the binary in the watched file as described above.

Example external script with RFCat

#!/usr/bin/python
import binascii
from rflib import *

bits_per_symbol = 3
nb_bits = 66 
preamble_pulses = 12
header_bits = 10

def reframe_packet(p):
	raw_frame = ''.join('{0:08b}'.format(ord(x), 'b') for x in p)
	preamble = ('01' * preamble_pulses ) + ('0' * header_bits)
	try:
		preamble_index = raw_frame.index(preamble)
		frame = raw_frame[preamble_index+ len(preamble):preamble_index+ len(preamble) + nb_bits*bits_per_symbol]
		return frame
	except:
		print "preamble index not found"
		return ""


def good_packet(p):
	if len(p) == nb_bits * bits_per_symbol:
		return True
	else:
		print "Bad packet: " + len(p) + " bits"
		return False

def store_in_file(p):
	f = open("/Users/acton/dspectrum_gui/tmp/test_change.tmp", 'w')
	f.write(p)
	f.truncate()
	f.close()
	
print "Getting ready..."
d = RfCat();
d.setFreq(433920000)
d.setMdmModulation(MOD_ASK_OOK)
d.setMdmDRate(2600)
d.makePktFLEN(255) 
d.setMaxPower()
d.lowball()
d.setPktPQT(0)
d.setMdmSyncWord(0b1010101010101000)

while True:
	try:
		y, t = d.RFrecv(1)
		print y
		print "^^^^^ recv"
	
		# try:
		packet_bits = reframe_packet(y)
		if packet_bits != "":
			if good_packet(packet_bits):
				data = store_in_file(packet_bits)
			else:
				print_packet
				print "was a bad packet"
	except KeyboardInterrupt:
		break
	except ChipconUsbTimeoutException:
		pass

Clone this wiki locally