config.js 2.42 KB
import Base from './base';
import _ from 'lodash';
import {
    log, tenToHex
}
from '../util';
import info from '../interface';

/**
 * 配置读写器信息
 * 频率,功率,灵敏度过滤
 */
class Config extends Base {
    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;
    }

    /**
     * 设置功率输入预处理
     * param: [15,15,0,0]
     * 分别对应0-3天线
     */
    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('');
    }

    /**
     * 设置灵敏度过滤预处理
     * param:{on:'1',rssi:-275}
     */
    preFilter(param) {
        let rssi = tenToHex(param.rssi).replace('ffff', '').toLocaleUpperCase();
        return info.setFilter.input + '0' + param.on + rssi + '00';
    }

    /**
     * 设置频率预处理
        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
     * ant:1
     * freq:1
     */
    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;
    }
}
export default Config;