Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
158 | KeyOz | 1 | /*************************************************************************** |
2 | * Copyright (C) 2008 by Manuel Schrape * |
||
3 | * manuel.schrape@gmx.de * |
||
4 | * * |
||
5 | * This program is free software; you can redistribute it and/or modify * |
||
6 | * it under the terms of the GNU General Public License as published by * |
||
7 | * the Free Software Foundation; either version 2 of the License. * |
||
8 | * * |
||
9 | * This program is distributed in the hope that it will be useful, * |
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
12 | * GNU General Public License for more details. * |
||
13 | * * |
||
14 | * You should have received a copy of the GNU General Public License * |
||
15 | * along with this program; if not, write to the * |
||
16 | * Free Software Foundation, Inc., * |
||
17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
18 | ***************************************************************************/ |
||
19 | |||
20 | #include "ToolBox.h" |
||
21 | |||
22 | ToolBox::ToolBox() |
||
23 | { |
||
24 | } |
||
25 | |||
199 | KeyOz | 26 | QString ToolBox::get_Float(long Wert, long Count) |
27 | { |
||
28 | QString Temp; |
||
29 | |||
30 | if (Wert > 0) |
||
31 | Temp = ""; |
||
32 | else |
||
33 | Temp = "-"; |
||
34 | |||
35 | Temp = Temp + QString("%1").arg(Wert / Count) + "." + QString("%1").arg(Wert % Count); |
||
36 | |||
37 | return Temp; |
||
38 | } |
||
39 | |||
40 | |||
41 | // Base64 Decoder |
||
158 | KeyOz | 42 | bool ToolBox::Decode64(sRxData &RX, bool Long) |
43 | { |
||
44 | unsigned char a,b,c,d; |
||
45 | unsigned char ptr = 0; |
||
46 | unsigned char x,y,z; |
||
47 | int ptrOut[150]; |
||
48 | |||
49 | int ptrIn = 3; |
||
50 | int max = RX.String.length(); |
||
51 | int len = RX.String.length(); |
||
52 | int DecLen = 0; |
||
53 | |||
54 | if (RX.Input[ptrIn] == 0) |
||
55 | { |
||
56 | qDebug("QString to Char ERROR...!!!!"); |
||
57 | return false; |
||
58 | } |
||
59 | |||
60 | while(len != 0) |
||
61 | { |
||
62 | a = RX.Input[ptrIn++] - '='; |
||
63 | b = RX.Input[ptrIn++] - '='; |
||
64 | c = RX.Input[ptrIn++] - '='; |
||
65 | d = RX.Input[ptrIn++] - '='; |
||
66 | |||
67 | if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
||
68 | |||
69 | x = (a << 2) | (b >> 4); |
||
70 | y = ((b & 0x0f) << 4) | (c >> 2); |
||
71 | z = ((c & 0x03) << 6) | d; |
||
72 | |||
73 | if(len--) ptrOut[ptr++] = x; else break; |
||
74 | if(len--) ptrOut[ptr++] = y; else break; |
||
75 | if(len--) ptrOut[ptr++] = z; else break; |
||
76 | } |
||
77 | |||
78 | for (int a=0; a<ptr; a++) |
||
79 | { |
||
80 | if (Long == false) |
||
81 | { |
||
82 | int b1, b2, b3; |
||
83 | |||
84 | b1 = ptrOut[a++]; |
||
85 | b2 = ptrOut[a]; |
||
86 | |||
87 | b3 = (b2 << 8) | b1; |
||
88 | |||
89 | if (b3 > 32767) |
||
90 | b3 = b3 - 65536; |
||
91 | |||
92 | RX.Decode[DecLen] = b3; |
||
93 | DecLen++; |
||
94 | } |
||
95 | else |
||
96 | { |
||
97 | RX.Decode[DecLen] = ptrOut[a]; |
||
98 | DecLen++; |
||
99 | } |
||
199 | KeyOz | 100 | |
101 | RX.DecLen = DecLen; |
||
158 | KeyOz | 102 | } |
103 | return true; |
||
104 | } |
||
105 | |||
199 | KeyOz | 106 | // Base64 Encoder |
107 | QString ToolBox::Encode64(char Data[150],unsigned int Length) |
||
108 | { |
||
109 | unsigned int pt = 0; |
||
110 | unsigned char a,b,c; |
||
111 | unsigned char ptr = 0; |
||
112 | |||
113 | char TX_Buff[150]; |
||
114 | |||
115 | while(Length > 0) |
||
116 | { |
||
117 | if(Length) { a = Data[ptr++]; Length--;} else a = 0; |
||
118 | if(Length) { b = Data[ptr++]; Length--;} else b = 0; |
||
119 | if(Length) { c = Data[ptr++]; Length--;} else c = 0; |
||
120 | |||
121 | TX_Buff[pt++] = '=' + (a >> 2); |
||
122 | TX_Buff[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
||
123 | TX_Buff[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
||
124 | TX_Buff[pt++] = '=' + ( c & 0x3f); |
||
125 | } |
||
126 | TX_Buff[pt] = 0; |
||
127 | |||
128 | return QString(TX_Buff); |
||
129 | } |
||
130 | |||
131 | // Datensatz nach 16bit Integer |
||
158 | KeyOz | 132 | int ToolBox::Data2Int(int *Data , int Start, bool is_signed) |
133 | { |
||
134 | int Out = (Data[Start+1]<<8) | (Data[Start+0]); |
||
135 | |||
136 | if ((Out > 32767) && (is_signed)) |
||
137 | Out = Out - 65536; |
||
138 | |||
139 | return Out; |
||
140 | |||
141 | } |
||
142 | |||
199 | KeyOz | 143 | // Datensatz nach 32bit Long |
158 | KeyOz | 144 | long ToolBox::Data2Long(int *Data , int Start, bool is_signed) |
145 | { |
||
146 | long Out = (Data[Start+3]<<24) | (Data[Start+2]<<16) | (Data[Start+1]<<8) | (Data[Start+0]); |
||
147 | |||
162 | KeyOz | 148 | if ((Out > 32767) && (is_signed)) |
149 | Out = Out; |
||
150 | |||
158 | KeyOz | 151 | return Out; |
152 | } |
||
153 | |||
199 | KeyOz | 154 | // Datensatz nach QString |
159 | KeyOz | 155 | QString ToolBox::Data2QString(int Data[150], int Start, int End) |
156 | { |
||
157 | char String[150]; |
||
158 | for (int a = Start; a < End; a++) |
||
159 | { |
||
160 | String[a - Start] = Data[a]; |
||
161 | } |
||
162 | String[End - Start] = '\0'; |
||
163 | |||
164 | return QString(String); |
||
165 | } |
||
166 | |||
199 | KeyOz | 167 | // Datensatz-CRC prüfen |
158 | KeyOz | 168 | bool ToolBox::check_CRC(QString RXString) |
169 | { |
||
170 | int CRC = 0; |
||
171 | char *RX; |
||
172 | |||
173 | int Length = RXString.length(); |
||
174 | |||
175 | RX = RXString.toLatin1().data(); |
||
176 | |||
177 | if (RX[1] == 127) |
||
178 | { |
||
179 | RX[1] = 0; |
||
180 | } |
||
181 | |||
182 | for(int i=0; i < Length-2; i++) |
||
183 | { |
||
184 | CRC+=RX[i]; |
||
185 | } |
||
186 | |||
187 | CRC = CRC % 4096; |
||
188 | |||
189 | if(RX[Length - 2] != ('=' + (CRC / 64))) |
||
190 | { |
||
191 | return false; |
||
192 | } |
||
193 | |||
194 | if(RX[Length - 1] != ('=' + CRC % 64)) |
||
195 | { |
||
196 | return false; |
||
197 | } |
||
198 | |||
199 | return true; |
||
200 | } |
||
201 | |||
199 | KeyOz | 202 | // Datensatz-CRC hinzufügen |
158 | KeyOz | 203 | QString ToolBox::add_CRC(QString TXString) |
204 | { |
||
205 | unsigned int tmpCRC = 0; |
||
206 | |||
207 | char *TXBuff; |
||
208 | char CRC[2]; |
||
209 | |||
210 | TXBuff = TXString.toLatin1().data(); |
||
211 | |||
212 | for(int i = 0; i < TXString.length(); i++) |
||
213 | { |
||
214 | tmpCRC += TXBuff[i]; |
||
215 | } |
||
216 | |||
217 | tmpCRC %= 4096; |
||
218 | |||
219 | CRC[0] = '=' + tmpCRC / 64; |
||
220 | CRC[1] = '=' + tmpCRC % 64; |
||
221 | CRC[2] = '\0'; |
||
222 | |||
223 | QString Return = TXString + QString(CRC); |
||
224 | |||
225 | return Return; |
||
226 | } |
||
227 | |||
199 | KeyOz | 228 | // Alle Icons |
229 | QIcon ToolBox::Icon(int ID) |
||
158 | KeyOz | 230 | { |
199 | KeyOz | 231 | QIcon Icons[30] ; |
232 | Icons[0].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledred.png")), QIcon::Normal, QIcon::Off); |
||
233 | Icons[1].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledyellow.png")), QIcon::Normal, QIcon::Off); |
||
234 | Icons[3].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledyellow.png")), QIcon::Normal, QIcon::Off); |
||
235 | Icons[4].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledoff.png")), QIcon::Normal, QIcon::Off); |
||
158 | KeyOz | 236 | |
199 | KeyOz | 237 | Icons[5].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/application-exit.png")), QIcon::Normal, QIcon::Off); |
238 | Icons[6].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/media-playback-stop.png")), QIcon::Normal, QIcon::Off); |
||
239 | Icons[7].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/media-record.png")), QIcon::Normal, QIcon::Off); |
||
240 | Icons[8].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/network-connect.png")), QIcon::Normal, QIcon::Off); |
||
241 | Icons[9].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/network-disconnect.png")), QIcon::Normal, QIcon::Off); |
||
242 | Icons[10].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/utilities-system-monitor.png")), QIcon::Normal, QIcon::Off); |
||
158 | KeyOz | 243 | |
199 | KeyOz | 244 | Icons[11].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/applications-system.png")), QIcon::Normal, QIcon::Off); |
245 | Icons[12].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/applications-internet.png")), QIcon::Normal, QIcon::Off); |
||
246 | Icons[13].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/preferences-other.png")), QIcon::Normal, QIcon::Off); |
||
247 | Icons[14].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/preferences-system.png")), QIcon::Normal, QIcon::Off); |
||
248 | Icons[15].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/folder.png")), QIcon::Normal, QIcon::Off); |
||
249 | Icons[16].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/folder-print.png")), QIcon::Normal, QIcon::Off); |
||
250 | Icons[17].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/clock.png")), QIcon::Normal, QIcon::Off); |
||
251 | Icons[18].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/configure.png")), QIcon::Normal, QIcon::Off); |
||
158 | KeyOz | 252 | |
199 | KeyOz | 253 | Icons[20].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-up-double.png")), QIcon::Normal, QIcon::Off); |
254 | Icons[21].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-up.png")), QIcon::Normal, QIcon::Off); |
||
255 | Icons[22].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-down-double.png")), QIcon::Normal, QIcon::Off); |
||
256 | Icons[23].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-down.png")), QIcon::Normal, QIcon::Off); |
||
257 | Icons[24].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-left-double.png")), QIcon::Normal, QIcon::Off); |
||
258 | Icons[25].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-left.png")), QIcon::Normal, QIcon::Off); |
||
259 | Icons[26].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-right-double.png")), QIcon::Normal, QIcon::Off); |
||
260 | Icons[27].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-right.png")), QIcon::Normal, QIcon::Off); |
||
158 | KeyOz | 261 | |
199 | KeyOz | 262 | return Icons[ID]; |
158 | KeyOz | 263 | } |