Subversion Repositories Projects

Rev

Rev 393 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 393 Rev 396
Line 1... Line 1...
1
#include <Parser.h>
1
#include <Parser.h>
Line 2... Line 2...
2
 
2
 
3
// Base64 Decoder
3
// Base64 Decoder
4
// see Parser.h for details about sRxData
4
// see Parser.h for details about sRxData
5
void Parser::decode64(sRxData &rx)
5
bool Parser::decode64(sRxData &rx)
6
{
6
{
7
    int length = rx.str.size();
7
    int length = rx.str.size();
8
    unsigned char a,b,c,d;
8
    unsigned char a,b,c,d;
9
    unsigned char ptr = 0;
9
    unsigned char ptr = 0;
Line 13... Line 13...
13
    int ptrIn = 3;
13
    int ptrIn = 3;
14
    int max = length;
14
    int max = length;
15
    int len = length;
15
    int len = length;
16
    int decLen = 0;
16
    int decLen = 0;
Line 17... Line 17...
17
 
17
 
-
 
18
    if (rx.input[ptrIn] == 0) {
-
 
19
        return false;
18
    if (rx.Input[ptrIn] == 0) {
20
        //TODO: catch error to show that something went wrong during the decode process
19
        throw "Nothing received";
21
        //throw "Nothing received";
Line 20... Line 22...
20
    }
22
    }
21
 
23
 
22
    while(len != 0) {
24
    while(len != 0) {
Line 35... Line 37...
35
        if(len--) ptrOut[ptr++] = y; else break;
37
        if(len--) ptrOut[ptr++] = y; else break;
36
        if(len--) ptrOut[ptr++] = z; else break;
38
        if(len--) ptrOut[ptr++] = z; else break;
37
    }
39
    }
Line 38... Line 40...
38
 
40
 
39
    for (int a=0; a<ptr; a++) {
41
    for (int a=0; a<ptr; a++) {
40
        if (Long == false) {
42
        if (length == false) {
Line 41... Line 43...
41
            int b1, b2, b3;
43
            int b1, b2, b3;
42
 
44
 
Line 43... Line 45...
43
            b1 = ptrOut[a++];
45
            b1 = ptrOut[a++];
Line 44... Line 46...
44
            b2 = ptrOut[a];
46
            b2 = ptrOut[a];
45
 
47
 
Line 46... Line 48...
46
            b3 = (b2 << 8) | b1;
48
            b3 = (b2 << 8) | b1;
47
 
49
 
48
            if (b3 > 32767)
50
            if (b3 > 32767)
49
                b3 = b3 - 65536;
51
                b3 = b3 - 65536;
50
 
52
 
51
            RX.decode[DecLen] = b3;
53
            rx.decode[decLen] = b3;
52
            DecLen++;
54
            decLen++;
53
        } else {
55
        } else {
-
 
56
            rx.decode[decLen] = ptrOut[a];
54
            RX.decode[DecLen] = ptrOut[a];
57
            decLen++;
Line 55... Line 58...
55
            DecLen++;
58
        }
56
        }
59
        rx.decLen = decLen;
57
        RX.DecLen = DecLen;
60
    }
Line 65... Line 68...
65
    unsigned char a,b,c;
68
    unsigned char a,b,c;
66
    unsigned char ptr = 0;
69
    unsigned char ptr = 0;
Line 67... Line 70...
67
 
70
 
Line 68... Line 71...
68
    char tx_buff[150];
71
    char tx_buff[150];
69
 
72
 
70
    while(Length > 0)
73
    while(length > 0)
71
    {
74
    {
72
        if(Length) { a = data[ptr++]; length--;} else a = 0;
75
        if(length) { a = data[ptr++]; length--;} else a = 0;
Line 73... Line 76...
73
        if(Length) { b = data[ptr++]; length--;} else b = 0;
76
        if(length) { b = data[ptr++]; length--;} else b = 0;
74
        if(Length) { c = data[ptr++]; length--;} else c = 0;
77
        if(length) { c = data[ptr++]; length--;} else c = 0;
75
 
78
 
76
        tx_buff[pt++] = '=' + (a >> 2);
79
        tx_buff[pt++] = '=' + (a >> 2);
Line 123... Line 126...
123
    return Out;
126
    return Out;
124
}
127
}
Line 125... Line 128...
125
 
128
 
126
float Parser::getFloat(long value, int count)
129
float Parser::getFloat(long value, int count)
127
{
130
{
Line 128... Line 131...
128
    long num = math.pow(10, count);
131
    long num = pow(10, count);
Line 129... Line 132...
129
 
132
 
130
    float temp = value;
133
    float temp = value;
Line 131... Line 134...
131
 
134
 
132
    return value / num;
135
    return temp / num;
133
}
136
}
Line 143... Line 146...
143
 
146
 
144
    return string(String);
147
    return string(String);
Line 145... Line 148...
145
}
148
}
146
 
149
 
147
// check CRC
150
// check CRC
-
 
151
bool Parser::check_CRC(string RXstr)
148
bool Parser::check_CRC(char * RX, int length)
152
{
149
{
153
    int length = RXstr.size();
Line 150... Line 154...
150
    int CRC = 0;
154
    int CRC = 0;
151
    char *RX;
155
    char *RX = (char *)RXstr.c_str();
152
 
156
 
153
    if (RX[1] == 127)
157
    if (RX[1] == 127)
Line 174... Line 178...
174
 
178
 
175
    return true;
179
    return true;
Line 176... Line 180...
176
}
180
}
177
 
181
 
178
// add CRC
182
// add CRC
-
 
183
string Parser::add_CRC(string TX)
179
string Parser::add_CRC(char * TX, int length)
184
{
Line 180... Line 185...
180
{
185
    int length = TX.size();
Line 181... Line 186...
181
    unsigned int tmpCRC = 0;
186
    unsigned int tmpCRC = 0;