Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
170 | 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 | |||
26 | // Base64 Decoder |
||
27 | bool ToolBox::Decode64(sRxData &RX, bool Long) |
||
28 | { |
||
29 | unsigned char a,b,c,d; |
||
30 | unsigned char ptr = 0; |
||
31 | unsigned char x,y,z; |
||
32 | int ptrOut[150]; |
||
33 | |||
34 | int ptrIn = 3; |
||
35 | int max = RX.String.length(); |
||
36 | int len = RX.String.length(); |
||
37 | int DecLen = 0; |
||
38 | |||
39 | if (RX.Input[ptrIn] == 0) |
||
40 | { |
||
41 | qDebug("QString to Char ERROR...!!!!"); |
||
42 | return false; |
||
43 | } |
||
44 | |||
45 | while(len != 0) |
||
46 | { |
||
47 | a = RX.Input[ptrIn++] - '='; |
||
48 | b = RX.Input[ptrIn++] - '='; |
||
49 | c = RX.Input[ptrIn++] - '='; |
||
50 | d = RX.Input[ptrIn++] - '='; |
||
51 | |||
52 | if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
||
53 | |||
54 | x = (a << 2) | (b >> 4); |
||
55 | y = ((b & 0x0f) << 4) | (c >> 2); |
||
56 | z = ((c & 0x03) << 6) | d; |
||
57 | |||
58 | if(len--) ptrOut[ptr++] = x; else break; |
||
59 | if(len--) ptrOut[ptr++] = y; else break; |
||
60 | if(len--) ptrOut[ptr++] = z; else break; |
||
61 | } |
||
62 | |||
63 | for (int a=0; a<ptr; a++) |
||
64 | { |
||
65 | if (Long == false) |
||
66 | { |
||
67 | int b1, b2, b3; |
||
68 | |||
69 | b1 = ptrOut[a++]; |
||
70 | b2 = ptrOut[a]; |
||
71 | |||
72 | b3 = (b2 << 8) | b1; |
||
73 | |||
74 | if (b3 > 32767) |
||
75 | b3 = b3 - 65536; |
||
76 | |||
77 | RX.Decode[DecLen] = b3; |
||
78 | DecLen++; |
||
79 | } |
||
80 | else |
||
81 | { |
||
82 | RX.Decode[DecLen] = ptrOut[a]; |
||
83 | DecLen++; |
||
84 | } |
||
85 | } |
||
86 | return true; |
||
87 | } |
||
88 | |||
89 | // Base64 Encoder |
||
90 | QString ToolBox::Encode64(char Data[150],unsigned int Length) |
||
91 | { |
||
92 | unsigned int pt = 0; |
||
93 | unsigned char a,b,c; |
||
94 | unsigned char ptr = 0; |
||
95 | |||
96 | char TX_Buff[150]; |
||
97 | |||
98 | while(Length > 0) |
||
99 | { |
||
100 | if(Length) { a = Data[ptr++]; Length--;} else a = 0; |
||
101 | if(Length) { b = Data[ptr++]; Length--;} else b = 0; |
||
102 | if(Length) { c = Data[ptr++]; Length--;} else c = 0; |
||
103 | |||
104 | TX_Buff[pt++] = '=' + (a >> 2); |
||
105 | TX_Buff[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
||
106 | TX_Buff[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
||
107 | TX_Buff[pt++] = '=' + ( c & 0x3f); |
||
108 | } |
||
109 | TX_Buff[pt] = 0; |
||
110 | |||
111 | return QString(TX_Buff); |
||
112 | } |
||
113 | |||
114 | // Datensatz nach 16bit Integer |
||
115 | int ToolBox::Data2Int(int *Data , int Start, bool is_signed) |
||
116 | { |
||
117 | int Out = (Data[Start+1]<<8) | (Data[Start+0]); |
||
118 | |||
119 | if ((Out > 32767) && (is_signed)) |
||
120 | Out = Out - 65536; |
||
121 | |||
122 | return Out; |
||
123 | |||
124 | } |
||
125 | |||
126 | // Datensatz nach 32bit Long |
||
127 | long ToolBox::Data2Long(int *Data , int Start, bool is_signed) |
||
128 | { |
||
129 | long Out = (Data[Start+3]<<24) | (Data[Start+2]<<16) | (Data[Start+1]<<8) | (Data[Start+0]); |
||
130 | |||
131 | if ((Out > 32767) && (is_signed)) |
||
132 | Out = Out; |
||
133 | |||
134 | return Out; |
||
135 | } |
||
136 | |||
137 | // Datensatz nach QString |
||
138 | QString ToolBox::Data2QString(int Data[150], int Start, int End) |
||
139 | { |
||
140 | char String[150]; |
||
141 | for (int a = Start; a < End; a++) |
||
142 | { |
||
143 | String[a - Start] = Data[a]; |
||
144 | } |
||
145 | String[End - Start] = '\0'; |
||
146 | |||
147 | return QString(String); |
||
148 | } |
||
149 | |||
150 | // Datensatz-CRC prüfen |
||
151 | bool ToolBox::check_CRC(QString RXString) |
||
152 | { |
||
153 | int CRC = 0; |
||
154 | char *RX; |
||
155 | |||
156 | int Length = RXString.length(); |
||
157 | |||
158 | RX = RXString.toLatin1().data(); |
||
159 | |||
160 | if (RX[1] == 127) |
||
161 | { |
||
162 | RX[1] = 0; |
||
163 | } |
||
164 | |||
165 | for(int i=0; i < Length-2; i++) |
||
166 | { |
||
167 | CRC+=RX[i]; |
||
168 | } |
||
169 | |||
170 | CRC = CRC % 4096; |
||
171 | |||
172 | if(RX[Length - 2] != ('=' + (CRC / 64))) |
||
173 | { |
||
174 | return false; |
||
175 | } |
||
176 | |||
177 | if(RX[Length - 1] != ('=' + CRC % 64)) |
||
178 | { |
||
179 | return false; |
||
180 | } |
||
181 | |||
182 | return true; |
||
183 | } |
||
184 | |||
185 | // Datensatz-CRC hinzufügen |
||
186 | QString ToolBox::add_CRC(QString TXString) |
||
187 | { |
||
188 | unsigned int tmpCRC = 0; |
||
189 | |||
190 | char *TXBuff; |
||
191 | char CRC[2]; |
||
192 | |||
193 | TXBuff = TXString.toLatin1().data(); |
||
194 | |||
195 | for(int i = 0; i < TXString.length(); i++) |
||
196 | { |
||
197 | tmpCRC += TXBuff[i]; |
||
198 | } |
||
199 | |||
200 | tmpCRC %= 4096; |
||
201 | |||
202 | CRC[0] = '=' + tmpCRC / 64; |
||
203 | CRC[1] = '=' + tmpCRC % 64; |
||
204 | CRC[2] = '\0'; |
||
205 | |||
206 | QString Return = TXString + QString(CRC); |
||
207 | |||
208 | return Return; |
||
209 | } |
||
210 | |||
211 | // Alle Icons |
||
212 | QIcon ToolBox::Icon(int ID) |
||
213 | { |
||
214 | QIcon Icons[30] ; |
||
215 | Icons[0].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledred.png")), QIcon::Normal, QIcon::Off); |
||
216 | Icons[1].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledyellow.png")), QIcon::Normal, QIcon::Off); |
||
217 | Icons[3].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledyellow.png")), QIcon::Normal, QIcon::Off); |
||
218 | Icons[4].addPixmap(QPixmap(QString::fromUtf8(":/LED/Images/16X16/ledoff.png")), QIcon::Normal, QIcon::Off); |
||
219 | |||
220 | Icons[5].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/application-exit.png")), QIcon::Normal, QIcon::Off); |
||
221 | Icons[6].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/media-playback-stop.png")), QIcon::Normal, QIcon::Off); |
||
222 | Icons[7].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/media-record.png")), QIcon::Normal, QIcon::Off); |
||
223 | Icons[8].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/network-connect.png")), QIcon::Normal, QIcon::Off); |
||
224 | Icons[9].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/network-disconnect.png")), QIcon::Normal, QIcon::Off); |
||
225 | Icons[10].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/utilities-system-monitor.png")), QIcon::Normal, QIcon::Off); |
||
226 | |||
227 | Icons[11].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/applications-system.png")), QIcon::Normal, QIcon::Off); |
||
228 | Icons[12].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/applications-internet.png")), QIcon::Normal, QIcon::Off); |
||
229 | Icons[13].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/preferences-other.png")), QIcon::Normal, QIcon::Off); |
||
230 | Icons[14].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/preferences-system.png")), QIcon::Normal, QIcon::Off); |
||
231 | Icons[15].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/folder.png")), QIcon::Normal, QIcon::Off); |
||
232 | Icons[16].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/folder-print.png")), QIcon::Normal, QIcon::Off); |
||
233 | Icons[17].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/clock.png")), QIcon::Normal, QIcon::Off); |
||
234 | Icons[18].addPixmap(QPixmap(QString::fromUtf8(":/Actions/Images/22X22/configure.png")), QIcon::Normal, QIcon::Off); |
||
235 | |||
236 | Icons[20].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-up-double.png")), QIcon::Normal, QIcon::Off); |
||
237 | Icons[21].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-up.png")), QIcon::Normal, QIcon::Off); |
||
238 | Icons[22].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-down-double.png")), QIcon::Normal, QIcon::Off); |
||
239 | Icons[23].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-down.png")), QIcon::Normal, QIcon::Off); |
||
240 | Icons[24].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-left-double.png")), QIcon::Normal, QIcon::Off); |
||
241 | Icons[25].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-left.png")), QIcon::Normal, QIcon::Off); |
||
242 | Icons[26].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-right-double.png")), QIcon::Normal, QIcon::Off); |
||
243 | Icons[27].addPixmap(QPixmap(QString::fromUtf8(":/Arrows/Images/32X32/arrow-right.png")), QIcon::Normal, QIcon::Off); |
||
244 | |||
245 | return Icons[ID]; |
||
246 | } |