Newer
Older
casic-robot-inspection / casic-server / src / main / java / com / casic / missiles / netty / InstructCode.java
casic_zt on 12 Apr 2024 4 KB 现场调试代码提交
package com.casic.missiles.netty;

import org.springframework.stereotype.Component;

@Component
public class InstructCode {

    /**
     * 默认参数
     * 设备初始化时需要依次发送1~16号指令
     */
    public static String[] InitCodeArr = {
            "1", "设置高压", "set set_voltage 0 1.2\n",
            "2", "复位adc", "cmd set_adc_delay_rst 1 0\n",
            "3", "逻辑复位", "cmd set_logic_rst 1 0\n",
            "4", "设置波形采样触发方式为下降沿", "cmd set_raw_trig_sel_adc2 3 0\n",
            "5", "设置波形采样触发周期", "cmd set_raw_trig_period_adc2 255 0\n",
            "6", "设置波形采样触发阈值", "cmd set_raw_trig_vth_adc2 1911 0\n",
            "7", "设置波形采样点数", "cmd set_raw_sample_len_adc2 2000 0\n",
            "8", "设置波形甄别触发方式", "cmd set_psd_trig_sel 3 0\n",
            "9", "设置波形甄别触发周期", "cmd set_psd_trig_period 100 0\n",
            "10", "设置波形甄别触发阈值", "cmd set_psd_trig_vth 1911 0\n",
            "11", "设置波形甄别门偏移", "cmd set_psd_gate_offset 12 0\n",
            "12", "设置波形甄别延迟", "cmd set_adc2_delay_num 6 0\n",
            "13", "设置波形甄别长门", "cmd set_psd_long_gate 112 0\n",
            "14", "设置波形甄别短门", "cmd set_psd_short_gate 27 0\n",
            "15", "取消复位adc", "cmd set_adc_delay_rst 0 0\n",
            "16", "取消逻辑复位", "cmd set_logic_rst 0 0\n"
    };

    //灵活配置参数
    public static String[] getInitCode(int channelNum, float vol,
                                       int rawTrig, int rawPeriod,
                                       int rowVth,int psdTrig,
                                       int psdPeriod, int psdVth,
                                       int psdOffset, int psdLongGate,
                                       int psdShortGate) {
        String[] initCodeArr = {
                "1", "设置高压", "set set_voltage " + channelNum + " " + vol + "\n",
                "2", "复位adc", "cmd set_adc_delay_rst 1 0\n",
                "3", "逻辑复位", "cmd set_logic_rst 1 0\n",
                "4", "设置波形采样触发方式为下降沿", "cmd set_raw_trig_sel_adc2 " + rawTrig + " 0\n",
                "5", "设置波形采样触发周期", "cmd set_raw_trig_period_adc2 " + rawPeriod + " 0\n",
                "6", "设置波形采样触发阈值", "cmd set_raw_trig_vth_adc2 " + (rowVth + 750) * 4096 / 1500 + " 0\n",
                "7", "设置波形采样点数", "cmd set_raw_sample_len_adc2 2000 0\n",
                "8", "设置波形甄别触发方式", "cmd set_psd_trig_sel " + psdTrig + " 0\n",
                "9", "设置波形甄别触发周期", "cmd set_psd_trig_period " + psdPeriod + " 0\n",
                "10", "设置波形甄别触发阈值", "cmd set_psd_trig_vth " + (psdVth + 750) * 4096 / 1500 + " 0\n",
                "11", "设置波形甄别门偏移", "cmd set_psd_gate_offset " + psdOffset / 8 + " 0\n",
                "12", "设置波形甄别延迟", "cmd set_adc2_delay_num 6 0\n",
                "13", "设置波形甄别长门", "cmd set_psd_long_gate " + psdLongGate / 2 + " 0\n",
                "14", "设置波形甄别短门", "cmd set_psd_short_gate " + psdShortGate / 2 + " 0\n",
                "15", "取消复位adc", "cmd set_adc_delay_rst 0 0\n",
                "16", "取消逻辑复位", "cmd set_logic_rst 0 0\n"
        };
        return initCodeArr;
    }

    /**
     * 加高压指令
     */
    public static final String DAC_UP = "cmd dac_up 0 0\n";
    /**
     * 关闭高压指令
     */
    public static final String DAC_DOWN = "cmd dac_down 0 0\n";

    /**
     * `
     * 电压采样帧头
     */
//    public static final String DAC_HEAD="AA55AA551ACFFC5D";
    public static final String DAC_HEAD = "55aa55aa5dfccf1a";
    public static final String DAC_HEAD_LENGTH = "54000000";
    public static final int DAC_DATA_LENGTH = 144;

    /**
     * 波形采样帧头
     */
//    public static final String WAVE_HEAD="AA55AA551ACFFC3D";
    public static final String WAVE_HEAD = "55aa55aa3dfccf1a";

    /**
     * PSD1采样帧头
     */
//    public static final String PSD1_HEAD="AA55AA551ACFFC4D";
    public static final String PSD1_HEAD = "55aa55aa4dfccf1a";

    /**
     * PSD2采样帧头
     */
//    public static final String PSD2_HEAD="F0F0A5A5";
    public static final String PSD2_HEAD = "f0f0a5a5";


    public static String[] getVolArr(String msg) {
        String[] volArr = new String[24];
        for (int j = 0; j < 24; j++) {
            //前16为电压值
            if (j < 16)
                volArr[j] = ByteUtil.reverseHex(msg.substring(j * 8, (j + 1) * 8));
                //后8为高低位值
            else
                volArr[j] = ByteUtil.reverseHex(msg.substring(128 + (j - 16) * 2, 128 + (j - 15) * 2));
        }
        return volArr;
    }

}