package com.dev.ntm.cmd;
|
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
import java.util.Arrays;
|
import java.util.Date;
|
|
import com.Com;
|
import com.dev.bts.data.FBS9100_ComBase;
|
|
public class NTM_Cmd
|
{
|
public static final short CMD_NULL = 0x0000;
|
public static final short CMD_HeartBeat = 0x0A01;
|
public static final short CMD_LogOut = 0x0A02;
|
public static final short CMD_LogIn = 0x0A03;
|
public static final short CMD_GetDisParm = 0x0A04;
|
public static final short CMD_SetDisParm = 0x0A05;
|
public static final short CMD_GetMonData = 0x0A06;
|
public static final short CMD_GetFileList = 0x0A07;
|
public static final short CMD_ReadFile = 0x0A08;
|
public static final short CMD_SetChrParm = 0x0A09;
|
public static final short CMD_GetChrParm = 0x0A0A;
|
public static final short CMD_StartDischarge = 0x0A0B;
|
public static final short CMD_PauseDischarge = 0x0A0C;
|
public static final short CMD_GetDischargeData = 0x0A0D;
|
public static final short CMD_StartCharge = 0x0A0E;
|
public static final short CMD_PauseCharge = 0x0A0F;
|
public static final short CMD_GetChargeData = 0x0A10;
|
|
public static final short CMD_ChangeToParamPage = 0x0A16;
|
|
public static final short CMD_StopDischarge = 0x0A1C;
|
public static final short CMD_StopCharge = 0x0A1D;
|
public static final short CMD_ClearDevAlarm = 0x0A1E;
|
public static final short CMD_StartCircleDC = 0x0A1F;
|
public static final short CMD_PauseCircleDC = 0x0A20;
|
public static final short CMD_StopCircleDC = 0x0A21;
|
|
public static final short CMD_GetBattGroupNames = 0x0A22;
|
public static final short CMD_GetTestFileNames = 0x0A23;
|
public static final short CMD_GetTestFile = 0x0A24;
|
|
public static final short CMD_GetVersion = 0x0A2A;
|
public static final short CMD_StartDFU = 0x1A2B;
|
public static final short CMD_GetTaskInf = 0x1A2D;
|
|
public static final short PAGE_TAG_MainHome = 0x80;
|
public static final short PAGE_TAG_DISCPARAM = 0x81;
|
|
public final int BYTE_LEN = 18;
|
public final byte SYNCode_STD = (byte) 0xAA;
|
|
private int SYNCode[] = {SYNCode_STD, SYNCode_STD, SYNCode_STD, SYNCode_STD};
|
private int ByteCount = 0;
|
public short CMD = 0;
|
public int RecState = 0;
|
public int type = 0;
|
public int workState = 0;
|
public int Alarm = 0;
|
public int DB1 = 0;
|
public int DB2 = 0;
|
public int DB3 = 0;
|
public int DB4 = 0;
|
private int CRC = 0;
|
|
//************************************//
|
public int ntm_PageStat = 0;
|
public byte target_addr = (byte) 255;
|
//************************************//
|
|
public void makeCmd(int addr, short cmd, int bytecount) {
|
target_addr = (byte) addr;
|
ByteCount = BYTE_LEN + bytecount;
|
CMD = cmd;
|
//RecState = addr;
|
}
|
|
public boolean putByteBuffer(final ByteBuffer bf)
|
{
|
if(bf.limit() < BYTE_LEN)
|
return false;
|
|
ByteBuffer tmpbuf = bf;
|
int crc0 = tmpbuf.getShort(BYTE_LEN-2) & 0xFFFF;
|
tmpbuf.putShort(BYTE_LEN-2, (short) 0);
|
int crc1 = NTM_Crc16.CalCRC16(tmpbuf, bf.limit());
|
if(crc0 != crc1) {
|
return false;
|
}
|
tmpbuf.position(0);
|
for(int n=0; n<4; n++){
|
SYNCode[n] = FBS9100_ComBase.changeByteToInt(tmpbuf.get());
|
}
|
if((0xAA!=SYNCode[0]) || (0xAA!=SYNCode[1])) {
|
return false;
|
}
|
|
ByteCount = FBS9100_ComBase.changeShortToInt(tmpbuf.getShort());
|
CMD = (short) (tmpbuf.getShort() & 0xFFFF);
|
RecState = FBS9100_ComBase.changeByteToInt(tmpbuf.get());
|
type = FBS9100_ComBase.changeByteToInt(tmpbuf.get());
|
ntm_PageStat = type;
|
|
workState = FBS9100_ComBase.changeByteToInt(tmpbuf.get());
|
Alarm = FBS9100_ComBase.changeByteToInt(tmpbuf.get());
|
DB1 = FBS9100_ComBase.changeByteToInt(tmpbuf.get());
|
DB2 = FBS9100_ComBase.changeByteToInt(tmpbuf.get());
|
DB3 = FBS9100_ComBase.changeByteToInt(tmpbuf.get());
|
DB4 = FBS9100_ComBase.changeByteToInt(tmpbuf.get());
|
CRC = FBS9100_ComBase.changeShortToInt(tmpbuf.getShort());
|
|
tmpbuf.compact();
|
tmpbuf.flip();
|
|
return true;
|
}
|
|
public ByteBuffer getByteBuffer(ByteBuffer bf_cmd, ByteBuffer bf_inf)
|
{
|
ByteBuffer bytebuffer = ByteBuffer.allocate(ByteCount);
|
bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
|
|
for(int n=0; n<3; n++){
|
bytebuffer.put(SYNCode_STD);
|
}
|
bytebuffer.put(target_addr);
|
|
bytebuffer.putShort(FBS9100_ComBase.changeIntToShort(ByteCount));
|
bytebuffer.putShort(CMD);
|
RecState = 0;
|
type = 0;
|
workState = 0;
|
Alarm = 0;
|
if(null != bf_cmd) {
|
if(CMD_ChangeToParamPage == CMD) {
|
if(bf_cmd.remaining() >= 1) {
|
RecState = bf_cmd.get();
|
bf_cmd.clear();
|
bf_cmd.flip();
|
}
|
} else if(CMD_GetBattGroupNames == CMD) {
|
if(bf_cmd.remaining() >= 2) {
|
RecState = bf_cmd.get();
|
type = bf_cmd.get();
|
bf_cmd.clear();
|
bf_cmd.flip();
|
}
|
} else if(CMD_GetTestFileNames == CMD) {
|
if(bf_cmd.remaining() >= 4) {
|
RecState = bf_cmd.get();
|
type = bf_cmd.get();
|
workState = bf_cmd.get();
|
Alarm = bf_cmd.get();
|
bf_cmd.clear();
|
bf_cmd.flip();
|
}
|
} else if(CMD_GetTestFile == CMD) {
|
if(bf_cmd.remaining() >= 2) {
|
RecState = bf_cmd.get();
|
type = bf_cmd.get();
|
bf_cmd.clear();
|
bf_cmd.flip();
|
}
|
}
|
}
|
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(RecState));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(type));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(workState));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(Alarm));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(0/*DB1*/));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(0/*DB2*/));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(0/*DB3*/));
|
bytebuffer.put(FBS9100_ComBase.changeIntToByte(0/*DB4*/));
|
bytebuffer.putShort((short) 0x0000);
|
if((null != bf_inf)) {
|
if((bf_inf.limit() > 0) && (bf_inf.remaining() > 0)) {
|
bytebuffer.put(bf_inf);
|
}
|
}
|
|
CRC = NTM_Crc16.CalCRC16(bytebuffer, bytebuffer.position());
|
bytebuffer.putShort(BYTE_LEN-2, FBS9100_ComBase.changeIntToShort(CRC));
|
bytebuffer.flip();
|
|
return bytebuffer;
|
}
|
|
public static String getDiscAlarm(int al_id) {
|
String res = "δ֪";
|
switch(al_id) {
|
case 0x00: res = "ÊÖ¶¯Í£Ö¹"; break;
|
case 0x01: res = "·Åµçʱ¼äµ½"; break;
|
case 0x02: res = "·ÅµçÈÝÁ¿µ½"; break;
|
case 0x03: res = "µ¥ÌåÏÂÏÞµ½"; break;
|
case 0x04: res = "×é¶ËÏÂÏÞµ½"; break;
|
case 0x05: res = "ÊеçÖжÏ"; break;
|
case 0x06: res = "ÄÚ´æ²»×ã"; break;
|
case 0x07: res = "ζÈÒì³£¸ß"; break;
|
case 0x08: res = "ÕýÔڷŵç"; break;
|
case 0x09: res = "ÊÖ¶¯ÔÝÍ£"; break;
|
case 0x0A: res = "ÔÝÍ£·Åµç"; break;
|
case 0x0B: res = "ͨÐŹÊÕÏ"; break;
|
case 0x0C: res = "µçÁ÷¹ÊÕÏ"; break;
|
case 0x0D: res = "ѹ²îÉÏÏÞµ½"; break;
|
case 0x0E: res = "×é¶ËµçѹÒì³£"; break;
|
case 0x0F: res = "·çÉÈÒì³£"; break;
|
case 0x10: res = "ÕûÁ÷Æ÷µçѹÒì³£"; break;
|
case 0x11: res = "IGBTÒì³£"; break;
|
case 0x12: res = "¸¨ÖúµçÔ´Òì³£"; break;
|
case 0x13: res = "µ¥ÌåζÈÒì³£¸ß"; break;
|
case 0x14: res = "BMSͨÐÅÒì³£"; break;
|
case 0x15: res = "´æ´¢Òì³£"; break;
|
case 0x16: res = "´Ó»ú¶Ï¿ª»òͨѶÒì³£"; break;
|
case 0x17: res = "´Ó»ú״̬Òì³£"; break;
|
|
case 0x40: res = "Í£Ö¹³äµç"; break;
|
case 0x41: res = "ÔÝÍ£³äµç"; break;
|
case 0x42: res = "ÕýÔÚ³äµç"; break;
|
case 0x43: res = "³äµçʱ¼äµ½"; break;
|
case 0x44: res = "³äµçÈÝÁ¿µ½"; break;
|
case 0x45: res = "µ¥ÌåÉÏÏÞµ½"; break;
|
case 0x46: res = "³äµçÒÑÍê³É"; break;
|
case 0x47: res = "ÍÑ¿ÛÆ÷¶Ï¿ª"; break;
|
case 0x48: res = "ζÈÒì³£¸ß"; break;
|
case 0x49: res = "ͨÐŹÊÕÏ"; break;
|
case 0x4A: res = "³äµçÄ£¿éÒì³£"; break;
|
case 0x4B: res = "×é¶ËÉÏÏÞµ½"; break;
|
case 0x4C: res = "ѹ²îÉÏÏÞµ½"; break;
|
case 0x4D: res = "µçÁ÷Òì³£"; break;
|
case 0x4E: res = "×é¶ËµçѹÒì³£"; break;
|
case 0x4F: res = "·çÉÈÒì³£"; break;
|
case 0x50: res = "ÕûÁ÷Æ÷µçѹÒì³£"; break;
|
case 0x51: res = "IGBTÒì³£"; break;
|
case 0x52: res = "¸¨ÖúµçÔ´Òì³£"; break;
|
case 0x53: res = "µ¥ÌåζÈÒì³£¸ß"; break;
|
case 0x54: res = "BMSͨÐÅÒì³£"; break;
|
case 0x55: res = "´æ´¢Òì³£"; break;
|
case 0x56: res = "´Ó»ú¶Ï¿ª»òͨѶÒì³£"; break;
|
case 0x57: res = "´Ó»ú״̬Òì³£"; break;
|
case 0x58: res = "δ֪Òì³£"; break;
|
}
|
return res;
|
}
|
|
public static String getAckCmdText(short cmd) {
|
String ack_msg = "";
|
|
switch(cmd) {
|
case CMD_LogOut: ack_msg = "CMD_LogOut"; break;
|
case CMD_LogIn: ack_msg = "CMD_LogIn"; break;
|
case CMD_GetDisParm: ack_msg = "CMD_GetDisParm"; break;
|
case CMD_SetDisParm: ack_msg = "CMD_SetDisParm"; break;
|
case CMD_GetMonData: ack_msg = "CMD_GetMonData"; break;
|
case CMD_GetFileList: ack_msg = "CMD_GetFileList"; break;
|
case CMD_ReadFile: ack_msg = "CMD_ReadFile"; break;
|
case CMD_SetChrParm: ack_msg = "CMD_SetChrParm"; break;
|
case CMD_GetChrParm: ack_msg = "CMD_GetChrParm"; break;
|
case CMD_StartDischarge: ack_msg = "CMD_StartDischarge"; break;
|
case CMD_PauseDischarge: ack_msg = "CMD_PauseDischarge"; break;
|
case CMD_GetDischargeData: ack_msg = "CMD_GetDischargeData"; break;
|
case CMD_StartCharge: ack_msg = "CMD_StartCharge"; break;
|
case CMD_PauseCharge: ack_msg = "CMD_PauseCharge"; break;
|
case CMD_GetChargeData: ack_msg = "CMD_GetChargeData"; break;
|
|
case CMD_ChangeToParamPage: ack_msg = "CMD_ChangeToParamPage"; break;
|
|
case CMD_StopDischarge: ack_msg = "CMD_StopDischarge"; break;
|
case CMD_StopCharge: ack_msg = "CMD_StopCharge"; break;
|
case CMD_ClearDevAlarm: ack_msg = "CMD_ClearDevAlarm"; break;
|
case CMD_StartCircleDC: ack_msg = "CMD_StartCircleDC"; break;
|
case CMD_PauseCircleDC: ack_msg = "CMD_PauseCircleDC"; break;
|
case CMD_StopCircleDC: ack_msg = "CMD_StopCircleDC"; break;
|
|
case CMD_GetBattGroupNames: ack_msg = "CMD_GetBattGroupNames"; break;
|
case CMD_GetTestFileNames: ack_msg = "CMD_GetTestFileNames"; break;
|
case CMD_GetTestFile: ack_msg = "CMD_GetTestFile"; break;
|
|
case CMD_GetVersion: ack_msg = "CMD_GetVersion"; break;
|
}
|
|
if(ack_msg.length() > 2) {
|
ack_msg = Com.get_DTF(new Date(), Com.DTF_YMDhms) + " Operate ack inf: " + ack_msg + " ";
|
}
|
|
return ack_msg;
|
}
|
|
@Override
|
public String toString() {
|
return "NT_Comm_Cmd [BYTE_LEN=" + BYTE_LEN + ", SYNCode=" + Arrays.toString(SYNCode) + ", ByteCount="
|
+ ByteCount + ", CMD=" + CMD + ", RecState=" + RecState + ", CRC=" + CRC + "]";
|
}
|
|
|
|
}
|
/***************************************************************************************
|
******************************** end of file (NT_Comm_Cmd) *****************************
|
***************************************************************************************/
|