//Variables
var draw_devices = function() {
    getFullPanel(0, 0, 9, 9, "tab-page-devices", "sec-devices", "DEVICE", "LIST", "VER 1.0");
    var panel = document.getElementById("sec-devices");
    panel.innerHTML += draw_devices_1();
}

var draw_devices_1 = function() {
    var html = getSectionTitle('ALL DEVICES');
    for (var i = 0; i < 40; i++) {
        //Device
        var rows = '';
        rows += draw_devices_head(i);
        rows += draw_devices_entry(i);
        html += getTabel(rows);
    }

    html = getPanel(html);
    return html;
}

var draw_devices_head = function(idx) {
    //Device
    var rows = '';
    var row = '';
    row += getInfoCellHI('dev-cell-IDX-' + idx, '', 'IDX', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-ID-' + idx, '', 'ID', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-D_IDX-' + idx, '', 'D_IDX', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-TYPE-' + idx, '', 'TYPE', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-SOFT-' + idx, '', 'SOFT', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-HARD-' + idx, '', 'HARD', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-TX-' + idx, '', 'TX', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-RX-' + idx, '', 'RX', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-INIT-' + idx, '', 'INIT', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-COMMS-' + idx, '', 'COMM', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-ERR-' + idx, '', 'ERR', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-WATER-' + idx, '', 'WTR', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-ENABLE-' + idx, '', 'ENBLE', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-V_RD-' + idx, '', 'V_RD', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-VOLT-' + idx, '', 'VOLT', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-K_TL-' + idx, '', 'K_TL', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-K_BL-' + idx, '', 'K_BL', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-K_TR-' + idx, '', 'K_TR', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-K_BR-' + idx, '', 'K_BR', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-ENG-' + idx, '', 'ENG', 'ai-cell-info-1');
    //Flow
    row += getInfoCellHI('dev-cell-ACT-' + idx, '', 'ACT', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-FA_RD-' + idx, '', 'A_RD', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-FAMP-' + idx, '', 'AMP', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-CALIB-' + idx, '', 'CALI', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-GOLD-' + idx, '', 'GOLD', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-TAR_APP-' + idx, '', 'T_APP', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-FTAR_FLO-' + idx, '', 'T_FLO', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-ACT_APP-' + idx, '', 'A_APP', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-FACT_FLO-' + idx, '', 'A_FLO', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-APP_DEV-' + idx, '', 'A_DEV', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-APP_D_P-' + idx, '', 'A_D_P', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-DIS_OFF-' + idx, '', 'DIS_OFF', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-SPD_OFF-' + idx, '', 'SPD_OFF', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-SPD_ACT-' + idx, '', 'SPD_ACT', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-10P-' + idx, '', '10P', 'ai-cell-info-1');
    //FC
    row += getInfoCellHI('dev-cell-ENG_S-' + idx, '', 'ENG_S', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-CA_RD-' + idx, '', 'A_RD', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-CAMP-' + idx, '', 'AMP', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-PIC_PLS-' + idx, '', 'PIC_PLS', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-PIC_SPD-' + idx, '', 'PIC_SPD', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-TRG_PRS-' + idx, '', 'TRG_PRS', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-ACT_PRS-' + idx, '', 'ACT_PRS', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-PRS_DEV-' + idx, '', 'PRS_DEV', 'ai-cell-info-1');
    //Hydraulic
    row += getInfoCellHI('dev-cell-HTRG_FLO-' + idx, '', 'T_FLO', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-HACT_FLO-' + idx, '', 'A_FLO', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-ACT_RPM-' + idx, '', 'A_RPM', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-U_VOL-' + idx, '', 'U_VOL', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-UNITS-' + idx, '', 'UNITS', 'ai-cell-info-1');
    row += getInfoCellHI('dev-cell-T_VOL-' + idx, '', 'T_VOL', 'ai-cell-info-1');
    rows += getInfoRowI('dev-cell-ROW-' + idx, row);
    return rows;
}

var draw_devices_entry = function(idx) {
    //Device
    var rows = '';
    var row = '';
    row += getInfoCellI('dev-cell-D-IDX-' + idx, '', idx, 'ai-cell-info-2');
    row += getInfoCellI('dev-cell-D-ID-' + idx, '', 0, 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-D_IDX-' + idx, '', 0, 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-TYPE-' + idx, '', 'A5', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-SOFT-' + idx, '', '1.0', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-HARD-' + idx, '', '1.0', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-TX-' + idx, '', (300 + (idx*2) + 1).toString(16), 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-RX-' + idx, '', (300 + (idx*2) + 2).toString(16), 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-INIT-' + idx, '', 'YES', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-COMMS-' + idx, '', 'OFF', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-ERR-' + idx, '', 'OFF', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-WATER-' + idx, '', 'OFF', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-ENABLE-' + idx, '', 'YES', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-V_RD-' + idx, '', '9d', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-VOLT-' + idx, '', '12.2', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-K_TL-' + idx, '', 'OFF', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-K_BL-' + idx, '', 'OFF', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-K_TR-' + idx, '', 'OFF', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-K_BR-' + idx, '', 'OFF', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-ENG-' + idx, '', 'ON', 'ai-cell-secondary-1');
    //Flow
    row += getInfoCellI('dev-cell-D-ACT-' + idx, '', 'ON', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-FA_RD-' + idx, '', '96', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-FAMP-' + idx, '', 'OFF', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-CALIB-' + idx, '', '100', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-GOLD-' + idx, '', '5268400', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-TAR_APP-' + idx, '', '200', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-FTAR_FLO-' + idx, '', '2000', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-ACT_APP-' + idx, '', '220', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-FACT_FLO-' + idx, '', '2200', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-APP_DEV-' + idx, '', '20', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-APP_D_P-' + idx, '', '10', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-DIS_OFF-' + idx, '', '-1.00', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-SPD_OFF-' + idx, '', '0.25', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-SPD_ACT-' + idx, '', '9.25', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-10P-' + idx, '', 'ON', 'ai-cell-secondary-1');
    //FC
    row += getInfoCellI('dev-cell-D-ENG_S-' + idx, '', 'ON', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-CA_RD-' + idx, '', '96', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-CAMP-' + idx, '', 'OFF', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-PIC_PLS-' + idx, '', '200', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-PIC_SPD-' + idx, '', '12.0', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-TRG_PRS-' + idx, '', '1.20', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-ACT_PRS-' + idx, '', '1.11', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-PRS_DEV-' + idx, '', '0.09', 'ai-cell-secondary-1');
    //Hydraulic
    row += getInfoCellI('dev-cell-D-HTRG_FLO-' + idx, '', '64000', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-HACT_FLO-' + idx, '', '60000', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-ACT_RPM-' + idx, '', '120', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-U_VOL-' + idx, '', '42', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-UNITS-' + idx, '', '16', 'ai-cell-secondary-1');
    row += getInfoCellI('dev-cell-D-T_VOL-' + idx, '', '642', 'ai-cell-secondary-1');
    rows += getInfoRowI('dev-cell-D-ROW-' + idx, row);
    return rows;
}

draw_devices();

///////////////////////////////////////
//Update devices
///////////////////////////////////////

var devices_count = 0;
var devices_type = [];
for (var i = 0; i < 40; i++) {
    devices_type[i] = 'AA';
}

var devices_update_number = function(devices)
{
    if (devices != devices_count) {
        for (var i = 0; i < devices; i++) {
            document.getElementById("dev-cell-ROW-" + i).className = '';
            document.getElementById("dev-cell-D-ROW-" + i).className = '';
        }
        for (var i = devices; i < 40; i++) {
            document.getElementById("dev-cell-ROW-" + i).className = 'hidden';
            document.getElementById("dev-cell-D-ROW-" + i).className = 'hidden';
        }

        devices_count = devices;
    }
}

var devices_update_device_main = function(idx, type, data)
{
    devices_update_device_main_hidden(idx, '');
    if (type.toString(16) == 'a5') devices_update_device_flow_main(idx, data);
    if (type.toString(16) == 'fc') devices_update_device_fc_main(idx, data);
    if (type.toString(16) == 'c7') devices_update_device_hydr_main(idx, data);
    devices_type[idx] = type;

    document.getElementById("dev-cell-D-IDX-" + idx).children[0].innerText = data[4];
    document.getElementById("dev-cell-D-IDX-" + idx).children[0].className = 'ai-cell ai-cell-info-1';
    
    document.getElementById("dev-cell-D-ID-" + idx).children[0].innerText = data[5];
    document.getElementById("dev-cell-D-D_IDX-" + idx).children[0].innerText = data[7];
    document.getElementById("dev-cell-D-TYPE-" + idx).children[0].innerText = data[6].toString(16);
    document.getElementById("dev-cell-D-TYPE-" + idx).children[0].className = 'ai-cell ai-cell-warning';

    document.getElementById("dev-cell-D-SOFT-" + idx).children[0].innerText = ((data[10] + data[11]*256)/10).toFixed(1);
    document.getElementById("dev-cell-D-HARD-" + idx).children[0].innerText = ((data[12] + data[13]*256)/10).toFixed(1);
    document.getElementById("dev-cell-D-TX-" + idx).children[0].innerText = (256 + data[14]).toString(16);
    document.getElementById("dev-cell-D-RX-" + idx).children[0].innerText = (256 + data[15]).toString(16);
    document.getElementById("dev-cell-D-VOLT-" + idx).children[0].innerText = (data[16]/10).toFixed(1);
    if ((data[16]/10) < 8 && (data[16]/10) > 14) {
        document.getElementById("dev-cell-D-V_RD-" + idx).children[0].className = 'ai-cell ai-cell-danger';
        document.getElementById("dev-cell-D-VOLT-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    } else {
        document.getElementById("dev-cell-D-V_RD-" + idx).children[0].className = 'ai-cell ai-cell-success';
        document.getElementById("dev-cell-D-VOLT-" + idx).children[0].className = 'ai-cell ai-cell-success';
    }
    if (Math.floor(data[8])%2 == 1) {
        document.getElementById("dev-cell-D-INIT-" + idx).children[0].innerText = 'YES';
        document.getElementById("dev-cell-D-INIT-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-INIT-" + idx).children[0].innerText = 'NO';
        document.getElementById("dev-cell-D-INIT-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    if (Math.floor(data[8]/2)%2 == 1) {
        document.getElementById("dev-cell-D-COMMS-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-COMMS-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    } else {
        document.getElementById("dev-cell-D-COMMS-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-COMMS-" + idx).children[0].className = 'ai-cell ai-cell-success';
    }
    if (Math.floor(data[8]/4)%2 == 1) {
        document.getElementById("dev-cell-D-ERR-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-ERR-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    } else {
        document.getElementById("dev-cell-D-ERR-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-ERR-" + idx).children[0].className = 'ai-cell ai-cell-success';
    }
    if (Math.floor(data[8]/8)%2 == 1) {
        document.getElementById("dev-cell-D-WATER-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-WATER-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    } else {
        document.getElementById("dev-cell-D-WATER-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-WATER-" + idx).children[0].className = 'ai-cell ai-cell-success';
    }
    if (Math.floor(data[8]/16)%2 == 1) {
        document.getElementById("dev-cell-D-ENABLE-" + idx).children[0].innerText = 'YES';
        document.getElementById("dev-cell-D-ENABLE-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-ENABLE-" + idx).children[0].innerText = 'NO';
        document.getElementById("dev-cell-D-ENABLE-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
}

var devices_update_device_seco = function(idx, type, data)
{
    devices_update_device_seco_hidden(idx, '');
    if (type.toString(16) == 'a5') devices_update_device_flow_seco(idx, data);
    if (type.toString(16) == 'fc') devices_update_device_fc_seco(idx, data);
    if (type.toString(16) == 'c7') devices_update_device_hydr_seco(idx, data);
    devices_type[idx] = type;
}

var devices_update_device_flow_main = function(idx, data)
{
    devices_update_device_flow_main_hidden(idx, '');
    devices_update_device_fc_main_hidden(idx, 'hidden');
    devices_update_device_hydr_main_hidden(idx, 'hidden');
    if (Math.floor(data[25])%2 == 1) {
        document.getElementById("dev-cell-D-ENG-" + idx).children[0].innerText = 'YES';
        document.getElementById("dev-cell-D-ENG-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-ENG-" + idx).children[0].innerText = 'NO';
        document.getElementById("dev-cell-D-ENG-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    if (Math.floor(data[37])%2 == 1) {
        document.getElementById("dev-cell-D-ACT-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-ACT-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-ACT-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-ACT-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    document.getElementById("dev-cell-D-CALIB-" + idx).children[0].innerText = data[26];
    document.getElementById("dev-cell-D-TAR_APP-" + idx).children[0].innerText = data[19] + data[20]*256;
    document.getElementById("dev-cell-D-FTAR_FLO-" + idx).children[0].innerText = data[17] + data[18]*256;
    document.getElementById("dev-cell-D-ACT_APP-" + idx).children[0].innerText = data[23] + data[24]*256;
    document.getElementById("dev-cell-D-FACT_FLO-" + idx).children[0].innerText = data[21] + data[22]*256;
    document.getElementById("dev-cell-D-APP_DEV-" + idx).children[0].innerText = data[33] + data[34]*256;
    document.getElementById("dev-cell-D-APP_D_P-" + idx).children[0].innerText = data[35] + data[36]*256;
    var temp = (data[27] + data[28]*256);
    if (temp > 32767) temp = (-65536) + temp;
    document.getElementById("dev-cell-D-DIS_OFF-" + idx).children[0].innerText = (temp/100).toFixed(2);
    temp = (data[29] + data[30]*256);
    if (temp > 32767) temp = (-65536) + temp;
    document.getElementById("dev-cell-D-SPD_OFF-" + idx).children[0].innerText = (temp/100).toFixed(2);
    document.getElementById("dev-cell-D-SPD_ACT-" + idx).children[0].innerText = ((data[31] + data[32]*256)/100).toFixed(2);
    if (Math.floor(data[25]/4)%2 == 1) {
        document.getElementById("dev-cell-D-10P-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-10P-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    } else {
        document.getElementById("dev-cell-D-10P-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-10P-" + idx).children[0].className = 'ai-cell ai-cell-success';
    }
}

var devices_update_device_fc_main = function(idx, data)
{
    devices_update_device_flow_main_hidden(idx, 'hidden');
    devices_update_device_fc_main_hidden(idx, '');
    devices_update_device_hydr_main_hidden(idx, 'hidden');

    if (Math.floor(data[17]/2)%2 == 1) {
        document.getElementById("dev-cell-D-ENG-" + idx).children[0].innerText = 'YES';
        document.getElementById("dev-cell-D-ENG-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-ENG-" + idx).children[0].innerText = 'NO';
        document.getElementById("dev-cell-D-ENG-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    if (Math.floor(data[17])%2 == 1) {
        document.getElementById("dev-cell-D-ENG_S-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-ENG_S-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-ENG_S-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-ENG_S-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    document.getElementById("dev-cell-D-PIC_PLS-" + idx).children[0].innerText = data[24];
    document.getElementById("dev-cell-D-PIC_SPD-" + idx).children[0].innerText = data[25];
    document.getElementById("dev-cell-D-TRG_PRS-" + idx).children[0].innerText = data[26];
    document.getElementById("dev-cell-D-ACT_PRS-" + idx).children[0].innerText = data[27];
    document.getElementById("dev-cell-D-PRS_DEV-" + idx).children[0].innerText = data[28];
}

var devices_update_device_hydr_main = function(idx, data)
{
    devices_update_device_flow_main_hidden(idx, 'hidden');
    devices_update_device_fc_main_hidden(idx, 'hidden');
    devices_update_device_hydr_main_hidden(idx, '');
    if (Math.floor(data[25])%2 == 1) {
        document.getElementById("dev-cell-D-ENG-" + idx).children[0].innerText = 'YES';
        document.getElementById("dev-cell-D-ENG-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-ENG-" + idx).children[0].innerText = 'NO';
        document.getElementById("dev-cell-D-ENG-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    document.getElementById("dev-cell-D-HTRG_FLO-" + idx).children[0].innerText = data[21];
    document.getElementById("dev-cell-D-HACT_FLO-" + idx).children[0].innerText = data[22];
    document.getElementById("dev-cell-D-ACT_RPM-" + idx).children[0].innerText = data[23];
    document.getElementById("dev-cell-D-U_VOL-" + idx).children[0].innerText = data[24];
    document.getElementById("dev-cell-D-UNITS-" + idx).children[0].innerText = data[25];
    document.getElementById("dev-cell-D-T_VOL-" + idx).children[0].innerText = data[26];
}

var devices_update_device_flow_seco = function(idx, data)
{
    devices_update_device_flow_seco_hidden(idx, '');
    devices_update_device_fc_seco_hidden(idx, 'hidden');
    devices_update_device_hydr_seco_hidden(idx, 'hidden');
    document.getElementById("dev-cell-D-V_RD-" + idx).children[0].innerText = data[75].toFixed(1);
    if (Math.floor(data[63]/2)%2 == 1) {
        document.getElementById("dev-cell-D-K_TL-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-K_TL-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-K_TL-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-K_TL-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    if (Math.floor(data[63])%2 == 1) {
        document.getElementById("dev-cell-D-K_BL-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-K_BL-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-K_BL-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-K_BL-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    if (Math.floor(data[63]/5)%2 == 1) {
        document.getElementById("dev-cell-D-K_TR-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-K_TR-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-K_TR-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-K_TR-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    if (Math.floor(data[63]/4)%2 == 1) {
        document.getElementById("dev-cell-D-K_BR-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-K_BR-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-K_BR-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-K_BR-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }

    var total = data[64] + data[65];
    document.getElementById("dev-cell-D-FA_RD-" + idx).children[0].innerText = total;
    if (total < 30 || total > 90) {
        document.getElementById("dev-cell-D-FA_RD-" + idx).children[0].className = 'ai-cell ai-cell-danger';
        document.getElementById("dev-cell-D-FAMP-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-FAMP-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    } else {
        document.getElementById("dev-cell-D-FA_RD-" + idx).children[0].className = 'ai-cell ai-cell-success';
        document.getElementById("dev-cell-D-FAMP-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-FAMP-" + idx).children[0].className = 'ai-cell ai-cell-success';
    }
    document.getElementById("dev-cell-D-GOLD-" + idx).children[0].innerText = (data[58] + data[59]*256 + data[60]*256*256 + data[61]*256*256*256 + data[62]*256*256*256*256).toString(16);
    
}

var devices_update_device_fc_seco = function(idx, data)
{
    devices_update_device_flow_seco_hidden(idx, 'hidden');
    devices_update_device_fc_seco_hidden(idx, '');
    devices_update_device_hydr_seco_hidden(idx, 'hidden');
    document.getElementById("dev-cell-D-V_RD-" + idx).children[0].innerText = data[75].toFixed(1);
    if (Math.floor(data[63]/2)%2 == 1) {
        document.getElementById("dev-cell-D-K_TL-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-K_TL-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-K_TL-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-K_TL-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    if (Math.floor(data[63])%2 == 1) {
        document.getElementById("dev-cell-D-K_BL-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-K_BL-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-K_BL-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-K_BL-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    if (Math.floor(data[63]/5)%2 == 1) {
        document.getElementById("dev-cell-D-K_TR-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-K_TR-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-K_TR-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-K_TR-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    if (Math.floor(data[63]/4)%2 == 1) {
        document.getElementById("dev-cell-D-K_BR-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-K_BR-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-K_BR-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-K_BR-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }

    var total = data[64] + data[65];
    document.getElementById("dev-cell-D-CA_RD-" + idx).children[0].innerText = total;
    if (total < 30 || total > 90) {
        document.getElementById("dev-cell-D-CA_RD-" + idx).children[0].className = 'ai-cell ai-cell-danger';
        document.getElementById("dev-cell-D-CAMP-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-CAMP-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    } else {
        document.getElementById("dev-cell-D-CA_RD-" + idx).children[0].className = 'ai-cell ai-cell-success';
        document.getElementById("dev-cell-D-CAMP-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-CAMP-" + idx).children[0].className = 'ai-cell ai-cell-success';
    }
}

var devices_update_device_hydr_seco = function(idx, data)
{
    devices_update_device_flow_seco_hidden(idx, 'hidden');
    devices_update_device_fc_seco_hidden(idx, 'hidden');
    devices_update_device_hydr_seco_hidden(idx, '');
    document.getElementById("dev-cell-D-V_RD-" + idx).children[0].innerText = data[54].toFixed(1);
    if (Math.floor(data[53]/2)%2 == 1) {
        document.getElementById("dev-cell-D-K_TL-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-K_TL-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-K_TL-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-K_TL-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    if (Math.floor(data[53])%2 == 1) {
        document.getElementById("dev-cell-D-K_BL-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-K_BL-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-K_BL-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-K_BL-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    if (Math.floor(data[53]/5)%2 == 1) {
        document.getElementById("dev-cell-D-K_TR-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-K_TR-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-K_TR-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-K_TR-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
    if (Math.floor(data[53]/4)%2 == 1) {
        document.getElementById("dev-cell-D-K_BR-" + idx).children[0].innerText = 'ON';
        document.getElementById("dev-cell-D-K_BR-" + idx).children[0].className = 'ai-cell ai-cell-success';
    } else {
        document.getElementById("dev-cell-D-K_BR-" + idx).children[0].innerText = 'OFF';
        document.getElementById("dev-cell-D-K_BR-" + idx).children[0].className = 'ai-cell ai-cell-danger';
    }
}

var devices_update_device_main_hidden = function(idx, hidden)
{
    document.getElementById("dev-cell-D-VOLT-" + idx).className = hidden;
    document.getElementById("dev-cell-D-IDX-" + idx).className = hidden;
    document.getElementById("dev-cell-D-ID-" + idx).className = hidden;
    document.getElementById("dev-cell-D-D_IDX-" + idx).className = hidden;
    document.getElementById("dev-cell-D-TYPE-" + idx).className = hidden;
    document.getElementById("dev-cell-D-SOFT-" + idx).className = hidden;
    document.getElementById("dev-cell-D-HARD-" + idx).className = hidden;
    document.getElementById("dev-cell-D-TX-" + idx).className = hidden;
    document.getElementById("dev-cell-D-RX-" + idx).className = hidden;
    document.getElementById("dev-cell-D-INIT-" + idx).className = hidden;
    document.getElementById("dev-cell-D-COMMS-" + idx).className = hidden;
    document.getElementById("dev-cell-D-ERR-" + idx).className = hidden;
    document.getElementById("dev-cell-D-WATER-" + idx).className = hidden;
    document.getElementById("dev-cell-D-ENABLE-" + idx).className = hidden;
    document.getElementById("dev-cell-D-ENG-" + idx).className = hidden;
    document.getElementById("dev-cell-VOLT-" + idx).className = hidden;
    document.getElementById("dev-cell-IDX-" + idx).className = hidden;
    document.getElementById("dev-cell-ID-" + idx).className = hidden;
    document.getElementById("dev-cell-D_IDX-" + idx).className = hidden;
    document.getElementById("dev-cell-TYPE-" + idx).className = hidden;
    document.getElementById("dev-cell-SOFT-" + idx).className = hidden;
    document.getElementById("dev-cell-HARD-" + idx).className = hidden;
    document.getElementById("dev-cell-TX-" + idx).className = hidden;
    document.getElementById("dev-cell-RX-" + idx).className = hidden;
    document.getElementById("dev-cell-INIT-" + idx).className = hidden;
    document.getElementById("dev-cell-COMMS-" + idx).className = hidden;
    document.getElementById("dev-cell-ERR-" + idx).className = hidden;
    document.getElementById("dev-cell-WATER-" + idx).className = hidden;
    document.getElementById("dev-cell-ENABLE-" + idx).className = hidden;
    document.getElementById("dev-cell-ENG-" + idx).className = hidden;
}

var devices_update_device_flow_main_hidden = function(idx, hidden)
{
    document.getElementById("dev-cell-D-ACT-" + idx).className = hidden;
    document.getElementById("dev-cell-D-CALIB-" + idx).className = hidden;
    document.getElementById("dev-cell-D-TAR_APP-" + idx).className = hidden;
    document.getElementById("dev-cell-D-FTAR_FLO-" + idx).className = hidden;
    document.getElementById("dev-cell-D-ACT_APP-" + idx).className = hidden;
    document.getElementById("dev-cell-D-FACT_FLO-" + idx).className = hidden;
    document.getElementById("dev-cell-D-APP_DEV-" + idx).className = hidden;
    document.getElementById("dev-cell-D-APP_D_P-" + idx).className = hidden;
    document.getElementById("dev-cell-D-DIS_OFF-" + idx).className = hidden;
    document.getElementById("dev-cell-D-SPD_OFF-" + idx).className = hidden;
    document.getElementById("dev-cell-D-SPD_ACT-" + idx).className = hidden;
    document.getElementById("dev-cell-D-10P-" + idx).className = hidden;
    document.getElementById("dev-cell-ACT-" + idx).className = hidden;
    document.getElementById("dev-cell-CALIB-" + idx).className = hidden;
    document.getElementById("dev-cell-TAR_APP-" + idx).className = hidden;
    document.getElementById("dev-cell-FTAR_FLO-" + idx).className = hidden;
    document.getElementById("dev-cell-ACT_APP-" + idx).className = hidden;
    document.getElementById("dev-cell-FACT_FLO-" + idx).className = hidden;
    document.getElementById("dev-cell-APP_DEV-" + idx).className = hidden;
    document.getElementById("dev-cell-APP_D_P-" + idx).className = hidden;
    document.getElementById("dev-cell-DIS_OFF-" + idx).className = hidden;
    document.getElementById("dev-cell-SPD_OFF-" + idx).className = hidden;
    document.getElementById("dev-cell-SPD_ACT-" + idx).className = hidden;
    document.getElementById("dev-cell-10P-" + idx).className = hidden;
}

var devices_update_device_fc_main_hidden = function(idx, hidden)
{
    document.getElementById("dev-cell-D-ENG_S-" + idx).className = hidden;
    document.getElementById("dev-cell-D-PIC_PLS-" + idx).className = hidden;
    document.getElementById("dev-cell-D-PIC_SPD-" + idx).className = hidden;
    document.getElementById("dev-cell-D-TRG_PRS-" + idx).className = hidden;
    document.getElementById("dev-cell-D-ACT_PRS-" + idx).className = hidden;
    document.getElementById("dev-cell-D-PRS_DEV-" + idx).className = hidden;
    document.getElementById("dev-cell-ENG_S-" + idx).className = hidden;
    document.getElementById("dev-cell-PIC_PLS-" + idx).className = hidden;
    document.getElementById("dev-cell-PIC_SPD-" + idx).className = hidden;
    document.getElementById("dev-cell-TRG_PRS-" + idx).className = hidden;
    document.getElementById("dev-cell-ACT_PRS-" + idx).className = hidden;
    document.getElementById("dev-cell-PRS_DEV-" + idx).className = hidden;
}

var devices_update_device_hydr_main_hidden = function(idx, hidden)
{
    document.getElementById("dev-cell-D-HTRG_FLO-" + idx).className = hidden;
    document.getElementById("dev-cell-D-HACT_FLO-" + idx).className = hidden;
    document.getElementById("dev-cell-D-ACT_RPM-" + idx).className = hidden;
    document.getElementById("dev-cell-D-U_VOL-" + idx).className = hidden;
    document.getElementById("dev-cell-D-UNITS-" + idx).className = hidden;
    document.getElementById("dev-cell-D-T_VOL-" + idx).className = hidden;
    document.getElementById("dev-cell-HTRG_FLO-" + idx).className = hidden;
    document.getElementById("dev-cell-HACT_FLO-" + idx).className = hidden;
    document.getElementById("dev-cell-ACT_RPM-" + idx).className = hidden;
    document.getElementById("dev-cell-U_VOL-" + idx).className = hidden;
    document.getElementById("dev-cell-UNITS-" + idx).className = hidden;
    document.getElementById("dev-cell-T_VOL-" + idx).className = hidden;
}

var devices_update_device_seco_hidden = function(idx, hidden)
{
    document.getElementById("dev-cell-D-V_RD-" + idx).className = hidden;
    document.getElementById("dev-cell-D-K_TL-" + idx).className = hidden;
    document.getElementById("dev-cell-D-K_BL-" + idx).className = hidden;
    document.getElementById("dev-cell-D-K_TR-" + idx).className = hidden;
    document.getElementById("dev-cell-D-K_BR-" + idx).className = hidden;
    document.getElementById("dev-cell-V_RD-" + idx).className = hidden;
    document.getElementById("dev-cell-K_TL-" + idx).className = hidden;
    document.getElementById("dev-cell-K_BL-" + idx).className = hidden;
    document.getElementById("dev-cell-K_TR-" + idx).className = hidden;
    document.getElementById("dev-cell-K_BR-" + idx).className = hidden;
}

var devices_update_device_flow_seco_hidden = function(idx, hidden)
{
    document.getElementById("dev-cell-D-FA_RD-" + idx).className = hidden;
    document.getElementById("dev-cell-D-FAMP-" + idx).className = hidden;
    document.getElementById("dev-cell-D-GOLD-" + idx).className = hidden;
    document.getElementById("dev-cell-FA_RD-" + idx).className = hidden;
    document.getElementById("dev-cell-FAMP-" + idx).className = hidden;
    document.getElementById("dev-cell-GOLD-" + idx).className = hidden;
}

var devices_update_device_fc_seco_hidden = function(idx, hidden)
{
    document.getElementById("dev-cell-D-CA_RD-" + idx).className = hidden;
    document.getElementById("dev-cell-D-CAMP-" + idx).className = hidden;
    document.getElementById("dev-cell-CA_RD-" + idx).className = hidden;
    document.getElementById("dev-cell-CAMP-" + idx).className = hidden;
}

var devices_update_device_hydr_seco_hidden = function(idx, hidden)
{
    
}