npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ht-infrared-protocol-sdk

v0.3.18

Published

航天中电蓝牙红外协议

Downloads

23

Readme

航天中电蓝牙红外协议SDK

该SDK基于微信小程序的蓝牙API,用于与航天中电蓝牙水表进行通信。

安装方式

npm install ht-infrared-protocol-sdk
  • 注意:微信小程序需在开发者工具中构建npm 工具 -> 构建npm

使用方式

引入

import {InfraredProtocolSDK, sdkDataType} from 'ht-infrared-protocol-sdk';

page({
    data: {
        sdk: sdkDataType
    }
})
  • InfraredProtocolSDK:SDK入口类
  • sdkDataType:值为 undefined 的类型指引

初始化

传入相关参数得到一个SDK实例。

this.data.sdk = new InfraredProtocolSDK({
    /**
     * 授权token 
     * 必填
     */
    token: '***********',

    /**
     * 蓝牙设备ID,获取方式请查阅微信小程序文档
     * 必填
     */
    deviceId: '***********',

    /**
     * 蓝牙服务ID,获取方式请查阅微信小程序文档
     * 必填
     */
    serviceId: '***********',

    /**
     * 蓝牙设备写入标识,获取方式请查阅微信小程序文档
     * 必填
     */
    writeId: '***********',

    /**
     * 蓝牙设备通知标识,获取方式请查阅微信小程序文档
     * 必填
     */
    notifyId: '***********',

    /**
     * 蓝牙发送接收消息时的回调 
     * 选填
     * @param type 'send' | 'receive' 发送|接收
     * @param msg string 报文
     */
    messageCallback: (type: 'send' | 'receive', msg: string) => {},

    /**
     * 解析命令响应成功后的回调 
     * 选填
     */
    cmdResCallback: (result: any) => {},

    /**
     * 初始化成功后的回调 
     * 选填
     */
    success: () => {},

    /**
     * 初始化失败后的回调 
     * 选填
     */
    failure: () => {},
});

SDK指令

指令成功后会执行success回调,回调参数result包含以下固定内容,不同指令会包含额外内容;指令失败后会执行failure回调,回调参数msg为错误信息

{
    /**
     * 命令码
     */
    commandCode
    
    /**
     * 目标地址
     */
    targetDeviceId
    
    /**
     * 解析结果
     */
    result
    
    /**
     * 本次操作日志
     */
    operateLog
}
1.开阀指令
/**
 * 发送开阀指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendOpenValveCommand(success, failure);

result额外内容:

{
    /**
     * 表数据信息
     */
    meterData: {
        /**
         * 表计数据(基表读数)
         */
        meterValue

        /**
         * 电池电压,单位:V
         */
        batteryVoltage

        /**
         * 脉冲当量,从当前累积流量字段中的单位中获取,协议直接返回的值,0-4
         */
        factor

        /**
         * 整数位,4-8
         */
        integer

        /**
         * 倍率
         * number 倍率 0x00(x1倍), 0x01(x10倍), 0x10(x100倍)
         */
        multiple 
    }
    /**
     * 表状态信息
     */
    stateData: {
        /**
         * 开关状态: true关阀,false开阀
         */
        switchingState

        /**
         * 阀门状态: true异常,false正常
         */
        valveState

        /**
         * 电池状态: true电压低,false正常
         */
        batteryState

        /**
         * 磁敏状态: true磁攻击,false正常
         */
        magneticState

        /**
         * 阀门状态: 0关阀 1开阀 2异常 null未知
         */
        getValveStatus()
    }

}
2.关阀指令
/**
 * 发送开阀指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendCloseValveCommand(success, failure);

result额外内容:同开阀指令

3.洗阀指令
/**
 * 发送开阀指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendWashValveCommand(success, failure);

result额外内容:同开阀指令

4.抄表指令
/**
 * 发送单播抄表指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendSingleReadMeterCommand(success, failure);

result额外内容

{
    /**
     * 表数据信息
     */
    meterData: {
        /**
         * 表计数据(基表读数)
         */
        meterValue

        /**
         * 正向脉冲数
         */
        forwardPulse

        /**
         * 反向脉冲数
         */
        reversePulse

        /**
         * 电池电压,单位:V
         */
        batteryVoltage

        /**
         * 脉冲当量,从当前累积流量字段中的单位中获取,协议直接返回的值,0-4
         */
        factor

        /**
         * 整数位,通过读表计数据获取,协议直接返回的值,4-8
         */
        integer

        /**
         * 倍率
         * number 倍率 0x00(x1倍), 0x01(x10倍), 0x10(x100倍)
         */
        multiple

        /**
         * 反向流量
         */
        getReverseFlow()
    }
    /**
     * 表状态信息
     */
    stateData: {
        /**
         * 开关状态: true关阀,false开阀
         */
        switchingState

        /**
         * 阀门状态: true异常,false正常
         */
        valveState

        /**
         * 电池状态: true电压低,false正常
         */
        batteryState

        /**
         * 磁敏状态: true磁攻击,false正常
         */
        magneticState

        /**
         * 阀门状态: 0关阀 1开阀 2异常 null未知
         */
        getValveStatus()
    }

}
5.读功能选项指令
/**
 * 发送读功能选项指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendReadDeviceFunctionCommand(success, failure);

result额外内容

{
    deviceFunction: {
        /**
         * 磁攻击选项,0只上报;1关阀并上报
         */
        magneticAttack

        /**
         * 日流量超限关阀选项,0忽略;1关阀
         */
        dailyFlowCloseValve

        /**
         * 瞬时流量超限报警选项,0忽略;1报警
         */
        instantaneousFlowAlarm

        /**
         * 欠费触摸开阀选项,0不开;1开阀
         */
        ownTouchOpenValve

        /**
         * 自动洗阀选项,0开启;1关闭
         */
        autoWashValve
    }
}
6.读功能选项指令
/**
 * 发送写功能选项指令
 * @param magneticAttack: number 磁攻击选项 ['只上报', '关阀并上报'] 取下标
 * @param dailyFlowCloseValve: number 日流量超限关阀选项 ['忽略', '关阀'] 取下标
 * @param instantaneousFlowAlarm: number 瞬时流量超限报警选项 ['忽略', '报警'] 取下标
 * @param ownTouchOpenValve: number 欠费触摸开阀选项 ['不开', '开阀'] 取下标
 * @param autoWashValve: number 自动洗阀选项 ['开启', '关闭'] 取下标
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendWriteDeviceFunctionCommand(magneticAttack, dailyFlowCloseValve, instantaneousFlowAlarm, ownTouchOpenValve, autoWashValve, success, failure);
7.配置表号指令
/**
 * 发送配置表号指令
 * @param deviceId: string 表号
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendWriteDeviceIdCommand(deviceId, success, failure);
8.读表号指令
/**
 * 发送读表号指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendReadDeviceIdCommand(success, failure);

result额外内容:

{
    /**
     * 表号
     */
    deviceId;
}
9.读设备信息指令
/**
 * 发送读设备信息指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendReadDeviceInfoCommand(success, failure);

result额外内容:

{
    /**
     * 设备信息
     */
    deviceInfo: {
        /**
         * imei
         */
        imei

        /**
         * imsi
         */
        imsi

        /**
         * iccid
         */
        iccid

        /**
         * APN
         */
        apn

        /**
         * 读设备信息成功标志(null:未知,0:失败,1:成功)
         */
        readDeviceInfo
    }

    /**
     * 水表版本信息
     */
    meterVersionInfo: {
        /**
         * 厂家标识
         */
        factory

        /**
         * 硬件版本信息
         */
        hardVersion

        /**
         * 硬件日期
         */
        hardDate

        /**
         * 软件版本信息
         */
        softVersion

        /**
         * 软件日期
         */
        softDate

        /**
         * NB软件版本信息
         */
        nbSoftVersion

        /**
         * NB软件日期
         */
        nbSoftDate

        /**
         * 拼接所有版本信息字段,组成一个新的字符串在页面显示
         */
        getVersionInfoString()
    }
}
10.读设备参数指令
/**
 * 发送读设备参数信息指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendReadDeviceParamsCommand(success, failure);

result额外内容:

{
    /**
     * 设备参数信息
     */
    deviceParameterInfo: {
        /**
         * 红外波特率
         *ZERO = 1200,
         *ONE = 2400,
         *TWO = 4800,
         *THREE = 9600,
         *FOUR = 19200,
         *FIVE = 38400,
         *SIX = 57600,
         *SEVEN = 115200,
         */
        infraredBaudRate

        /**
         * 阀门超时时间,单位:秒
         */
        valveTimeout

        /**
         * 洗阀时间,单位:天,取值范围:10到60,0表示不洗阀
         */
        washValveTime

        /**
         * 洗阀倒计时,单位:天
         */
        washValveCountdown
    }
}
11.写设备参数指令
/**
 * 发送写设备参数指令
 * @param infraredBaudRate: number 红外波特率 ['1200bps', '2400bps', '4800bps', '9600bps', '19200bps', '38400bps', '57600bps', '115200bps'] 取下标
 * @param valveTimeout: number 阀门超时时间,单位/秒
 * @param washValveTime: number 洗阀时间,单位:天,取值范围:10到60,0表示不洗阀
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendWriteDeviceParamsCommand(infraredBaudRate, valveTimeout, washValveTime, success, failure);
12.读计量配置信息指令
/**
 * 发送读取计量配置信息指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendReadMeasuringConfigCommand(success, failure);

result额外内容:

{
    /**
     * 设备参数信息
     */
    measuringConfigInfo: {
        /**
         * 出厂计量方式
         */
        defaultMeasuringType

        /**
         * 出厂计量扩展
         */
        defaultMeasuringExtend

        /**
         * 出厂计数方向
         */
        defaultCountingDirection

        /**
         * 当前计量方式
         * 0:'默认计量' 1:'光电计量' 2:'无磁计量' 3:'两线脉冲计量' 4:'两线脉冲双向计量' 5:'单线脉冲计量' 6:'三线脉冲双向计量'
         */
        measuringTypeIndex

        /**
         * 当前计量扩展(光电)
         * 0:'默认188协议' 1:'定制TTL协议'
         */
        measuringExtendIndex1

        /**
         * 当前计量扩展(无磁)
         * 0:为峰协议' 1:'马圣协议'
         */
        measuringExtendIndex2

        /**
         * 当前计数方向
         * 0:'默认计数方向', 1:'默认相反方向'
         */
        countingDirectionIndex
    }
}
13.写计量配置信息指令
/**
 * 发送写计量配置指令
 * @param measuringTypeIndex: number 计量方式 0:'默认计量' 1:'光电计量' 2:'无磁计量' 3:'两线脉冲计量' 4:'两线脉冲双向计量' 5:'单线脉冲计量' 6:'三线脉冲双向计量'
 * @param extend: number 计量方式扩展  光电计量 0:'默认188协议' 1:'定制TTL协议';  无磁计量 0:为峰协议' 1:'马圣协议'
 * @param countingDirectionIndex: number 计数方向 0:'默认计数方向', 1:'默认相反方向'
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendWriteMeasuringConfigCommand(measuringTypeIndex, extend, countingDirectionIndex, success, failure);
14.读设备信号指令
/**
 * 发送读设备信号指令
 * @param nbType: 0|1  0:实时信号 1:历史信号
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendReadDeviceNbSignalCommand(nbType, success, failure);

result额外内容:

{
    /**
     * NB信号数据
     */
    meterSignalInfo: {
        /**
         * 接收信号强度指示
         */
        rcvRssi

        /**
         * 参考信号接收功率
         */
        rsrp

        /**
         * 无线信号覆盖等级
         */
        ecl

        /**
         * 物理小区标识
         */
        pci

        /**
         * 信号与干扰加信噪比
         */
        sinr

        /**
         * 基站ID信息
         */
        cellId

        /**
         * 读水表信号成功标志(null:未知,0:失败,1:成功)
         */
        readMeterSignal
    }
}
15.写基表读数指令
/**
 * 发送写基表读数指令
 * @param forwardValue: string 正向表计底度
 * @param reverseValue: string 反向表计底度
 * @param integerIndex: number 整数位数 ['3', '4', '5', '6', '7', '8'] 取下标
 * @param factor: number 脉冲当量 ['1.0m³', '0.1m³', '0.01m³', '0.001m³', '0.0001m³'] 取下标
 * @param factor: number 脉冲当量 ['1.0m³', '0.1m³', '0.01m³', '0.001m³', '0.0001m³'] 取下标
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 * @param multiple: number 倍率 0x00(x1倍), 0x01(x10倍), 0x10(x100倍)
 */
sdk.sendWriteMeterBaseValueCommand(forwardValue, reverseValue, integerIndex, factor, success, failure, multiple);
16.开NB控制指令
/**
 * 发送水表开NB控制指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendDeviceNbOpenCommand(success, failure);
17.关NB控制指令
/**
 * 发送水表关NB控制指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendDeviceNbCloseCommand(success, failure);
18.复位NB控制指令
/**
 * 发送水表复位NB控制指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendDeviceNbResetCommand(success, failure);
19.读NB状态指令
/**
 * 发送读NB状态指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendReadNbStateCommand(success, failure);

result额外内容:

{
    /**
     * NB状态 0:打开NB 1:关闭NB
     */
    nbState;
}
20.复位MCU状态指令
/**
 * 发送mcu控制指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendDeviceMcuCtrlCommand(success, failure);
21.数据上报指令
/**
 * 发送数据上报指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendReportDeviceInfoCommand(success, failure);
22.读无磁数据指令
/**
 * 发送读无磁数据指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendReadNoMagnetismInfoCommand(success, failure);

result额外内容:

{
    /**
     * 设备参数信息
     */
    noMagnetismInfo: {
        /**
         * 正向累计脉冲数
         */
        forwardPulseNumber

        /**
         * 反向累计脉冲数
         */
        reversePulseNumber

        /**
         * 信号强度A
         */
        signalStrengthA

        /**
         * 信号强度B
         */
        signalStrengthB

        /**
         * 信号等级
         */
        signalLevel

        /**
         * 状态字
         */
        statusWord

        /**
         * 读无磁信号成功标志(null:未知,0:失败,1:成功)
         */
        readNoMagnetism

    }
}
23.一键读取指令
/**
 * 发送一键读取指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendReadProductionTestDataCommand(success, failure);

result额外内容:

{
    /**
     * 设备信息 
     */
    deviceInfo: {
        //详见 读设备信息指令
    }

    /**
     * 表号
     */
    deviceId

    /**
     * 脉冲当量
     */
    factor

    /**
     * 表底数
     */
    meterValue

    /**
     * 反向流量
     */
    reverseFlow

    /**
     * 设备状态
     */
    stateData: {
        //详见 抄表指令
    }

    /**
     * 电池电压,单位:V
     */
    batteryVoltage

    /**
     * 功能选项
     */
    deviceFunction: {
        //详见 读功能选项指令
    }

    /**
     * 阀门超时时间,单位:秒
     */
    valveTimeout

    /**
     * 无磁信号等级
     */
    signalLevel

    /**
     * 整数位数
     */
    integer
}
24.蓝牙寻表指令(闪灯)
/**
 * 发送蓝牙寻表指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendLocateMeterCommand(success, failure);
25.读IP信息指令
/**
 * 发送读IP信息指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendReadIpInfoCommand(success, failure);

result额外内容:

{
    /**
     * IP信息数据
     */
    ipInfo: {
        /**
         * IP通道:0:主用ip,1:备用ip
         */
        ipChannel

        /**
         * 主IP信息
         */
        masterIp

        /**
         * 主端口信息
         */
        masterPort

        /**
         * 备用IP信息
         */
        standbyIp

        /**
         * 备用端口信息
         */
        standbyPort

        /**
         * 升级IP信息
         */
        upgradeIp

        /**
         * 升级端口信息
         */
        upgradePort

    }
}
26.写IP信息指令
/**
 * 发送写IP信息指令
 * @param ipChannel: number IP通道:0:主用ip,1:备用ip
 * @param masterIp: string 主IP
 * @param masterPort: number 主端口
 * @param standbyIp: string 备用IP
 * @param standbyPort: number 备用端口
 * @param upgradeIp: string 升级IP
 * @param upgradePort: number 升级端口
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendWriteIpInfoCommand(ipChannel, masterIp, masterPort, standbyIp, standbyPort, upgradeIp, upgradePort, success, failure);
27.开启升级通道指令
/**
 * 发送开启升级通道指令
 * @param success: (result)=>{}
 * @param failure: (msg)=>{}
 */
sdk.sendOpenUpgradeChannelCommand(success, failure);

其他

InfraredProtocolSDK静态方法

/**
 * 设置命令超时时间
 * @param normalTimeout: number ms
 */
InfraredProtocolSDK.setNormalTimeout(normalTimeout);

/**
 * 获取命令超时时间
 */
InfraredProtocolSDK.getNormalTimeout();

实例方法

/**
 * 返回当前实际操作的设备地址
 */
sdk.getTargetDeviceId();

/**
 * 释放资源
 */
sdk.dispose();