Subversion Repositories HomeAutomation

Rev

Rev 976 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 976 Rev 981
Line 93... Line 93...
93
 
93
 
94
    for (int n = 0; n < commandNodes.size(); n++)
94
    for (int n = 0; n < commandNodes.size(); n++)
95
    {
95
    {
96
        map<string, string> attributes = commandNodes[n].getAttributes();
96
        map<string, string> attributes = commandNodes[n].getAttributes();
97
 
97
 
98
        if (commandId > 128)
98
        if (commandId >= 128)
99
        {
99
        {
100
            if (stoi(attributes["id"]) == commandId && attributes["module"] == moduleName)
100
            if (stoi(attributes["id"]) == commandId && attributes["module"] == moduleName)
101
            {
101
            {
102
                return attributes["name"];
102
                return attributes["name"];
103
            }
103
            }
Line 122... Line 122...
122
 
122
 
123
        if (attributes["name"].compare(commandName) == 0)
123
        if (attributes["name"].compare(commandName) == 0)
124
        {
124
        {
125
            int commandId = stoi(attributes["id"]);
125
            int commandId = stoi(attributes["id"]);
126
 
126
 
127
            if (commandId > 128)
127
            if (commandId >= 128)
128
            {
128
            {
129
                if (attributes["module"] == moduleName)
129
                if (attributes["module"] == moduleName)
130
                {
130
                {
131
                    return commandId;
131
                    return commandId;
132
                }
132
                }
Line 242... Line 242...
242
    {
242
    {
243
        map<string, string> attributes = commandNodes[n].getAttributes();
243
        map<string, string> attributes = commandNodes[n].getAttributes();
244
 
244
 
245
        bool correct = false;
245
        bool correct = false;
246
 
246
 
247
        if (commandId > 128)
247
        if (commandId >= 128)
248
        {
248
        {
249
            if (stoi(attributes["id"]) == commandId && attributes["module"] == moduleName)
249
            if (stoi(attributes["id"]) == commandId && attributes["module"] == moduleName)
250
            {
250
            {
251
                correct = true;
251
                correct = true;
252
            }
252
            }
Line 294... Line 294...
294
        {
294
        {
295
            if (iter->second.getStartBit() + iter->second.getBitLength() > heighestBit)
295
            if (iter->second.getStartBit() + iter->second.getBitLength() > heighestBit)
296
                heighestBit = iter->second.getStartBit() + iter->second.getBitLength();
296
                heighestBit = iter->second.getStartBit() + iter->second.getBitLength();
297
 
297
 
298
            //cout << iter->first << ":" <<  stoi(iter->second.getValue()) << endl;
298
            //cout << iter->first << ":" <<  stoi(iter->second.getValue()) << endl;
299
            int a = stoi(iter->second.getValue());
299
            unsigned int a = stoi(iter->second.getValue());
300
           
300
           
301
            bin.replace(iter->second.getStartBit(), iter->second.getBitLength(), uint2bin(a, iter->second.getBitLength()));
301
            bin.replace(iter->second.getStartBit(), iter->second.getBitLength(), uint2bin(a, iter->second.getBitLength()));
302
        }
302
        }
303
        else if (iter->second.getType() == "float")
303
        else if (iter->second.getType() == "float")
304
        {
304
        {
Line 317... Line 317...
317
 
317
 
318
                //cout << iter->second.getValue()[n] << ":" << (unsigned int)iter->second.getValue()[n] << endl;
318
                //cout << iter->second.getValue()[n] << ":" << (unsigned int)iter->second.getValue()[n] << endl;
319
                bin.replace(iter->second.getStartBit()+n*8, 8, uint2bin((unsigned int)iter->second.getValue()[n], 8));
319
                bin.replace(iter->second.getStartBit()+n*8, 8, uint2bin((unsigned int)iter->second.getValue()[n], 8));
320
            }
320
            }
321
        }
321
        }
-
 
322
        else if (iter->second.getType() == "hexstring")
-
 
323
        {
-
 
324
            for (int n = 0; n < iter->second.getValue().length(); n++)
-
 
325
            {
-
 
326
                if (iter->second.getStartBit()+n*4 + 4 > heighestBit)
-
 
327
                    heighestBit = iter->second.getStartBit()+n*4 + 4;
-
 
328
 
-
 
329
                string character;
-
 
330
                character += iter->second.getValue()[n];
-
 
331
 
-
 
332
                bin.replace(iter->second.getStartBit()+n*4, 4, hex2bin(character));
-
 
333
            }
-
 
334
        }
322
    }
335
    }
323
 
336
 
324
    bin = bin.substr(0, heighestBit);
337
    bin = bin.substr(0, heighestBit);
325
 
338
 
326
    //cout << bin2hex(bin) << endl;
339
    //cout << bin2hex(bin) << endl;
327
 
340
 
328
    return bin2hex(bin);
341
    return bin2hex(bin);
329
}
342
}
330
 
343
 
331
map<string, CanVariable> CanIdTranslator::translateData(int commandId, string moduleName, string dataHex)
344
map<string, CanVariable> CanIdTranslator::translateData(int commandId, string moduleName, string dataHex)
332
{
345
{
333
    map<string, CanVariable> variables;
346
    map<string, CanVariable> variables;
334
    XmlNode commandsNode = xmlNode.findChild("commands");
347
    XmlNode commandsNode = xmlNode.findChild("commands");
335
    vector<XmlNode> commandNodes = commandsNode.getChildren();
348
    vector<XmlNode> commandNodes = commandsNode.getChildren();
336
 
349
 
337
    string dataBin = hex2bin(dataHex);
350
    string dataBin = hex2bin(dataHex);
338
    //string dataString = "{";
351
    //string dataString = "{";
339
 
352
 
340
    for (int n = 0; n < commandNodes.size(); n++)
353
    for (int n = 0; n < commandNodes.size(); n++)
341
    {
354
    {
342
        map<string, string> attributes = commandNodes[n].getAttributes();
355
        map<string, string> attributes = commandNodes[n].getAttributes();
343
 
356
 
344
        bool correct = false;
357
        bool correct = false;
345
 
358
 
346
        if (commandId > 128)
359
        if (commandId >= 128)
347
        {
360
        {
348
            if (stoi(attributes["id"]) == commandId && attributes["module"] == moduleName)
361
            if (stoi(attributes["id"]) == commandId && attributes["module"] == moduleName)
349
            {
362
            {
350
                correct = true;
363
                correct = true;
351
            }
364
            }
352
        }
365
        }
353
        else if (stoi(attributes["id"]) == commandId)
366
        else if (stoi(attributes["id"]) == commandId)
354
        {
367
        {
355
            correct = true;
368
            correct = true;
356
        }
369
        }
357
 
370
 
358
        if (correct)
371
        if (correct)
359
        {
372
        {
360
            XmlNode varablesNode = commandNodes[n].findChild("variables");
373
            XmlNode varablesNode = commandNodes[n].findChild("variables");
361
 
374
 
362
            vector<XmlNode> variableNodes = varablesNode.getChildren();
375
            vector<XmlNode> variableNodes = varablesNode.getChildren();
363
 
376
 
364
            for (int c = 0; c < variableNodes.size(); c++)
377
            for (int c = 0; c < variableNodes.size(); c++)
365
            {
378
            {
366
                map<string, string> attributes = variableNodes[c].getAttributes();
379
                map<string, string> attributes = variableNodes[c].getAttributes();
367
 
380
 
368
                int bitStart = stoi(attributes["start_bit"]);
381
                int bitStart = stoi(attributes["start_bit"]);
369
                int bitLength = stoi(attributes["bit_length"]);
382
                int bitLength = stoi(attributes["bit_length"]);
370
 
383
 
Line 390... Line 403...
390
                {
403
                {
391
                    variable.setValue(ftos(bin2float(bits)));
404
                    variable.setValue(ftos(bin2float(bits)));
392
                    //dataString += ftos(bin2float(bits));
405
                    //dataString += ftos(bin2float(bits));
393
                }
406
                }
394
                else if (attributes["type"] == "ascii")
407
                else if (attributes["type"] == "ascii")
395
                {
408
                {
396
                    string str;
409
                    string str;
397
                    //dataString += "'";
410
                    //dataString += "'";
398
 
411
 
399
                    for (int k = 0; k < bits.length(); k += 8)
412
                    for (int k = 0; k < bits.length(); k += 8)
400
                    {
413
                    {
401
                        str += (char)bin2uint(bits.substr(k, 8));
414
                        str += (char)bin2uint(bits.substr(k, 8));
402
                        //dataString += (char)bin2uint(bits.substr(k, 4));
415
                        //dataString += (char)bin2uint(bits.substr(k, 4));
403
                    }
416
                    }
404
 
417
 
405
                    variable.setValue(str);
418
                    variable.setValue(str);
406
                    //cout << "Parsed ascii: " << str << "\n";
419
                    //cout << "Parsed ascii: " << str << "\n";
407
                    //dataString += "'";
420
                    //dataString += "'";
-
 
421
                }
-
 
422
                else if (attributes["type"] == "hexstring")
-
 
423
                {
-
 
424
                    string str;
-
 
425
 
-
 
426
                    for (int k = 0; k < bits.length(); k += 4)
-
 
427
                    {
-
 
428
                        str += bin2hex(bits.substr(k, 4));
-
 
429
                        //dataString += (char)bin2uint(bits.substr(k, 4));
-
 
430
                    }
-
 
431
 
-
 
432
                    variable.setValue(str);
408
                }
433
                }
409
 
434
 
410
                variables[attributes["name"]] = variable;
435
                variables[attributes["name"]] = variable;
411
 
436
 
412
                //dataString += ", type : '" + attributes["type"] + "', bits : " + attributes["bit_length"] + ", unit : '" + attributes["unit"] + "' },";
437
                //dataString += ", type : '" + attributes["type"] + "', bits : " + attributes["bit_length"] + ", unit : '" + attributes["unit"] + "' },";