示例#1
0
文件: serve.py 项目: jamielitest/knx
 def getSection(self, entry, level=0, path=None):
     if path is None:
         path = []
     result = []
     level += 1
     for section in entry['sections']:
         visibleDescription = section[
             'visibleDescription'] if 'visibleDescription' in section else ''
         newSection = {
             'name': section['name'],
             'number': section['number'],
             'visibleDescription': visibleDescription,
             'sections': []
         }
         path.append(escape(section['number']).encode('utf-8'))
         pathStr = urllib.quote('/'.join(path))
         self._items[pathStr] = self._cleanupItems(section['items'])
         newSection['path'] = pathStr
         result.append(newSection)
         subSections = self.getSection(section, level, path)
         path.pop()
         if subSections:
             newSection['sections'].append(subSections[0])
     level -= 1
     return result
示例#2
0
 def dumpParameterTypes(self, app):
     if app.device_type == 0xa01d:
         pass
     # ParameterTypes
     for key, item in sorted(app.parameterTypes.items(), key = lambda x: x[0]):
         parameterTypeId = "%s_PT-%s" % (app.applicationId, knx_escape.escape(item['parameter_type_name']))
         atNumber = item['atomic_type_number']
         print '<ParameterType Id="%s" Name="%s" InternalDescription="%s">' % (parameterTypeId, item['parameter_type_name'], item['parameter_type_description'] or '')
         if atNumber == 1:
             print '   <TypeNumber SizeInBit="%u" Type="unsignedInt" minInclusive="%u" maxInclusive="%u" />' % (item['parameter_type_size'], item['parameter_minimum_value'], item['parameter_maximum_value'])
         elif atNumber == 4:
             print '   <TypeRestriction Base="Value" SizeInBit="%u">' % (item['parameter_type_size'], )
             for value in sorted(item['listOfValues'], key = lambda x: x['display_order']):
                 enumId = "%s_EN-%u" % (parameterTypeId, value['real_value'])
                 print '      <Enumeration Text="%s" Value="%s" Id="%s" DisplayOrder="%u" />' % (value['displayed_value'], value['real_value'], enumId, value['display_order'])
             print '   </TypeRestriction>'
         elif atNumber == 5:
             print '   <TypeRestriction Base="BinaryValue" SizeInBit="%u">' % (item['parameter_type_size'], )
             for value in sorted(item['listOfValues'], key = lambda x: x['display_order']):
                 enumId = "%s_EN-%u" % (parameterTypeId, value['real_value'])
                 print '      <Enumeration Text="%s" Value="%s" Id="%s" DisplayOrder="%u" BinaryValue="%s" />' % (value['displayed_value'], value['real_value'], enumId, value['display_order'], value['binary_value'])
             print '   </TypeRestriction>'
         elif atNumber == 0:
             print "   <TypeNone />"
         else:
             print "Uups!"
         print "</ParameterType>"
     # Parameter
     for item in sorted(app.parameters, key = lambda x: x['parameter_number']):
         if item['par_parameter_id'] is None:
             print item['parameter_name'], item['parameter_description']
示例#3
0
    def getHardware(self, devices):
        for dev in sorted(devices.values(), key = lambda x: x.catalog_entry_id): # virtual_device_id
            hardware = dict(_id = dev.hardwareId, name = dev.hardwareProduct.product_name,
                serialNumber = dev.hardwareProduct.product_serial_number, versionNumber = dev.hardwareProduct.product_version_number,
                busCurrent = dev.hardwareProduct.bus_current, hasApplicationProgram = True if dev.program_id else False,
                hardware2Programs = [], products = [],
            )
            if dev.hardwareProduct.original_manufacturer_id:
                hardware['originalManufacturer'] = "M-%04X" % dev.hardwareProduct.original_manufacturer_id
            products = list(self.db.catalog_entry.find({"product_id": dev.catalogEntry.product_id}, sort = [("catalog_entry_id", mongo.ASCENDING)]))
            for product in products:

                productId = "%s2_P-%s" % (dev.hardwareId, knx_escape.escape(product['order_number']))

                productDict = dict(_id = productId, text = product['entry_name'], orderNumber = product['order_number'],
                    isRailMounted = True if product['din_flag'] else False, widthInMillimeter = product['entry_width_in_millimeters'],
                    translations = self.getTranslations('catalog_entry', product['catalog_entry_id'])
                 )
                hardware['products'].append(productDict)
            prodProg = list(self.db.product_to_program.find({"product_id": dev.hardwareProduct.product_id}))
            for p2p in prodProg:
                dt = self.db.application_program.find_one({'program_id': p2p['program_id']}, {'device_type': 1, 'program_version': 1, '_id': 0})
                if dt:
                    deviceType = dt['device_type']
                    programVersion = dt['program_version']
                    programNumber = "M-%04X_H-%s-%u_HP-%04X-%02X" % (product['manufacturer_id'], knx_escape.escape(dev.hardwareProduct.product_serial_number), dev.hardwareProduct.product_version_number, deviceType, int(programVersion))
                    programNumber = "%s-%s" % (programNumber, hashlib.sha1(programNumber).hexdigest()[-4 : ].upper())
                    print '<Hardware2Program %s />' % (programNumber)
                if p2p['registration_year']:
                    year = p2p['registration_year']
                    if year < 1900:
                        year += 1900
                    if p2p['prod2prog_status_code'] in (10, 20):
                        print "        *** Reg-Number: %u/%u" % (year, p2p['registration_number'])
            self.db.hardware.update({"_id": hardware['_id']}, hardware, upsert = True, safe = True)
示例#4
0
 def hardwareId(self):
     hardwareId = "M-%04X_H-%s-%u" % (self.hardwareProduct.manufacturer_id,
         (knx_escape.escape(self.hardwareProduct.product_serial_number)),
         self.hardwareProduct.product_version_number
     )
     if self.hardwareProduct.original_manufacturer_id:
         hardwareId = "%s-O%04X" % (hardwareId, self.hardwareProduct.original_manufacturer_id)
     return hardwareId
示例#5
0
 def hardwareId(self):
     hardwareId = "M-{0:04X}_H-{1!s}-{2:d}".format(
         self.hardwareProduct.manufacturer_id,
         (knx_escape.escape(self.hardwareProduct.product_serial_number)),
         self.hardwareProduct.product_version_number)
     if self.hardwareProduct.original_manufacturer_id:
         hardwareId = "{0!s}-O{1:04X}".format(
             hardwareId, self.hardwareProduct.original_manufacturer_id)
     return hardwareId
示例#6
0
 def dumpParameterTypes(self, app):
     if app.device_type == 0xa01d:
         pass
     # ParameterTypes
     for key, item in sorted(app.parameterTypes.items(),
                             key=lambda x: x[0]):
         parameterTypeId = "{0!s}_PT-{1!s}".format(
             app.applicationId,
             knx_escape.escape(item['parameter_type_name']))
         atNumber = item['atomic_type_number']
         print '<ParameterType Id="{0!s}" Name="{1!s}" InternalDescription="{2!s}">'.format(
             parameterTypeId, item['parameter_type_name'],
             item['parameter_type_description'] or '')
         if atNumber == 1:
             print '   <TypeNumber SizeInBit="{0:d}" Type="unsignedInt" minInclusive="{1:d}" maxInclusive="{2:d}" />'.format(
                 item['parameter_type_size'],
                 item['parameter_minimum_value'],
                 item['parameter_maximum_value'])
         elif atNumber == 4:
             print '   <TypeRestriction Base="Value" SizeInBit="{0:d}">'.format(
                 item['parameter_type_size'])
             for value in sorted(item['listOfValues'],
                                 key=lambda x: x['display_order']):
                 enumId = "{0!s}_EN-{1:d}".format(parameterTypeId,
                                                  value['real_value'])
                 print '      <Enumeration Text="{0!s}" Value="{1!s}" Id="{2!s}" DisplayOrder="{3:d}" />'.format(
                     value['displayed_value'], value['real_value'], enumId,
                     value['display_order'])
             print '   </TypeRestriction>'
         elif atNumber == 5:
             print '   <TypeRestriction Base="BinaryValue" SizeInBit="{0:d}">'.format(
                 item['parameter_type_size'])
             for value in sorted(item['listOfValues'],
                                 key=lambda x: x['display_order']):
                 enumId = "{0!s}_EN-{1:d}".format(parameterTypeId,
                                                  value['real_value'])
                 print '      <Enumeration Text="{0!s}" Value="{1!s}" Id="{2!s}" DisplayOrder="{3:d}" BinaryValue="{4!s}" />'.format(
                     value['displayed_value'], value['real_value'], enumId,
                     value['display_order'], value['binary_value'])
             print '   </TypeRestriction>'
         elif atNumber == 0:
             print "   <TypeNone />"
         else:
             print "Uups!"
         print "</ParameterType>"
     # Parameter
     for item in sorted(app.parameters,
                        key=lambda x: x['parameter_number']):
         if item['par_parameter_id'] is None:
             print item['parameter_name'], item['parameter_description']
示例#7
0
文件: serve.py 项目: lumovan/knx
 def getSection(self, entry, level = 0, path = []):
     result = []
     level += 1
     for section in entry['sections']:
         visibleDescription = section['visibleDescription'] if 'visibleDescription' in section else ''
         newSection = {'name': section['name'], 'number': section['number'], 'visibleDescription': visibleDescription , 'sections': []}
         path.append(escape(section['number']).encode('utf-8'))
         pathStr = urllib.quote('/'.join(path))
         self._items[pathStr] = self._cleanupItems(section['items'])
         newSection['path'] = pathStr
         result.append(newSection)                
         subSections = self.getSection(section, level, path)
         path.pop()
         if subSections:
             newSection['sections'].append(subSections[0])
     level -= 1
     return result
示例#8
0
文件: serve.py 项目: jamielitest/knx
import pymongo as mongo
import json

from tornado.options import define, options
from knxReTk.utilz.knx_escape import escape, unescape

SERVER_VERSION = "1.0"
SERVER_NAME = "KNXToolServer"

define("port", default=8086, help="run on the given port", type=int)

cookieSecret = lambda: base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes
                                        )
unescaper = lambda x: unescape(urllib.unquote(x))
escaper = lambda x: urllib.quote(escape(x))
expiration = lambda minutes: datetime.datetime.utcnow() + datetime.timedelta(
    minutes=minutes)


class Catalog(object):
    def __init__(self, conn, dbName):
        self._rawEntries = list(conn[dbName].catalog.find())
        self._items = {}
        self._sections = []
        for entry in self._rawEntries:
            self._sections.append(self.getSection(entry))
        self._sections = self._sections[0]

    @property
    def sections(self):
示例#9
0
    def getHardware(self, devices):
        for dev in sorted(
                devices.values(),
                key=lambda x: x.catalog_entry_id):  # virtual_device_id
            hardware = dict(
                _id=dev.hardwareId,
                name=dev.hardwareProduct.product_name,
                serialNumber=dev.hardwareProduct.product_serial_number,
                versionNumber=dev.hardwareProduct.product_version_number,
                busCurrent=dev.hardwareProduct.bus_current,
                hasApplicationProgram=True if dev.program_id else False,
                hardware2Programs=[],
                products=[],
            )
            if dev.hardwareProduct.original_manufacturer_id:
                hardware['originalManufacturer'] = "M-{0:04X}".format(
                    dev.hardwareProduct.original_manufacturer_id)
            products = list(
                self.db.catalog_entry.find(
                    {"product_id": dev.catalogEntry.product_id},
                    sort=[("catalog_entry_id", mongo.ASCENDING)]))
            for product in products:

                productId = "{0!s}2_P-{1!s}".format(
                    dev.hardwareId, knx_escape.escape(product['order_number']))

                productDict = dict(
                    _id=productId,
                    text=product['entry_name'],
                    orderNumber=product['order_number'],
                    isRailMounted=True if product['din_flag'] else False,
                    widthInMillimeter=product['entry_width_in_millimeters'],
                    translations=self.getTranslations(
                        'catalog_entry', product['catalog_entry_id']))
                hardware['products'].append(productDict)
            prodProg = list(
                self.db.product_to_program.find(
                    {"product_id": dev.hardwareProduct.product_id}))
            for p2p in prodProg:
                dt = self.db.application_program.find_one(
                    {'program_id': p2p['program_id']}, {
                        'device_type': 1,
                        'program_version': 1,
                        '_id': 0
                    })
                if dt:
                    deviceType = dt['device_type']
                    programVersion = dt['program_version']
                    programNumber = "M-{0:04X}_H-{1!s}-{2:d}_HP-{3:04X}-{4:02X}".format(
                        product['manufacturer_id'],
                        knx_escape.escape(
                            dev.hardwareProduct.product_serial_number),
                        dev.hardwareProduct.product_version_number, deviceType,
                        int(programVersion))
                    programNumber = "{0!s}-{1!s}".format(
                        programNumber,
                        hashlib.sha1(programNumber).hexdigest()[-4:].upper())
                    print '<Hardware2Program {0!s} />'.format((programNumber))
                if p2p['registration_year']:
                    year = p2p['registration_year']
                    if year < 1900:
                        year += 1900
                    if p2p['prod2prog_status_code'] in (10, 20):
                        print "        *** Reg-Number: {0:d}/{1:d}".format(
                            year, p2p['registration_number'])
            self.db.hardware.update({"_id": hardware['_id']},
                                    hardware,
                                    upsert=True,
                                    safe=True)
示例#10
0
 def productId(self):
     productId = "{0!s}_P-{1!s}".format(
         self.hardwareId, knx_escape.escape(self.catalogEntry.order_number))
     return productId
示例#11
0
 def catalogItemId(self):
     catalogItemId = "{0!s}_CI-{1!s}-{2:d}".format(
         self.hardwareProductId,
         knx_escape.escape(self.catalogEntry.order_number),
         self.hardwareProduct.product_version_number)
     return catalogItemId
示例#12
0
文件: serve.py 项目: lumovan/knx
import tornado.web

import pymongo as mongo
import json

from tornado.options import define, options
from knxReTk.utilz.knx_escape import escape, unescape

SERVER_VERSION = "1.0"
SERVER_NAME = "KNXToolServer"

define("port", default = 8086, help = "run on the given port", type = int)

cookieSecret = lambda: base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes)
unescaper = lambda x: unescape(urllib.unquote(x))
escaper = lambda x: urllib.quote(escape(x))
expiration = lambda minutes: datetime.datetime.utcnow() + datetime.timedelta(minutes = minutes)


class Catalog(object):

    def __init__(self, conn, dbName):
        self._rawEntries = list(conn[dbName].catalog.find())
        self._items = {}
        self._sections = []
        for entry in self._rawEntries:
            self._sections.append(self.getSection(entry))
        self._sections = self._sections[0]

    @property
    def sections(self):
示例#13
0
 def productId(self):
     productId = "%s_P-%s" % (self.hardwareId, knx_escape.escape(self.catalogEntry.order_number), )
     return productId
示例#14
0
 def catalogItemId(self):
     catalogItemId = "%s_CI-%s-%u" % (self.hardwareProductId, knx_escape.escape(self.catalogEntry.order_number),
         self.hardwareProduct.product_version_number)
     return catalogItemId