config.js 3.02 KB
/**
 * @fileOverview 读写器配置类
 * @author qiqi.zhou@yoho.cn
 */
import Base from './base';
import _ from 'lodash';
import {
    log, tenToHex
}
from '../util';
import info from '../interface';

/**
 * @class 配置读写器信息
 * @description 频率,功率,灵敏度过滤
 * @module lib/directive/Config
 * @extends {Base}
 * @member @see {@link Base}
 */
class Config extends Base {
    /**
     * 初始化和配置输入处理
     * @return {void}
     */
    constructor() {
        super(null);

        let power = info.setPower.input,
            filter = info.setFilter.input,
            frequency = info.setFrequency.input;

        this.reproc[power] = this.prePower;
        this.reproc[filter] = this.preFilter;
        this.reproc[frequency] = this.preFrequency;
    }

    /**
     * @method prePower
     * @description 设置功率输入预处理
     * @param {Array} param 天线功率,eg.[15,15,0,0]分别对应0-3天线
     * @return {String} 指令
     */
    prePower(param) {
        let ret = [];

        _.forIn(param, function (val, key) {
            val = tenToHex(val).toLocaleUpperCase();
            val = (val.length < 2) ? ('0' + val) : val;
            ret.push(val);
        });

        return info.setPower.input + ret.join('');
    }

    /**
     * @method preFilter
     * @description 设置灵敏度过滤预处理
     * @param {Object} param 配置1表示开启,0表示关闭,eg. {on:'1',rssi:-27.5}
     */
    preFilter(param) {
        let rssi = tenToHex(param.rssi * 10);
        rssi = rssi.replace('ffff', '').toLocaleUpperCase();
        return info.setFilter.input + '0' + param.on + rssi + '00';
    }

    /**
     * @method preFrequency
     * @description 设置频率预处理
        0 915.75
        1 915.25
        2 903.25
        3 926.75
        4 926.25
        5 904.25
        6 927.25
        7 920.25
        8 919.25
        9 909.25
        10 918.75
        11 917.75
        12 905.25
        13 904.75
        14 925.25
        15 921.75
        16 914.75
        17 906.75
        18 913.75
        19 922.25
        20 911.25
        21 911.75
        22 903.75
        23 908.75
        24 905.75
        25 912.25
        26 906.25
        27 917.25
        28 914.25
        29 907.25
        30 918.25
        31 916.25
        32 910.25
        33 910.75
        34 907.75
        35 924.75
        36 909.75
        37 919.75
        38 916.75
        39 913.25
        40 923.75
        41 908.25
        42 925.75
        43 912.75
        44 924.25
        45 921.25
        46 920.75
        47 922.75
        48 902.75
        49 923.25
     * @param {Number} param  ant标示天线的端口,freq标示频率(使用枚举值)
     */
    preFrequency(param) {
        let ant = param.ant < 10 ? ('0' + param.ant) : param.ant,
            freq = tenToHex(param.freq).toLocaleUpperCase();
        freq = freq.length < 2 ? ('0' + freq) : freq;
        return info.setFrequency.input + ant + '0000' + freq;
    }
}
/**
 * @exports lib/directive/Config
 */
export default Config;