package com.base; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class ComBase { public static final byte CapType_Rest = 0; public static final byte CapType_Real = 1; public static byte changeIntToByte(int data) { return (byte) (data & 0xFF); } public static short changeIntToShort(int data) { return (short) (data & 0xFFFF); } public static byte changeShortToByte(short data) { return (byte) (data & 0xFF); } public static int changeByteToInt(byte data) { int tmp = data; return tmp & 0xFF; } public static int changeShortToInt(short data) { int tmp = data; return tmp & 0xFFFF; } public static double changeShortToDouble(short data) { int tmp = data & 0xFFFF; return tmp; } public static short changeDoubleToShort(double data) { int tmp = (int) data; return (short) (tmp & 0xFFFF); } public static ByteBuffer mkFloat32Buffer(float value) { ByteBuffer buff = ByteBuffer.allocate(4); buff.order(ByteOrder.BIG_ENDIAN); buff.putFloat(value); buff.flip(); return buff; } public static ByteBuffer mkUInt16Buffer(int value) { ByteBuffer buff = ByteBuffer.allocate(2); buff.order(ByteOrder.BIG_ENDIAN); buff.putShort(ComBase.changeIntToShort(value)); buff.flip(); return buff; } public static ByteBuffer mkInt32Buffer(int value) { ByteBuffer buff = ByteBuffer.allocate(4); buff.order(ByteOrder.BIG_ENDIAN); buff.putShort(ComBase.changeIntToShort((value>>16)&0xFFFF)); buff.putShort(ComBase.changeIntToShort((value&0xFFFF))); buff.flip(); return buff; } public static ByteBuffer mkInt32Buffer(long value) { ByteBuffer buff = ByteBuffer.allocate(4); buff.order(ByteOrder.BIG_ENDIAN); buff.putShort(ComBase.changeIntToShort(((int)value>>16)&0xFFFF)); buff.putShort(ComBase.changeIntToShort(((int)value&0xFFFF))); buff.flip(); return buff; } public static double GetFDCurrent(double stdcap, int hourrate) { double res = 0.055D; switch (hourrate) { case 1: res = 0.514D; break; case 2: res = 0.306D; break; case 3: res = 0.25D; break; case 4: res = 0.2D; break; case 5: res = 0.166D; break; case 6: res = 0.146D; break; case 7: res = 0.131D; break; case 8: res = 0.118D; break; case 9: res = 0.108D; break; case 10: res = 0.1D; break; case 20: res = 0.055D; break; case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: default: res = 0.055D; } return stdcap * res; } public static int GetHourRate(double stdah, double current) { int index = 0; double[] value = { 5.14D, 3.06D, 2.5D, 2.0D, 1.66D, 1.46D, 1.31D, 1.18D, 1.08D, 1.0D, 0.55D }; if (stdah < 1.0D) { stdah = 1.0D; } double res = current / (stdah / 10.0D); if (res >= 5.14D) return 1; if (res <= 0.55D) return 20; for (index = 0; index < 10; index++) { if ((res <= value[index]) && (res > value[(index + 1)])) break; } if (value[index] - res < res - value[(index + 1)]) { return index + 1; } if (index + 2 > 10) return 20; return index + 2; } public static double N_TO_10H(int n_H) { switch (n_H) { case 1: return 1.818181818181818D; case 2: return 1.639344262295082D; case 3: return 1.333333333333333D; case 4: return 1.265822784810126D; case 5: return 1.200480192076831D; case 6: return 1.141552511415525D; case 7: return 1.09051254089422D; case 8: return 1.059322033898305D; case 9: return 1.026694045174538D; case 10: return 1.0D; case 20: return 0.9090909090909091D; case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: } return 1.0D; } public static double GetMonomerCap(double STDAH, int HourRate, double SumAH, double MaxMonomerVol, double MonomerVol, double MonomerVolType, byte CapType) { if (MaxMonomerVol - MonomerVolType * 0.9D <= 0.0D) { return 0.0D; } if (STDAH < 1.0D) { STDAH = 1.0D; } if (SumAH < 0.0D) { SumAH *= -1.0D; } double tmp_cap = MonomerVol - MonomerVolType * 0.9D; tmp_cap *= (STDAH - SumAH * N_TO_10H(HourRate)); double dt_vol = MaxMonomerVol - MonomerVolType * 0.9D; if (dt_vol < 0.01D) dt_vol = 0.01D; tmp_cap /= dt_vol; if (tmp_cap < 0.0D) { tmp_cap = 0.0D; } if (CapType == 0) return tmp_cap; if (CapType == 1) { return tmp_cap + SumAH * N_TO_10H(HourRate); } return (tmp_cap + SumAH * N_TO_10H(HourRate)) * 100.0D / STDAH; } public static int GetRestTimeSecond(double restcap, double curr) { double tmp_curr = Math.abs(curr); if (tmp_curr < 0.1D) { tmp_curr = 0.1D; } int rest_time = (int) (restcap / tmp_curr * 3600.0D); if (rest_time > 356400) { rest_time = 356400; } return rest_time; } public static void main(String[] args) { int ff = 123456; System.out.println(ff &0xFFFF); } } /* * Location: * C:\Users\LiJun\Desktop\公司各种设备资料\9600显示模块相关文件\后台程序\2018-09-07\BattFBS9600XSP. * jar Qualified Name: com.base.ComBase JD-Core Version: 0.6.2 */