Example #1
0
static int cec_process_command_scan(const char* data)
{
  if (strncmp(data, "scan", 4) == 0)
  {
    char buffer[10000] = { 0 };
    char tmpbuf[50];
    int bufferpos = 0;
    cec_logical_addresses addresses;
    cec_logical_address activeSource;
    uint8_t iPtr;

    printf("requesting CEC bus information ...\n");

    bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "CEC bus information\n===================\n");
    addresses = g_iface.get_active_devices(g_iface.connection);
    activeSource = g_iface.get_active_source(g_iface.connection);
    for (iPtr = 0; iPtr < 16; iPtr++)
    {
      if (addresses.addresses[iPtr])
      {
        cec_menu_language lang;
        cec_osd_name osdName;
        uint64_t iVendorId        = g_iface.get_device_vendor_id(g_iface.connection, (cec_logical_address)iPtr);
        uint16_t iPhysicalAddress = g_iface.get_device_physical_address(g_iface.connection, (cec_logical_address)iPtr);
        int      bActive          = g_iface.is_active_source(g_iface.connection, (cec_logical_address)iPtr);
        cec_version iCecVersion   = g_iface.get_device_cec_version(g_iface.connection, (cec_logical_address)iPtr);
        cec_power_status power    = g_iface.get_device_power_status(g_iface.connection, (cec_logical_address)iPtr);

        g_iface.logical_address_to_string(iPtr, tmpbuf, sizeof(tmpbuf));
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "device #%X: %s\n", (int)iPtr, tmpbuf);
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "address:       %x.%x.%x.%x\n", (iPhysicalAddress >> 12) & 0xF, (iPhysicalAddress >> 8) & 0xF, (iPhysicalAddress >> 4) & 0xF, iPhysicalAddress & 0xF);
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "active source: %s\n", (bActive ? "yes" : "no"));
        g_iface.vendor_id_to_string(iVendorId, tmpbuf, sizeof(tmpbuf));
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "vendor:        %s\n", tmpbuf);
        g_iface.get_device_osd_name(g_iface.connection, (cec_logical_address)iPtr, osdName);
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "osd string:    %s\n", osdName);
        g_iface.cec_version_to_string(iCecVersion, tmpbuf, sizeof(tmpbuf));
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "CEC version:   %s\n", tmpbuf);
        g_iface.power_status_to_string(power, tmpbuf, sizeof(tmpbuf));
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "power status:  %s\n", tmpbuf);
        g_iface.get_device_menu_language(g_iface.connection, iPtr, lang);
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "language:      %s\n", lang);
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "\n\n");
      }
    }
Example #2
0
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "active source: %s\n", (bActive ? "yes" : "no"));
        g_iface.vendor_id_to_string(iVendorId, tmpbuf, sizeof(tmpbuf));
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "vendor:        %s\n", tmpbuf);
        g_iface.get_device_osd_name(g_iface.connection, (cec_logical_address)iPtr, osdName);
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "osd string:    %s\n", osdName);
        g_iface.cec_version_to_string(iCecVersion, tmpbuf, sizeof(tmpbuf));
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "CEC version:   %s\n", tmpbuf);
        g_iface.power_status_to_string(power, tmpbuf, sizeof(tmpbuf));
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "power status:  %s\n", tmpbuf);
        g_iface.get_device_menu_language(g_iface.connection, iPtr, lang);
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "language:      %s\n", lang);
        bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "\n\n");
      }
    }

    activeSource = g_iface.get_active_source(g_iface.connection);
    g_iface.logical_address_to_string(activeSource, tmpbuf, sizeof(tmpbuf));
    bufferpos += snprintf(buffer + bufferpos, sizeof(buffer) - bufferpos, "currently active source: %s (%d)", tmpbuf, (int)activeSource);

    printf("%s\n", buffer);
    return 1;
  }

  return 0;
}

static int cec_process_console_command(const char* buffer)
{
  size_t buflen;
  buflen = strlen(buffer);