|
From: <ni...@us...> - 2010-11-11 14:37:08
|
Revision: 105
http://openautomation.svn.sourceforge.net/openautomation/?rev=105&view=rev
Author: nilss1
Date: 2010-11-11 14:37:02 +0000 (Thu, 11 Nov 2010)
Log Message:
-----------
Fix 14Byte encoding
Modified Paths:
--------------
PyWireGate/trunk/knx_connector/DPT_Types.py
PyWireGate/trunk/knx_connector/KNX_Connector.py
Modified: PyWireGate/trunk/knx_connector/DPT_Types.py
===================================================================
--- PyWireGate/trunk/knx_connector/DPT_Types.py 2010-11-11 08:07:20 UTC (rev 104)
+++ PyWireGate/trunk/knx_connector/DPT_Types.py 2010-11-11 14:37:02 UTC (rev 105)
@@ -96,7 +96,10 @@
elif dsobj:
if "dptid" in dsobj.config:
dpt = dsobj.config['dptid']
- else:
+ if dpt == -1:
+ dpt = self.guessDPT(msg)
+ #return False
+ if dpt == 0:
return False
return self._encode(msg,dpt)
@@ -438,6 +441,7 @@
return res.decode('iso-8859-15')
def encodeDPT16(self,val):
+ self.debug("DPT16encode: %r (%s)" % (val,type(val)))
if type(val) == unicode:
val = val.encode('iso-8859-15')
## max 14
@@ -478,9 +482,22 @@
## 14byte String
return 16
return 0
+ def guessDPT(self,raw):
+ if type(raw) == int:
+ if raw < 256:
+ return 5
+ elif raw < 655535:
+ return 7
+ elif type(raw) == float:
+ if raw > -671088.64 and raw < 670760.96:
+ return 9
+ else:
+ return 14
+ elif type(raw) == str or type(raw) == unicode:
+ return 16
+ return 0
-
if __name__ == "__main__":
dpttypes = dpt_type(False)
print dpttypes.decode([24,88],dptid=9)
Modified: PyWireGate/trunk/knx_connector/KNX_Connector.py
===================================================================
--- PyWireGate/trunk/knx_connector/KNX_Connector.py 2010-11-11 08:07:20 UTC (rev 104)
+++ PyWireGate/trunk/knx_connector/KNX_Connector.py 2010-11-11 14:37:02 UTC (rev 105)
@@ -174,13 +174,17 @@
def send(self,msg,dstaddr):
try:
- if type(msg) <> list:
- self.log("Failed send %r to %r" % (msg,dstaddr),'warn')
- return
addr = self.str2grpaddr(dstaddr)
if addr:
- msg = [0,KNXWRITEFLAG] + msg
- self.sendQueue.put((addr,msg))
+ apdu = [0]
+ if type(msg) == int:
+ apdu.append(KNXWRITEFLAG | msg)
+ elif type(msg) == list:
+ apdu = apdu +[KNXWRITEFLAG]+ msg
+ else:
+ self.WG.errorlog("invalid Message %r to %r" % (msg,dstaddr))
+ return
+ self.sendQueue.put((addr,apdu))
#self.KNX.EIBSendGroup(addr,msg)
except:
self.WG.errorlog("Failed send %r to %r" % (msg,dstaddr))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|