<commit_before>#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <fstream>
#include <string>

#include "depthai/depthai.hpp"

int main(int argc, char** argv) {
    if(argc < 2) {
        std::cout << "Usage: " << argv[0] << " [GPIO_MODE/USB_RECOVERY/NORMAL/FAST] [params]" << std::endl;
        std::cout << "\tOptions:\n";
        std::cout << "\t\t" << argv[0] << " GPIO_MODE gpioModeNum" << std::endl;
        std::cout << "\t\t" << argv[0] << " USB_RECOVERY" << std::endl;
        std::cout << "\t\t" << argv[0] << " NORMAL [offset] [location] [dummyCycles] [frequency]" << std::endl;
        std::cout << "\t\t" << argv[0] << " FAST [offset] [location] [dummyCycles] [frequency]" << std::endl;
        return 0;
    }
    std::string mode{argv[1]};
    std::transform(mode.begin(), mode.end(), mode.begin(), ::tolower);
    std::function<std::tuple<bool, std::string>(dai::DeviceBootloader&)> flash = nullptr;

    if(mode == "gpio_mode") {
        // gpio mode header
        if(argc < 3) {
            std::cout << "Usage: " << argv[0] << " GPIO_MODE gpioModeNum" << std::endl;
            return 0;
        }
        int gpioMode = std::stoi(std::string(argv[2]));

        flash = [gpioMode](dai::DeviceBootloader& bl) { return bl.flashGpioModeBootHeader(dai::DeviceBootloader::Memory::FLASH, gpioMode); };
    } else if(mode == "usb_recovery") {
        // usb recovery header
        flash = [](dai::DeviceBootloader& bl) { return bl.flashUsbRecoveryBootHeader(dai::DeviceBootloader::Memory::FLASH); };
    } else if(mode == "normal" || mode == "fast") {
        if(argc != 2 && argc != 3 && argc <= 3) {
            std::cout << "Usage: " << argv[0] << " NORMAL/FAST [offset] [location] [dummyCycles] [frequency]" << std::endl;
            std::cout << "Usage: " << argv[0] << " NORMAL/FAST [frequency]" << std::endl;
            return 0;
        }
        int64_t offset = -1;
        int64_t location = -1;
        int32_t dummyCycles = -1;
        int32_t frequency = -1;
        if(argc > 3) {
            if(argc >= 3) {
                offset = std::stoi(std::string(argv[2]));
            }
            if(argc >= 4) {
                location = std::stoi(std::string(argv[3]));
            }
            if(argc >= 5) {
                dummyCycles = std::stoi(std::string(argv[4]));
            }
            if(argc >= 6) {
                frequency = std::stoi(std::string(argv[5]));
            }
        } else if(argc == 3) {
            frequency = std::stoi(std::string(argv[2]));
        }

        if(mode == "normal") {
            flash = [offset, location, dummyCycles, frequency](dai::DeviceBootloader& bl) {
                return bl.flashBootHeader(dai::DeviceBootloader::Memory::FLASH, offset, location, dummyCycles, frequency);
            };
        } else if(mode == "fast") {
            flash = [offset, location, dummyCycles, frequency](dai::DeviceBootloader& bl) {
                return bl.flashFastBootHeader(dai::DeviceBootloader::Memory::FLASH, offset, location, dummyCycles, frequency);
            };
        }
    }

    // Find device and flash specified boot header
    bool res = false;
    dai::DeviceInfo info;
    std::tie(res, info) = dai::DeviceBootloader::getFirstAvailableDevice();

    if(res) {
        std::cout << "Found device with name: " << info.name << std::endl;
        dai::DeviceBootloader bl(info);
        // Flash the specified boot header
        if(flash) {
            bool success;
            std::string errorMsg;
            std::tie(success, errorMsg) = flash(bl);<commit_msg>Updated flash_boot_header example<commit_after>#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <fstream>
#include <string>

#include "depthai/depthai.hpp"

int main(int argc, char** argv) {
    if(argc < 2) {
        std::cout << "Usage: " << argv[0] << " [GPIO_MODE/USB_RECOVERY/NORMAL/FAST] [params]" << std::endl;
        std::cout << "\tOptions:\n";
        std::cout << "\t\t" << argv[0] << " GPIO_MODE gpioModeNum" << std::endl;
        std::cout << "\t\t" << argv[0] << " USB_RECOVERY" << std::endl;
        std::cout << "\t\t" << argv[0] << " NORMAL [frequency] [location] [dummyCycles] [offset]" << std::endl;
        std::cout << "\t\t" << argv[0] << " FAST [frequency] [location] [dummyCycles] [offset]" << std::endl;
        return 0;
    }
    std::string mode{argv[1]};
    std::transform(mode.begin(), mode.end(), mode.begin(), ::tolower);
    std::function<std::tuple<bool, std::string>(dai::DeviceBootloader&)> flash = nullptr;

    if(mode == "gpio_mode") {
        // gpio mode header
        if(argc < 3) {
            std::cout << "Usage: " << argv[0] << " GPIO_MODE gpioModeNum" << std::endl;
            return 0;
        }
        int gpioMode = std::stoi(std::string(argv[2]));

        flash = [gpioMode](dai::DeviceBootloader& bl) { return bl.flashGpioModeBootHeader(dai::DeviceBootloader::Memory::FLASH, gpioMode); };
    } else if(mode == "usb_recovery") {
        // usb recovery header
        flash = [](dai::DeviceBootloader& bl) { return bl.flashUsbRecoveryBootHeader(dai::DeviceBootloader::Memory::FLASH); };
    } else if(mode == "normal" || mode == "fast") {
        if(argc != 2 && argc != 3 && argc <= 3) {
            std::cout << "Usage: " << argv[0] << " NORMAL/FAST [frequency] [location] [dummyCycles] [offset]" << std::endl;
            std::cout << "Usage: " << argv[0] << " NORMAL/FAST [frequency]" << std::endl;
            return 0;
        }
        int64_t offset = -1;
        int64_t location = -1;
        int32_t dummyCycles = -1;
        int32_t frequency = -1;
        if(argc > 3) {
            if(argc >= 3) {
                offset = std::stoi(std::string(argv[2]));
            }
            if(argc >= 4) {
                location = std::stoi(std::string(argv[3]));
            }
            if(argc >= 5) {
                dummyCycles = std::stoi(std::string(argv[4]));
            }
            if(argc >= 6) {
                frequency = std::stoi(std::string(argv[5]));
            }
        } else if(argc == 3) {
            frequency = std::stoi(std::string(argv[2]));
        }

        if(mode == "normal") {
            flash = [offset, location, dummyCycles, frequency](dai::DeviceBootloader& bl) {
                return bl.flashBootHeader(dai::DeviceBootloader::Memory::FLASH, frequency, location, dummyCycles, offset);
            };
        } else if(mode == "fast") {
            flash = [offset, location, dummyCycles, frequency](dai::DeviceBootloader& bl) {
                return bl.flashFastBootHeader(dai::DeviceBootloader::Memory::FLASH, frequency, location, dummyCycles, offset);
            };
        }
    }

    // Find device and flash specified boot header
    bool res = false;
    dai::DeviceInfo info;
    std::tie(res, info) = dai::DeviceBootloader::getFirstAvailableDevice();

    if(res) {
        std::cout << "Found device with name: " << info.name << std::endl;
        dai::DeviceBootloader bl(info);
        // Flash the specified boot header
        if(flash) {
            bool success;
            std::string errorMsg;
            std::tie(success, errorMsg) = flash(bl);
{'fraction_non_alphanumeric': 0.17786451073320322, 'fraction_numerical': 0.011430164482854754, 'mean_word_length': 2.4117926771279126, 'pattern_counts': {'":': 0, '<': 167, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1548000', 'n_tokens_mistral': 2331, 'n_tokens_neox': 2290, 'n_words': 467}