Subversion Repositories Projects

Rev

Rev 674 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 674 Rev 801
Line 21... Line 21...
21
HandlerMK::HandlerMK()
21
HandlerMK::HandlerMK()
22
{
22
{
23
}
23
}
24
24
25
// Datensatz nach 16bit Integer
25
// Datensatz nach 16bit Integer
26
int HandlerMK::Data2Int(unsigned char Data[150] , int Start, bool is_signed)
26
int HandlerMK::Data2Int(unsigned char Data[160] , int Start, bool is_signed)
27
{
27
{
28
    int Out = (Data[Start+1]<<8) | (Data[Start+0]);
28
    int Out = (Data[Start+1]<<8) | (Data[Start+0]);
29
29
30
    if ((Out > 32767) && (is_signed))
30
    if ((Out > 32767) && (is_signed))
31
      Out = Out - 65536;
31
      Out = Out - 65536;
Line 137... Line 137...
137
137
138
    return ptr;
138
    return ptr;
139
}
139
}
140
140
141
// Base64 Encoder
141
// Base64 Encoder
142
QString HandlerMK::Encode64(char Data[150],unsigned int Length)
142
QString HandlerMK::Encode64(char Data[160],unsigned int Length)
143
{
143
{
144
    unsigned int pt = 0;
144
    unsigned int pt = 0;
145
    unsigned char a,b,c;
145
    unsigned char a,b,c;
146
    unsigned char ptr = 0;
146
    unsigned char ptr = 0;
147
147
148
    char TX_Buff[150];
148
    char TX_Buff[160];
149
149
150
    while(Length > 0)
150
    while(Length > 0)
151
    {
151
    {
152
        if(Length) { a = Data[ptr++]; Length--;} else a = 0;
152
        if(Length) { a = Data[ptr++]; Length--;} else a = 0;
153
        if(Length) { b = Data[ptr++]; Length--;} else b = 0;
153
        if(Length) { b = Data[ptr++]; Length--;} else b = 0;
Line 161... Line 161...
161
    TX_Buff[pt] = 0;
161
    TX_Buff[pt] = 0;
162
162
163
    return QString(TX_Buff);
163
    return QString(TX_Buff);
164
}
164
}
165
165
166
QString HandlerMK::make_Frame(char t_CMD, int t_Adress, char t_Data[150], unsigned int t_Length)
166
QString HandlerMK::make_Frame(char t_CMD, int t_Adress, char t_Data[160], unsigned int t_Length)
167
{
167
{
168
    QString tx_Data = Encode64(t_Data, t_Length);
168
    QString tx_Data = Encode64(t_Data, t_Length);
169
169
170
    tx_Data = add_CRC(QString("#" + QString('a' + t_Adress) + QString(t_CMD) + tx_Data)) + "\r";
170
    tx_Data = add_CRC(QString("#" + QString('a' + t_Adress) + QString(t_CMD) + tx_Data)) + "\r";
171
171