Commit e2f21ddc authored by Manuel Broseta's avatar Manuel Broseta

Version 1.1 created

parent 10253a9a
This diff is collapsed.
[Dolphin]
Timestamp=2015,10,15,15,27,23
Version=3
ViewMode=2
[Dolphin]
Timestamp=2015,10,15,15,13,34
Version=3
ViewMode=2
import os, re
import pickle
import alin
#DEFAULT_PATH = "/home/projects/alba-em/deviceslib/"
class Generator():
def __init__(self):
self.fread = []
self.vendorID = None
self.product = None
self.wboutput = {}
self.default_path = os.path.dirname(alin.__file__)+"/deviceslib/"
if not os.path.exists(self.default_path):
os.makedirs(self.default_path)
def readWBFile(self, filename):
try:
with open(filename) as f:
self.fread = [" ".join(l.split()) for l in f]
except Exception, e:
print "Error while opening in wb file: %s"%str(e)
return
def getInputVendorID(self):
self._vendorID = None
while not self._vendorID:
self.vendorID = raw_input ("\nEnter VENDOR ID code (hex format, max. 8 bytes)" \
"(i.e: a1ba for Alba or ce42 for CERN) or enter 'Q' to quit: ")
if self.vendorID.lower() == "q":
print "\nProgram aborted!!!\n"
return None
try:
self.vendorID = int(self.vendorID.lower(),16)
if self._vendorID > 0xffffffffffffffff:
print "Number exceeds maximum value. Please enter hexadecimal " \
"(max. 8 bytes) vendor ID value!!\n "
self.vendorID = None
else:
return self.vendorID
except:
print "Incorrect number format!!! Please enter hexadecimal vendor ID value!!\n"
def getInputProduct(self):
self.product = None
while not self.product:
self.product = raw_input ("\nEnter PRODUCT (hex format, max 4 bytes)" \
"or enter 'Q' to quit: ")
if self.product.lower() == "q":
print "\nProgram aborted!!!\n"
return None
try:
self.product = int(self.product.lower(),16)
if self.product > 0xffffffff:
print "Number exceeds maximum value. Please enter hexadecimal "\
"(max. 4 bytes) product value!!\n"
self.product = None
else:
return self.product
except:
print "Incorrect number format!!! Please enter hexadecimal product value!!\n"
def processWBData(self):
self.wboutput = {}
offset = 0
l = 0
while l<len(self.fread):
# Read device description
if "name = " in self.fread[l] or "description =" in self.fread[l]:
if self.fread[l].split()[0] not in self.wboutput.keys():
self.wboutput[self.fread[l].split()[0]] = re.search('"(.*)"',self.fread[l].split("=")[1]).group(1)
else:
self.wboutput[self.fread[l].split()[0]] += re.search('"(.*)"',self.fread[l].split("=")[1]).group(1)
# Read registers
elif "reg {" in self.fread[l]:
reg_name = ""
bit_position = 0
l += 1
while "};" not in self.fread[l]:
if "align" in self.fread[l]:
offset += int(self.fread[l].split("=")[1].replace(";",""))
elif "prefix" in self.fread[l]:
reg_name += re.search('"(.*)"',self.fread[l].split("=",1)[1]).group(1)
elif "field {" in self.fread[l]:
l += 1
size = 0
type = ""
description = ""
field_name = ""
store_reg = True
while "};" not in self.fread[l]:
if "prefix =" in self.fread[l]:
if "reserved" in self.fread[l].lower():
store_reg = False
else:
field_name = re.search('"(.*)"',self.fread[l].split("=",1)[1]).group(1)
store_reg = True
elif "access_bus =" in self.fread[l]:
access = self.fread[l].split("=")[1].replace(";","")
elif "type = " in self.fread[l] and "BIT" in self.fread[l]:
size = 1
elif "size = " in self.fread[l]:
size = int(self.fread[l].split("=")[1].replace(";",""))
elif "description = " in self.fread[l]:
description = re.search('"(.*)"',self.fread[l].split("=",1)[1]).group(1)
elif "align" in self.fread[l]:
bit_offset = int(self.fread[l].split("=")[1].replace(";",""))
if bit_position % bit_offset:
ad = bit_offset - (bit_position % bit_offset)
bit_position += ad
l +=1
if store_reg:
data = {}
if field_name != "":
reg = reg_name+"_"+field_name
else:
reg = reg_name
data[reg]={}
data[reg]["bit_position"] = bit_position
data[reg]["size"] = size
data[reg]["access"] = access
data[reg]["description"] = description
bit_position += size
data[reg]["address"] = offset
if "regs" not in self.wboutput.keys():
self.wboutput["regs"]=[data]
else:
self.wboutput["regs"].append(data)
l+=1
offset +=1
# Increment line counter
l += 1
def getWBData(self):
return self.wboutput
def writeWBDataToFile(self,filename=""):
try:
with open(self.default_path+filename,"w") as f:
pickle.dump(self.wboutput, f)
except Exception, e:
print "Error while writing the output file: %s"%str(e)
return
if __name__ == "__main__":
import sys, os.path
args = ' '.join(sys.argv[1:])
if len(args)>1:
for el in args:
if os.path.isfile(el):
...
elif os.path.isdir(args):
arch = os.listdir(args)
for el in arch:
....
else:
if os.path.isfile(args):
....
try:
filename = args
if not filename.endswith(".wb"):
print "\nIncorrect filename selected!!\n" \
"You should pass the *.wb file of the device to be generated\n"
sys.exit()
except:
print "\nNo file name selected!!!\nInput the device.wb file"
sys.exit()
gen = Generator()
gen.readWBFile(filename)
# 1.- Build the devine name
try:
vend = gen.getInputVendorID()
if vend is None:
sys.exit()
prod = gen.getInputProduct()
if prod is None:
sys.exit()
devFileName = "%016x:%08x"%(vend,prod)
except Exception, e:
devFileName = None
print str(e)
if devFileName is not None:
# 2. Read the wb file
gen.processWBData()
# 3. Write output to file
gen.writeWBDataToFile(devFileName)
print "\nFile %s generated succesfully!!\n"%devFileName
else:
print "Incorrect filename generated!!"
sys.exit()
#----------------------------------------------------------------------------------------------------------------------
#
# ctemsdb.py file
#
# File used to read SDB information form spec card
# History:
# 30/03/2015 - file created
#
#----------------------------------------------------------------------------------------------------------------------
__author__ = "Manolo Broseta"
__copyright__ = "Copyright 2015, ALBA"
__license__ = "GPLv3 or later"
__version__ = "1.0"
__email__ = "mbroseta@cells.es"
__status__ = "Development"
import os.path
import pickle
from alin import alindrv, alindev
__OFFSET__ = 0x00 #0x100
__DEVICE_FOLDER__ = "/home/projects/alba-em/deviceslib/"
def showDevice(devfile=""):
dev_map = {}
output = open(devfile, 'rb')
dev_map = pickle.load(output)
return dev_map
def help():
print "ALIN usage as follows:\n"
print "\t# alin <command_1>=<value> <command_2>=<value>....."
print "\nCommands are optional. By defult, short SDB structure info is shown."
print "List of available commands are:\n"
print "\taddress:\tContinuous read of a memory address. This read will be updated every second until 'enter' key will be pressed.\n"
print "\tdevicemap:\tShows the available devices list and lets the user to select which device memory map to show.\n"
print "\tinfo:\t\tTo display the detailed SDB structure.\n"
print "\thelp:\t\tshows this help\n"
print "\tload:\t\tTo load a new binary file into the Spec FPGA."
print "\t\t\tThe file location has to be specified, i.e.: alin load='/lib/firmware/fmc/spec-init.bin'.\n"
print "\toffset:\t\tTo define the address position where the SDB magic number is located. By defult offset values is 0x100.\n"
print "\trange:\t\tThis shows an address range of memary. It has to be specified the init address and the end address."
print "\t\t\tI.e.: alin range init=0x100 end=0x11f\n"
print "\twrite:\t\tThis commands lets write a value in a certain position."
print "\t\t\tI.e.: alin write=0x100 data=0x01\n"
print "\tdev:\t\tThis commands shows the list of registers for a particular device, if previously the device pickle file has been generated using the alingen tool"
print "\t\t\tThe device name have to be between quotes with the following format VendorId:Product. I.e.: alin dev='alba:609'"
print "\t\t\tOther options available for a device are:"
print "\t\t\t\tR: Reads a regsiter. I.e.: alin dev='<VendorID:Product>' R=<REG_NAME>"
print "\t\t\t\tW: Write and then 'data=' to enter the ex value to write. I.e.: alin dev='<VendorID:Product>' W=<REG_NAME> data=0x<hex_value>"
print "\t\t\t\tI: Displays complete register info I.e.: alin dev='<VendorID:Product>' I=<REG_NAME>"
print "\n"
if __name__ == "__main__":
import sys, os.path
import select
args = ' '.join(sys.argv[1:])
if 'help' in args:
# Shows help command
help()
sys.exit()
else:
# Offset commnad
offset = __OFFSET__
if 'offset' in args:
for el in args.split(' '):
if "offset=" in el:
offset = int(el.split('=')[1],16)
app = alindrv.alinSDB(offset)
# Load new file command
if 'load' in args:
filename = ''
for el in args.split(' '):
if "load=" in el:
filename = (el.split('=')[1])
if os.path.isfile(filename):
ret = app.SDB_loadFile(filename)
if ret:
print('the bitstream has been successfully loaded')
else:
print('the bitstream loading has failed or cannot find the bitstream!!!')
app.SDB_readData(offset)
# Continuous read of an address
if 'address' in args:
address = OFFSET
for el in args.split(' '):
if 'address=' in el:
address=int(el.split('=')[1],16)
print "\nPress 'Enter' to stop reading the address:\n"
i = []
while i==[]:
value = app.SDB_readAddress(address)
sys.stdout.write("\rSDB Read data: Address=%s Value=%s"%(hex(address),format(value,'#010x')))
sys.stdout.flush()
i, o, e = select.select( [sys.stdin], [], [], 1 )
sys.exit()
if 'write' in args:
address = OFFSET
data = 0
for el in args.split(' '):
print el
if 'write=' in el:
address=int(el.split('=')[1],16)
if 'data=' in el:
data=int(el.split('=')[1],16)
if address != OFFSET:
app.SDB_writeAddress(address,data)
sys.exit()
# Display range of addresses
if 'range' in args:
init_address_found = False
end_address_found = False
for el in args.split(' '):
if 'init=' in el:
init_address_found = True
init_address=int(el.split('=')[1],16)
if 'end=' in el:
end_address_found = True
end_address=int(el.split('=')[1],16)
if not init_address_found:
init_address = OFFSET
if end_address_found:
end_address = init_address+4
if not end_address_found:
end_address = init_address+4
rd_blk = []
rd_blk = app.SDB_readAddressRange(init_address,end_address)
for el in rd_blk:
print "%06x"%el[0],
print ' '.join([("%02x"%el[a]) for a in range(1,17)]),
print " >",''.join([chr(el[a]) if el[a]>0x1F and el[a]<0x80 else chr(0x2E) for a in range(1,17)]),"<"
sys.exit()
if 'dev=' in args:
devname = ''
action = None
for el in args.split(' '):
if "dev=" in el:
devname = (el.split('=')[1]).lower()
if ":" not in devname:
print "\nIncorret device name format!!!\n"
sys.exit()
vd, pd = devname.split(":")
vd = int(vd.lower(),16)
pd = int(pd.lower(),16)
devname = "%016x:%08x"%(vd,pd)
elif "R=" in el or "r=" in el:
action = "READ"
regname = (el.split('=')[1])
elif "W=" in el or "w=" in el:
action = "WRITE"
regname = (el.split('=')[1])
elif "data=" in el:
data = int(el.split('=')[1],16)
elif "I=" in el or "i=" in el:
action = "INFO"
regname = (el.split('=')[1])
device = alindev.alinDevice(devname)
if action == "READ":
value = device.readAttribute(regname)
txt = "%s "%regname.upper()
txt = txt.ljust(30,'.')
txt += ": %s"%hex(value)
print "\n"+txt+"\n"
elif action == "WRITE":
device.writeAttribute(regname,data)
value = device.readAttribute(regname)
txt = "%s "%regname.upper()
txt = txt.ljust(30,'.')
txt += ": %s"%hex(value)
print "\n"+txt+"\n"
elif action == "INFO":
temp = {}
temp = device.getAttributeInfo(regname)
try:
print "\nDescriptrion:"
dp = temp['desc'].split("\\n")
for el in dp:
print "\t",el
except:
print "\n%s\n"%temp['desc']
print "\nAddress: %s"%hex(temp['address'])
print "Bit position: %s"%str(temp['position'])
print "Size: %s"%str(temp['size'])
print "Type: %s"%temp['access']
txt = "%s "%regname.upper()
txt = txt.ljust(30,'.')
txt += ": %s"%hex(temp['value'])
print "\n"+txt+"\n"
else:
devinfo = {}
devinfo = device.getDeviceInfo()
temp = []
temp = device.getDeviceData()
print "\nDevice: %s"%devname.upper()
print "Description: %s\n"%devinfo['description']
for el in temp:
txt = "%s "%el[0]
txt = txt.ljust(30,'.')
txt += ": %s"%el[1]
print txt
print "\n"
sys.exit()
# Display device memory map
if 'devicemap' in args:
numf = False
rd_blk = []
for el in args.split(' '):
if 'num=' in el:
numf = True
dv = data=int(el.split('=')[1])
rd_blk = app.SDB_showDeviceMemory(dv)
if not numf:
print "Select device from the list:\n"
#app.SDB_showDeviceList()
app.SDB_showTree()
dv = raw_input("\nSelect device number to show (any other key to exit):")
rd_blk = app.SDB_showDeviceMemory(dv)
if rd_blk is not None:
for el in rd_blk:
print "%06x"%el[0],
print ' '.join([("%02x"%el[a]) for a in range(1,17)]),
print " >",''.join([chr(el[a]) if el[a]>0x1F and el[a]<0x80 else chr(0x2E) for a in range(1,17)]),"<"
else:
# Show sdb in tree mode or long mode instead
if 'info' in args:
app.SDB_showInfo()
elif 'tree' in args:
app.SDB_showTree()
else:
app.SDB_showTree()
sys.exit()
\ No newline at end of file
import logging
import logging.handlers
import time
from alin import alindev
from datetime import datetime
dev = alindev.alinDevice('a1ba:608')
try:
try:
n_cycles = int(input('\nNumero de ciclos: '))
except:
n_cyckles = 1
try:
delay = int(input("\nIntervalo entre ciclos en segundos: "))
except:
delay = 1
Log_file = raw_input ("\nNombre fichero salida sin extension:")
if n_cycles < 0: n_cycles = 1
if delay < 0: delay = 1
if len(Log_file)<=0:
data = time.strftime("%Y%m%d_%H%M%S")
LOG_FILENAME = '/home/projects/alba-em/logs/Current_'+data+'.csv'
else:
LOG_FILENAME = '/home/projects/alba-em/logs/'+Log_file+'.csv'
my_logger = logging.getLogger('Alba Em#')
my_logger.setLevel(logging.DEBUG)
handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=5000000, backupCount=5)
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s,%(message)s')
handler.setFormatter(formatter)
my_logger.addHandler(handler)
# Enable ADC
dev.writeAttribute('CTL_FSM_CMD',0x01)
dev.writeAttribute('CTL_ADC_OS',0x06)
ch1 = ch2 = ch3 = ch3 = ch4 = ch5 = ch6 = ch7 = ch8 = samples_counter = 0
msg = " Ch1, Ch2, Ch3, Ch4, Ch5, Ch6, Ch7, Ch8, Samples Counter"
my_logger.info(msg)
print msg
counter = 0
while counter<n_cycles:
def getChannel(ch):
#readch = s.SDB_readAddress(ch)
readch = dev.readAttribute(ch)
if readch>0x7fffffff:
readch-=0x100000000
readch = (readch*10)/131072.
return readch
ch1 = getChannel('ADC_CH1')
ch2 = getChannel('ADC_CH2')
ch3 = getChannel('ADC_CH3')
ch4 = getChannel('ADC_CH4')
ch5 = getChannel('ADC_CH5')
ch6 = getChannel('ADC_CH6')
ch7 = getChannel('ADC_CH7')
ch8 = getChannel('ADC_CH8')
samples_counter = dev.readAttribute('SAMPLES_CNT')
msg = " " +str(ch1)+", "+str(ch2)+", "+str(ch3)+", "+str(ch4)+", "
msg += str(ch5)+", "+str(ch6)+", "+str(ch7)+", "+str(ch8)+", "+str(samples_counter)
print msg
my_logger.info(msg)
counter +=1
time.sleep(delay)
print "\nSEQUENCE COMPLETED!!!!"
print "\nGenerate output file:",LOG_FILENAME+"\n"
except Exception, e:
print "\nSEQUENCE ABORTED"
print str(e)
[Dolphin]
Timestamp=2015,10,15,15,24,21
Version=3
ViewMode=2
# EAeDIP128-6 Python Driver
#
# Created: March 2015
# by: Manolo Broseta at ALBA Computing Division
#
Alba_logo = [ 0x80, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe,
0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xe0, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x0f, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff,
0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xfc, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff,
0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff,
0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xfe, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00,
0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xf8, 0x0f, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x03, 0x00, 0x00, 0x80, 0xff, 0xff, 0x3f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00,
0x00, 0x80, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff,
0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xe0, 0x01, 0x00, 0xc0, 0x03, 0x00, 0x00, 0xf8, 0xff, 0x7f, 0x00,
0x00, 0x80, 0x0f, 0x00, 0x00, 0xf0, 0x03, 0x00, 0xc0, 0x03, 0x00, 0x00,
0xf8, 0xff, 0xff, 0x01, 0x00, 0xc0, 0x1f, 0x00, 0x00, 0xf8, 0x07, 0x00,
0xc0, 0x03, 0x00, 0x00, 0xf8, 0x00, 0xe0, 0x03, 0x00, 0xe0, 0x3f, 0x00,
0x00, 0xbc, 0x0f, 0x00, 0xc0, 0x03, 0x00, 0x00, 0xf8, 0x00, 0xc0, 0x03,
0x00, 0xf0, 0x7d, 0x00, 0x00, 0x1e, 0x1f, 0x00, 0xc0, 0x03, 0x00, 0x00,
0x78, 0x00, 0xc0, 0x03, 0x00, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x3e, 0x00,
0xc0, 0x03, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x01, 0x00, 0x7c, 0xf0, 0x01,
0x80, 0x07, 0x7c, 0x00, 0xc0, 0x03, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x00,
0x00, 0x3e, 0xe0, 0x03, 0xc0, 0xff, 0xff, 0x00, 0xc0, 0x03, 0x00, 0x00,
0xf8, 0xff, 0xff, 0x03, 0x00, 0xff, 0xff, 0x07, 0xe0, 0xff, 0xff, 0x01,
0xc0, 0x03, 0x00, 0x00, 0x78, 0x00, 0xc0, 0x03, 0x80, 0xff, 0xff, 0x0f,
0xf0, 0x00, 0xe0, 0x01, 0xc0, 0x03, 0x00, 0x00, 0x78, 0x00, 0xc0, 0x03,
0xc0, 0x07, 0x00, 0x1f, 0x78, 0x00, 0xc0, 0x03, 0xc0, 0xff, 0xff, 0x01,
0xf8, 0xff, 0xff, 0x03, 0xe0, 0x03, 0x00, 0x3e, 0x3c, 0x00, 0x80, 0x07,
0x80, 0xff, 0xff, 0x01, 0xf8, 0xff, 0xff, 0x01, 0xf0, 0x01, 0x00, 0x7c,
0x1e, 0x00, 0x00, 0x0f, 0x00, 0xfc, 0xff, 0x01, 0xf8, 0xff, 0x3f, 0x00,
0xf0, 0x00, 0x00, 0x78 ]
Face_image = [ 0x33, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x01,
0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xe0,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0xf0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0x00,
0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xc0, 0x4f, 0x00, 0x00, 0x00, 0xfc,
0xff, 0xfb, 0x4f, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xfb, 0x49, 0x00, 0x00,
0x00, 0xfc, 0xff, 0xf3, 0x43, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xf3, 0x8d,
0x00, 0x00, 0x00, 0xfc, 0xff, 0xf3, 0x80, 0x00, 0x00, 0x00, 0xfc, 0xff,
0xe3, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00,
0xf8, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x03, 0x00, 0x00,
0x00, 0x00, 0xf8, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x43,
0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x83, 0x00, 0x00, 0x00, 0x00, 0xc0,
0xff, 0x83, 0x01, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x07, 0x01, 0x00, 0x00,
0x00, 0xc0, 0xff, 0x07, 0x02, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x07, 0x00,
0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
0x0f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00,
0xc0, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x07, 0x00, 0x00,
0x00, 0x00, 0xe0, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x07,
0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x07, 0x02, 0x00, 0x00, 0x80, 0xff,
0xff, 0x07, 0x07, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xef, 0x07, 0x00, 0x00,
0xf8, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x07,
0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xd0, 0xff, 0xf7,
0xff, 0x05, 0x00, 0x00, 0xc0, 0xff, 0x7f, 0x7f, 0x0e, 0x00, 0x00, 0x80,
0xfe, 0x9f, 0x3d, 0x1f, 0x00, 0x00, 0x00, 0xfc, 0xfd, 0xbf, 0x1f, 0x00,
0x00, 0x00, 0xfc, 0xff, 0xbf, 0x1f, 0x00, 0x00, 0x04, 0xf8, 0xfc, 0x1f,
0x1e, 0x00, 0x00, 0x00, 0x78, 0xcc, 0x03, 0x02, 0x00, 0x00, 0x00, 0x20,
0xc8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00 ]
\ No newline at end of file
# Panel programme
#
# Created: March 2015
# by: Manolo Broseta at ALBA Computing Division
#
import time, sys, select, math
from paneldrv import *
from image_res import *
from alin import alindev
DEVNAME = 'a1ba:608'
class Panel():
def __init__(self, parent=None):
self.drv = PanelDriver()
self.panel_brightness = 0
self.panel_illumination = False
self.drv.SetProtocol(32,10)
self.device = alindev.alinDevice(DEVNAME)
# Load binary file
# Enable ADC
self.device.writeAttribute('CTL_FSM_CMD',0x01)
self.ch_address = { "ch1": {'add':'ADC_CH1', 'pos':(5,17)},
"ch2": {'add':'ADC_CH2', 'pos':(5,29)},
"ch3": {'add':'ADC_CH3', 'pos':(5,41)},
"ch4": {'add':'ADC_CH4', 'pos':(5,53)},
"ch5": {'add':'ADC_CH5', 'pos':(70,17)},
"ch6": {'add':'ADC_CH6', 'pos':(70,29)},
"ch7": {'add':'ADC_CH7', 'pos':(70,41)},
"ch8": {'add':'ADC_CH8', 'pos':(70,53)}
}
def ProcessData(self,arg):
if arg is not None and len(arg)>0:
if arg[0] == DC1_BYTE:
data_len = arg[1]
if data_len>0:
if DEBUG:
print "I2C_READ_DATA= ",
for el in arg[2:data_len]:
print hex(el)+",",
print
if data_len>DATA_LEN: data_len=DATA_LEN
r_data = [chr(el) for el in arg[2:data_len]]
r_data = ''.join(r_data)
r_data = r_data.split('\x1b')
for data in r_data:
try:
if data[0] == 'H':
if ord(data[2]) == 0x01:
x=0
try:
x = ord(data[3])
except:
pass
y=0
try:
y = ord(data[4])
except:
pass
print "Press X=%s Y=%s"%(str(x),str(y))
self.PrintPressed(x, y)
elif ord(data[2]) == 0x00 or ord(data[2]) == 0x02:
#self.PrintReleased()
pass
except:
pass
if not self.displayed_logo:
self.drv.SendData('#ZF 2')
self.drv.SendData('#ZB 0')
self.drv.SendData('#ZZ 1,2')
self.drv.SendData('#ZL 5,0, ALBA-EM\sADC\sChannels\n')
self.drv.SendData('#ZF 1')
self.drv.SendData('#ZZ 1,2')
for idx, el in self.ch_address.iteritems():
value = self.getChannel(el['add'])
text_val = str(value)
text = idx+":\s"+text_val[:8]+"\n"
x = el['pos'][0]
y = el['pos'][1]
text = "#ZL "+str(x)+","+str(y)+","+text
self.drv.SendData(text)
def getChannel(self, ch):
readch = self.device.readAttribute(ch)
if readch>0x7fffffff:
readch-=0x100000000
readch = round((readch*10)/131072.,6)
return readch
def PrintPressed(self, x=0,y=0):
self.Logo_set(False)
def Panel_set(self, bright=100, illumination=True):
self.panel_brightness = bright
self.panel_illumination = illumination
self.drv.PanelSettings(self.panel_brightness, self.panel_illumination)
def Logo_display(self):
self.drv.ClearScreen()
# Delete cursor
self.drv.SendData('#TC 0')
# Set Panel brightness and illumination
self.Panel_set(bright= 100)
# Draw Alba Logo
self.drv.DrawImage(0,0,Alba_logo)
# Set tocuh screen area
self.drv.SendData('#AH 0,0,127,64')
self.drv.SendData('#AA 0')
self.drv.SendData('#AA 1')
self.wellcome_disp_counter = 0
self.displayed_logo = True
self.brightness_counter = 0
def Logo_set(self,status=True):
if status and not self.displayed_logo:
self.Logo_display()
self.displayed_logo = True
elif not status:
self.Panel_set(bright=100)
self.brightness_counter = 0
if self.displayed_logo:
self.drv.ClearScreen()
#self.drv.SendData("#YS 2") # Buzzer
self.displayed_logo = False
else:
# do nothing if:
# - request to display Logo, but Logo already in screen
pass
def Logo_refresh_control(self):
self.wellcome_disp_counter += 1
self.brightness_counter += 1
if self.wellcome_disp_counter > 120:
self.wellcome_disp_counter = 0
self.Logo_set(True)
if self.brightness_counter > 60 and self.panel_brightness > 100:
self.Panel_set(bright=50)
elif self.brightness_counter > 90 and self.panel_brightness > 20:
self.Panel_set(bright=20)
elif self.brightness_counter > 180 and self.panel_illumination:
self.Panel_set(bright=10)
def TouchQuery(self):
self.Logo_display()
while 1:
ret_val = self.drv.GetData()
self.ProcessData(ret_val)
time.sleep(1)
self.Logo_refresh_control()
if __name__ == "__main__":
import sys, select
args = ' '.join(sys.argv[1:])
Work = Panel()
Work.TouchQuery()
sys.exit()
# EAeDIP128-6 Python Driver
#
# Created: March 2015
# by: Manolo Broseta at ALBA Computing Division
#
import smbus
import time, sys, select, math
from image_res import *
I2C_ADDRESS = 0x94
# Fixed I2C bus numbers given by the I2C-tool using the NUC board
NUC_I2C_BUS_0 = 8
NUC_I2C_BUS_1 = 9
DC1_BYTE = 0x11
DC2_BYTE = 0x12
ACK_VALUE = 0x06
NACK_VALUE = 0x15
DATA_LEN = 32
# Conversion to the I2C_ADDRESS to be used used by the I2C-tools
# Only the 7 MSB shifted 1 bit to the right
I2C_ADDRESS = I2C_ADDRESS >> 1
DEBUG = False
class PanelDriver():
def __init__(self, parent=None):
self.bus = smbus.SMBus(NUC_I2C_BUS_0)
def SendData(self,arg):
try:
cmds_list = arg.replace(","," ").split(" ")
except:
cmds_list = arg
lst = []
for cmd in cmds_list:
if "^" in cmd:
if cmd[1] in ['L','M','J']:
lst.append(ord(cmd[1])-64)
else:
if cmd.isdigit():
lst.append(int(cmd))
else:
for ch in cmd:
if ord(ch) == 0x23:
lst.append(0x1B)
else:
lst.append(ord(ch))
# if '#Z' not in cmd:
# lst.append(0x0A)
send_list = []
send_list.append(DC1_BYTE)
bcc = DC1_BYTE
# Fisrt value to be sent is te len of the protocol
send_list.append(len(lst))
# build the list to send
for it in lst:
bcc = bcc + it
send_list.append(it)
bcc = bcc + len(lst)
# Add the checksum as last element
bcc = bcc & 0xff
send_list.append(bcc)
if DEBUG:
print "I2C_WRITE_DATA= ",
for el in send_list:
print hex(el)+",",
print
self.bus.write_block_data(I2C_ADDRESS, 0, send_list)
ret_value = self.bus.read_byte(I2C_ADDRESS)
return(ret_value)
def SetProtocol(self, size=32,timeout=0):
send_list = [DC2_BYTE, 3, 0x44, size, timeout]
# build the list to send
bcc = 0
for it in send_list:
bcc = bcc + it
# Add the checksum as last element
bcc = bcc & 0xff
send_list.append(bcc)
self.bus.write_block_data(I2C_ADDRESS, 0, send_list)
ret_value = self.bus.read_byte(I2C_ADDRESS)
return(ret_value)
def GetProtocol(self):
# Start Request for content of send buffer
send_list = [DC2_BYTE, 0x01, 0x50]
bcc = 0
for it in send_list:
bcc = bcc + it
bcc = bcc & 0xff
send_list.append(bcc)
self.bus.write_block_data(I2C_ADDRESS, 0, send_list)
ret_value = []
if self.bus.read_byte(I2C_ADDRESS) == ACK_VALUE:
ret_value = self.bus.read_i2c_block_data(I2C_ADDRESS,0)
return ret_value
def GetData(self):
# Start Request for content of send buffer
send_list = [DC2_BYTE, 0x01, 0x53]
bcc = 0
for it in send_list:
bcc = bcc + it
bcc = bcc & 0xff
send_list.append(bcc)
self.bus.write_block_data(I2C_ADDRESS, 0, send_list)
ret_value = []
if self.bus.read_byte(I2C_ADDRESS) == ACK_VALUE:
ret_value = self.bus.read_i2c_block_data(I2C_ADDRESS,0)
return ret_value
def ClearScreen(self):
r_d = self.SendData("^L")
r_d = self.SendData("#DL")
r_d = self.SendData("#RL 0,0,128,64")
return r_d
def PanelSettings(self, bright= 100, illumination=True):
if bright >100 : bright = 100
self.SendData("#YH "+str(bright))
self.SendData("#YL "+str(int(illumination)))
if DEBUG:
print "Panel Brightness = %s Illumination = %s"%(str(bright),illumination)
def DrawImage(self,pos_x=0,pos_y=0,image=[]):
width = image[0]
real_width = ((width/8)*8)+8
if real_width>128:real_width = 128
blocks = real_width/8
height = image[1]
init_pos_x = pos_x
init_pos_y = pos_y
#for a in range(0,len(image)-2,blocks):
for a in range(len(image)-2):
y = ((a * 8) / real_width)
x = ((a * 8 ) - (y * real_width))
y += init_pos_y
x += init_pos_x
if x>120 or y>63: pass
#dato = image[(a+2):(a+2+blocks)]
#dato_inv = [int("{:08b}".format(a)[::-1],2) for a in dato]
#temp = "#UL "+str(x)+","+str(y)+","+str(blocks*8)+",1"
#for a in dato_inv:
# temp += ","+str(a)
dato = image[a+2]
dato_inv = int("{:08b}".format(dato)[::-1],2)
temp = "#UL "+str(x)+","+str(y)+",8,1,"+str(dato_inv)
self.SendData(temp)
if DEBUG:
print temp
# Panel programme
#
# Created: March 2015
# by: Manolo Broseta at ALBA Computing Division
#
import time, sys, select, math
from paneldrv import *
from image_res import *
class Panel_Off():
def __init__(self, parent=None):
self.drv = PanelDriver()
self.drv.ClearScreen()
self.drv.SendData('#TC 0')
self.drv.PanelSettings(bright=70)
self.drv.DrawImage(40,0,Face_image)
self.drv.SendData('#ZB 1')
self.drv.SendData('#ZL 0,20,BYE\n')
self.drv.SendData('#ZL 10,30,BYE\n')
self.drv.SendData('#ZL 90,20,BYE\n')
self.drv.SendData('#ZL 100,30,BYE\n')
time.sleep(5)
self.drv.SendData('#PD 0,0')
self.drv.ClearScreen()
if __name__ == "__main__":
import sys, select
args = ' '.join(sys.argv[1:])
Work = Panel_Off()
sys.exit()
[Dolphin]
Timestamp=2015,10,15,15,25,4
Version=3
ViewMode=2
import socket
import sys
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect the socket to the port where the server is listening
server_address = ('10.0.36.222', 5025)
print >>sys.stderr, '\nConnecting to %s port %s' % server_address
sock.connect(server_address)
try:
# Send data
message = 'This is the message. It will be repeated.'
print >>sys.stderr, 'Sending --> "%s"' % message
sock.sendall(message)
# Look for the response
amount_received = 0
amount_expected = len(message)
while amount_received < amount_expected:
data = sock.recv(128)
amount_received += len(data)
print >>sys.stderr, '\nReceived <-- "%s"' % data
finally:
print >>sys.stderr, '\nClosing socket'
sock.close()
import socket
import sys
import os
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the port
server_address = ('10.0.36.222', 5025)
print >>sys.stderr, '\nStarting up on %s port %s' % server_address
sock.bind(server_address)
# Listen for incoming connections
sock.listen(1)
while True:
# Wait for a connection
print >>sys.stderr, '\nWaiting for a connection.......'
connection, client_address = sock.accept()
try:
print >>sys.stderr, '\nConnection started from', client_address
print >>sys.stderr, '\n*** Type "quit" to finish connection ***'
# Receive the data in small chunks and retransmit it
while True:
data = connection.recv(128)
data = " ".join(data.splitlines())
print >>sys.stderr, '--> ',data,
if data:
if data.lower() == 'quit' or data.lower()=='exit':
print >>sys.stderr, '\nNo more data from', client_address
break
else:
available_cmds = ['help', 'offset', 'load', 'address', 'write', 'range', 'dev', 'info', 'tree']
if ('devicemap' in data and 'num' in data) or any(item in data.split()[0] for item in available_cmds) :
data = " ".join(data.splitlines())
cmd = "ctabem "+data+" > tempout"
print cmd
os.system(cmd)
with open("tempout") as f:
for line in f:
connection.sendall("> "+line)
print >>sys.stderr, '< ',line,
else:
data = "NOT VALID COMMAND\n"
connection.sendall(data)
print >>sys.stderr, '<-- ',data,
finally:
# Clean up the connection
connection.close()
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