|
From: <ma...@us...> - 2010-12-13 21:50:31
|
Revision: 217
http://openautomation.svn.sourceforge.net/openautomation/?rev=217&view=rev
Author: mayerch
Date: 2010-12-13 21:50:25 +0000 (Mon, 13 Dec 2010)
Log Message:
-----------
Initial commit for setting up the transform infrastructure
Added Paths:
-----------
CometVisu/trunk/visu/transforms/
CometVisu/trunk/visu/transforms/transform_default.js
CometVisu/trunk/visu/transforms/transform_knx.js
Added: CometVisu/trunk/visu/transforms/transform_default.js
===================================================================
--- CometVisu/trunk/visu/transforms/transform_default.js (rev 0)
+++ CometVisu/trunk/visu/transforms/transform_default.js 2010-12-13 21:50:25 UTC (rev 217)
@@ -0,0 +1,77 @@
+/* transform_default.js (c) 2010 by Christian Mayer [CometVisu at ChristianMayer dot de]
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+*/
+
+/**
+ * This class defines the default transforms:
+ * encode: transform JavaScript to bus value
+ * decode: transform bus to JavaScript value
+ */
+Transform = {
+ 'raw': {
+ name : 'Only the RAW value',
+ encode: function( i ){
+ return i;
+ },
+ decode: function( i ){
+ return i;
+ }
+ },
+ 'int': {
+ name : 'Cast to Int',
+ encode: function( i ){
+ return i.toString();
+ },
+ decode: function( i ){
+ return parseInt( i );
+ }
+ },
+ 'float': {
+ name : 'Cast to Float',
+ encode: function( i ){
+ return i.toString();
+ },
+ decode: function( i ){
+ return parseFloat( i );
+ }
+ }
+}
+
+/****************************************************************************
+ * All functions below are only in this, i.e. the default, file.
+ * All further transforms will only have the above data structure.
+ ***************************************************************************/
+
+function addTransform( prefix, transforms )
+{
+ for( trans in transforms )
+ {
+ if( transforms[trans].link )
+ {
+ Transform[ trans ] = transforms[ transforms[trans].link ];
+ } else {
+ Transform[ trans ] = transforms[ trans ];
+ }
+ }
+}
+
+/**
+ * The universal decoding function.
+ */
+function decode( raw, type )
+{
+ return decodeDPT( raw, type.substr(4) ); // filter away the 'DPT:'
+}
Added: CometVisu/trunk/visu/transforms/transform_knx.js
===================================================================
--- CometVisu/trunk/visu/transforms/transform_knx.js (rev 0)
+++ CometVisu/trunk/visu/transforms/transform_knx.js 2010-12-13 21:50:25 UTC (rev 217)
@@ -0,0 +1,36 @@
+/* transform_knx.js (c) 2010 by Christian Mayer [CometVisu at ChristianMayer dot de]
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+*/
+
+/**
+ * This class defines the default transforms:
+ * encode: transform JavaScript to bus value
+ * decode: transform bus to JavaScript value
+ */
+addTransform( 'DPT', {
+ '1.001': {
+ name : 'DPT_Switch',
+ encode: function( i ){
+ return i.toSting( 16 );
+ },
+ decode: function( i ){
+ return parseInt( i , 16 );
+ }
+ },
+ '1': {
+ link : '1.001'
+ }
+} );
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|