Example #1
0
int main (int argc, char *argv[])
{
	static const char *args = "/dev/hidrawX page";
	auto mem_type = HIDPP20::IOnboardProfiles::MemoryType::Writeable;
	HIDPP::DeviceIndex device_index = HIDPP::DefaultDevice;

	std::vector<Option> options = {
		DeviceIndexOption (device_index),
		VerboseOption (),
		Option ('r', "rom",
			Option::NoArgument, "",
			"Read data from ROM",
			[&mem_type] (const char *) -> bool {
				mem_type = HIDPP20::IOnboardProfiles::MemoryType::ROM;
				return true;
			}),
	};
	Option help = HelpOption (argv[0], args, &options);
	options.push_back (help);

	int first_arg;
	if (!Option::processOptions (argc, argv, options, first_arg))
		return EXIT_FAILURE;

	if (argc-first_arg != 2) {
		fprintf (stderr, "%s", getUsage (argv[0], args, &options).c_str ());
		return EXIT_FAILURE;
	}

	const char *path = argv[first_arg];
	char *endptr;
	unsigned int page = strtol (argv[first_arg+1], &endptr, 0);
	if (*endptr != '\0') {
		fprintf (stderr, "Invalid page number.\n");
		return EXIT_FAILURE;
	}

	try {
		HIDPP20::Device dev (path, device_index);
		HIDPP20::IOnboardProfiles iop (&dev);
		auto desc = iop.getDescription ();
		unsigned int i = 0;
		while (i < desc.sector_size) {
			auto data = iop.memoryRead (mem_type, page, i);
			write (1, data.data (), data.size ());
			i += data.size ();
		}
	}
	catch (HIDPP20::Error e) {
		fprintf (stderr, "HID++2 error %d: %s\n", e.errorCode (), e.what ());
		return e.errorCode ();
	}

	return EXIT_SUCCESS;
}
Example #2
0
int main (int argc, char *argv[])
{
	static const char *args = "/dev/hidrawX";
	HIDPP::DeviceIndex device_index = HIDPP::DefaultDevice;

	std::vector<Option> options = {
		DeviceIndexOption (device_index),
		VerboseOption (),
	};
	Option help = HelpOption (argv[0], args, &options);
	options.push_back (help);

	int first_arg;
	if (!Option::processOptions (argc, argv, options, first_arg))
		return EXIT_FAILURE;

	if (argc-first_arg != 1) {
		fprintf (stderr, "%s", getUsage (argv[0], args, &options).c_str ());
		return EXIT_FAILURE;
	}

	const char *path = argv[first_arg];

	try {
		unsigned int major, minor;
		HIDPP::Device dev (path, device_index);
		dev.getProtocolVersion (major, minor);
		printf ("%d.%d\n", major, minor);
		Log::printf (Log::Info, "Device is %s (%04hx:%04hx)\n",
			     dev.name ().c_str (),
			     dev.vendorID (), dev.productID ());
	}
	catch (HIDPP::Device::NoHIDPPReportException e) {
		Log::info () << "Device is not a HID++ device" << std::endl;
		return EXIT_FAILURE;
	}
	catch (std::system_error e) {
		fprintf (stderr, "Failed to open %s: %s\n", path, e.what ());
		return EXIT_FAILURE;
	}
	return EXIT_SUCCESS;
}
Example #3
0
int main (int argc, char *argv[])
{
	std::vector<Option> options = {
		VerboseOption (),
	};
	Option help = HelpOption (argv[0], "", &options);
	options.push_back (help);

	int first_arg;
	if (!Option::processOptions (argc, argv, options, first_arg))
		return EXIT_FAILURE;

	if (argc-first_arg != 0) {
		fprintf (stderr, "%s", getUsage (argv[0], "", &options).c_str ());
		return EXIT_FAILURE;
	}

	int ret;

	struct udev *ctx = udev_new ();
	if (!ctx) {
		fprintf (stderr, "Failed to create udev context\n");
		return EXIT_FAILURE;
	}

	struct udev_enumerate *enumerator = udev_enumerate_new (ctx);
	if (!enumerator) {
		fprintf (stderr, "Failed to create udev enumerator\n");
		return EXIT_FAILURE;
	}
	if (0 != (ret = udev_enumerate_add_match_subsystem (enumerator, "hidraw"))) {
		fprintf (stderr, "Failed to add match: %s\n", strerror (ret));
		return EXIT_FAILURE;
	}
	if (0 != (ret = udev_enumerate_scan_devices (enumerator))) {
		fprintf (stderr, "Failed to scan devices: %s\n", strerror (ret));
		return EXIT_FAILURE;
	}

	struct udev_list_entry *current;
	udev_list_entry_foreach (current, udev_enumerate_get_list_entry (enumerator)) {
		struct udev_device *device = udev_device_new_from_syspath (ctx, udev_list_entry_get_name (current));
		const char *hidraw_node = udev_device_get_devnode (device);
		try {
			for (HIDPP::DeviceIndex index: {
					HIDPP::DefaultDevice,
					HIDPP::CordedDevice,
					HIDPP::WirelessDevice1,
					HIDPP::WirelessDevice2,
					HIDPP::WirelessDevice3,
					HIDPP::WirelessDevice4,
					HIDPP::WirelessDevice5,
					HIDPP::WirelessDevice6 }) {
				try {
					HIDPP::Device dev (hidraw_node, index);
					unsigned int major, minor;
					dev.getProtocolVersion (major, minor);
					printf ("%s", hidraw_node);
					if (index != HIDPP::DefaultDevice)
						printf (" (device %d)", index);
					printf (": %s (%04hx:%04hx) HID++ %d.%d\n",
							dev.name ().c_str (),
							dev.vendorID (), dev.productID (),
							major, minor);
				}
				catch (HIDPP10::Error e) {
					if (e.errorCode () != HIDPP10::Error::UnknownDevice && e.errorCode () != HIDPP10::Error::InvalidSubID) {
						Log::printf (Log::Error,
							     "Error while querying %s wireless device %d: %s\n",
							     hidraw_node, index, e.what ());
					}
				}
				catch (HIDPP20::Error e) {
					Log::printf (Log::Error, "Error while querying %s device %d: %s\n",
						     hidraw_node, index, e.what ());
				}
				catch (HIDRaw::TimeoutError e) {
					Log::printf (Log::Warning, "Device %s (index %d) timed out\n",
						     hidraw_node, index);
				}
			}

		}
		catch (HIDPP::Device::NoHIDPPReportException e) {
		}
		catch (std::system_error e) {
			Log::printf (Log::Warning, "Failed to open %s: %s\n", hidraw_node, e.what ());
		}
		udev_device_unref (device);
	}

	udev_enumerate_unref (enumerator);
	udev_unref (ctx);

	return 0;
}
int main (int argc, char *argv[])
{
	static const char *args = "/dev/hidrawX feature_index function [parameters...]";
	HIDPP::DeviceIndex device_index = HIDPP::DefaultDevice;

	std::vector<Option> options = {
		DeviceIndexOption (device_index),
		VerboseOption (),
	};
	Option help = HelpOption (argv[0], args, &options);
	options.push_back (help);

	int first_arg;
	if (!Option::processOptions (argc, argv, options, first_arg))
		return EXIT_FAILURE;

	if (argc-first_arg < 3) {
		fprintf (stderr, "Too few arguments.\n");
		fprintf (stderr, "%s", getUsage (argv[0], args, &options).c_str ());
		return EXIT_FAILURE;
	}

	char *endptr;

	const char *path = argv[first_arg];
	int feature_index = strtol (argv[first_arg+1], &endptr, 0);
	if (*endptr != '\0' || feature_index < 0 || feature_index > 255) {
		fprintf (stderr, "Invalid feature index.\n");
		return EXIT_FAILURE;
	}
	int function = strtol (argv[first_arg+2], &endptr, 0);
	if (*endptr != '\0' || function < 0 || function > 15) {
		fprintf (stderr, "Invalid function.\n");
		return EXIT_FAILURE;
	}

	std::vector<uint8_t> params, results;
	for (int i = 0; first_arg+3+i < argc; ++i) {
		int value = strtol (argv[first_arg+3+i], &endptr, 16);
		if (*endptr != '\0' || value < 0 || value > 255) {
			fprintf (stderr, "Invalid parameter %d value.\n", i);
			return EXIT_FAILURE;
		}
		params.push_back (static_cast<uint8_t> (value));
	}

	try {
		HIDPP20::Device dev (path, device_index);
		results = dev.callFunction (static_cast<uint8_t> (feature_index),
					    static_cast<unsigned int> (function),
					    params);
	}
	catch (HIDPP20::Error e) {
		fprintf (stderr, "Error code %d: %s\n", e.errorCode (), e.what ());
		return e.errorCode ();
	}

	bool first = true;
	for (uint8_t value: results) {
		if (first)
			first = false;
		else
			printf (" ");
		printf ("%02hhx", value);
	}
	printf ("\n");

	return EXIT_SUCCESS;
}
Example #5
0
void Help(const char *name)
{
	std::cerr << "\n" << name << " Version ";
	std::cerr << ssfit_VERSION_MAJOR << ".";
	std::cerr << ssfit_VERSION_MINOR;
	std::cerr << "\n";
	std::cerr << "\n";

	std::cerr << "USAGE: " << "\n";
	const char *usage = "-i <input filename> -p <number> -v <number> -t <number> [-r <ranges filename>] [-R <pressure ranges filename>] [-s <save filename prefix>] [-n <number>] [--kelvin] [--curves] [--scan] [--data] [--approximate] [--fixp] [--fixv] [--fixt] [--blockdata]";
	std::string USAGE = name;
	USAGE += " ";
	USAGE += usage;
	HelpOption(USAGE.c_str(),
	           NULL,
	           NULL);
	std::cerr << "OPTIONS:" << "\n";
	HelpOption("--blockdata",
	           "-b",
	           "The data file is in block format.");
	HelpOption("--fixp",
	           NULL,
	           "Fix Pstar to the value specified on the command line.");
	HelpOption("--fixv",
	           NULL,
	           "Fix Vstar to the value specified on the command line.");
	HelpOption("--fixt",
	           NULL,
	           "Fix Tstar to the value specified on the command line.");
	HelpOption("--dataonly",
	           "--data, -d",
	           "Save the data in easy to plot files. This will not do any fitting.");
	HelpOption("--scan",
	           NULL,
	           "Scan the fitting parameters around the minimum after and initial fitting, following by a second round of fitting.");
	HelpOption("--curves",
	           NULL,
	           "Generate curves for nice plotting (see -n option).");
	HelpOption("--approximate",
	           "--approx",
	           "Use an approximate equation for fitting (See documentation for more details).");
	HelpOption("--kelvin",
	           NULL,
	           "The input temperatures are in Kelvin. The default is Celsius. All output temperatures are, however, in Kelvin.");
	HelpOption("--input <filename>",
	           "-i <filename>",
	           "Input file containing PVT data.");
	HelpOption("--ranges <filename>",
	           "-r <filename>",
	           "File specifying the temperature ranges, for each pressure, to use for fitting and curve generating.");
	HelpOption("--pranges <filename>",
	           "-R <filename>",
	           "File specifying the pressure ranges, for each temperature, to use for  curve generating.");
	HelpOption("--pstar <number>",
	           "-p <number>",
	           "Initial Pstar value to use for fitting.");
	HelpOption("--vstar <number>",
	           "-v <number>",
	           "Initial Vstar value to use for fitting.");
	HelpOption("--tstar <number>",
	           "-t <number>",
	           "Initial Tstar value to use for fitting.");
	HelpOption("--numpoints <number>",
	           "-n <number>",
	           "Number of points to use for curve generation.");
	HelpOption("--yonly",
	           "-y",
	           "Only calculate y. Used to T < Tg. pstar, vstar, and tstar are fixed.");
	HelpOption("--save <filename>",
	           "-s <filename>",
	           "Name use as prefix for saving data. If not specified then 'default' will be used. The type of data will be appended to this, for example: using '--save Polystyrene' will save data as 'Polystyrene-PVTVy.dat'.");
	HelpOption("--help",
	           "-h",
	           "Show this help.");

	std::cerr << "\n";
	std::cerr << "Compiled on " << __DATE__;
	std::cerr << " at " << __TIME__ << ".\n";
	std::cerr << "Author: Brian G. Olson ([email protected])\n";
	std::cerr << "https://github.com/olsonbg/ssfit\n";
}
Example #6
0
int main (int argc, char *argv[])
{
    static const char *args = "/dev/hidrawX";
    HIDPP::DeviceIndex device_index = HIDPP::DefaultDevice;
    bool do_write_tests = false;

    std::vector<Option> options = {
        DeviceIndexOption (device_index),
        VerboseOption (),
        Option ('w', "write",
        Option::NoArgument, "",
        "Also do write tests with HID++ 1.0 devices.",
        [&do_write_tests] (const char *optarg) -> bool {
            do_write_tests = true;
            return true;
        })
    };
    Option help = HelpOption (argv[0], args, &options);
    options.push_back (help);

    int first_arg;
    if (!Option::processOptions (argc, argv, options, first_arg))
        return EXIT_FAILURE;

    if (argc-first_arg != 1) {
        fprintf (stderr, "%s", getUsage (argv[0], args, &options).c_str ());
        return EXIT_FAILURE;
    }

    const char *path = argv[first_arg];

    /*
     * Check protocol version
     */
    unsigned int major, minor;
    try {
        HIDPP::Device dev (path, device_index);
        dev.getProtocolVersion (major, minor);
        printf ("%s (%04hx:%04hx) is a HID++ %d.%d device\n",
                dev.name ().c_str (),
                dev.vendorID (), dev.productID (),
                major, minor);

    }
    catch (HIDPP::Device::NoHIDPPReportException e) {
        printf ("%s is not a HID++ device\n", path);
        return EXIT_FAILURE;
    }
    catch (std::system_error e) {
        fprintf (stderr, "Failed to open %s: %s\n", path, e.what ());
        return EXIT_FAILURE;
    }
    /*
     * HID++ 1.0
     */
    if (major == 1 && minor == 0) {
        HIDPP10::Device dev (path, device_index);

        for (unsigned int address = 0; address < 256; ++address) {
            testRegister (&dev, HIDPP::ShortParamLength, static_cast<uint8_t> (address), do_write_tests);
            testRegister (&dev, HIDPP::LongParamLength, static_cast<uint8_t> (address), do_write_tests);
        }
        if (do_write_tests) {
            try {
                HIDPP10::IIndividualFeatures iif (&dev);
                unsigned int old_flags = iif.flags ();
                iif.setFlags (0x00FFFFFF);
                unsigned int flags = iif.flags ();
                iif.setFlags (old_flags);
                printf ("Individual features: %06x\n", flags);
                if (flags & HIDPP10::IIndividualFeatures::SpecialButtonFunction) {
                    printf (" - Special Button Function\n");
                }
                if (flags & HIDPP10::IIndividualFeatures::EnhancedKeyUsage) {
                    printf (" - Enhanced Key Usage\n");
                }
                if (flags & HIDPP10::IIndividualFeatures::FastForwardRewind) {
                    printf (" - Fast Forward/Rewind\n");
                }
                if (flags & HIDPP10::IIndividualFeatures::ScrollingAcceleration) {
                    printf (" - Scrolling Acceleration\n");
                }
                if (flags & HIDPP10::IIndividualFeatures::ButtonsControlResolution) {
                    printf (" - Buttons Control Resolution\n");
                }
                if (flags & HIDPP10::IIndividualFeatures::InhibitLockKeySound) {
                    printf (" - Inhibit Lock KeyS ound\n");
                }
                if (flags & HIDPP10::IIndividualFeatures::MXAir3DEngine) {
                    printf (" - 3D Engine\n");
                }
                if (flags & HIDPP10::IIndividualFeatures::LEDControl) {
                    printf (" - LED Control\n");
                }
            }
            catch (HIDPP10::Error e) {
                printf ("Individual features: %s\n", e.what ());
            }
        }
    }
    /*
     * HID++ 2.0 and later
     */
    else if (major >= 2) {
        HIDPP20::Device dev (path, device_index);
        HIDPP20::IFeatureSet ifeatureset (&dev);

        unsigned int feature_count = ifeatureset.getCount ();
        for (unsigned int i = 1; i <= feature_count; ++i) {
            uint8_t feature_index = i;
            uint16_t feature_id;
            bool obsolete, hidden;

            feature_id = ifeatureset.getFeatureID (feature_index, &obsolete, &hidden);
            printf ("Feature 0x%02hhx: [0x%04hx]", feature_index, feature_id);
            if (obsolete)
                printf (" obsolete");
            if (hidden)
                printf (" hidden");
            printf ("\n");
        }
    }
    else {
        fprintf (stderr, "Unsupported HID++ protocol version.\n");
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}