Subversion Repositories HomeAutomation

Rev

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

Rev 991 Rev 997
Line 430... Line 430...
430
                bin.replace(iter->second.getStartBit()+n*4, 4, hex2bin(character));
430
                bin.replace(iter->second.getStartBit()+n*4, 4, hex2bin(character));
431
            }
431
            }
432
        }
432
        }
433
    }
433
    }
434
 
434
 
-
 
435
    try
-
 
436
    {
435
    bin = bin.substr(0, highestBit);
437
        bin = bin.substr(0, highestBit);
-
 
438
    }
-
 
439
    catch (std::out_of_range& e)
-
 
440
    {
-
 
441
        cout << "DEBUG: translateValidDataToHex exception: " << e.what() << "\n";
-
 
442
        cout << "DEBUG: A bin=" << bin << " :: highestBit=" << highestBit << endl;
-
 
443
    }
436
 
444
 
437
    return bin2hex(bin);
445
    return bin2hex(bin);
438
}
446
}
439
 
447
 
440
map<string, CanVariable> CanIdTranslator::translateData(vector<XmlNode> variableNodes, string dataHex)
448
map<string, CanVariable> CanIdTranslator::translateData(vector<XmlNode> variableNodes, string dataHex)
441
{
449
{
442
    map<string, CanVariable> variables;
450
    map<string, CanVariable> variables;
443
    string dataBin = hex2bin(dataHex);
451
    string dataBin = hex2bin(dataHex);
-
 
452
    //dataBin = rpad(dataBin, 64, '0');
444
 
453
 
445
    for (int c = 0; c < variableNodes.size(); c++)
454
    for (int c = 0; c < variableNodes.size(); c++)
446
    {
455
    {
447
        map<string, string> attributes = variableNodes[c].getAttributes();
456
        map<string, string> attributes = variableNodes[c].getAttributes();
448
 
457
 
449
        int bitStart = stoi(attributes["start_bit"]);
458
        int bitStart = stoi(attributes["start_bit"]);
450
        int bitLength = stoi(attributes["bit_length"]);
459
        int bitLength = stoi(attributes["bit_length"]);
-
 
460
        string bits;
451
 
461
 
-
 
462
        try
-
 
463
        {
452
        string bits = dataBin.substr(bitStart, bitLength);
464
            bits = dataBin.substr(bitStart, bitLength);
-
 
465
        }
-
 
466
        catch (std::out_of_range& e)
-
 
467
        {
-
 
468
            return variables;
-
 
469
        }
453
 
470
 
454
        CanVariable variable;
471
        CanVariable variable;
455
 
472
 
456
        variable.setName(attributes["name"]);
473
        variable.setName(attributes["name"]);
457
        variable.setType(attributes["type"]);
474
        variable.setType(attributes["type"]);
458
        variable.setUnit(attributes["unit"]);
475
        variable.setUnit(attributes["unit"]);
459
        variable.setStartBit(bitStart);
476
        variable.setStartBit(bitStart);
460
        variable.setBitLength(bitLength);
477
        variable.setBitLength(bitLength);
461
 
478
 
462
        if (attributes["type"] == "uint")
479
        if (attributes["type"] == "uint")
463
        {
480
        {
464
            variable.setValue(itos(bin2uint(bits)));
481
            variable.setValue(itos(bin2uint(bits)));
465
        }
482
        }
466
        else if (attributes["type"] == "float")
483
        else if (attributes["type"] == "float")
Line 470... Line 487...
470
        else if (attributes["type"] == "ascii")
487
        else if (attributes["type"] == "ascii")
471
        {
488
        {
472
            string str;
489
            string str;
473
 
490
 
474
            for (int k = 0; k < bits.length(); k += 8)
491
            for (int k = 0; k < bits.length(); k += 8)
-
 
492
            {
-
 
493
                try
475
            {
494
                {
476
                str += (char)bin2uint(bits.substr(k, 8));
495
                    str += (char)bin2uint(bits.substr(k, 8));
-
 
496
                }
-
 
497
                catch (std::out_of_range& e)
-
 
498
                {
-
 
499
                    cout << "DEBUG: TranslateData exception: " << e.what() << "\n";
-
 
500
                    cout << "DEBUG: B bits=" << bits << " :: k=" << k << endl;
-
 
501
                    continue;
-
 
502
                }
477
            }
503
            }
478
 
504
 
479
            variable.setValue(str);
505
            variable.setValue(str);
480
        }
506
        }
481
        else if (attributes["type"] == "hexstring")
507
        else if (attributes["type"] == "hexstring")
482
        {
508
        {
483
            string str;
509
            string str;
484
 
510
 
485
            for (int k = 0; k < bits.length(); k += 4)
511
            for (int k = 0; k < bits.length(); k += 4)
-
 
512
            {
-
 
513
                try
486
            {
514
                {
487
                str += bin2hex(bits.substr(k, 4));
515
                    str += bin2hex(bits.substr(k, 4));
-
 
516
                }
-
 
517
                catch (std::out_of_range& e)
-
 
518
                {
-
 
519
                    cout << "DEBUG: TranslateData exception: " << e.what() << "\n";
-
 
520
                    cout << "DEBUG: C bits=" << bits << " :: k=" << k << endl;
-
 
521
                    continue;
-
 
522
                }
488
            }
523
            }
489
 
524
 
490
            variable.setValue(str);
525
            variable.setValue(str);
491
        }
526
        }
492
 
527