Difference between revisions of "KNX contactless"
From OpenScience
| Line 1: | Line 1: | ||
| + | == WAV-Files == | ||
| + | |||
* [http://wwwiuk.informatik.uni-rostock.de/fileadmin/wwwiuk/download/Sample441.wav Sample WAV-File at 44.1kHz sampling frequency] The sound was sampled at 96kHz and than downsampled to 44.1kHz in order to make in playable on most sound cards. | * [http://wwwiuk.informatik.uni-rostock.de/fileadmin/wwwiuk/download/Sample441.wav Sample WAV-File at 44.1kHz sampling frequency] The sound was sampled at 96kHz and than downsampled to 44.1kHz in order to make in playable on most sound cards. | ||
* [http://wwwiuk.informatik.uni-rostock.de/fileadmin/wwwiuk/download/Sample.wav Sample WAV-File at 96kHz sampling frequency] | * [http://wwwiuk.informatik.uni-rostock.de/fileadmin/wwwiuk/download/Sample.wav Sample WAV-File at 96kHz sampling frequency] | ||
* [http://wwwiuk.informatik.uni-rostock.de/fileadmin/wwwiuk/download/Sample2.wav Sample WAV-File at 96kHz sampling frequency] | * [http://wwwiuk.informatik.uni-rostock.de/fileadmin/wwwiuk/download/Sample2.wav Sample WAV-File at 96kHz sampling frequency] | ||
| + | |||
| + | See [http://de.wikipedia.org/wiki/RIFF_WAVE] for information about the file format. | ||
| + | |||
| + | == Programm == | ||
| + | |||
| + | ''' | ||
| + | Created on 30.09.2013 | ||
| + | |||
| + | @author: thm | ||
| + | ''' | ||
| + | |||
| + | import struct | ||
| + | #f = open('/Users/thm/Downloads/test.raw', 'rb') | ||
| + | f = open('/Users/thm/Documents/workspace/KNX Forensics/Data/Sample3.wav', 'rb') | ||
| + | f.seek(46) | ||
| + | sample1 = 0 | ||
| + | sample2 = 0 | ||
| + | sample3 = 0 | ||
| + | lasti = 0 | ||
| + | decoded = '0' | ||
| + | ordered = '' | ||
| + | hexvalue = '' | ||
| + | telegrambytes = [] | ||
| + | i = 1 | ||
| + | while True: | ||
| + | sample1 = sample2 | ||
| + | sample2 = sample3 | ||
| + | buf = f.read(4) | ||
| + | if not buf: break | ||
| + | sample3 = struct.unpack('<f', buf)[0] | ||
| + | if sample1 < sample2: | ||
| + | if sample2 >= sample3: | ||
| + | if sample2 > 0.1: | ||
| + | samplessincelast = i - lasti | ||
| + | print i, sample2, samplessincelast, decoded | ||
| + | if (samplessincelast > 155) and (decoded != ''): | ||
| + | print 'Full telegram ', decoded, hex(int(decoded, 2)) | ||
| + | databits = '' | ||
| + | char = '' | ||
| + | symbol = '' | ||
| + | length = len(decoded) | ||
| + | if length > 11: | ||
| + | for pos in range(0,length): | ||
| + | symbol = symbol + decoded[pos] | ||
| + | if len(symbol) == 13: | ||
| + | startbit = symbol[0] | ||
| + | paritybit = symbol[9] | ||
| + | stopbit = symbol[10] | ||
| + | gap = symbol[11] + symbol[12] | ||
| + | for symbolpos in range(1,9): | ||
| + | databits = symbol[symbolpos] + databits | ||
| + | ordered = ordered + databits + ' ' | ||
| + | telegrambytes.append(databits) | ||
| + | hexvalue = hexvalue + hex(int(databits, 2)) + ' ' | ||
| + | print 'Symbol', symbol, 'Startbit', startbit, 'Databits (LSB first)', databits, 'Paritybit', paritybit, 'Stopbit', stopbit, 'Gap', gap | ||
| + | char = '' | ||
| + | symbol = '' | ||
| + | databits = '' | ||
| + | print 'Full Decoded Frame: ' + ordered + ' hex: ' + hexvalue | ||
| + | |||
| + | print | ||
| + | print telegrambytes[0], ' Control byte' | ||
| + | typeoftelegram = telegrambytes[0][0] + telegrambytes[0][1] | ||
| + | print typeoftelegram, ' ', | ||
| + | if typeoftelegram == '00': | ||
| + | print 'Extended Data Request' | ||
| + | elif typeoftelegram == '10': | ||
| + | print 'Data Request' | ||
| + | elif typeoftelegram == '11': | ||
| + | print 'Poll Data Request' | ||
| + | repeatedtelegram = telegrambytes[0][2] | ||
| + | print ' ', repeatedtelegram,' ', | ||
| + | if repeatedtelegram == '1': | ||
| + | print 'First transmission' | ||
| + | elif repeatedtelegram == '0': | ||
| + | print 'Retransmission' | ||
| + | fixedone = telegrambytes[0][3] | ||
| + | print ' ', fixedone, ' ', | ||
| + | if fixedone == '1': | ||
| + | print 'Fixed 1 - OK' | ||
| + | elif fixedone == '0': | ||
| + | print 'Fixed 1 - Error' | ||
| + | telegrampriority = telegrambytes[0][4] + telegrambytes[0][5] | ||
| + | print ' ', telegrampriority, ' ', | ||
| + | if telegrampriority == '11': | ||
| + | print 'Priority - Low' | ||
| + | elif telegrampriority == '01': | ||
| + | print 'Priority - High' | ||
| + | elif telegrampriority == '10': | ||
| + | print 'Priority - Alarm' | ||
| + | elif telegrampriority == '00': | ||
| + | print 'Priority - System' | ||
| + | fixedzeros = telegrambytes[0][6] + telegrambytes[0][7] | ||
| + | print ' ', fixedzeros, '', | ||
| + | if fixedzeros == '00': | ||
| + | print 'Fixed 00 - OK' | ||
| + | else: | ||
| + | print 'Fixed 00 - Error' | ||
| + | |||
| + | print | ||
| + | print telegrambytes[1], ' Source address - first byte' | ||
| + | area = telegrambytes[1][0] + telegrambytes[1][1] + telegrambytes[1][2] + telegrambytes[1][3] | ||
| + | areai = int(area,2) | ||
| + | print area, ' Area:', areai | ||
| + | line = telegrambytes[1][4] + telegrambytes[1][5] + telegrambytes[1][6] + telegrambytes[1][7] | ||
| + | linei = int(line,2) | ||
| + | print ' ', line, ' Line:', linei | ||
| + | print telegrambytes[2], ' Source address - second byte' | ||
| + | device = telegrambytes[2] | ||
| + | devicei = int(device,2) | ||
| + | print device, ' Device:', devicei | ||
| + | |||
| + | print | ||
| + | print telegrambytes[3], ' Destination address - first byte' | ||
| + | daf = telegrambytes[3][0] | ||
| + | print daf, ' ', | ||
| + | if daf == '0': | ||
| + | print 'Group address' | ||
| + | elif daf == '1': | ||
| + | print 'Physical address' | ||
| + | maingroup = telegrambytes[3][1] + telegrambytes[3][2] + telegrambytes[3][3] + telegrambytes[3][4] | ||
| + | maingroupi = int(maingroup,2) | ||
| + | print '', maingroup, ' Main group:', maingroupi | ||
| + | middlegroup = telegrambytes[3][5] + telegrambytes[3][6] + telegrambytes[3][7] | ||
| + | middlegroupi = int(middlegroup,2) | ||
| + | print ' ', middlegroup, ' Middle group:', middlegroupi | ||
| + | print telegrambytes[4], ' Destination address - second byte' | ||
| + | subgroup = telegrambytes[4] | ||
| + | subgroupi = int(subgroup,2) | ||
| + | print subgroup, ' Subgroup:', subgroupi | ||
| + | print | ||
| + | print 'Telegram:', areai, '.', linei, '.', devicei, ' ', maingroupi, '/', middlegroupi, '/', subgroupi | ||
| + | print | ||
| + | else: | ||
| + | print 'ACK / NOACK' | ||
| + | ordered = '' | ||
| + | decoded = '0' | ||
| + | hexvalue = '' | ||
| + | telegrambytes = [] | ||
| + | else: | ||
| + | num = (samplessincelast + 5) / 10 | ||
| + | if num > 1: | ||
| + | for j in range(1,num): | ||
| + | decoded = decoded + '1' | ||
| + | decoded = decoded + '0' | ||
| + | lasti = i | ||
| + | i = i + 1 | ||
| + | f.close | ||
Revision as of 15:15, 6 November 2013
WAV-Files
- Sample WAV-File at 44.1kHz sampling frequency The sound was sampled at 96kHz and than downsampled to 44.1kHz in order to make in playable on most sound cards.
- Sample WAV-File at 96kHz sampling frequency
- Sample WAV-File at 96kHz sampling frequency
See [1] for information about the file format.
Programm
Created on 30.09.2013 @author: thm
import struct
- f = open('/Users/thm/Downloads/test.raw', 'rb')
f = open('/Users/thm/Documents/workspace/KNX Forensics/Data/Sample3.wav', 'rb') f.seek(46) sample1 = 0 sample2 = 0 sample3 = 0 lasti = 0 decoded = '0' ordered = hexvalue = telegrambytes = [] i = 1 while True:
sample1 = sample2
sample2 = sample3
buf = f.read(4)
if not buf: break
sample3 = struct.unpack('<f', buf)[0]
if sample1 < sample2:
if sample2 >= sample3:
if sample2 > 0.1:
samplessincelast = i - lasti
print i, sample2, samplessincelast, decoded
if (samplessincelast > 155) and (decoded != ):
print 'Full telegram ', decoded, hex(int(decoded, 2))
databits =
char =
symbol =
length = len(decoded)
if length > 11:
for pos in range(0,length):
symbol = symbol + decoded[pos]
if len(symbol) == 13:
startbit = symbol[0]
paritybit = symbol[9]
stopbit = symbol[10]
gap = symbol[11] + symbol[12]
for symbolpos in range(1,9):
databits = symbol[symbolpos] + databits
ordered = ordered + databits + ' '
telegrambytes.append(databits)
hexvalue = hexvalue + hex(int(databits, 2)) + ' '
print 'Symbol', symbol, 'Startbit', startbit, 'Databits (LSB first)', databits, 'Paritybit', paritybit, 'Stopbit', stopbit, 'Gap', gap
char =
symbol =
databits =
print 'Full Decoded Frame: ' + ordered + ' hex: ' + hexvalue
print
print telegrambytes[0], ' Control byte'
typeoftelegram = telegrambytes[0][0] + telegrambytes[0][1]
print typeoftelegram, ' ',
if typeoftelegram == '00':
print 'Extended Data Request'
elif typeoftelegram == '10':
print 'Data Request'
elif typeoftelegram == '11':
print 'Poll Data Request'
repeatedtelegram = telegrambytes[0][2]
print ' ', repeatedtelegram,' ',
if repeatedtelegram == '1':
print 'First transmission'
elif repeatedtelegram == '0':
print 'Retransmission'
fixedone = telegrambytes[0][3]
print ' ', fixedone, ' ',
if fixedone == '1':
print 'Fixed 1 - OK'
elif fixedone == '0':
print 'Fixed 1 - Error'
telegrampriority = telegrambytes[0][4] + telegrambytes[0][5]
print ' ', telegrampriority, ' ',
if telegrampriority == '11':
print 'Priority - Low'
elif telegrampriority == '01':
print 'Priority - High'
elif telegrampriority == '10':
print 'Priority - Alarm'
elif telegrampriority == '00':
print 'Priority - System'
fixedzeros = telegrambytes[0][6] + telegrambytes[0][7]
print ' ', fixedzeros, ,
if fixedzeros == '00':
print 'Fixed 00 - OK'
else:
print 'Fixed 00 - Error'
print
print telegrambytes[1], ' Source address - first byte'
area = telegrambytes[1][0] + telegrambytes[1][1] + telegrambytes[1][2] + telegrambytes[1][3]
areai = int(area,2)
print area, ' Area:', areai
line = telegrambytes[1][4] + telegrambytes[1][5] + telegrambytes[1][6] + telegrambytes[1][7]
linei = int(line,2)
print ' ', line, ' Line:', linei
print telegrambytes[2], ' Source address - second byte'
device = telegrambytes[2]
devicei = int(device,2)
print device, ' Device:', devicei
print
print telegrambytes[3], ' Destination address - first byte'
daf = telegrambytes[3][0]
print daf, ' ',
if daf == '0':
print 'Group address'
elif daf == '1':
print 'Physical address'
maingroup = telegrambytes[3][1] + telegrambytes[3][2] + telegrambytes[3][3] + telegrambytes[3][4]
maingroupi = int(maingroup,2)
print , maingroup, ' Main group:', maingroupi
middlegroup = telegrambytes[3][5] + telegrambytes[3][6] + telegrambytes[3][7]
middlegroupi = int(middlegroup,2)
print ' ', middlegroup, ' Middle group:', middlegroupi
print telegrambytes[4], ' Destination address - second byte'
subgroup = telegrambytes[4]
subgroupi = int(subgroup,2)
print subgroup, ' Subgroup:', subgroupi
print
print 'Telegram:', areai, '.', linei, '.', devicei, ' ', maingroupi, '/', middlegroupi, '/', subgroupi
print
else:
print 'ACK / NOACK'
ordered =
decoded = '0'
hexvalue =
telegrambytes = []
else:
num = (samplessincelast + 5) / 10
if num > 1:
for j in range(1,num):
decoded = decoded + '1'
decoded = decoded + '0'
lasti = i
i = i + 1
f.close