Skip to main content

Python API to find Free-WiLi devices

Project description

FreeWili Finder

A cross-platform C/C++ library for discovering and interfacing with FreeWili devices connected to a host system.

Overview

The FreeWili Finder library provides both modern C++ and C APIs to:

  • Discover all connected FreeWili devices automatically
  • Enumerate USB devices associated with each FreeWili
  • Identify device types (Serial ports, Mass storage, FTDI/FPGA, etc.)
  • Access device information (VID/PID, serial numbers, port paths)

Features

  • Dual API Support: Modern C++23 API with std::expected error handling, plus C API for maximum compatibility
  • Cross-Platform: Supports Windows, macOS, and Linux
  • Type Safety: Strongly-typed USB device classification system
  • Error Handling: Comprehensive error reporting and handling
  • Memory Safe: RAII in C++, explicit memory management in C API
  • Testing: Full test suite with GoogleTest integration

Quick Start

C++ API Example

#include <fwfinder.hpp>
#include <iostream>

int main() {
    if (auto devices = Fw::find_all(); devices.has_value()) {
        for (const auto& device : devices.value()) {
            std::cout << "Found: " << device.name
                     << " (Serial: " << device.serial << ")\n";

            // Get serial ports
            auto serials = device.getUSBDevices(Fw::USBDeviceType::Serial);
            for (const auto& serial : serials) {
                std::cout << "  Port: " << serial.port.value_or("Unknown") << "\n";
            }
        }
    } else {
        std::cerr << "Error: " << devices.error() << "\n";
    }
    return 0;
}

C API Example

#include <cfwfinder.h>
#include <stdio.h>

int main(void) {
    fw_freewili_device_t* devices[16];
    uint32_t device_count = 16;
    char error_msg[256];
    uint32_t error_size = sizeof(error_msg);

    if (fw_device_find_all(devices, &device_count, error_msg, &error_size) == fw_error_success) {
        printf("Found %u device(s)\n", device_count);

        for (uint32_t i = 0; i < device_count; ++i) {
            char name[64];
            fw_device_get_str(devices[i], fw_stringtype_name, name, sizeof(name));
            printf("Device: %s\n", name);
        }

        fw_device_free(devices, device_count);
    }
    return 0;
}

Building

Prerequisites

  • CMake 3.20 or later
  • C++23 compatible compiler (GCC 11+, Clang 14+, MSVC 2022+)
  • Platform dependencies:
    • Linux: libudev-dev
    • macOS: Xcode command line tools
    • Windows: Windows SDK (SetupAPI, Cfgmgr32)

Build Instructions

# Clone the repository
git clone https://github.com/your-org/freewili-finder.git
cd freewili-finder

# Create build directory
mkdir build && cd build

# Configure
cmake .. -DCMAKE_BUILD_TYPE=Release

# Build
cmake --build .

# Run tests
ctest --output-on-failure

CMake Options

  • FW_FINDER_BUILD_TESTS=ON/OFF - Build test suite (default: ON)
  • FW_BUILD_C_API=ON/OFF - Build C API library (default: ON)
  • FW_BUILD_STATIC=ON/OFF - Build static libraries (default: ON)
  • FW_BUILD_EXAMPLES=ON/OFF - Build example applications (default: ON)

API Reference

C++ API (fwfinder.hpp)

Core Functions

namespace Fw {
    // Find all connected FreeWili devices
    auto find_all() noexcept -> std::expected<FreeWiliDevices, std::string>;

    // USB device type detection
    auto getUSBDeviceTypeFrom(uint16_t vid, uint16_t pid) -> USBDeviceType;
    auto getUSBDeviceTypeName(USBDeviceType type) -> std::string;
}

Device Types

enum class USBDeviceType {
    Hub,              // USB Hub (parent device)
    Serial,           // Serial Port (general)
    SerialMain,       // MainCPU Serial Port
    SerialDisplay,    // DisplayCPU Serial Port
    MassStorage,      // Mass Storage Device
    ESP32,            // ESP32 USB (JTAG/RTT)
    FTDI,             // FTDI/FPGA Device
    Other             // Other USB device
};

C API (cfwfinder.h)

Core Functions

// Find all devices
fw_error_t fw_device_find_all(fw_freewili_device_t** devices, uint32_t* count,
                              char* error_msg, uint32_t* error_size);

// Device validation and info
bool fw_device_is_valid(fw_freewili_device_t* device);
fw_error_t fw_device_get_str(fw_freewili_device_t* device, fw_stringtype_t type,
                             char* buffer, uint32_t buffer_size);

// USB device enumeration
fw_error_t fw_usb_device_begin(fw_freewili_device_t* device);
fw_error_t fw_usb_device_count(fw_freewili_device_t* device, uint32_t* count);
fw_error_t fw_usb_device_next(fw_freewili_device_t* device);
fw_error_t fw_usb_device_get_str(fw_freewili_device_t* device, fw_stringtype_t type,
                                 char* buffer, uint32_t buffer_size);
fw_error_t fw_usb_device_get_int(fw_freewili_device_t* device, fw_inttype_t type,
                                 uint32_t* value);

// Memory management
fw_error_t fw_device_free(fw_freewili_device_t** devices, uint32_t count);

Examples

Complete example applications are provided in the examples/ directory:

  • basic_usage.cpp - Modern C++ API demonstration
  • c_api_basic_usage.cpp - C API demonstration (compiled as C++)
  • c_api_basic_usage_pure_c.c - Pure C implementation

Build and run examples:

cd build
make basic_usage_cpp basic_usage_c
./examples/basic_usage_cpp
./examples/basic_usage_c

Project Structure

freewili-finder/
├── include/
│   ├── fwfinder.hpp          # Main C++ API header
│   └── usbdef.hpp            # USB device definitions
├── src/
│   ├── fwfinder.cpp          # Core implementation
│   ├── fwfinder_linux.cpp    # Linux-specific code
│   ├── fwfinder_mac.cpp      # macOS-specific code
│   ├── fwfinder_windows.cpp  # Windows-specific code
│   └── usbdef.cpp            # USB device type mappings
├── c_api/
│   ├── include/cfwfinder.h   # C API header
│   ├── src/cfwfinder.cpp     # C API implementation
│   └── test/                 # C API tests
├── test/                     # C++ API tests
├── examples/                 # Example applications
└── bindings/                 # Language bindings (Python, etc.)

Testing

The library includes comprehensive tests using GoogleTest:

cd build
ctest --output-on-failure

Tests cover:

  • Device discovery functionality
  • USB device type detection
  • C API functionality
  • Cross-platform compatibility
  • Error handling scenarios

Platform Support

Platform Status Requirements
Linux ✅ Supported libudev
macOS ✅ Supported IOKit framework
Windows ✅ Supported Windows SDK (SetupAPI, Cfgmgr32)

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please ensure all tests pass and add tests for new functionality.

License

Copyright Free-Wili

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyfwfinder-0.4.0-cp312-abi3-win_amd64.whl (149.9 kB view details)

Uploaded CPython 3.12+Windows x86-64

pyfwfinder-0.4.0-cp312-abi3-manylinux_2_34_x86_64.whl (246.4 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.34+ x86-64

pyfwfinder-0.4.0-cp312-abi3-macosx_10_15_universal2.whl (180.3 kB view details)

Uploaded CPython 3.12+macOS 10.15+ universal2 (ARM64, x86-64)

pyfwfinder-0.4.0-cp311-cp311-win_amd64.whl (151.0 kB view details)

Uploaded CPython 3.11Windows x86-64

pyfwfinder-0.4.0-cp311-cp311-manylinux_2_34_x86_64.whl (250.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

pyfwfinder-0.4.0-cp311-cp311-macosx_10_15_universal2.whl (187.2 kB view details)

Uploaded CPython 3.11macOS 10.15+ universal2 (ARM64, x86-64)

pyfwfinder-0.4.0-cp310-cp310-win_amd64.whl (150.7 kB view details)

Uploaded CPython 3.10Windows x86-64

pyfwfinder-0.4.0-cp310-cp310-manylinux_2_34_x86_64.whl (250.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

pyfwfinder-0.4.0-cp310-cp310-macosx_10_15_universal2.whl (186.2 kB view details)

Uploaded CPython 3.10macOS 10.15+ universal2 (ARM64, x86-64)

pyfwfinder-0.4.0-cp39-cp39-win_amd64.whl (151.1 kB view details)

Uploaded CPython 3.9Windows x86-64

pyfwfinder-0.4.0-cp39-cp39-manylinux_2_34_x86_64.whl (250.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

pyfwfinder-0.4.0-cp39-cp39-macosx_10_15_universal2.whl (186.7 kB view details)

Uploaded CPython 3.9macOS 10.15+ universal2 (ARM64, x86-64)

pyfwfinder-0.4.0-cp38-cp38-win_amd64.whl (150.4 kB view details)

Uploaded CPython 3.8Windows x86-64

pyfwfinder-0.4.0-cp38-cp38-manylinux_2_34_x86_64.whl (249.5 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

pyfwfinder-0.4.0-cp38-cp38-macosx_10_15_universal2.whl (184.4 kB view details)

Uploaded CPython 3.8macOS 10.15+ universal2 (ARM64, x86-64)

File details

Details for the file pyfwfinder-0.4.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.4.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 149.9 kB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyfwfinder-0.4.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 660de01e07f16ce6b2a22d06bf2138040bb40c382d927055aa7e2165becb7c91
MD5 dd1bee21f0be5db94350320e8c4950a8
BLAKE2b-256 8c6dde1e09aa9637b63123c18b33e3d0a2aef03951d8c1486c307d3afc928aba

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp312-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.4.0-cp312-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 71fc98d1d88c14dd679367ef04c243ebffabf2f27837ecf4259d091dbcc93664
MD5 cca55871ae4296a27b7f10ecd448fdeb
BLAKE2b-256 832a42d2cca6c8451eee50092f6046dfe2dcf18d6b33b727ddd00ce8559bbccc

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp312-abi3-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.4.0-cp312-abi3-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 388b3b9356150677590ebdac000e04caae3ebb06fe475b85380433dd6d78d0d9
MD5 028d2413fe97ce8396b34bcc0af4354a
BLAKE2b-256 e4be60adce9f48d8a4b94a91d5730c18b2c93b24bb4d8250e506e4ab4d1396a6

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.4.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 151.0 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyfwfinder-0.4.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cb5c3cc6511cc465253947ad483ddc7ce4bf90eaeda2f98a840251b3cac7a90b
MD5 45de2396cd2ee672b43f0d3ca395ffc2
BLAKE2b-256 95c69e713eff155b450d292aa3aa0c29684a4e6ea5195d0f6b6d2b972b16db04

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.4.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6f146eb542aab6933dd366ec920a5990c04d236d7c7f0475dea41b26aaea2b50
MD5 9a46713d78e1ca47baaa08b5d04a9017
BLAKE2b-256 fcac63884af6b31b040e43eb33e36879b1815f78b2fca0cd38cab90693daa2eb

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp311-cp311-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.4.0-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 3e4593113a65c13a008f8bcfc925315678584098f561fab427d4422e069d890e
MD5 aae52ed4f390480fc0dbe34f6373e932
BLAKE2b-256 aa96306a9eee9a6461deda3a823039861e8c4a3d5e7b0bdf4bb1ca36682bc8b0

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.4.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 150.7 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyfwfinder-0.4.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d89399b8f63cc5ef64b652e9c09e5856158f1a4fb9ff39034b8bad18c5248d46
MD5 3e42886222d95da5c86e48701c771d2d
BLAKE2b-256 a7288a8666b9f954a74c48f485ffb0c0091906ef66ba4f096eeb47e0ff8a68c6

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.4.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f88eb7e6fce798d111dca11eb9a1495cceaebd2f022806f5feb2f9ee8ef947e8
MD5 1539d048d6b7ff8d06fa8dad99ed63c9
BLAKE2b-256 08b72d9ee58d63fd4f1a4ef093067d5cf132961c3f2379f8d44ce54561881193

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp310-cp310-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.4.0-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 74f332338c711929a8d57c34b3f1df9614ca189494fe47b598b38cdec743da12
MD5 817d29e32e60fabb76c1789e7bbeb749
BLAKE2b-256 2b79f1367daf8cabe7e59093edac366bcad5c9cc33afa6aa6121f2953a089cbf

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.4.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 151.1 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyfwfinder-0.4.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b03fae52f0f135ec6caae0cf00f354bb3a4b8f8161d2668c1faced8921c1c2b3
MD5 e5d968efb26b8476d8a5e2770b33fdc5
BLAKE2b-256 7ffc90c1030710521c33983904a81ecfc3503cd46a9bef488000fd0623837c98

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.4.0-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 15c4ea86c694479170ab1042a2a62353045cc6a87adc2d49c3efcb45537a0014
MD5 b3cc59c20206e345af6aa305f68c0734
BLAKE2b-256 d869c81603a8b4868cf104ad469b245d4a8b2de7a02b1d76ecc5514dd6e61c20

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp39-cp39-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.4.0-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 dfaf4afff7a3e9562910951f4163b8e61aeb36f320f20b5d339ff44624033950
MD5 469d26c42325161dabe9fa1b9d403190
BLAKE2b-256 f58c63a5066ba278e1461b5bdec5ae2faa6312fd2f6805314f3a8ef47381afea

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.4.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 150.4 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyfwfinder-0.4.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 090a09af74a3bef0f1e92646696e595a6dc8f16fd4e69516159b18e2c844888a
MD5 a101c1b7c3bcbbfd250f06fb32ef15f0
BLAKE2b-256 d040c6f796d00afafa837d8f2c1aff280370d5e271925188438232ea14ce4fd9

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.4.0-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e07e4ad883cace68ec4ef29b3ea0bfa8c4f515170d4f8d40cfd97aceeed47a55
MD5 887725023c8b47d3d8f8143dcaec6137
BLAKE2b-256 a8cc64fdeea02af4c32910c3b951cc5b1955e6d5c0cc03d0012f42a8d78b86cb

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.4.0-cp38-cp38-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.4.0-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 db2730a34f59c08ac93c22e56a417372ca14beb7ef914b1217d72afbc3ad2f42
MD5 ffc980b3b6ead38b1ddd4c957e455878
BLAKE2b-256 d9402932f17801dd51072b2d467329d0383081597d1c93480792e59399c22e8d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page