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.1-cp312-abi3-win_amd64.whl (149.9 kB view details)

Uploaded CPython 3.12+Windows x86-64

pyfwfinder-0.4.1-cp312-abi3-manylinux_2_34_x86_64.whl (246.5 kB view details)

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

pyfwfinder-0.4.1-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.1-cp311-cp311-win_amd64.whl (151.1 kB view details)

Uploaded CPython 3.11Windows x86-64

pyfwfinder-0.4.1-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.1-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.1-cp310-cp310-win_amd64.whl (150.8 kB view details)

Uploaded CPython 3.10Windows x86-64

pyfwfinder-0.4.1-cp310-cp310-manylinux_2_34_x86_64.whl (250.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

pyfwfinder-0.4.1-cp310-cp310-macosx_10_15_universal2.whl (186.3 kB view details)

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

pyfwfinder-0.4.1-cp39-cp39-win_amd64.whl (151.2 kB view details)

Uploaded CPython 3.9Windows x86-64

pyfwfinder-0.4.1-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.1-cp39-cp39-macosx_10_15_universal2.whl (186.8 kB view details)

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

pyfwfinder-0.4.1-cp38-cp38-win_amd64.whl (150.5 kB view details)

Uploaded CPython 3.8Windows x86-64

pyfwfinder-0.4.1-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.1-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.1-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.4.1-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.1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 37a8f0a5b7df88e05d3e168f3289e1f1c926c03b17b92a4b9e5f627fa6c14f66
MD5 e828d737d09924880f3026d7f5472d21
BLAKE2b-256 8a6896acda4b7af4d1be7240aec5b64a1d54bfdac9102f49c6420e2592764a6a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.4.1-cp312-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f261c85795f63fc3dc29ffd7d284fe7bcc59a8661b213721f55cfa1e535ae882
MD5 a05814c96ec1e2e44b9fb395e19c96cc
BLAKE2b-256 addb0a8b9ce0c68bcc0a791be556feb3d54ce9d79f458318cc405e9730853fbc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.4.1-cp312-abi3-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 f7374c93cfd2ac868b39ab4c8e0c6e566bfc32401c8a19ad197d04de818b615d
MD5 612e92fa485cbb97ffd915bc5dc19e3c
BLAKE2b-256 e6886826737a1d08d4d8fdba804daa74d90ab03f80173bd8ad09fd1d7c093b05

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfwfinder-0.4.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 151.1 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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 736b11898c77c114ba689243437e6e6e3ed7ea527574ed61d2fbdda7fab64cf5
MD5 de5b8fa2fded671d35063367546e5695
BLAKE2b-256 f1fd2cbf6f68c3ed7140fcc266dfd394029f0b48f8ed015362653ab91fbfba6c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.4.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e9b28bde51f8321792aea5b3f84eaf77fc7670de1a1dff80631f25f6d051e358
MD5 2eecc05fac742f23f63cc553a0a6bf85
BLAKE2b-256 35dacd487499923b6e4a2e2b953e677f14c99f804d7880138461a5e4b4269729

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.4.1-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 17985971376f5a58d2f2dcf90d0b51f5c01a82488af1b7ee27d03296b081b24a
MD5 1a964b5bb6b741b5f8c07c4a25f2693d
BLAKE2b-256 34f7921b663976d0cd2cc5d1d6cfb9555c4ac72d9836eeb543e1dd352d075f86

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfwfinder-0.4.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 150.8 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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 fa2c89f0967905e32e36ca3f8d126447d85bf5635d77f6e561ae05d4c3487130
MD5 fe621b21094ad2760ed0934153607331
BLAKE2b-256 195e35b3f9541b283f6da44de092c7589e0c5132e5993d403b761e545662125d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.4.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b6d272afdb3edd11edf0654d95f4053f5b3fdfdb619acdc4baac9b1336918fde
MD5 f1440f4cc7248d6b3dff34cbd0e34954
BLAKE2b-256 41f097ff32d46a3b279ca8f7943ce53b5580bca7bd3eeb1f6be451a24285c48c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.4.1-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 514a036971cd0ea69949a9ffa2c9fc11815c99d14db9ebba6f05420490793615
MD5 97ae54c584001092599d7135f915d8ee
BLAKE2b-256 174ec511d0cfd0836b63d71019cf8b03a4e6244fa65dba2b12683d3c90b87991

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfwfinder-0.4.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 151.2 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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 487bf7dff89c7b7f3d951769109e2009cf6ea5cb9e7e3d0f00404db5a25c5bc8
MD5 d87b611c1d7286cf8b03ea3901e51af2
BLAKE2b-256 704b4fa346afd05ef2a2bec96195361850cccce7f7b0272b6dea763f22be93dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.4.1-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6486c73b92fe047034e081ffdb553a5137cdf15c959a94166496c58987434025
MD5 21d086d044cce2ef47b0776ef0819df8
BLAKE2b-256 28724022cfbe46d26e8703a1f8eaec58abe04e5741109a65f7062f7e091dbd05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.4.1-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 55c1949b5722763a66cf3a94d6916ce2c5d7ac169d1f83a0823589204f56c88f
MD5 f4053b0368ce4ef5097ad131fd19b2ec
BLAKE2b-256 855982ceca965adddbedeba367d6ad753e5fe3a95e25b63f45a37acdba8b125b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyfwfinder-0.4.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 150.5 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.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 6244d8dfb31c88c9d4a10c578199f568922fd0265822a9f36fc6297467cc218a
MD5 c929e555539b5be7ab1787f99f0a0c77
BLAKE2b-256 ec16d1a8667ff443902005d105a679e73d7c30f7a216eed3e141f9b167908c43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.4.1-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c75ddb087c88e180ef2ba40b059f943472c302516eb9c84d5ca9aba49a808908
MD5 ed37f7fcc14596f9cc0f1f9192948c44
BLAKE2b-256 527c2a42874c8e76c404f9615578e4fd610c44d5942589232f4190111efde968

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfwfinder-0.4.1-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 1493cc8fa86545595937845d0332ab0c9cdd9a1d1c126f2615291b3f7e11867f
MD5 84d1f1d1e8913ecd5386de5efa65a335
BLAKE2b-256 ee4c51fdb7398f4a39807a888e8f4367fe784af0f64eb00d716504b84173db74

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