package com.fpt.handheld_ultrasound.connect;
public class SendCommand {//发送信号格式,由APP到设备的指令协议
public static final byte[] HEADER = {(byte) 0x44, (byte) 0x4D, (byte) 0xAA, (byte) 0xBB};
//1:解、冻结
public static byte[] c_freeze() {//冻结
byte[] cmd = {0x00, 0x00, 0x00, 0x30};
byte[] type = {0x00, 0x00, 0x00, 0x01};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd, type,len, param);
}
public static byte[] c_unfreeze() {//解冻
byte[] cmd = {0x00, 0x00, 0x00, 0x30};
byte[] type = {0x00, 0x00, 0x00, 0x2};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd,type, len, param);
}
//0 1 2 3 4模式
public static byte[] c_setMode_B() {
byte[] cmd = {0x00, 0x00, 0x00, 0x31};
byte[] type = {0x00, 0x00, 0x00, 0x0};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd, type,len, param);
}
public static byte[] c_setMode_M() {
byte[] cmd = {0x00, 0x00, 0x00, 0x31};
byte[] type = {0x00, 0x00, 0x00, 0x31};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x02};
return compose(cmd,type, len, param);
}
public static byte[] c_setMode_CFM() {
byte[] cmd = {0x00, 0x00, 0x00, 0x31};
byte[] type = {0x00, 0x00, 0x00, 0x31};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x06};
return compose(cmd, type,len, param);
}
public static byte[] c_setMode_PW() {
byte[] cmd = {0x00, 0x00, 0x00, 0x31};
byte[] type = {0x00, 0x00, 0x00, 0x31};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x05};
return compose(cmd,type, len, param);
}
public static byte[] c_update() {
byte[] cmd = {0x00, 0x00, 0x00, 0x31};
byte[] type = {0x00, 0x00, 0x00, 0x31};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x04};
return compose(cmd, type,len, param);
}
public static byte[] c_depth_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0x32};
byte[] type = {0x00, 0x00, 0x00, 0x32};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_depth_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0x32};
byte[] type = {0x00, 0x00, 0x00, 0x32};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd,type, len, param);
}
public static byte[] c_gain_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0x33};
byte[] type = {0x00, 0x00, 0x00, 0x33};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd,type, len, param);
}
public static byte[] c_gain_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0x33};
byte[] type = {0x00, 0x00, 0x00, 0x33};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_freq_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0x34};
byte[] type = {0x00, 0x00, 0x00, 0x34};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd, type,len, param);
}
public static byte[] c_freq_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0x34};
byte[] type = {0x00, 0x00, 0x00, 0x34};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd,type, len, param);
}
public static byte[] c_SR_sub() {//噪音
byte[] cmd = {0x00, 0x00, 0x00, 0x35};
byte[] type = {0x00, 0x00, 0x00, 0x35};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_SR_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0x35};
byte[] type = {0x00, 0x00, 0x00, 0x35};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd,type, len, param);
}
public static byte[] c_FOCUS_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0x36};
byte[] type = {0x00, 0x00, 0x00, 0x36};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_FOCUS_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0x36};
byte[] type = {0x00, 0x00, 0x00, 0x36};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd,type, len, param);
}
// System.arraycopy(HEADER, 0, lastCommand, 0, HEADER.length);
// System.arraycopy(cmd, 0, lastCommand, HEADER.length, cmd.length);
public static byte[] c_set_ROI_PST(int x,int y) {//cfm模式移动
byte[] cmd = {0x00, 0x00, 0x00, 0x37};
byte[] type = {0x00, 0x00, 0x00, 0x02};
byte[] len = {0x00, 0x00, 0x00, 0x08};
byte[] param=new byte[8];
byte[] xb=intToByteArray(x);
byte[] yb =intToByteArray(y);
System.arraycopy(xb,0,param,0,xb.length);
System.arraycopy(yb,0,param,xb.length,yb.length);
// byte[] param = { xbyte,0x00,0x00,0x00,0x02};
return compose(cmd,type, len, param);
}
public static byte[] c_Set_ROI_SIZE(int x,int y) {
byte[] cmd = {0x00, 0x00, 0x00, 0X38};
byte[] type = {0x00, 0x00, 0x00, 0X02};
byte[] len = {0x00, 0x00, 0x00, 0x8};//20(为16进制,10进制为:32)
byte[] param = new byte[8];
byte[] xb=intToByteArray(x);
byte[] yb =intToByteArray(y);
System.arraycopy(xb,0,param,0,xb.length);
System.arraycopy(yb,0,param,xb.length,yb.length);
return compose(cmd, type,len, param);
}
public static byte[] c_set_MLINE_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0x38};
byte[] type = {0x00, 0x00, 0x00, 0x38};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd, type,len, param);
}
public static byte[] c_set_MLINE_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0x38};
byte[] type = {0x00, 0x00, 0x00, 0x38};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd, type,len, param);
}
public static byte[] c_set_PW_GATE_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0x39};
byte[] type = {0x00, 0x00, 0x00, 0x39};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_set_PW_GATE_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0x39};
byte[] type = {0x00, 0x00, 0x00, 0x39};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd,type, len, param);
}
public static byte[] c_set_TGC() {
byte[] cmd = {0x00, 0x00, 0x00, 0x3A};
byte[] type = {0x00, 0x00, 0x00, 0x3A};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd, type,len, param);
}
public static byte[] c_DGAIN_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0x3B};
byte[] type = {0x00, 0x00, 0x00, 0x3B};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd, type,len, param);
}
public static byte[] c_DGAIN_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0x3B};
byte[] type = {0x00, 0x00, 0x00, 0x3B};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd,type, len, param);
}
public static byte[] c_cfmFreq_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0x40};
byte[] type = {0x00, 0x00, 0x00, 0x03};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_cfmFreq_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0x40};
byte[] type = {0x00, 0x00, 0x00, 0x03};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd,type, len, param);
}
public static byte[] c_DR_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0x3C};
byte[] type = {0x00, 0x00, 0x00, 0x3C};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_DR_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0x3C};
byte[] type = {0x00, 0x00, 0x00, 0x3C};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd, type,len, param);
}
public static byte[] c_WF_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0x3D};
byte[] type = {0x00, 0x00, 0x00, 0x3D};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_WF_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0x3D};
byte[] type = {0x00, 0x00, 0x00, 0x3D};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd,type, len, param);
}
public static byte[] c_PWGAIN_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0x3E};
byte[] type = {0x00, 0x00, 0x00, 0x3E};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_PWGAIN_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0x3E};
byte[] type = {0x00, 0x00, 0x00, 0x3E};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd, type,len, param);
}
public static byte[] c_set_PWLINE() {
byte[] cmd = {0x00, 0x00, 0x00, 0x3F};
byte[] type = {0x00, 0x00, 0x00, 0x3F};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_CFMFREQ_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0x40};
byte[] type = {0x00, 0x00, 0x00, 0x40};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd, type,len, param);
}
public static byte[] c_PWFREQ_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0x41};
byte[] type = {0x00, 0x00, 0x00, 0x41};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_PWFREQ_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0x41};
byte[] type = {0x00, 0x00, 0x00, 0x41};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd, type,len, param);
}
public static byte[] c_CFMPRF_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0X42};
byte[] type = {0x00, 0x00, 0x00, 0X02};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd, type,len, param);
}
public static byte[] c_CFMPRF_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0X42};
byte[] type = {0x00, 0x00, 0x00, 0X02};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd, type,len, param);
}
public static byte[] c_PWPRF_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0X43};
byte[] type = {0x00, 0x00, 0x00, 0X43};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_PWPRF_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0X43};
byte[] type = {0x00, 0x00, 0x00, 0X43};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd,type, len, param);
}
public static byte[] c_MGAIN_sub() {
byte[] cmd = {0x00, 0x00, 0x00, 0X44};
byte[] type = {0x00, 0x00, 0x00, 0X44};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd, type,len, param);
}
public static byte[] c_MGAIN_add() {
byte[] cmd = {0x00, 0x00, 0x00, 0X44};
byte[] type = {0x00, 0x00, 0x00, 0X44};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd, type,len, param);
}
public static byte[] c_THI_close() {
byte[] cmd = {0x00, 0x00, 0x00, 0X45};
byte[] type = {0x00, 0x00, 0x00, 0X45};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd, type,len, param);
}
public static byte[] c_THI_open() {
byte[] cmd = {0x00, 0x00, 0x00, 0X45};
byte[] type = {0x00, 0x00, 0x00, 0X45};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd,type, len, param);
}
/*
get方法
*
* */
public static byte[] c_get_TIMI() {
byte[] cmd = {0x00, 0x00, 0x00, 0X09};
byte[] type = {0x00, 0x00, 0x00, 0X09};
byte[] len = {0x00, 0x00, 0x00, 0x04};
byte[] param = {0x00,0x00,0x00,0x00};
return compose(cmd, type,len, param);
}
public static byte[] c_get_BPARA() {
byte[] cmd = {0x00, 0x00, 0x00, 0X0A};
byte[] type = {0x00, 0x00, 0x00, 0X02};
byte[] len = {0x00, 0x00, 0x00, 0x10};
byte[] param = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_get_CPARA() {
byte[] cmd = {0x00, 0x00, 0x00, 0X0B};
byte[] type = {0x00, 0x00, 0x00, 0X0B};
byte[] len = {0x00, 0x00, 0x00, 0x0c};
byte[] param = {0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00};
return compose(cmd, type,len, param);
}
public static byte[] c_get_DPARA() {
byte[] cmd = {0x00, 0x00, 0x00, 0X0C};
byte[] type = {0x00, 0x00, 0x00, 0X0C};
byte[] len = {0x00, 0x00, 0x00, 0x08};
byte[] param = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
return compose(cmd,type, len, param);
}
public static byte[] c_get_ROI() {
byte[] cmd = {0x00, 0x00, 0x00, 0X17};
byte[] type = {0x00, 0x00, 0x00, 0X03};
byte[] len = {0x00, 0x00, 0x00, 0x20};//20(为16进制,10进制为:32)
byte[] param = {0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00};
return compose(cmd, type,len, param);
}
public static byte[] c_get_FREEZE() {
byte[] cmd = {0x00, 0x00, 0x00, 0X10};
byte[] type = {0x00, 0x00, 0x00, 0X01};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x00};
return compose(cmd, type,len, param);
}
public static byte[] c_get_UNFREEZE() {
byte[] cmd = {0x00, 0x00, 0x00, 0X10};
byte[] type = {0x00, 0x00, 0x00, 0X10};
byte[] len = {0x00, 0x00, 0x00, 0x01};
byte[] param = {0x01};
return compose(cmd, type,len, param);
}
private static byte[] compose(byte[] cmd,byte[] type, byte[] len, byte[] param) {
/***
* src - 源数组。
srcPos - 源数组中的起始位置。
dest - 目标数组。
destPos - 目标数据中的起始位置。
length - 要复制的数组元素的数量。
*/
byte[] lastCommand = new byte[HEADER.length + cmd.length +type.length+ len.length + param.length];
System.arraycopy(HEADER, 0, lastCommand, 0, HEADER.length);
System.arraycopy(cmd, 0, lastCommand, HEADER.length, cmd.length);
System.arraycopy(type, 0, lastCommand, HEADER.length+cmd.length, type.length);
System.arraycopy(len, 0, lastCommand, HEADER.length + cmd.length +type.length, len.length);
System.arraycopy(param, 0, lastCommand, HEADER.length + cmd.length + len.length+type.length, param.length);
return lastCommand;
}
public static byte[] intToByteArray(int i) {
byte[] result = new byte[4];
// 由高位到低位
result[0] = (byte) ((i >> 24) & 0xFF);
result[1] = (byte) ((i >> 16) & 0xFF);
result[2] = (byte) ((i >> 8) & 0xFF);
result[3] = (byte) (i & 0xFF);
return result;
}
public static int byteArrayToInt(byte[] b) {
return b[3] & 0xFF |
(b[2] & 0xFF) << 8 |
(b[1] & 0xFF) << 16 |
(b[0] & 0xFF) << 24;
}
}
命令头、及其他解析元素解析ByteToInt
最新推荐文章于 2022-06-13 23:15:13 发布