<commit_before>#include "Global.h"

#include <vector>
#include <iostream>
#include <thread>
#include <unordered_map>
#include <cmath>
#include <chrono>

#ifdef _WIN32
#ifndef _CRT_SECURE_NO_WARNINGS
#	define _CRT_SECURE_NO_WARNINGS
#endif
#ifndef _SCL_SECURE_NO_WARNINGS
#	define _SCL_SECURE_NO_WARNINGS
#endif
#	define _WINSOCK_DEPRECATED_NO_WARNINGS
#	include <WinSock2.h>
#	include <Windows.h>
void initializeWSA() {
	WSADATA data;
	WSAStartup(MAKEWORD(2, 2), &data);
}
#endif

#include "Controller.h"
#include "Job.h"
#include "JobHandler.h"
#include "Sensor.h"

#include "Controller/UDPClientController.h"
#include "Controller/MotorController.h"
#include "Controller/HeadFlapController.h"
#include "JobHandler/ForwardHandler.h"
#include "JobHandler/R2Server.h"
#include "Sensor/UDPServerSensor.h"
#include "Sensor/UltrasoundSensor.h"
#include "Sensor/DrawerSensor.h"
#include "Sensor/HeadSensor.h"
#include "Sensor/RFIDSensor.h"
#include "Sensor/LidarSensor.h"
#include "Sensor/IMUSensor.h"
#include "Sensor/PowerHandler.h"

/** Initializes sensors */
smap<ptr<Sensor>> initializeSensors(smap<string>& args) {
	smap<ptr<Sensor>> sensors;
	if (args.find("udp-server-ip") != args.end() && args.find("udp-server-port") != args.end()) {
		sensors["UDP SERVER"] = std::make_shared<UDPServerSensor>(args["udp-server-ip"], atoi(args["udp-server-port"].c_str()));
	}
	else {
		sensors["UDP SERVER"] = std::make_shared<UDPServerSensor>("0.0.0.0", 9000);
	}

	if (!(args["ultrasound-serial-port"].empty() && args["ultrasound-serial-port2"].empty())) {
		sensors["R2 ULTRASOUND"] = std::make_shared<UltrasoundSensor>(args["ultrasound-serial-port"].c_str(), 9600, args["ultrasound-serial-port2"].c_str(), 9600);
	}
	else {
		//sensors["R2 ULTRASOUND"] = std::make_shared<UltrasoundSensor>("COM7", 9600, "COM8", 9600);
		std::cout << "No ultrasound serial port(s) specified." << std::endl;
	}

	if (!(args["drawer-serial-port"].empty())) {
		sensors["R2 DRAWER"] = std::make_shared<DrawerSensor>(args["drawer-serial-port"].c_str(), 9600);
	}
	else {
		std::cout << "No drawer serial port specified." << std::endl;
	}

	if (!(args["head-serial-port"].empty())) {
		sensors["R2 HEAD"] = std::make_shared<HeadSensor>(args["head-serial-port"].c_str(), 9600);
	}
	else {
		std::cout << "No head serial port specified." << std::endl;
	}

	if (!(args["rfid-serial-port"].empty())) {
		sensors["R2 RFID"] = std::make_shared<RFIDSensor>(args["rfid-serial-port"].c_str(), 9600);
	}
	else {
		//sensors["R2 RFID"] = std::make_shared<RFIDSensor>("COM4", 9600);
		std::cout << "No RFID serial port specified." << std::endl;
	}
	if (!(args["lidar-serial-port"].empty())) {
		sensors["R2 LIDAR"] = std::make_shared<LidarSensor>(args["lidar-serial-port"].c_str(), 9600);
	}
	else {
		std::cout << "No LIDAR serial port specified." << std::endl;
	}

	if (!(args["imu-serial-port"].empty())) {
		sensors["R2 IMU"] = std::make_shared<IMUSensor>(args["imu-serial-port"].c_str(), 9600);
	}
	else {
		//sensors["R2 IMU"] = std::make_shared<IMUSensor>("COM3", 9600);
		std::cout << "No IMU serial port specified." << std::endl;
	}

	if (!(args["power-serial-port"].empty())) {
		sensors["R2 POWER"] = std::make_shared<PowerHandler>(args["power-serial-port"].c_str(), 9600);
	}
	else {
		std::cout << "No power serial port specified." << std::endl;
	}

	return sensors;
}

/** Initializes controllers */
smap<ptr<Controller>> initializeControllers(smap<string>& args) {
	smap<ptr<Controller>> controllers;
	if (args.find("udp-pi-ip") != args.end() && args.find("udp-pi-port") != args.end()) {
		controllers["UDP PI"] = std::make_shared<UDPClientController>(args["udp-pi-ip"], atoi(args["udp-pi-port"].c_str()));
	}
	else {
		std::cout << "No UDP Pi ip or port specified." << std::endl;
	}
	if (!(args["head-flap-serial-port"].empty())) {
		controllers["R2 HEAD FLAP"] = std::make_shared<HeadFlapController>(args["head-flap-serial-port"].c_str(), 9600);
	}
	else {
		//controllers["R2 HEAD FLAP"] = std::make_shared<HeadFlapController>("COM4", 9600);
		std::cout << "No head flap serial port specified." << std::endl;
	}

	return controllers;
}

/** Initialize a list of jobs */
deque<Job> initializeJobs(smap<string>& args) {
	deque<Job> jobs;<commit_msg>Change empty() to != end() for arguments<commit_after>#include "Global.h"

#include <vector>
#include <iostream>
#include <thread>
#include <unordered_map>
#include <cmath>
#include <chrono>

#ifdef _WIN32
#ifndef _CRT_SECURE_NO_WARNINGS
#	define _CRT_SECURE_NO_WARNINGS
#endif
#ifndef _SCL_SECURE_NO_WARNINGS
#	define _SCL_SECURE_NO_WARNINGS
#endif
#	define _WINSOCK_DEPRECATED_NO_WARNINGS
#	include <WinSock2.h>
#	include <Windows.h>
void initializeWSA() {
	WSADATA data;
	WSAStartup(MAKEWORD(2, 2), &data);
}
#endif

#include "Controller.h"
#include "Job.h"
#include "JobHandler.h"
#include "Sensor.h"

#include "Controller/UDPClientController.h"
#include "Controller/MotorController.h"
#include "Controller/HeadFlapController.h"
#include "JobHandler/ForwardHandler.h"
#include "JobHandler/R2Server.h"
#include "Sensor/UDPServerSensor.h"
#include "Sensor/UltrasoundSensor.h"
#include "Sensor/DrawerSensor.h"
#include "Sensor/HeadSensor.h"
#include "Sensor/RFIDSensor.h"
#include "Sensor/LidarSensor.h"
#include "Sensor/IMUSensor.h"
#include "Sensor/PowerHandler.h"

/** Initializes sensors */
smap<ptr<Sensor>> initializeSensors(smap<string>& args) {
	smap<ptr<Sensor>> sensors;
	if (args.find("udp-server-ip") != args.end() && args.find("udp-server-port") != args.end()) {
		sensors["UDP SERVER"] = std::make_shared<UDPServerSensor>(args["udp-server-ip"], atoi(args["udp-server-port"].c_str()));
	}
	else {
		sensors["UDP SERVER"] = std::make_shared<UDPServerSensor>("0.0.0.0", 9000);
	}

	if (args.find("ultrasound-front-serial-port") != args.end() && args.find("ultrasound-back-serial-port") != args.end()) {
		sensors["R2 ULTRASOUND"] = std::make_shared<UltrasoundSensor>(args["ultrasound-front-serial-port"].c_str(), 9600, args["ultrasound-back-serial-port"].c_str(), 9600);
	}
	else {
		//sensors["R2 ULTRASOUND"] = std::make_shared<UltrasoundSensor>("COM7", 9600, "COM8", 9600);
		std::cout << "No ultrasound serial port(s) specified." << std::endl;
	}

	if (args.find("drawer-serial-port") != args.end()) {
		sensors["R2 DRAWER"] = std::make_shared<DrawerSensor>(args["drawer-serial-port"].c_str(), 9600);
	}
	else {
		std::cout << "No drawer serial port specified." << std::endl;
	}

	if (args.find("head-serial-port") != args.end()) {
		sensors["R2 HEAD"] = std::make_shared<HeadSensor>(args["head-serial-port"].c_str(), 9600);
	}
	else {
		std::cout << "No head serial port specified." << std::endl;
	}

	if (args.find("rfid-serial-port") != args.end()) {
		sensors["R2 RFID"] = std::make_shared<RFIDSensor>(args["rfid-serial-port"].c_str(), 9600);
	}
	else {
		//sensors["R2 RFID"] = std::make_shared<RFIDSensor>("COM4", 9600);
		std::cout << "No RFID serial port specified." << std::endl;
	}
	if (args.find("lidar-serial-port") != args.end()) {
		sensors["R2 LIDAR"] = std::make_shared<LidarSensor>(args["lidar-serial-port"].c_str(), 9600);
	}
	else {
		std::cout << "No LIDAR serial port specified." << std::endl;
	}

	if (args.find("imu-serial-port") != args.end()) {
		sensors["R2 IMU"] = std::make_shared<IMUSensor>(args["imu-serial-port"].c_str(), 9600);
	}
	else {
		//sensors["R2 IMU"] = std::make_shared<IMUSensor>("COM3", 9600);
		std::cout << "No IMU serial port specified." << std::endl;
	}

	if (args.find("power-serial-port") != args.end()) {
		sensors["R2 POWER"] = std::make_shared<PowerHandler>(args["power-serial-port"].c_str(), 9600);
	}
	else {
		std::cout << "No power serial port specified." << std::endl;
	}

	return sensors;
}

/** Initializes controllers */
smap<ptr<Controller>> initializeControllers(smap<string>& args) {
	smap<ptr<Controller>> controllers;
	if (args.find("udp-pi-ip") != args.end() && args.find("udp-pi-port") != args.end()) {
		controllers["UDP PI"] = std::make_shared<UDPClientController>(args["udp-pi-ip"], atoi(args["udp-pi-port"].c_str()));
	}
	else {
		std::cout << "No UDP Pi ip or port specified." << std::endl;
	}
	if (args.find("head-flap-serial-port") != args.end()) {
		controllers["R2 HEAD FLAP"] = std::make_shared<HeadFlapController>(args["head-flap-serial-port"].c_str(), 9600);
	}
	else {
		//controllers["R2 HEAD FLAP"] = std::make_shared<HeadFlapController>("COM4", 9600);
		std::cout << "No head flap serial port specified." << std::endl;
	}

	return controllers;
}

/** Initialize a list of jobs */
deque<Job> initializeJobs(smap<string>& args) {
	deque<Job> jobs;
{'fraction_non_alphanumeric': 0.20319794584500467, 'fraction_numerical': 0.02054154995331466, 'mean_word_length': 5.7155172413793105, 'pattern_counts': {'":': 0, '<': 147, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '324631', 'n_tokens_mistral': 3432, 'n_tokens_neox': 3262, 'n_words': 555}