Commit 60cdea41 authored by Matthieu Cattin's avatar Matthieu Cattin

struct: Prepare for merge with master.

calibr_box.py is board specific (the type of box differ depending on the board).
Therefore it is removed from the common pts. If a mean to differentiate between
the box if implemented, it might come back to common pts.

cp210x driver is removed, because it is now stored in the usb-relay-box1 project's repo.

cp210x_eeprom.py is removed, because it is specific to the board (e.g. not the same for fmc-adc)
parent cb370ad5
#! /usr/bin/env python
# coding: utf8
# Copyright CERN, 2011
# Author: Matthieu Cattin <matthieu.cattin@cern.ch>
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org
import sys
import rr
import time
import os
import re
from ctypes import *
from ptsexcept import *
from cp210x import usb, valuefile, cp210x
from cp210x.eeprom import EEPROM
"""
cp210x_eeprom: Access to USB-UART bridge CP2103 EEPROM
Note: The EEPROM is used to store calibration data.
The data is stored as a string in the "Product String".
Format example: "234.45, 163.08, 174.98, 205.81"
"""
CALIBR_CHANNELS = ['ch1-ch2', 'ch1-ch3', 'ch1-ch4', 'ch1-ch5']
class CP210xEepromOperationError(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return ("CP210x EEPROM: %s" %(self.msg))
class CCP210x_Eeprom:
def __init__(self, vid, pid):
usb.init()
usb_patterns = []
vid = int(vid, 16)
pid = int(pid, 16)
usb_patterns.append(dict(idVendor=vid, idProduct=pid))
self.dev = [item for item in cp210x.Cp210xProgrammer.list_devices(usb_patterns)]
self.dev = self.dev[0]
def get_calibr_data(self):
self.dev.open()
try:
eeprom = EEPROM(self.dev)
except:
raise CP210xEepromOperationError('Cannot open device.')
finally:
self.dev.close()
eeprom_value = eeprom.get_values()
product_string = eeprom_value['product_string']
#print "Product string: \"%s\"" % product_string
calibr_string_list = product_string.split(' ')
if len(calibr_string_list) != 4:
raise CP210xEepromOperationError('Product string has the wrong format.')
calibr_data = {}
for i in range(len(calibr_string_list)):
pattern = r'\b[0-9]{3}\.[0-9]{2}\b'
if re.search(pattern, calibr_string_list[i]):
calibr_data[CALIBR_CHANNELS[i]] = calibr_string_list[i]
else:
raise CP210xEepromOperationError('Product string has the wrong format.')
return calibr_data
def set_calibr_data(self, data):
self.dev.open()
product_string = data[CALIBR_CHANNELS[0]] + ' ' + data[CALIBR_CHANNELS[1]] + ' ' + data[CALIBR_CHANNELS[2]] + ' ' + data[CALIBR_CHANNELS[3]]
#print "New product string value: \"%s\"" % product_string
try:
self.dev.set_product_string(product_string)
print "Calibration data written to cp210x EEPROM."
finally:
self.dev.close()
#! /usr/bin/env python
# coding: utf8
# Copyright CERN, 2011
# Author: Matthieu Cattin <matthieu.cattin@cern.ch>
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org
import sys
import time
import os
import cp210x_gpio
"""
calibr_box: Access to calibration box via USB-UART bridge CP2103
"""
class CalibrBoxOperationError(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return ("Calibration box: %s" %(self.msg))
class CCalibr_box:
def __init__(self, device):
self.cp210x = cp210x_gpio.CCP210x(device)
# Select AWG as default output
# self.cp210x.gpio_get();
self.cp210x.gpio_set(0x0);
self.state = 0;
def select_output(self, out):
# print("Cur %x" % self.state)
self.state = self.state & 0x3;
if(out == 1):
self.state = self.state | ( 0xc );
elif(out == 2):
self.state = self.state | ( 0x8 );
elif(out == 3):
self.state = self.state | ( 0x4 );
elif(out == 4):
self.state = self.state | ( 0x0 );
else:
raise CalibrBoxOperationError("Invalid output selection!")
self.cp210x.gpio_set(self.state)
def select_trigger_loopback(self, tloop):
if(tloop):
self.state = self.state | 2;
else:
self.state = self.state & ~2;
self.cp210x.gpio_set(self.state)
obj-m = cp210x.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment