Administrator
2022-06-17 c5bff04a7761b7aca5dbd511a5989ebab20adb24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package com.base;
 
 
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 (double)(tmp);
    }
    //------------------------------------------------------------------------------
    public static short changeDoubleToShort(double data)
    {
        int tmp = (int)data;
        return (short)(tmp & 0xFFFF);
    }
    
    public static String bytesToHexString(byte[] src, int len){
        StringBuilder stringBuilder = new StringBuilder("");
        if (src == null || len <= 0) {
            return null;
        }
        for (int i = 0; i < len; i++) {
            int v = src[i] & 0xFF;
            String hv = Integer.toHexString(v).toUpperCase();
            if (hv.length() < 2) {
                stringBuilder.append(0);
            }
            stringBuilder.append(hv + ",");
        }
        return stringBuilder.toString();
    }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    public static double GetFDCurrent(double stdcap, int hourrate)
    {
        double res = 0.055;
        switch(hourrate)
        {
            case 1: res = 0.514; break;
            case 2: res = 0.306; break;
            case 3: res = 0.250; break;
            case 4: res = 0.200; break;
            case 5: res = 0.166; break;
            case 6: res = 0.146; break;
            case 7: res = 0.131; break;
            case 8: res = 0.118; break;
            case 9: res = 0.108; break;
            case 10: res = 0.100; break;
            case 20: res = 0.055; break;
            default: res = 0.055; break;
        }
        
        return (stdcap * res);
    }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    public static int GetHourRate(double stdah, double current)
    {
        int index = 0;
        double value[]={5.14, 3.06, 2.50, 2.00, 1.66, 1.46, 1.31, 1.18, 1.08, 1.00, 0.55};
        double res;
        
        if(stdah < 1)
            stdah = 1;
        
        res = current/(stdah/10);
        if(res >= 5.14) return 1;
        else if(res <= 0.55) return 20;
        else
        {
            for(index=0; index<10; index++)
            {
                if((res<=value[index]) && (res>value[index+1]))    break;
                else continue;
            }
            if((value[index]-res) < (res-value[index+1]))
            {
                return (index+1);
            }
            else
            {
                if(index+2 > 10) return (20);
                else return (index+2);
            }
        }  
    }
    //------------------------------------------------------------------------------
    //------------------------------------------------------------------------------
    public static double N_TO_10H(int n_H)
    {
        switch(n_H)
        {
            case  1 : return(1/0.55);
            case  2 : return(1/0.61);
            case  3 : return(1/0.75);
            case  4 : return(1/0.79);
            case  5 : return(1/0.833);
            case  6 : return(1/0.876);
            case  7 : return(1/0.917);
            case  8 : return(1/0.944);
            case  9 : return(1/0.974);
            case  10: return(1/1);
            case  20: return(1/1.1);
        }
        return 1.0;
    }
    //-------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------
    public static double GetMonomerCap(double STDAH, int HourRate, double SumAH, double MaxMonomerVol,
                                        double MonomerVol, double MonomerVolType, byte CapType)
    {
        if(MaxMonomerVol - MonomerVolType*0.9 <= 0)
            return 0;
 
        if(STDAH < 1)
            STDAH = 1;
        
        if(SumAH < 0)
            SumAH *= (-1);
 
        double tmp_cap;
        tmp_cap = MonomerVol - MonomerVolType * 0.9;
        tmp_cap *= (STDAH - SumAH * N_TO_10H(HourRate));
        double dt_vol = MaxMonomerVol - MonomerVolType*0.9;
        if(dt_vol < 0.01)
            dt_vol = 0.01;
        tmp_cap = tmp_cap/dt_vol;
        if(tmp_cap < 0)
            tmp_cap = 0;
 
        if(CapType == CapType_Rest)
            return tmp_cap;
        else if(CapType == CapType_Real)
            return (tmp_cap + SumAH * N_TO_10H(HourRate));
        else
            return ((tmp_cap + SumAH * N_TO_10H(HourRate))*100 / STDAH);
    }
    //----------------------------------------------------------------------------------
    //----------------------------------------------------------------------------------
    public static int GetRestTimeSecond(double restcap, double curr)
    {
        double tmp_curr = Math.abs(curr);
        if(tmp_curr < 0.1)
            tmp_curr = 0.1;
        
        int rest_time = (int)((restcap / tmp_curr) * 3600);
        if(rest_time > (99*3600))
            rest_time = (99*3600);
        
        return rest_time;
    }
    //----------------------------------------------------------------------------------
}
/***************************************************************************************
******************************* end of file (FBS_ComBase)*******************************
***************************************************************************************/