config.js 5.26 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,
            stayTime = info.setAntStayTime.input,
            frequency = info.setFrequency.input,
            frequencyRegion = info.setFrequencyRegion.input,
            speedMode = info.setSpeedMode.input,
            tagGroup = info.setTagGroup.input;

        this.reproc[power] = this.prePower;
        this.reproc[filter] = this.preFilter;
        this.reproc[stayTime] = this.preStayTime;
        this.reproc[frequency] = this.preFrequency;
        this.reproc[frequencyRegion] = this.preFrequencyRegion;
        this.reproc[speedMode] = this.preSpeedMode;
        this.reproc[tagGroup] = this.preTagGroup;
    }

    /**
     * @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 preStayTime
     * @description 设置天线驻留时间预处理
     * @param {Object} param param 读写时长 eg 100 (单位:ms)
     * @return {String} 指令
     */
    preStayTime(param) {
        let time = tenToHex(param).toLocaleUpperCase();
        time = _.padLeft(time, 8, '0');
        return info.setAntStayTime.input + time;
    }

    /**
     * @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 freq = tenToHex(param).toLocaleUpperCase();
        freq = freq.length < 2 ? ('0' + freq) : freq;
        return info.setFrequency.input + freq + '000000';
    }

    /**
     * @method preFrequencyRegion
     * @description 设置频率区域
     * @param {Object} param 频率区域的值 eg: 0:FCC,1:CCC,2:NCC,3:JPN
     */

     preFrequencyRegion(param) {
        return info.setFrequencyRegion.input + '0' + tenToHex(param).toLocaleUpperCase() + '000000';
     }

    /**
     * @method preSpeedMode
     * @description 设置速度模式
     * @param {Object} param 速度模式的值 eg: 0:高速,1:正常速度,2:省电模式
     */

     preSpeedMode(param) {
        return info.setSpeedMode.input + '0' + tenToHex(param).toLocaleUpperCase() + '000000';
     }

    /**
     * @method preTagGroup
     * @description 设置标签组预处理
     * @param {Object} param 标签组的值 eg: {'session':0,'target':0,'search_mode':1}
     *                      其中session:0代表S0,1代表S1,2代表S2,3代表S3
     *                      target:0代表A,1代表B
     *                      search_mode:0代表DUAL_TARGET,1代表SINGLE_TARGET,2代表SINGLE_TARGET_WITH_SUPPRESSION
     */

     preTagGroup(param) {
        let session = '0'+tenToHex(param.session * 10).toLocaleUpperCase(),
            target = '0'+tenToHex(param.target).toLocaleUpperCase(),
            search_mode = '0'+tenToHex(param.search_mode).toLocaleUpperCase();
        return info.setTagGroup.input + session +target + search_mode + '00';
    }
}
/**
 * @exports lib/directive/Config
 */
export default Config;