UNPKG

@candy-line/node-red-contrib-omron-2jcie-bu

Version:

OMRON 2JCIE-BU Environment Sensor (USB Type) Serial Data Translator

17 lines 2.35 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(e){e.nodes.registerType("2JCIE-BU in",class{constructor(t){e.nodes.createNode(this,t),this.name=t.name,this.messageFormat=t.messageFormat||"standard",this.parser=new _jcieBuCommon.Omron2jcieBuPacketParser(t.ttl||1e4);const a=(e,t,a,s)=>{let r;switch(this.messageFormat){case"standard":a.payload=Object.assign(t,{timestamp:s}),r=[a];break;case"chart":r=Object.keys(t.data||{}).map(e=>"id"===e||"number"!=typeof t.data[e]?null:{topic:e,payload:t.data[e],timestamp:s}).filter(e=>e);break;default:r=[a]}return r};this.on("input",e=>{try{const t=(new Date).toISOString(),s=e.payload,r=this.parser.parseResponse(s);if(r.finished){switch(r.address){case 20513:e.topic="getLatestSensorData";break;case 21506:e.topic="getMountingOrientation";break;case 6154:e.topic="getDeviceInformation";break;case 20753:e.topic="setLED"}a(0,r,e,t).forEach(e=>{this.send(e)})}}catch(e){this.error(e)}})}});e.nodes.registerType("2JCIE-BU out",class{constructor(t){e.nodes.createNode(this,t),this.name=t.name,this.builder=new _jcieBuCommon.Omron2jcieBuPacketBuilder,this.on("input",e=>{let t;const{topic:a,payload:s}=e;try{switch(a){case"getLatestSensorData":t=this.builder.buildReadLatestDataLongRequest();break;case"getMountingOrientation":t=this.builder.buildReadMountingOrientationRequest();break;case"getDeviceInformation":t=this.builder.buildReadDeviceInformationRequest();break;case"setLED":t=this.builder.buildWriteLEDSettingsRequest(s);break;default:throw Error(`Unknown command: ${a}`)}e.payload=t,this.send(e)}catch(e){this.error(e)}})}})},require("source-map-support/register");var _jcieBuCommon=require("./2jcie-bu-common");module.exports=exports.default; /** * @license * Copyright (c) 2019 CANDY LINE INC. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */