├── libs ├── shock.py ├── i2c_lib.py ├── torturedevices.py ├── slaves.py ├── lcddriver.py ├── slave.py ├── torturedevice.py ├── punmqtt.py ├── slaveprogram.py ├── lib_oled96.py └── MFRC522.py ├── pics ├── bdsm.png ├── blow.png └── tens.png ├── fonts ├── FreeMono.ttf ├── FreeSans.ttf ├── FreeSerif.ttf ├── FreeMonoBold.ttf └── FreeSerifItalic.ttf ├── stripboard └── control-unit.png ├── config ├── config.ini └── config.ini.example ├── .gitignore ├── README.md ├── punisher.py ├── sql └── punisher.sql └── LICENSE /libs/shock.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pics/bdsm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PhilineGraystone/bdsm-trainer/HEAD/pics/bdsm.png -------------------------------------------------------------------------------- /pics/blow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PhilineGraystone/bdsm-trainer/HEAD/pics/blow.png -------------------------------------------------------------------------------- /pics/tens.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PhilineGraystone/bdsm-trainer/HEAD/pics/tens.png -------------------------------------------------------------------------------- /fonts/FreeMono.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PhilineGraystone/bdsm-trainer/HEAD/fonts/FreeMono.ttf -------------------------------------------------------------------------------- /fonts/FreeSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PhilineGraystone/bdsm-trainer/HEAD/fonts/FreeSans.ttf -------------------------------------------------------------------------------- /fonts/FreeSerif.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PhilineGraystone/bdsm-trainer/HEAD/fonts/FreeSerif.ttf -------------------------------------------------------------------------------- /fonts/FreeMonoBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PhilineGraystone/bdsm-trainer/HEAD/fonts/FreeMonoBold.ttf -------------------------------------------------------------------------------- /fonts/FreeSerifItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PhilineGraystone/bdsm-trainer/HEAD/fonts/FreeSerifItalic.ttf -------------------------------------------------------------------------------- /stripboard/control-unit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PhilineGraystone/bdsm-trainer/HEAD/stripboard/control-unit.png -------------------------------------------------------------------------------- /config/config.ini: -------------------------------------------------------------------------------- 1 | [database] 2 | hostname = localhost 3 | username = punisher 4 | password = punisher 5 | database = punisher 6 | 7 | [mqtt] 8 | hostname = 172.16.6.254 9 | username = punisher 10 | password = punisher 11 | -------------------------------------------------------------------------------- /config/config.ini.example: -------------------------------------------------------------------------------- 1 | [database] 2 | hostname = localhost 3 | username = punisher 4 | password = punisher 5 | database = punisher 6 | 7 | [mqtt] 8 | hostname = localhost 9 | username = punisher 10 | password = punisher 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | *.py[cod] 3 | *.egg-info/ 4 | .installed.cfg 5 | *.egg 6 | *.manifest 7 | *.spec 8 | pip-log.txt 9 | pip-delete-this-directory.txt 10 | htmlcov/ 11 | .tox/ 12 | .coverage 13 | .coverage.* 14 | .cache 15 | nosetests.xml 16 | coverage.xml 17 | *,cover 18 | *.mo 19 | *.pot 20 | *.log 21 | docs/_build/ 22 | target/ 23 | -------------------------------------------------------------------------------- /libs/i2c_lib.py: -------------------------------------------------------------------------------- 1 | import smbus 2 | from time import * 3 | 4 | class i2c_device: 5 | def __init__(self, addr, port=1): 6 | self.addr = addr 7 | self.bus = smbus.SMBus(port) 8 | 9 | # Write a single command 10 | def write_cmd(self, cmd): 11 | self.bus.write_byte(self.addr, cmd) 12 | sleep(0.0001) 13 | 14 | # Write a command and argument 15 | def write_cmd_arg(self, cmd, data): 16 | self.bus.write_byte_data(self.addr, cmd, data) 17 | sleep(0.0001) 18 | 19 | # Write a block of data 20 | def write_block_data(self, cmd, data): 21 | self.bus.write_block_data(self.addr, cmd, data) 22 | sleep(0.0001) 23 | 24 | # Read a single byte 25 | def read(self): 26 | return self.bus.read_byte(self.addr) 27 | 28 | # Read 29 | def read_data(self, cmd): 30 | return self.bus.read_byte_data(self.addr, cmd) 31 | 32 | # Read a block of data 33 | def read_block_data(self, cmd): 34 | return self.bus.read_block_data(self.addr, cmd) 35 | -------------------------------------------------------------------------------- /libs/torturedevices.py: -------------------------------------------------------------------------------- 1 | from torturedevice import torturedevice 2 | 3 | class torturedevices(): 4 | 5 | devices = {} 6 | functions = dict() 7 | 8 | def add_device( self, mqtt, model, device, ip, online ): 9 | if not device in self.devices.keys(): 10 | self.devices[ device ] = torturedevice( mqtt, model, device, ip, online ) 11 | 12 | def remove_device( self, device ): 13 | self.devices.pop( device, None ) 14 | 15 | def device_online( self, device ): 16 | if device in self.devices.keys(): 17 | return True 18 | else: 19 | return False 20 | 21 | def get_device( self, device ): 22 | if not device in self.devices.keys(): 23 | return False 24 | else: 25 | return self.devices[ device ] 26 | 27 | def count_devices(self): 28 | i = len( self.devices ) 29 | return i 30 | 31 | def set_response(self, device, response): 32 | if not device in self.devices.keys(): 33 | return False 34 | else: 35 | return self.devices[ device ].set_response( response ) 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WW6MCU8NV8CTG) 2 | 3 | # BDSM Trainer - Control Unit 4 | The BDSM Trainer (i.e. the control unit) is a Raspberry Pi and the software itself is written in Python3. As database server a MySQL server is used (in the beginning I tried it with SQLite, but it had problems with it all the time). 5 | 6 | I was inspired by the Fancy Steel Advanced Training Collar and thought that it could be built bigger. Of course some functions are also taken from the literature. 7 | 8 | So now the BDSM Trainer was created. Each slave has his own RFID card, with which the slave can log on to the trainer (or his dome). The control unit can process several slaves at the same time and train them completely separately. 9 | 10 | Currently the control unit supports the protocols IP/HTTP, IP/HTTPS and the 433 Mhz radio network. Originally the 433 Mhz network was only intended for the dog shock collar. At the moment I am using it to communicate with an Arduino, but it does not work very well. In the end the 433 radio network should only be there for the collar. 11 | 12 | What is still to come: 13 | * Integration of buttplug.io 14 | * Integration of shock collars 15 | * Other game modes 16 | * API for external app. 17 | * Many many devices to train the slave better 18 | * Saving a complex training plan 19 | * whatever else comes to mind. 20 | 21 | With pleasure I take up further ideas or can develop new ideas together ... 22 | 23 | # Required components 24 | 25 | * Raspberry 3+ or better (WLAN required) 26 | * LCD-i2c (as info screen) 27 | * XY-FST Sender or better (my recommendation: H34A) (433 Mhz sender) 28 | * XY-MK-5V Receiver or better (my recommendation: H3V4F) (433 Mhz receiver) 29 | * 128 x 64 OLED display 0,96" 30 | * RFID-RC522 (RFID Receiver) 31 | 32 | # Stripboard 33 | ![The stripboard](stripboard/control-unit.png) 34 | 35 | # Status 36 | Still under strong development, but functional 37 | 38 | # Disclaimer 39 | All devices listed here are for study purposes only. Please do not use them on living creatures. I take no responsibility if anything happens. And always remember, safety and health comes first. -------------------------------------------------------------------------------- /libs/slaves.py: -------------------------------------------------------------------------------- 1 | from slave import slave 2 | 3 | class slaves(): 4 | slaves = {} 5 | devices = [] 6 | 7 | def add_slave( self, mqtt, devices, slave_id, rfid, name, program, modes ): 8 | if not rfid in self.slaves.keys(): 9 | self.slaves[ rfid ] = slave( mqtt, devices, slave_id, name, rfid, program, modes ) 10 | 11 | def slave_online( self, rfid ): 12 | if rfid in self.slaves.keys(): 13 | return True 14 | else: 15 | return False 16 | 17 | def remove_slave( self, rfid ): 18 | self.slaves[ rfid ].disconnect() 19 | self.slaves.pop( rfid, None ) 20 | 21 | def count_slaves( self ): 22 | return len( self.slaves ) 23 | 24 | def add_device( self, rfid, device ): 25 | self.slaves[ rfid ].add_device( device ) 26 | 27 | def add_offline_device( self, rfid, device ): 28 | self.slaves[ rfid ].add_offline_device( device ) 29 | 30 | def execute_program(self): 31 | for slave in self.slaves.keys(): 32 | self.slaves[ slave ].execute() 33 | 34 | def torture_possible(self, rfid): 35 | for device in self.devices: 36 | if device['rfid'] == rfid: 37 | return True 38 | else: 39 | return False 40 | 41 | def get_modes( self, rfid ): 42 | for slave in self.persons: 43 | if slave['rfid'] == rfid: 44 | return slave['modes'] 45 | 46 | def get_id( self, rfid ): 47 | for slave in self.persons: 48 | if slave['rfid'] == rfid: 49 | return slave['id'] 50 | 51 | def which( self, dev ): 52 | for device in self.devices: 53 | if device['device'] == dev: 54 | return device['rfid'] 55 | return False 56 | 57 | 58 | def get_device( self, rfid ): 59 | dev = [] 60 | for device in self.devices: 61 | if device['rfid'] == rfid: 62 | dev.append( device ) 63 | return dev 64 | 65 | def all_slaves( self ): 66 | return self.persons 67 | 68 | 69 | def get_slave_id_from_offline_device(self, off_device): 70 | for slave in self.slaves.keys(): 71 | if self.slaves[ slave ].get_offline_device( off_device ) == True: 72 | self.slaves[ slave ].set_offline_device_as_online( off_device ) 73 | 74 | 75 | def set_online_device_to_offline(self, on_device): 76 | for slave in self.slaves.keys(): 77 | if self.slaves[ slave ].get_online_device( on_device ) == True: 78 | self.slaves[ slave ].set_online_device_as_offline( on_device ) 79 | -------------------------------------------------------------------------------- /libs/lcddriver.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append("./lib") 3 | 4 | import i2c_lib 5 | from time import * 6 | 7 | # LCD Address 8 | ADDRESS = 0x27 9 | 10 | # commands 11 | LCD_CLEARDISPLAY = 0x01 12 | LCD_RETURNHOME = 0x02 13 | LCD_ENTRYMODESET = 0x04 14 | LCD_DISPLAYCONTROL = 0x08 15 | LCD_CURSORSHIFT = 0x10 16 | LCD_FUNCTIONSET = 0x20 17 | LCD_SETCGRAMADDR = 0x40 18 | LCD_SETDDRAMADDR = 0x80 19 | 20 | # flags for display entry mode 21 | LCD_ENTRYRIGHT = 0x00 22 | LCD_ENTRYLEFT = 0x02 23 | LCD_ENTRYSHIFTINCREMENT = 0x01 24 | LCD_ENTRYSHIFTDECREMENT = 0x00 25 | 26 | # flags for display on/off control 27 | LCD_DISPLAYON = 0x04 28 | LCD_DISPLAYOFF = 0x00 29 | LCD_CURSORON = 0x02 30 | LCD_CURSOROFF = 0x00 31 | LCD_BLINKON = 0x01 32 | LCD_BLINKOFF = 0x00 33 | 34 | # flags for display/cursor shift 35 | LCD_DISPLAYMOVE = 0x08 36 | LCD_CURSORMOVE = 0x00 37 | LCD_MOVERIGHT = 0x04 38 | LCD_MOVELEFT = 0x00 39 | 40 | # flags for function set 41 | LCD_8BITMODE = 0x10 42 | LCD_4BITMODE = 0x00 43 | LCD_2LINE = 0x08 44 | LCD_1LINE = 0x00 45 | LCD_5x10DOTS = 0x04 46 | LCD_5x8DOTS = 0x00 47 | 48 | # flags for backlight control 49 | LCD_BACKLIGHT = 0x08 50 | LCD_NOBACKLIGHT = 0x00 51 | 52 | En = 0b00000100 # Enable bit 53 | Rw = 0b00000010 # Read/Write bit 54 | Rs = 0b00000001 # Register select bit 55 | 56 | class lcd: 57 | #initializes objects and lcd 58 | def __init__(self): 59 | self.lcd_device = i2c_lib.i2c_device(ADDRESS) 60 | 61 | self.lcd_write(0x03) 62 | self.lcd_write(0x03) 63 | self.lcd_write(0x03) 64 | self.lcd_write(0x02) 65 | 66 | self.lcd_write(LCD_FUNCTIONSET | LCD_2LINE | LCD_5x8DOTS | LCD_4BITMODE) 67 | self.lcd_write(LCD_DISPLAYCONTROL | LCD_DISPLAYON) 68 | self.lcd_write(LCD_CLEARDISPLAY) 69 | self.lcd_write(LCD_ENTRYMODESET | LCD_ENTRYLEFT) 70 | sleep(0.2) 71 | 72 | # clocks EN to latch command 73 | def lcd_strobe(self, data): 74 | self.lcd_device.write_cmd(data | En | LCD_BACKLIGHT) 75 | sleep(.0005) 76 | self.lcd_device.write_cmd(((data & ~En) | LCD_BACKLIGHT)) 77 | sleep(.0001) 78 | 79 | def lcd_write_four_bits(self, data): 80 | self.lcd_device.write_cmd(data | LCD_BACKLIGHT) 81 | self.lcd_strobe(data) 82 | 83 | # write a command to lcd 84 | def lcd_write(self, cmd, mode=0): 85 | self.lcd_write_four_bits(mode | (cmd & 0xF0)) 86 | self.lcd_write_four_bits(mode | ((cmd << 4) & 0xF0)) 87 | 88 | #turn on/off the lcd backlight 89 | def lcd_backlight(self, state): 90 | if state in ("on","On","ON"): 91 | self.lcd_device.write_cmd(LCD_BACKLIGHT) 92 | elif state in ("off","Off","OFF"): 93 | self.lcd_device.write_cmd(LCD_NOBACKLIGHT) 94 | else: 95 | print("Unknown State!") 96 | 97 | # put string function 98 | def lcd_display_string(self, string, line): 99 | if line == 1: 100 | self.lcd_write(0x80) 101 | if line == 2: 102 | self.lcd_write(0xC0) 103 | if line == 3: 104 | self.lcd_write(0x94) 105 | if line == 4: 106 | self.lcd_write(0xD4) 107 | 108 | for char in string: 109 | self.lcd_write(ord(char), Rs) 110 | 111 | # clear lcd and set to home 112 | def lcd_clear(self): 113 | self.lcd_write(LCD_CLEARDISPLAY) 114 | self.lcd_write(LCD_RETURNHOME) 115 | -------------------------------------------------------------------------------- /libs/slave.py: -------------------------------------------------------------------------------- 1 | from slaveprogram import slaveprogram 2 | 3 | class slave: 4 | slave_id = 0; 5 | slave_name = "" 6 | slave_rfid = "" 7 | slave_devices = [] 8 | slave_offline_devices = [] 9 | slave_program = "" 10 | slave_mode = "" 11 | 12 | mqtt = None 13 | devices = None 14 | 15 | def __init__(self, mqtt, devices, slave_id, slave_name, rfid, program, mode): 16 | self.mqtt = mqtt 17 | self.devices = devices 18 | 19 | self.slave_id = slave_id 20 | self.slave_name = slave_name 21 | self.slave_rfid = rfid 22 | self.slave_mode = mode 23 | self.slave_program = slaveprogram( self, program ) 24 | 25 | 26 | def add_device(self, device): 27 | self.slave_devices.append( device ) 28 | self.mqtt.publish("punisher/devices/"+device+"/settings", "{\"slave_id\": "+str(self.slave_id)+", \"slave_name\": \""+self.slave_name+"\"} "); 29 | 30 | def add_offline_device(self, device): 31 | self.slave_offline_devices.append( device ) 32 | 33 | def disconnect(self): 34 | for device in self.slave_devices: 35 | self.mqtt.publish("punisher/devices/"+device+"/settings", "{\"slave_id\": 0, \"slave_name\": \""+self.slave_name+"\"} "); 36 | 37 | def get_offline_device(self, off_device ): 38 | for device in self.slave_offline_devices: 39 | if device == off_device: 40 | return True 41 | return False 42 | 43 | def get_online_device(self, on_device ): 44 | for device in self.slave_devices: 45 | if device == on_device: 46 | return True 47 | return False 48 | 49 | 50 | def set_offline_device_as_online(self, off_device): 51 | self.remove_offline_device( off_device ) 52 | self.add_device( off_device ) 53 | 54 | def set_online_device_as_offline(self, on_device): 55 | self.remove_online_device( on_device ) 56 | self.add_offline_device( on_device ) 57 | 58 | def remove_offline_device(self, off_device ): 59 | self.slave_offline_devices.remove( off_device ) 60 | 61 | def remove_online_device(self, on_device ): 62 | self.slave_devices.remove( on_device ) 63 | 64 | def execute(self): 65 | self.slave_program.execute() 66 | 67 | def get_slave_name(self): 68 | return self.slave_name 69 | 70 | def get_slave_rfid(self): 71 | return self.slave_rfid 72 | 73 | def inital_settings(self): 74 | pass 75 | 76 | def shock(self, seconds, countdown): 77 | for device in self.slave_devices: 78 | self.devices.devices[ device ].shock( seconds, countdown ) 79 | 80 | def vibe(self): 81 | pass 82 | 83 | def piep(self): 84 | pass 85 | 86 | def stretch(self): 87 | pass 88 | 89 | def switch(self): 90 | pass 91 | 92 | def pet(self): 93 | for device in self.slave_devices: 94 | self.devices.devices[ device ].pet() 95 | 96 | def wlan_fence(self): 97 | for device in self.slave_devices: 98 | self.devices.devices[ device ].wlan_fence() 99 | 100 | def sleep_deprivation(self): 101 | for device in self.slave_devices: 102 | self.devices.devices[ device ].sleep_deprivation() 103 | 104 | def remote_control(self): 105 | for device in self.slave_devices: 106 | self.devices.devices[ device ].remote_control() 107 | 108 | def maglock(self, minutes): 109 | for device in self.slave_devices: 110 | self.devices.devices[ device ].maglock( minutes ) 111 | 112 | def collar_settings(self, shock, vibe, beep, duration): 113 | for device in self.slave_devices: 114 | self.devices.devices[ device ].collar_settings( shock, vibe, beep, duration ) 115 | 116 | 117 | def blowjob(self, wait, jobcount, punishment, delay): 118 | for device in self.slave_devices: 119 | self.devices.devices[ device ].blowjob( wait, jobcount, punishment, delay ) 120 | 121 | -------------------------------------------------------------------------------- /libs/torturedevice.py: -------------------------------------------------------------------------------- 1 | class torturedevice: 2 | func_shock = False 3 | func_vibe = False 4 | func_piep = False 5 | func_stretch = False 6 | func_switch = False 7 | func_lock = False 8 | func_blowjob = False 9 | 10 | mode_pet = False 11 | mode_wlan_fence = False 12 | mode_sleep_dep = False 13 | mode_remote = False 14 | 15 | device_collar = False 16 | 17 | uuid_device = "" 18 | uuid_model = "" 19 | uuid_name = "" 20 | ip_address = "" 21 | status = False 22 | 23 | mqtt = None 24 | 25 | owner = None 26 | registred = None 27 | last_response = None 28 | 29 | def __init__(self, mqtt, model, device, ip_address, status): 30 | self.mqtt = mqtt 31 | 32 | self.uuid_device = device 33 | self.uuid_model = model 34 | self.ip_address = ip_address 35 | self.status = status 36 | self.owner = False 37 | self.registered = False 38 | 39 | if model == "eaa4cae0-65d6-4cf2-80ef-d8d0f8e8f6f0": 40 | self.uuid_name = "Stretcher and Shocker" 41 | self.func_shock = True 42 | self.func_stretch = True 43 | 44 | if model == "73903cef-049d-4439-a9ab-f05825e0ef25": 45 | self.uuid_name = "Collar v1.0" 46 | self.func_shock = True 47 | self.func_vibe = True 48 | self.func_piep = True 49 | self.mode_pet = True 50 | self.mode_wlan_fence= True 51 | self.mode_sleep_dep = True 52 | self.mode_remote = True 53 | self.device_collar = True 54 | 55 | if model == "1acf784c-4bfd-4a06-b4ff-ee578a37fac4": 56 | self.func_lock = True 57 | 58 | if model == "4f1fb373-8cca-492b-a619-2e53318d2493": 59 | self.uuid_name = "Blowjob Trainer V2.0"; 60 | self.func_blowjob = True 61 | 62 | def get_device(self): 63 | return self.uuid_device 64 | 65 | def inital_settings(self): 66 | pass 67 | 68 | def shock(self, seconds, countdown): 69 | if self.func_shock == True: 70 | self.mqtt.publish('punisher/devices/'+str(self.uuid_device)+'/shock', '{"seconds": '+str(seconds)+', "countdown": '+str(countdown)+'}' ) 71 | 72 | def vibe(self): 73 | pass 74 | 75 | def piep(self): 76 | pass 77 | 78 | def stretch(self): 79 | pass 80 | 81 | def switch(self): 82 | pass 83 | 84 | def blowjob(self, wait, jobcounter, punishment, delay): 85 | if self.func_blowjob == True: 86 | self.mqtt.publish('punisher/devices/'+str(self.uuid_device)+'/blowjob', '{"wait": '+str(wait)+', "count": '+str(jobcount)+', "punishment": '+str(punishment)+', "delay": '+str(delay)+'}' ) 87 | 88 | def pet(self): 89 | if self.mode_pet == True: 90 | self.mqtt.publish('punisher/devices/'+str(self.uuid_device)+'/settings', '{"mode": 4}' ) 91 | 92 | def wlan_fence(self): 93 | if self.mode_wlan_fence == True: 94 | self.mqtt.publish('punisher/devices/'+str(self.uuid_device)+'/settings', '{"mode": 1}' ) 95 | 96 | def sleep_deprivation(self): 97 | if self.mode_sleep_dep == True: 98 | self.mqtt.publish('punisher/devices/'+str(self.uuid_device)+'/settings', '{"mode": 3}' ) 99 | 100 | def remote_control(self): 101 | if self.mode_remote == True: 102 | self.mqtt.publish('punisher/devices/'+str(self.uuid_device)+'/settings', '{"mode": 0}' ) 103 | 104 | def maglock(self, minutes): 105 | if self.func_lock == True: 106 | self.mqtt.publish('punisher/devices/'+str(self.uuid_device)+'/lock', '{"minutes": '+str(minutes)+'}' ) 107 | 108 | def collar_settings(self, shock, vibe, beep, duration): 109 | if self.device_collar == True: 110 | self.mqtt.publish('punisher/devices/'+str(self.uuid_device)+'/settings', '{"shock": '+str(shock)+', "vibe": '+str(vibe)+', "beep": '+str(beep)+', "duration": '+str(duration)+'}' ) 111 | 112 | def set_response(self, response): 113 | self.last_response = response 114 | 115 | def get_response(self): 116 | return self.last_response 117 | 118 | -------------------------------------------------------------------------------- /libs/punmqtt.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # coding=utf-8 3 | import paho.mqtt.client as paho 4 | import time 5 | 6 | #logger = object() 7 | 8 | 9 | class PunMQTT(paho.Client): 10 | tdevice = {} 11 | 12 | def on_connect(self, mqttc, obj, flags, rc): 13 | if rc == 0: 14 | self.logger.debug('MQTT: Connection successfully established') 15 | self.subscribe('punisher/devices/+/response',0) 16 | self.subscribe('punisher/devices/+/available',0) 17 | self.subscribe('punisher/devices/+/actionresponse',0) 18 | self.subscribe('$SYS/broker/uptime',0) 19 | elif rc == 1: 20 | self.logger.debug('MQTT: Connection successfully established') 21 | print("Wrong protocol version") 22 | cleanup() 23 | sys.exit(1) 24 | elif rc == 2: 25 | self.logger.debug('MQTT: Identification failed') 26 | print("Identification failed") 27 | cleanup() 28 | sys.exit(1) 29 | elif rc == 3: 30 | self.logger.debug('MQTT: Server not reachable') 31 | print("Server not reachable") 32 | cleanup() 33 | sys.exit(1) 34 | elif rc == 4: 35 | self.logger.debug('MQTT: User or password not correct') 36 | print("User or password not correct") 37 | cleanup() 38 | sys.exit(1) 39 | elif rc == 5: 40 | self.logger.debug('MQTT: Not authorized') 41 | print("Not authorized") 42 | cleanup() 43 | sys.exit(1) 44 | else: 45 | self.logger.debug('MQTT: Invalid return code') 46 | print("Invalid return code") 47 | cleanup() 48 | sys.exit(1) 49 | 50 | def on_message(self, mqttc, obj, msg): 51 | # print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload)) 52 | device = msg.topic.split('/') 53 | 54 | for ddevice in self.tdevice.keys(): 55 | if int( self.tdevice[ ddevice ][ 'timestamp' ] + 120 ) < int( time.time() ): 56 | self.logger.debug('MQTT: Remove a device (timeout):' + str( ddevice ) ) 57 | self.tdevice.pop( ddevice, None ) 58 | self.devices.remove_device( ddevice ) 59 | self.slaves.set_online_device_to_offline( ddevice ) 60 | 61 | if device[3] == "response": 62 | device = str( device[2] ) 63 | if device in self.tdevice.keys(): 64 | answer = msg.payload.decode("utf-8") 65 | if len( answer ) == 36: 66 | uuids = answer.split(',') 67 | self.devices.add_device( self, uuids[0], device, None, True ) 68 | self.tdevice[ device ] = {'timestamp': int( time.time() + 120), 'status': 'online' } 69 | self.slaves.get_slave_id_from_offline_device( device ) 70 | 71 | if device[3] == "available": 72 | device = str( device[2] ) 73 | if not device in self.tdevice.keys(): 74 | self.logger.debug('MQTT: Announce a new device:' + str( device ) ) 75 | self.publish('punisher/devices/'+str( device )+'/settings', '{"initial": "functions"}') 76 | self.tdevice[ device ] = {'timestamp': int(time.time() + 120), 'status': 'pending'} 77 | else: 78 | if self.tdevice[ device ][ 'status' ] is not 'pending': 79 | self.tdevice[ device ] = {'timestamp': int(time.time() + 120), 'status': 'online'} 80 | 81 | if device[3] == "actionresponse": 82 | device = str( device[2] ) 83 | if device in self.tdevice.keys(): 84 | answer = msg.payload.decode("utf-8") 85 | self.devices.set_response( ddevice, answer ) 86 | 87 | def on_publish(self, mqttc, obj, mid): 88 | self.logger.debug("MQTT - Published: "+str(mid)) 89 | 90 | def on_subscribe(self, mqttc, obj, mid, granted_qos): 91 | self.logger.debug("MQTT - Subscribed: "+str(mid)+" "+str(granted_qos)) 92 | 93 | def on_log(self, mqttc, obj, level, string): 94 | self.logger.debug("MQTT - FULLLOG: "+string) 95 | 96 | def run(self, config, logger, devices, db, slaves): 97 | self.logger = logger 98 | self.devices = devices 99 | self.cursor = db 100 | self.slaves = slaves 101 | 102 | self.username_pw_set( config['mqtt']['username'], config['mqtt']['password'] ) 103 | self.connect( config['mqtt']['hostname'], 1883, 60 ) 104 | self.loop_start() 105 | -------------------------------------------------------------------------------- /libs/slaveprogram.py: -------------------------------------------------------------------------------- 1 | from random import seed 2 | from random import random 3 | from random import randint 4 | from datetime import datetime 5 | 6 | class slaveprogram(): 7 | 8 | program = None 9 | slave = None 10 | stamp = None 11 | nextaction = None 12 | 13 | def __init__( self, slave, slaveprogram ): 14 | self.slave = slave 15 | self.program = slaveprogram 16 | self.stamp = datetime.timestamp( datetime.now() ) 17 | self.nextaction = datetime.timestamp( datetime.now() ) + 60 18 | 19 | self.execute() 20 | 21 | def execute( self ): 22 | if int( self.nextaction ) < int( datetime.timestamp( datetime.now() ) ): 23 | if len( self.program ) > 0: 24 | active = False 25 | if active == False and len( self.program ) > 0 and self.program[0][2] == "SHOCK": 26 | print( "Execute SHOCK" ) 27 | parameter = self.program[0][3].split('|') 28 | self.nextaction = int( datetime.timestamp( datetime.now() ) ) + int( parameter[0] ) + int( parameter[1] ) + 10 29 | self.slave.shock( parameter[0], parameter[1] ) 30 | active = True 31 | if len( self.program ) > 0: 32 | self.program = self.program[1:] 33 | 34 | if active == False and len( self.program ) > 0 and self.program[0][2] == "PET": 35 | print( "Switch to PET Mode" ) 36 | self.slave.pet() 37 | active = True 38 | if len( self.program ) > 0: 39 | self.program = self.program[1:] 40 | 41 | if active == False and len( self.program ) > 0 and self.program[0][2] == "WLAN_FENCE": 42 | print( "Switch to WLAN Fence Mode" ) 43 | self.slave.wlan_fence() 44 | active = True 45 | if len( self.program ) > 0: 46 | self.program = self.program[1:] 47 | 48 | if active == False and len( self.program ) > 0 and self.program[0][2] == "SLEEP_DEPRIVATION": 49 | print( "Switch to SLEEP DEPRIVATION Mode" ) 50 | self.slave.sleep_deprivation() 51 | active = True 52 | if len( self.program ) > 0: 53 | self.program = self.program[1:] 54 | 55 | if active == False and len( self.program ) > 0 and self.program[0][2] == "REMOTE_CONTROL": 56 | print( "Switch to REMOTE CONTROL Mode" ) 57 | self.slave.remote_control() 58 | active = True 59 | if len( self.program ) > 0: 60 | self.program = self.program[1:] 61 | 62 | if active == False and len( self.program ) > 0 and self.program[0][2] == "MAGLOCK": 63 | print( "Execute MAGLOCK" ) 64 | parameter = self.program[0][3] 65 | self.slave.maglock( parameter ) 66 | active = True 67 | if len( self.program ) > 0: 68 | self.program = self.program[1:] 69 | 70 | if active == False and len( self.program ) > 0 and self.program[0][2] == "COLLAR_SETTINGS": 71 | print( "Change Collar Settings" ) 72 | parameter = self.program[0][3].split('|') 73 | self.slave.collar_settings( parameter[0], parameter[1], parameter[2], parameter[3] ) 74 | active = True 75 | if len( self.program ) > 0: 76 | self.program = self.program[1:] 77 | 78 | if active == False and len( self.program ) > 0 and self.program[0][2] == "BLOWJOB_TRAINING": 79 | print( "Execute BLOWJOB TRAINING" ) 80 | parameter = self.program[0][3].split('|') 81 | self.slave.collar_settings( parameter[0], parameter[1], parameter[2], parameter[3] ) 82 | active = True 83 | if len( self.program ) > 0: 84 | self.program = self.program[1:] 85 | 86 | if active == False and len( self.program ) > 0 and self.program[0][2] == "WAIT": 87 | print( "Execute WAIT" ) 88 | self.nextaction = int( datetime.timestamp( datetime.now() ) ) + ( int( self.program[0][3] ) * 60 ) 89 | active = True 90 | if len( self.program ) > 0: 91 | self.program = self.program[1:] 92 | 93 | if active == False and len( self.program ) > 0 and self.program[0][2] == "WAITEVENT": 94 | print( "Execute WAITEVENT" ) 95 | 96 | -------------------------------------------------------------------------------- /libs/lib_oled96.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Substantially derived from code by (c) 2015 Richard Hull The MIT License (MIT) 4 | # https://github.com/rm-hull/ssd1306: 5 | # "Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # "of this software and associated documentation files (the "Software"), to deal 7 | # "in the Software without restriction, including without limitation the rights 8 | # "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # "copies of the Software, and to permit persons to whom the Software is 10 | # "furnished to do so, subject to the following conditions: 11 | # "The above copyright notice and this permission notice shall be included in 12 | # "all copies or substantial portions of the Software." 13 | # 14 | # B Lavery 2015: 15 | # This derivative "library" module is not installed to the python system as Hull's version was: 16 | # it simply resides alongside your own python script. 17 | # In this version, the I2C bus object needs to be handed in as a parameter from your user code. 18 | # This makes this one same library file work with either Raspberry Pi or Virtual GPIO system. 19 | # Hull's (clever) auto-displaying "canvas" is replaced by a persistent draw object 20 | # which can be incrementally changed. This canvas needs coded "display()" calls to push to the hardware. 21 | 22 | from PIL import Image, ImageDraw 23 | 24 | 25 | class ssd1306(): 26 | 27 | def __init__(self, bus, address=0x3C): 28 | self.cmd_mode = 0x00 29 | self.data_mode = 0x40 30 | self.bus = bus 31 | self.addr = address 32 | self.width = 128 33 | self.height = 64 34 | self.pages = int(self.height / 8) 35 | self.image = Image.new('1', (self.width, self.height)) 36 | self.canvas = ImageDraw.Draw(self.image) # this is a "draw" object for preparing display contents 37 | 38 | self._command( 39 | const.DISPLAYOFF, 40 | const.SETDISPLAYCLOCKDIV, 0x80, 41 | const.SETMULTIPLEX, 0x3F, 42 | const.SETDISPLAYOFFSET, 0x00, 43 | const.SETSTARTLINE, 44 | const.CHARGEPUMP, 0x14, 45 | const.MEMORYMODE, 0x00, 46 | const.SEGREMAP, 47 | const.COMSCANDEC, 48 | const.SETCOMPINS, 0x12, 49 | const.SETCONTRAST, 0xCF, 50 | const.SETPRECHARGE, 0xF1, 51 | const.SETVCOMDETECT, 0x40, 52 | const.DISPLAYALLON_RESUME, 53 | const.NORMALDISPLAY, 54 | const.DISPLAYON) 55 | 56 | def _command(self, *cmd): 57 | """ 58 | Sends a command or sequence of commands through to the 59 | device - maximum allowed is 32 bytes in one go. 60 | LIMIT ON ARDUINO: CMD BYTE + 31 = 32, SO LIMIT TO 31 bl 61 | """ 62 | assert(len(cmd) <= 31) 63 | self.bus.write_i2c_block_data(self.addr, self.cmd_mode, list(cmd)) 64 | 65 | def _data(self, data): 66 | """ 67 | Sends a data byte or sequence of data bytes through to the 68 | device - maximum allowed in one transaction is 32 bytes, so if 69 | data is larger than this it is sent in chunks. 70 | In our library, only data operation used is 128x64 long, ie whole canvas. 71 | """ 72 | 73 | for i in range(0, len(data), 31): 74 | self.bus.write_i2c_block_data(self.addr, self.data_mode, list(data[i:i+31])) 75 | 76 | 77 | def display(self): 78 | """ 79 | The image on the "canvas" is flushed through to the hardware display. 80 | Takes the 1-bit image and dumps it to the SSD1306 OLED display. 81 | """ 82 | 83 | self._command( 84 | const.COLUMNADDR, 0x00, self.width-1, # Column start/end address 85 | const.PAGEADDR, 0x00, self.pages-1) # Page start/end address 86 | 87 | pix = list(self.image.getdata()) 88 | step = self.width * 8 89 | buf = [] 90 | for y in range(0, self.pages * step, step): 91 | i = y + self.width-1 92 | while i >= y: 93 | byte = 0 94 | for n in range(0, step, self.width): 95 | byte |= (pix[i + n] & 0x01) << 8 96 | byte >>= 1 97 | 98 | buf.append(byte) 99 | i -= 1 100 | 101 | self._data(buf) # push out the whole lot 102 | 103 | def cls(self): 104 | self.canvas.rectangle((0, 0, self.width-1, self.height-1), outline=0, fill=0) 105 | self.display() 106 | 107 | def onoff(self, onoff): 108 | if onoff == 0: 109 | self._command(const.DISPLAYOFF) 110 | else: 111 | self._command(const.DISPLAYON) 112 | 113 | 114 | class const: 115 | CHARGEPUMP = 0x8D 116 | COLUMNADDR = 0x21 117 | COMSCANDEC = 0xC8 118 | COMSCANINC = 0xC0 119 | DISPLAYALLON = 0xA5 120 | DISPLAYALLON_RESUME = 0xA4 121 | DISPLAYOFF = 0xAE 122 | DISPLAYON = 0xAF 123 | EXTERNALVCC = 0x1 124 | INVERTDISPLAY = 0xA7 125 | MEMORYMODE = 0x20 126 | NORMALDISPLAY = 0xA6 127 | PAGEADDR = 0x22 128 | SEGREMAP = 0xA0 129 | SETCOMPINS = 0xDA 130 | SETCONTRAST = 0x81 131 | SETDISPLAYCLOCKDIV = 0xD5 132 | SETDISPLAYOFFSET = 0xD3 133 | SETHIGHCOLUMN = 0x10 134 | SETLOWCOLUMN = 0x00 135 | SETMULTIPLEX = 0xA8 136 | SETPRECHARGE = 0xD9 137 | SETSEGMENTREMAP = 0xA1 138 | SETSTARTLINE = 0x40 139 | SETVCOMDETECT = 0xDB 140 | SWITCHCAPVCC = 0x2 141 | -------------------------------------------------------------------------------- /punisher.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # coding=utf-8 3 | 4 | # Bibliotheken importieren 5 | import sys 6 | punisherdir = sys.path[0] 7 | sys.path.append( punisherdir+'/libs' ) 8 | 9 | from lib_oled96 import ssd1306 10 | from smbus import SMBus 11 | from PIL import Image 12 | from time import sleep 13 | from collections import defaultdict 14 | from random import seed 15 | from random import random 16 | from random import randint 17 | from datetime import datetime 18 | from urllib.request import urlopen 19 | from torturedevices import torturedevices 20 | from slaves import slaves 21 | from rpi_rf import RFDevice 22 | from punmqtt import PunMQTT 23 | import logging 24 | import configparser 25 | #import paho.mqtt.client as paho 26 | import RPi.GPIO as GPIO 27 | import MFRC522 28 | import signal 29 | import lcddriver 30 | import json 31 | import random 32 | import pymysql 33 | import os 34 | import time 35 | import signal 36 | 37 | stamp = dict() 38 | realstamp = dict() 39 | tordevices = torturedevices() 40 | slaves = slaves() 41 | rfdevice = RFDevice( 27 ) 42 | rfsend = RFDevice( 17 ) 43 | rfdevice.enable_rx() 44 | rfsend.enable_tx() 45 | rfdevice.tx_repeat = 10 46 | old_slave_count = -1 47 | old_device_count = -1 48 | logger = logging.getLogger( 'Punisher' ) 49 | logger.setLevel( logging.DEBUG ) 50 | log = logging.FileHandler('logs/punisher.log') 51 | log.setLevel( logging.DEBUG ) 52 | logger.addHandler( log ) 53 | formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') 54 | log.setFormatter( formatter ) 55 | logger.addHandler( log ) 56 | 57 | config = configparser.ConfigParser() 58 | config.read('config/config.ini') 59 | 60 | i2cbus = SMBus(1) 61 | oled = ssd1306(i2cbus) 62 | lcd = lcddriver.lcd() 63 | draw = oled.canvas 64 | MIFAREReader = MFRC522.MFRC522() 65 | 66 | def cleanup(): 67 | lcd.lcd_clear() 68 | oled.cls() 69 | oled.display() 70 | GPIO.cleanup() 71 | db.close() 72 | rfdevice.cleanup() 73 | rfsend.cleanup() 74 | 75 | def showLogo(): 76 | oled.cls() 77 | oled.display() 78 | draw.bitmap((32, 0), Image.open(punisherdir+'/pics/bdsm.png'), fill=1) 79 | oled.display() 80 | 81 | def showfunc( pic ): 82 | oled.cls() 83 | oled.display() 84 | draw.bitmap((32, 0), Image.open(punisherdir+'/pics/'+pic), fill=1) 85 | oled.display() 86 | 87 | def showLCD(line1, line2): 88 | lcd.lcd_clear() 89 | lcd.lcd_display_string(line1, 1) 90 | lcd.lcd_display_string(line2, 2) 91 | 92 | def listToString(s): 93 | str1 = "" 94 | for ele in s: 95 | str1 += str(ele) 96 | return str1 97 | 98 | def defaultLCD(): 99 | global tordevices, old_slave_count, old_device_count 100 | 101 | if old_slave_count != slaves.count_slaves() or old_device_count != tordevices.count_devices(): 102 | if slaves.count_slaves() == 0: 103 | showLCD('BDSM Trainer', str(tordevices.count_devices())+' Devices found') 104 | else: 105 | showLCD(str(slaves.count_slaves())+' Slave avail.', str(tordevices.count_devices())+' Devices found') 106 | old_slave_count = slaves.count_slaves() 107 | old_device_count = tordevices.count_devices() 108 | 109 | def load_program( slave_id ): 110 | global cursor 111 | cursor.execute('SELECT * FROM slave_program WHERE sp_slave = "'+str( slave_id )+'" AND sp_enabled = "Y"') 112 | program_details = cursor.fetchone() 113 | 114 | cursor.execute('SELECT * FROM program_commands WHERE pc_program = "'+str( program_details[0] )+'"') 115 | commands = cursor.fetchall() 116 | return( commands ) 117 | 118 | 119 | def program(): 120 | slaves.execute_program() 121 | 122 | def rfid(): 123 | (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL) 124 | if status == MIFAREReader.MI_OK: 125 | (status,uid) = MIFAREReader.MFRC522_Anticoll() 126 | key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] 127 | try: 128 | MIFAREReader.MFRC522_SelectTag(uid) 129 | except: 130 | log.warning('RFID has an error') 131 | status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, 8, key, uid) 132 | if status == MIFAREReader.MI_OK: 133 | data = MIFAREReader.MFRC522_Read(8) 134 | MIFAREReader.MFRC522_StopCrypto1() 135 | slaveid = listToString(data[:9]) 136 | cursor.execute('SELECT * FROM slaves, program WHERE slave_rfid = "'+slaveid+'" AND pro_id = slave_program') 137 | slave = cursor.fetchone() 138 | if slave is None: 139 | logger.info( 'Slave not found - RFID '+slaveid ) 140 | showLCD('Slave not found','') 141 | sleep(2) 142 | defaultLCD() 143 | else: 144 | if slaves.slave_online( slave[1] ): 145 | logger.debug( "Slave '"+slave[2]+"' disconnected - RFID "+slaveid ) 146 | slaves.remove_slave( slave[1] ) 147 | showLCD(slave[2], 'Slave disconnected') 148 | sleep(2) 149 | showLCD('Training program', 'disabled...') 150 | sleep(2) 151 | defaultLCD() 152 | else: 153 | logger.debug( "Slave '"+slave[2]+"' connected - RFID "+slaveid ) 154 | program = load_program( slave[0] ) 155 | slaves.add_slave( punmqtt, tordevices, slave[0], slave[1], slave[2], program, slave[7] ) 156 | stamp[ slave[1] ] = datetime.timestamp( datetime.now() ) 157 | realstamp[ slave[1] ] = datetime.timestamp( datetime.now() ) 158 | cursor.execute('SELECT * FROM devtoslave, devices WHERE dts_slaveid = "'+str(slave[0])+'" AND dev_id = dts_deviceid') 159 | device = cursor.fetchall() 160 | for dev in device: 161 | if tordevices.device_online( dev[4] ): 162 | slaves.add_device( slave[1], dev[4] ) 163 | else: 164 | slaves.add_offline_device( slave[1], dev[4] ) 165 | 166 | showLCD(slave[2], 'Slave connected') 167 | sleep(2) 168 | showLCD('Training program', slave[6]+' started...') 169 | sleep(10) 170 | defaultLCD() 171 | 172 | 173 | 174 | 175 | try: 176 | db = pymysql.connect( config['database']['hostname'], config['database']['username'], config['database']['password'], config['database']['database'] ) 177 | except: 178 | print("Error: MySQL connection failed, program start failed") 179 | lcd.lcd_clear() 180 | oled.cls() 181 | oled.display() 182 | GPIO.cleanup() 183 | db.close() 184 | rfdevice.cleanup() 185 | rfsend.cleanup() 186 | mqtt.loop.stop() 187 | sys.exit(1) 188 | 189 | cursor = db.cursor() 190 | 191 | punmqtt = PunMQTT('Punisher') 192 | punmqtt.run( config, logger, tordevices, cursor, slaves ) 193 | 194 | showLogo() 195 | defaultLCD() 196 | 197 | try: 198 | while True: 199 | rfid() 200 | defaultLCD(); 201 | if slaves.count_slaves() > 0 and tordevices.count_devices() > 0: 202 | program() 203 | 204 | except KeyboardInterrupt: 205 | cleanup() 206 | -------------------------------------------------------------------------------- /sql/punisher.sql: -------------------------------------------------------------------------------- 1 | -- MySQL dump 10.17 Distrib 10.3.22-MariaDB, for debian-linux-gnueabihf (armv8l) 2 | -- 3 | -- Host: localhost Database: punisher 4 | -- ------------------------------------------------------ 5 | -- Server version 10.3.22-MariaDB-0+deb10u1 6 | 7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 10 | /*!40101 SET NAMES utf8mb4 */; 11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; 12 | /*!40103 SET TIME_ZONE='+00:00' */; 13 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 14 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 15 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 16 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 17 | 18 | -- 19 | -- Table structure for table `current_device` 20 | -- 21 | 22 | DROP TABLE IF EXISTS `current_device`; 23 | /*!40101 SET @saved_cs_client = @@character_set_client */; 24 | /*!40101 SET character_set_client = utf8 */; 25 | CREATE TABLE `current_device` ( 26 | `cd_id` int(11) NOT NULL AUTO_INCREMENT, 27 | `cd_devid` int(11) NOT NULL, 28 | `cd_name` varchar(120) NOT NULL, 29 | PRIMARY KEY (`cd_id`), 30 | UNIQUE KEY `cd_devid` (`cd_devid`) 31 | ) ENGINE=MEMORY DEFAULT CHARSET=utf8; 32 | /*!40101 SET character_set_client = @saved_cs_client */; 33 | 34 | -- 35 | -- Dumping data for table `current_device` 36 | -- 37 | 38 | LOCK TABLES `current_device` WRITE; 39 | /*!40000 ALTER TABLE `current_device` DISABLE KEYS */; 40 | /*!40000 ALTER TABLE `current_device` ENABLE KEYS */; 41 | UNLOCK TABLES; 42 | 43 | -- 44 | -- Table structure for table `current_slave` 45 | -- 46 | 47 | DROP TABLE IF EXISTS `current_slave`; 48 | /*!40101 SET @saved_cs_client = @@character_set_client */; 49 | /*!40101 SET character_set_client = utf8 */; 50 | CREATE TABLE `current_slave` ( 51 | `cur_id` int(10) unsigned NOT NULL AUTO_INCREMENT, 52 | `cur_slaveid` int(10) unsigned NOT NULL, 53 | `cur_name` varchar(255) NOT NULL, 54 | `cur_program` varchar(60) NOT NULL, 55 | PRIMARY KEY (`cur_id`), 56 | UNIQUE KEY `cur_slaveid` (`cur_slaveid`) 57 | ) ENGINE=MEMORY DEFAULT CHARSET=utf8; 58 | /*!40101 SET character_set_client = @saved_cs_client */; 59 | 60 | -- 61 | -- Dumping data for table `current_slave` 62 | -- 63 | 64 | LOCK TABLES `current_slave` WRITE; 65 | /*!40000 ALTER TABLE `current_slave` DISABLE KEYS */; 66 | /*!40000 ALTER TABLE `current_slave` ENABLE KEYS */; 67 | UNLOCK TABLES; 68 | 69 | -- 70 | -- Table structure for table `devices` 71 | -- 72 | 73 | DROP TABLE IF EXISTS `devices`; 74 | /*!40101 SET @saved_cs_client = @@character_set_client */; 75 | /*!40101 SET character_set_client = utf8 */; 76 | CREATE TABLE `devices` ( 77 | `dev_id` int(10) unsigned NOT NULL AUTO_INCREMENT, 78 | `dev_name` varchar(60) NOT NULL, 79 | `dev_address` varchar(60) NOT NULL, 80 | `dev_protocol` enum('433','MQTT') NOT NULL DEFAULT 'MQTT', 81 | PRIMARY KEY (`dev_id`), 82 | UNIQUE KEY `dev_name` (`dev_name`) 83 | ) ENGINE=Aria AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 PAGE_CHECKSUM=1; 84 | /*!40101 SET character_set_client = @saved_cs_client */; 85 | 86 | -- 87 | -- Dumping data for table `devices` 88 | -- 89 | 90 | LOCK TABLES `devices` WRITE; 91 | /*!40000 ALTER TABLE `devices` DISABLE KEYS */; 92 | INSERT INTO `devices` VALUES (1,'torturedevice01','172.16.1.204','MQTT'),(2,'torturedevice02','172.16.1.205','MQTT'),(3,'torturedevice03','9803','433'); 93 | /*!40000 ALTER TABLE `devices` ENABLE KEYS */; 94 | UNLOCK TABLES; 95 | 96 | -- 97 | -- Table structure for table `devtoslave` 98 | -- 99 | 100 | DROP TABLE IF EXISTS `devtoslave`; 101 | /*!40101 SET @saved_cs_client = @@character_set_client */; 102 | /*!40101 SET character_set_client = utf8 */; 103 | CREATE TABLE `devtoslave` ( 104 | `dts_id` int(10) unsigned NOT NULL AUTO_INCREMENT, 105 | `dts_deviceid` int(10) unsigned NOT NULL, 106 | `dts_slaveid` int(10) unsigned NOT NULL, 107 | PRIMARY KEY (`dts_id`) 108 | ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8; 109 | /*!40101 SET character_set_client = @saved_cs_client */; 110 | 111 | -- 112 | -- Dumping data for table `devtoslave` 113 | -- 114 | 115 | LOCK TABLES `devtoslave` WRITE; 116 | /*!40000 ALTER TABLE `devtoslave` DISABLE KEYS */; 117 | INSERT INTO `devtoslave` VALUES (3,1,1),(4,2,1),(5,3,1); 118 | /*!40000 ALTER TABLE `devtoslave` ENABLE KEYS */; 119 | UNLOCK TABLES; 120 | 121 | -- 122 | -- Table structure for table `program` 123 | -- 124 | 125 | DROP TABLE IF EXISTS `program`; 126 | /*!40101 SET @saved_cs_client = @@character_set_client */; 127 | /*!40101 SET character_set_client = utf8 */; 128 | CREATE TABLE `program` ( 129 | `pro_id` int(11) NOT NULL AUTO_INCREMENT, 130 | `pro_name` varchar(120) NOT NULL, 131 | `pro_functions` varchar(255) NOT NULL, 132 | PRIMARY KEY (`pro_id`), 133 | UNIQUE KEY `pro_name` (`pro_name`) 134 | ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; 135 | /*!40101 SET character_set_client = @saved_cs_client */; 136 | 137 | -- 138 | -- Dumping data for table `program` 139 | -- 140 | 141 | LOCK TABLES `program` WRITE; 142 | /*!40000 ALTER TABLE `program` DISABLE KEYS */; 143 | INSERT INTO `program` VALUES (1,'Painplay','tens|random'),(2,'Blowjob','blowjob|50'); 144 | /*!40000 ALTER TABLE `program` ENABLE KEYS */; 145 | UNLOCK TABLES; 146 | 147 | -- 148 | -- Table structure for table `slaves` 149 | -- 150 | 151 | DROP TABLE IF EXISTS `slaves`; 152 | /*!40101 SET @saved_cs_client = @@character_set_client */; 153 | /*!40101 SET character_set_client = utf8 */; 154 | CREATE TABLE `slaves` ( 155 | `slave_id` int(11) NOT NULL AUTO_INCREMENT, 156 | `slave_rfid` varchar(255) NOT NULL, 157 | `slave_name` varchar(255) NOT NULL, 158 | `slave_collar` varchar(255) NOT NULL, 159 | `slave_program` int(11) unsigned NOT NULL, 160 | PRIMARY KEY (`slave_id`), 161 | UNIQUE KEY `slave_rfid` (`slave_rfid`) 162 | ) ENGINE=Aria AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 PAGE_CHECKSUM=1; 163 | /*!40101 SET character_set_client = @saved_cs_client */; 164 | 165 | -- 166 | -- Dumping data for table `slaves` 167 | -- 168 | 169 | LOCK TABLES `slaves` WRITE; 170 | /*!40000 ALTER TABLE `slaves` DISABLE KEYS */; 171 | INSERT INTO `slaves` VALUES (1,'','','',1); 172 | /*!40000 ALTER TABLE `slaves` ENABLE KEYS */; 173 | UNLOCK TABLES; 174 | 175 | -- 176 | -- Table structure for table `torfunctions` 177 | -- 178 | 179 | DROP TABLE IF EXISTS `torfunctions`; 180 | /*!40101 SET @saved_cs_client = @@character_set_client */; 181 | /*!40101 SET character_set_client = utf8 */; 182 | CREATE TABLE `torfunctions` ( 183 | `tf_id` int(10) unsigned NOT NULL AUTO_INCREMENT, 184 | `tf_devid` int(10) unsigned NOT NULL, 185 | `tf_name` varchar(120) NOT NULL, 186 | `tf_pic` varchar(80) NOT NULL, 187 | `tf_call` varchar(120) NOT NULL, 188 | `tf_args` enum('seconds','enable','disable','random') NOT NULL DEFAULT 'seconds', 189 | PRIMARY KEY (`tf_id`) 190 | ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; 191 | /*!40101 SET character_set_client = @saved_cs_client */; 192 | 193 | -- 194 | -- Dumping data for table `torfunctions` 195 | -- 196 | 197 | LOCK TABLES `torfunctions` WRITE; 198 | /*!40000 ALTER TABLE `torfunctions` DISABLE KEYS */; 199 | INSERT INTO `torfunctions` VALUES (1,1,'tens','tens.png','tortureon','seconds'),(2,2,'tens','tens.png','tortureon','seconds'),(3,3,'blowjob','blow.png','433','enable'); 200 | /*!40000 ALTER TABLE `torfunctions` ENABLE KEYS */; 201 | UNLOCK TABLES; 202 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; 203 | 204 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 205 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 206 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 207 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 208 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 209 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 210 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 211 | 212 | -- Dump completed on 2020-05-16 22:02:02 213 | -------------------------------------------------------------------------------- /libs/MFRC522.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf8 -*- 3 | # 4 | # Copyright 2014,2018 Mario Gomez 5 | # 6 | # This file is part of MFRC522-Python 7 | # MFRC522-Python is a simple Python implementation for 8 | # the MFRC522 NFC Card Reader for the Raspberry Pi. 9 | # 10 | # MFRC522-Python is free software: you can redistribute it and/or modify 11 | # it under the terms of the GNU Lesser General Public License as published by 12 | # the Free Software Foundation, either version 3 of the License, or 13 | # (at your option) any later version. 14 | # 15 | # MFRC522-Python is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU Lesser General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU Lesser General Public License 21 | # along with MFRC522-Python. If not, see . 22 | # 23 | import RPi.GPIO as GPIO 24 | import spidev 25 | import signal 26 | import time 27 | import logging 28 | 29 | class MFRC522: 30 | MAX_LEN = 16 31 | 32 | PCD_IDLE = 0x00 33 | PCD_AUTHENT = 0x0E 34 | PCD_RECEIVE = 0x08 35 | PCD_TRANSMIT = 0x04 36 | PCD_TRANSCEIVE = 0x0C 37 | PCD_RESETPHASE = 0x0F 38 | PCD_CALCCRC = 0x03 39 | 40 | PICC_REQIDL = 0x26 41 | PICC_REQALL = 0x52 42 | PICC_ANTICOLL = 0x93 43 | PICC_SElECTTAG = 0x93 44 | PICC_AUTHENT1A = 0x60 45 | PICC_AUTHENT1B = 0x61 46 | PICC_READ = 0x30 47 | PICC_WRITE = 0xA0 48 | PICC_DECREMENT = 0xC0 49 | PICC_INCREMENT = 0xC1 50 | PICC_RESTORE = 0xC2 51 | PICC_TRANSFER = 0xB0 52 | PICC_HALT = 0x50 53 | 54 | MI_OK = 0 55 | MI_NOTAGERR = 1 56 | MI_ERR = 2 57 | 58 | Reserved00 = 0x00 59 | CommandReg = 0x01 60 | CommIEnReg = 0x02 61 | DivlEnReg = 0x03 62 | CommIrqReg = 0x04 63 | DivIrqReg = 0x05 64 | ErrorReg = 0x06 65 | Status1Reg = 0x07 66 | Status2Reg = 0x08 67 | FIFODataReg = 0x09 68 | FIFOLevelReg = 0x0A 69 | WaterLevelReg = 0x0B 70 | ControlReg = 0x0C 71 | BitFramingReg = 0x0D 72 | CollReg = 0x0E 73 | Reserved01 = 0x0F 74 | 75 | Reserved10 = 0x10 76 | ModeReg = 0x11 77 | TxModeReg = 0x12 78 | RxModeReg = 0x13 79 | TxControlReg = 0x14 80 | TxAutoReg = 0x15 81 | TxSelReg = 0x16 82 | RxSelReg = 0x17 83 | RxThresholdReg = 0x18 84 | DemodReg = 0x19 85 | Reserved11 = 0x1A 86 | Reserved12 = 0x1B 87 | MifareReg = 0x1C 88 | Reserved13 = 0x1D 89 | Reserved14 = 0x1E 90 | SerialSpeedReg = 0x1F 91 | 92 | Reserved20 = 0x20 93 | CRCResultRegM = 0x21 94 | CRCResultRegL = 0x22 95 | Reserved21 = 0x23 96 | ModWidthReg = 0x24 97 | Reserved22 = 0x25 98 | RFCfgReg = 0x26 99 | GsNReg = 0x27 100 | CWGsPReg = 0x28 101 | ModGsPReg = 0x29 102 | TModeReg = 0x2A 103 | TPrescalerReg = 0x2B 104 | TReloadRegH = 0x2C 105 | TReloadRegL = 0x2D 106 | TCounterValueRegH = 0x2E 107 | TCounterValueRegL = 0x2F 108 | 109 | Reserved30 = 0x30 110 | TestSel1Reg = 0x31 111 | TestSel2Reg = 0x32 112 | TestPinEnReg = 0x33 113 | TestPinValueReg = 0x34 114 | TestBusReg = 0x35 115 | AutoTestReg = 0x36 116 | VersionReg = 0x37 117 | AnalogTestReg = 0x38 118 | TestDAC1Reg = 0x39 119 | TestDAC2Reg = 0x3A 120 | TestADCReg = 0x3B 121 | Reserved31 = 0x3C 122 | Reserved32 = 0x3D 123 | Reserved33 = 0x3E 124 | Reserved34 = 0x3F 125 | 126 | serNum = [] 127 | 128 | def __init__(self, bus=0, device=0, spd=1000000, pin_mode=10, pin_rst=-1, debugLevel='WARNING'): 129 | self.spi = spidev.SpiDev() 130 | self.spi.open(bus, device) 131 | self.spi.max_speed_hz = spd 132 | 133 | self.logger = logging.getLogger('mfrc522Logger') 134 | self.logger.addHandler(logging.StreamHandler()) 135 | level = logging.getLevelName(debugLevel) 136 | self.logger.setLevel(level) 137 | 138 | gpioMode = GPIO.getmode() 139 | 140 | if gpioMode is None: 141 | GPIO.setmode(pin_mode) 142 | else: 143 | pin_mode = gpioMode 144 | 145 | if pin_rst == -1: 146 | if pin_mode == 11: 147 | pin_rst = 15 148 | else: 149 | pin_rst = 22 150 | 151 | GPIO.setup(pin_rst, GPIO.OUT) 152 | GPIO.output(pin_rst, 1) 153 | self.MFRC522_Init() 154 | 155 | def MFRC522_Reset(self): 156 | self.Write_MFRC522(self.CommandReg, self.PCD_RESETPHASE) 157 | 158 | def Write_MFRC522(self, addr, val): 159 | val = self.spi.xfer2([(addr << 1) & 0x7E, val]) 160 | 161 | def Read_MFRC522(self, addr): 162 | val = self.spi.xfer2([((addr << 1) & 0x7E) | 0x80, 0]) 163 | return val[1] 164 | 165 | def Close_MFRC522(self): 166 | self.spi.close() 167 | GPIO.cleanup() 168 | 169 | def SetBitMask(self, reg, mask): 170 | tmp = self.Read_MFRC522(reg) 171 | self.Write_MFRC522(reg, tmp | mask) 172 | 173 | def ClearBitMask(self, reg, mask): 174 | tmp = self.Read_MFRC522(reg) 175 | self.Write_MFRC522(reg, tmp & (~mask)) 176 | 177 | def AntennaOn(self): 178 | temp = self.Read_MFRC522(self.TxControlReg) 179 | if (~(temp & 0x03)): 180 | self.SetBitMask(self.TxControlReg, 0x03) 181 | 182 | def AntennaOff(self): 183 | self.ClearBitMask(self.TxControlReg, 0x03) 184 | 185 | def MFRC522_ToCard(self, command, sendData): 186 | backData = [] 187 | backLen = 0 188 | status = self.MI_ERR 189 | irqEn = 0x00 190 | waitIRq = 0x00 191 | lastBits = None 192 | n = 0 193 | 194 | if command == self.PCD_AUTHENT: 195 | irqEn = 0x12 196 | waitIRq = 0x10 197 | if command == self.PCD_TRANSCEIVE: 198 | irqEn = 0x77 199 | waitIRq = 0x30 200 | 201 | self.Write_MFRC522(self.CommIEnReg, irqEn | 0x80) 202 | self.ClearBitMask(self.CommIrqReg, 0x80) 203 | self.SetBitMask(self.FIFOLevelReg, 0x80) 204 | 205 | self.Write_MFRC522(self.CommandReg, self.PCD_IDLE) 206 | 207 | for i in range(len(sendData)): 208 | self.Write_MFRC522(self.FIFODataReg, sendData[i]) 209 | 210 | self.Write_MFRC522(self.CommandReg, command) 211 | 212 | if command == self.PCD_TRANSCEIVE: 213 | self.SetBitMask(self.BitFramingReg, 0x80) 214 | 215 | i = 2000 216 | while True: 217 | n = self.Read_MFRC522(self.CommIrqReg) 218 | i -= 1 219 | if ~((i != 0) and ~(n & 0x01) and ~(n & waitIRq)): 220 | break 221 | 222 | self.ClearBitMask(self.BitFramingReg, 0x80) 223 | 224 | if i != 0: 225 | if (self.Read_MFRC522(self.ErrorReg) & 0x1B) == 0x00: 226 | status = self.MI_OK 227 | 228 | if n & irqEn & 0x01: 229 | status = self.MI_NOTAGERR 230 | 231 | if command == self.PCD_TRANSCEIVE: 232 | n = self.Read_MFRC522(self.FIFOLevelReg) 233 | lastBits = self.Read_MFRC522(self.ControlReg) & 0x07 234 | if lastBits != 0: 235 | backLen = (n - 1) * 8 + lastBits 236 | else: 237 | backLen = n * 8 238 | 239 | if n == 0: 240 | n = 1 241 | if n > self.MAX_LEN: 242 | n = self.MAX_LEN 243 | 244 | for i in range(n): 245 | backData.append(self.Read_MFRC522(self.FIFODataReg)) 246 | else: 247 | status = self.MI_ERR 248 | 249 | return (status, backData, backLen) 250 | 251 | def MFRC522_Request(self, reqMode): 252 | status = None 253 | backBits = None 254 | TagType = [] 255 | 256 | self.Write_MFRC522(self.BitFramingReg, 0x07) 257 | 258 | TagType.append(reqMode) 259 | (status, backData, backBits) = self.MFRC522_ToCard(self.PCD_TRANSCEIVE, TagType) 260 | 261 | if ((status != self.MI_OK) | (backBits != 0x10)): 262 | status = self.MI_ERR 263 | 264 | return (status, backBits) 265 | 266 | def MFRC522_Anticoll(self): 267 | backData = [] 268 | serNumCheck = 0 269 | 270 | serNum = [] 271 | 272 | self.Write_MFRC522(self.BitFramingReg, 0x00) 273 | 274 | serNum.append(self.PICC_ANTICOLL) 275 | serNum.append(0x20) 276 | 277 | (status, backData, backBits) = self.MFRC522_ToCard(self.PCD_TRANSCEIVE, serNum) 278 | 279 | if (status == self.MI_OK): 280 | i = 0 281 | if len(backData) == 5: 282 | for i in range(4): 283 | serNumCheck = serNumCheck ^ backData[i] 284 | if serNumCheck != backData[4]: 285 | status = self.MI_ERR 286 | else: 287 | status = self.MI_ERR 288 | 289 | return (status, backData) 290 | 291 | def CalulateCRC(self, pIndata): 292 | self.ClearBitMask(self.DivIrqReg, 0x04) 293 | self.SetBitMask(self.FIFOLevelReg, 0x80) 294 | 295 | for i in range(len(pIndata)): 296 | self.Write_MFRC522(self.FIFODataReg, pIndata[i]) 297 | 298 | self.Write_MFRC522(self.CommandReg, self.PCD_CALCCRC) 299 | i = 0xFF 300 | while True: 301 | n = self.Read_MFRC522(self.DivIrqReg) 302 | i -= 1 303 | if not ((i != 0) and not (n & 0x04)): 304 | break 305 | pOutData = [] 306 | pOutData.append(self.Read_MFRC522(self.CRCResultRegL)) 307 | pOutData.append(self.Read_MFRC522(self.CRCResultRegM)) 308 | return pOutData 309 | 310 | def MFRC522_SelectTag(self, serNum): 311 | backData = [] 312 | buf = [] 313 | buf.append(self.PICC_SElECTTAG) 314 | buf.append(0x70) 315 | 316 | for i in range(5): 317 | buf.append(serNum[i]) 318 | 319 | pOut = self.CalulateCRC(buf) 320 | buf.append(pOut[0]) 321 | buf.append(pOut[1]) 322 | (status, backData, backLen) = self.MFRC522_ToCard(self.PCD_TRANSCEIVE, buf) 323 | 324 | if (status == self.MI_OK) and (backLen == 0x18): 325 | self.logger.debug("Size: " + str(backData[0])) 326 | return backData[0] 327 | else: 328 | return 0 329 | 330 | def MFRC522_Auth(self, authMode, BlockAddr, Sectorkey, serNum): 331 | buff = [] 332 | 333 | # First byte should be the authMode (A or B) 334 | buff.append(authMode) 335 | 336 | # Second byte is the trailerBlock (usually 7) 337 | buff.append(BlockAddr) 338 | 339 | # Now we need to append the authKey which usually is 6 bytes of 0xFF 340 | for i in range(len(Sectorkey)): 341 | buff.append(Sectorkey[i]) 342 | 343 | # Next we append the first 4 bytes of the UID 344 | for i in range(4): 345 | buff.append(serNum[i]) 346 | 347 | # Now we start the authentication itself 348 | (status, backData, backLen) = self.MFRC522_ToCard(self.PCD_AUTHENT, buff) 349 | 350 | # Check if an error occurred 351 | if not (status == self.MI_OK): 352 | self.logger.error("AUTH ERROR!!") 353 | if not (self.Read_MFRC522(self.Status2Reg) & 0x08) != 0: 354 | self.logger.error("AUTH ERROR(status2reg & 0x08) != 0") 355 | 356 | # Return the status 357 | return status 358 | 359 | def MFRC522_StopCrypto1(self): 360 | self.ClearBitMask(self.Status2Reg, 0x08) 361 | 362 | def MFRC522_Read(self, blockAddr): 363 | recvData = [] 364 | recvData.append(self.PICC_READ) 365 | recvData.append(blockAddr) 366 | pOut = self.CalulateCRC(recvData) 367 | recvData.append(pOut[0]) 368 | recvData.append(pOut[1]) 369 | (status, backData, backLen) = self.MFRC522_ToCard(self.PCD_TRANSCEIVE, recvData) 370 | if not (status == self.MI_OK): 371 | self.logger.error("Error while reading!") 372 | 373 | if len(backData) == 16: 374 | self.logger.debug("Sector " + str(blockAddr) + " " + str(backData)) 375 | return backData 376 | else: 377 | return None 378 | 379 | def MFRC522_Write(self, blockAddr, writeData): 380 | buff = [] 381 | buff.append(self.PICC_WRITE) 382 | buff.append(blockAddr) 383 | crc = self.CalulateCRC(buff) 384 | buff.append(crc[0]) 385 | buff.append(crc[1]) 386 | (status, backData, backLen) = self.MFRC522_ToCard(self.PCD_TRANSCEIVE, buff) 387 | if not (status == self.MI_OK) or not (backLen == 4) or not ((backData[0] & 0x0F) == 0x0A): 388 | status = self.MI_ERR 389 | 390 | self.logger.debug("%s backdata &0x0F == 0x0A %s" % (backLen, backData[0] & 0x0F)) 391 | if status == self.MI_OK: 392 | buf = [] 393 | for i in range(16): 394 | buf.append(writeData[i]) 395 | 396 | crc = self.CalulateCRC(buf) 397 | buf.append(crc[0]) 398 | buf.append(crc[1]) 399 | (status, backData, backLen) = self.MFRC522_ToCard(self.PCD_TRANSCEIVE, buf) 400 | if not (status == self.MI_OK) or not (backLen == 4) or not ((backData[0] & 0x0F) == 0x0A): 401 | self.logger.error("Error while writing") 402 | if status == self.MI_OK: 403 | self.logger.debug("Data written") 404 | 405 | 406 | def MFRC522_DumpClassic1K(self, key, uid): 407 | for i in range(64): 408 | status = self.MFRC522_Auth(self.PICC_AUTHENT1A, i, key, uid) 409 | # Check if authenticated 410 | if status == self.MI_OK: 411 | self.MFRC522_Read(i) 412 | else: 413 | self.logger.error("Authentication error") 414 | 415 | def MFRC522_Init(self): 416 | self.MFRC522_Reset() 417 | 418 | self.Write_MFRC522(self.TModeReg, 0x8D) 419 | self.Write_MFRC522(self.TPrescalerReg, 0x3E) 420 | self.Write_MFRC522(self.TReloadRegL, 30) 421 | self.Write_MFRC522(self.TReloadRegH, 0) 422 | 423 | self.Write_MFRC522(self.TxAutoReg, 0x40) 424 | self.Write_MFRC522(self.ModeReg, 0x3D) 425 | self.AntennaOn() 426 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | punisher 294 | Copyright (C) 2020 Adnae Inviere 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------