static int discover_print(char *target_ip_str) { uint32_t target_ip = 0; if (target_ip_str) { target_ip = parse_ip_addr(target_ip_str); if (target_ip == 0) { fprintf(stderr, "invalid ip address: %s\n", target_ip_str); return -1; } } struct hdhomerun_discover_device_t result_list[64]; int count = hdhomerun_discover_find_devices_custom_v2(target_ip, HDHOMERUN_DEVICE_TYPE_TUNER, HDHOMERUN_DEVICE_ID_WILDCARD, result_list, 64); if (count < 0) { fprintf(stderr, "error sending discover request\n"); return -1; } if (count == 0) { printf("no devices found\n"); return 0; } int index; for (index = 0; index < count; index++) { struct hdhomerun_discover_device_t *result = &result_list[index]; printf("hdhomerun device %08X found at %u.%u.%u.%u\n", (unsigned int)result->device_id, (unsigned int)(result->ip_addr >> 24) & 0x0FF, (unsigned int)(result->ip_addr >> 16) & 0x0FF, (unsigned int)(result->ip_addr >> 8) & 0x0FF, (unsigned int)(result->ip_addr >> 0) & 0x0FF ); } return count; }
bool HDHRDevice::validate() { if(mDeviceInfo.device_id != 0) { struct hdhomerun_discover_device_t deviceInfo; bool valid = hdhomerun_discover_validate_device_id(mDeviceInfo.device_id); bool done = false; // if validation fails, give it a few seconds to come back // putting the system to sleep on Mac OS X seems to cause a problem if(valid) { int result, iter = 5; do { // -1 = error, 0 = none found, else number of devices found (max 1 here) result = hdhomerun_discover_find_devices_custom_v2(0, HDHOMERUN_DEVICE_TYPE_TUNER, mDeviceInfo.device_id, &deviceInfo, 1); // flog( "Native.log", "hdhomerun_discover_find_device(%08lx) returned %d\r\n", mDeviceInfo.device_id, result); if(result == -1) return false; if(result != 1) { if(--iter == 0) { done = true; } else { sleep(1); } } else done = true; } while(!done); if(result == 1) { // update cached info if we didn't get an error if((deviceInfo.device_type != mDeviceInfo.device_type) || (deviceInfo.ip_addr != mDeviceInfo.ip_addr)) { memcpy(&mDeviceInfo, &deviceInfo, sizeof(struct hdhomerun_discover_device_t)); } return true; } } else { // clear an invalid entry (id is invalid) // FIXME: threading issues? mDeviceInfo.ip_addr = 0; mDeviceInfo.device_type = 0; // mDeviceInfo.device_id = 0; flog( "Native.log", "I have an invalid device ID!!! (%08lx)\r\n", (unsigned long)mDeviceInfo.device_id); } } return false; }
static int hdhomerun_device_selector_load_from_str_discover(struct hdhomerun_device_selector_t *hds, uint32_t target_ip, uint32_t device_id) { struct hdhomerun_discover_device_t result; int discover_count = hdhomerun_discover_find_devices_custom_v2(target_ip, HDHOMERUN_DEVICE_TYPE_TUNER, device_id, &result, 1); if (discover_count != 1) { return 0; } int count = 0; unsigned int tuner_index; for (tuner_index = 0; tuner_index < result.tuner_count; tuner_index++) { struct hdhomerun_device_t *hd = hdhomerun_device_create(result.device_id, result.ip_addr, tuner_index, hds->dbg); if (!hd) { continue; } hdhomerun_device_selector_add_device(hds, hd); count++; } return count; }