<commit_before>/*
* File: lego_module.cpp
* Author: m79lol, iskinmike
*
*/

#define _CRT_SECURE_NO_WARNINGS

#include <windows.h>
#include <time.h>
#include <vector>
#include <map>

#include "../module_headers/module.h"
#include "../module_headers/robot_module.h"
#include "lego_ev3_robot_module.h"
#include "SimpleIni.h"

EXTERN_C IMAGE_DOS_HEADER __ImageBase;

const unsigned int COUNT_LEGO_FUNCTIONS = 24;
const unsigned int COUNT_AXIS = 11;

#define ADD_LEGO_0_FUNCTION(FUNCTION_NAME) \
	lego_functions[function_id] = new FunctionData(function_id + 1, 0, NULL, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_1F_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[1]; \
	Params[0] = FunctionData::FLOAT; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 1, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_1S_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[1]; \
	Params[0] = FunctionData::STRING; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 1, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_2F_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[2]; \
	Params[0] = FunctionData::FLOAT; \
	Params[1] = FunctionData::FLOAT; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 2, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_1S1F_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[2]; \
	Params[0] = FunctionData::STRING; \
	Params[1] = FunctionData::FLOAT; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 2, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_4F_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[4]; \
	Params[0] = FunctionData::FLOAT; \
	Params[1] = FunctionData::FLOAT; \
	Params[2] = FunctionData::FLOAT; \
	Params[3] = FunctionData::FLOAT; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 4, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_1S3F_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[4]; \
	Params[0] = FunctionData::STRING; \
	Params[1] = FunctionData::FLOAT; \
	Params[2] = FunctionData::FLOAT; \
	Params[3] = FunctionData::FLOAT; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 4, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_2S2F_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[4]; \
	Params[0] = FunctionData::STRING; \
	Params[1] = FunctionData::STRING; \
	Params[2] = FunctionData::FLOAT; \
	Params[3] = FunctionData::FLOAT; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 4, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define DEFINE_ALL_FUNCTIONS \
	ADD_LEGO_1S_FUNCTION("motorBrake")\
	ADD_LEGO_1S_FUNCTION("motorGetDirection")\
	ADD_LEGO_1S_FUNCTION("motorGetTacho")\
	ADD_LEGO_1S3F_FUNCTION("motorMoveTo")\
	ADD_LEGO_1S_FUNCTION("motorOff")\
	ADD_LEGO_1S_FUNCTION("motorResetTacho")\
	ADD_LEGO_1S1F_FUNCTION("motorSetDirection")\
	ADD_LEGO_1S1F_FUNCTION("motorSetSpeed")\
	ADD_LEGO_2S2F_FUNCTION("setTrackVehicle")\
	ADD_LEGO_1S_FUNCTION("waitMotorToStop")\
	ADD_LEGO_4F_FUNCTION("waitMultiMotorsToStop")\
	ADD_LEGO_1F_FUNCTION("trackVehicleBackward")\
	ADD_LEGO_1F_FUNCTION("trackVehicleForward")\
	ADD_LEGO_0_FUNCTION("trackVehicleOff")\
	ADD_LEGO_1F_FUNCTION("trackVehicleSpinLeft")\
	ADD_LEGO_1F_FUNCTION("trackVehicleSpinRight")\
	ADD_LEGO_2F_FUNCTION("trackVehicleTurnLeftForward")\
	ADD_LEGO_2F_FUNCTION("trackVehicleTurnLeftReverse")\
	ADD_LEGO_2F_FUNCTION("trackVehicleTurnRightForward")\
	ADD_LEGO_2F_FUNCTION("trackVehicleTurnRightForward")\
	ADD_LEGO_0_FUNCTION("trackVehicleBrake") \
	ADD_LEGO_2F_FUNCTION("readSensor")\
	ADD_LEGO_1S1F_FUNCTION("isMotorRunning")\
	ADD_LEGO_1S1F_FUNCTION("getMotorSpeed");


#define ADD_ROBOT_AXIS(AXIS_NAME, UPPER_VALUE, LOWER_VALUE) \
robot_axis[axis_id] = new AxisData; \
robot_axis[axis_id]->axis_index = axis_id + 1; \
robot_axis[axis_id]->upper_value = UPPER_VALUE; \
robot_axis[axis_id]->lower_value = LOWER_VALUE; \
robot_axis[axis_id]->name = AXIS_NAME; \
axis_id++;

#define DEFINE_ALL_AXIS \
ADD_ROBOT_AXIS("locked", 1, 0)\
ADD_ROBOT_AXIS("speedMotorA", 100, -100)\
ADD_ROBOT_AXIS("speedMotorB", 100, -100)\
ADD_ROBOT_AXIS("speedMotorC", 100, -100)\
ADD_ROBOT_AXIS("speedMotorD", 100, -100)\
ADD_ROBOT_AXIS("moveMotorA", 1000, -1000)\
ADD_ROBOT_AXIS("moveMotorB", 1000, -1000)\
ADD_ROBOT_AXIS("moveMotorC", 1000, -1000)\
ADD_ROBOT_AXIS("moveMotorD", 1000, -1000)\
ADD_ROBOT_AXIS("straight", 100, -100)\
ADD_ROBOT_AXIS("rotation", 100, -100);


const char* LegoRobotModule::getUID() {
	return "Lego_EV3_Module";
};
FunctionData** LegoRobotModule::getFunctions(unsigned int *count_functions) {
	*count_functions = COUNT_LEGO_FUNCTIONS;
	return lego_functions;
};

LegoRobotModule::LegoRobotModule() {
	srand(time(NULL));
	lego_functions = new FunctionData*[COUNT_LEGO_FUNCTIONS];
	system_value function_id = 0;
	FunctionData::ParamTypes *Params = NULL;

	// define robot functions
	DEFINE_ALL_FUNCTIONS

	// define robot axis
	robot_axis = new AxisData*[COUNT_AXIS];
	system_value axis_id = 0;
	DEFINE_ALL_AXIS
};

inline void isSpeed(variable_value num){
	if ((num < (-100)) || (num > 100)) 
	{
		throw std::exception();
	}
};

inline void isPercent(variable_value num){
	if ((num < 0) || (num > 100))
	{
		throw std::exception();
	}
};

inline void isMotor(wchar_t num){
	switch (num)
	{
	case 'A':
	case 'B':
	case 'C':
	case 'D':{
		break;
	}
	default:
		throw std::exception();
	}
};

void LegoRobotModule::destroy() {
	for (unsigned int j = 0; j < COUNT_LEGO_FUNCTIONS; ++j) {
		delete lego_functions[j];
	}
	for (unsigned int j = 0; j < COUNT_AXIS; ++j) {
		delete robot_axis[j];
	}
	delete[] lego_functions;
	delete[] robot_axis;
	delete this;
};
int LegoRobotModule::init(){
	InitializeCriticalSection(&LRM_cs);
	CSimpleIniA ini;
	ini.SetMultiKey(true);

	HMODULE lr_handle;

	lr_handle = GetModuleHandleW(L"lego_module.dll");

	WCHAR DllPath[MAX_PATH] = { 0 };
	
	//GetModuleFileNameW((HINSTANCE)&__ImageBase, DllPath, _countof(DllPath));
	GetModuleFileNameW(lr_handle, DllPath, _countof(DllPath));
	WCHAR *tmp = wcsrchr(DllPath, L'\\');
	WCHAR ConfigPath[MAX_PATH] = { 0 };<commit_msg>Дополнен деструктор destroy()<commit_after>/*
* File: lego_module.cpp
* Author: m79lol, iskinmike
*
*/

#define _CRT_SECURE_NO_WARNINGS

#include <windows.h>
#include <time.h>
#include <vector>
#include <map>

#include "../module_headers/module.h"
#include "../module_headers/robot_module.h"
#include "lego_ev3_robot_module.h"
#include "SimpleIni.h"

EXTERN_C IMAGE_DOS_HEADER __ImageBase;

const unsigned int COUNT_LEGO_FUNCTIONS = 24;
const unsigned int COUNT_AXIS = 11;

#define ADD_LEGO_0_FUNCTION(FUNCTION_NAME) \
	lego_functions[function_id] = new FunctionData(function_id + 1, 0, NULL, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_1F_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[1]; \
	Params[0] = FunctionData::FLOAT; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 1, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_1S_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[1]; \
	Params[0] = FunctionData::STRING; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 1, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_2F_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[2]; \
	Params[0] = FunctionData::FLOAT; \
	Params[1] = FunctionData::FLOAT; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 2, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_1S1F_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[2]; \
	Params[0] = FunctionData::STRING; \
	Params[1] = FunctionData::FLOAT; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 2, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_4F_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[4]; \
	Params[0] = FunctionData::FLOAT; \
	Params[1] = FunctionData::FLOAT; \
	Params[2] = FunctionData::FLOAT; \
	Params[3] = FunctionData::FLOAT; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 4, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_1S3F_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[4]; \
	Params[0] = FunctionData::STRING; \
	Params[1] = FunctionData::FLOAT; \
	Params[2] = FunctionData::FLOAT; \
	Params[3] = FunctionData::FLOAT; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 4, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define ADD_LEGO_2S2F_FUNCTION(FUNCTION_NAME) \
	Params = new FunctionData::ParamTypes[4]; \
	Params[0] = FunctionData::STRING; \
	Params[1] = FunctionData::STRING; \
	Params[2] = FunctionData::FLOAT; \
	Params[3] = FunctionData::FLOAT; \
	lego_functions[function_id] = new FunctionData(function_id + 1, 4, Params, FUNCTION_NAME); \
	function_id++; 
//////

#define DEFINE_ALL_FUNCTIONS \
	ADD_LEGO_1S_FUNCTION("motorBrake")\
	ADD_LEGO_1S_FUNCTION("motorGetDirection")\
	ADD_LEGO_1S_FUNCTION("motorGetTacho")\
	ADD_LEGO_1S3F_FUNCTION("motorMoveTo")\
	ADD_LEGO_1S_FUNCTION("motorOff")\
	ADD_LEGO_1S_FUNCTION("motorResetTacho")\
	ADD_LEGO_1S1F_FUNCTION("motorSetDirection")\
	ADD_LEGO_1S1F_FUNCTION("motorSetSpeed")\
	ADD_LEGO_2S2F_FUNCTION("setTrackVehicle")\
	ADD_LEGO_1S_FUNCTION("waitMotorToStop")\
	ADD_LEGO_4F_FUNCTION("waitMultiMotorsToStop")\
	ADD_LEGO_1F_FUNCTION("trackVehicleBackward")\
	ADD_LEGO_1F_FUNCTION("trackVehicleForward")\
	ADD_LEGO_0_FUNCTION("trackVehicleOff")\
	ADD_LEGO_1F_FUNCTION("trackVehicleSpinLeft")\
	ADD_LEGO_1F_FUNCTION("trackVehicleSpinRight")\
	ADD_LEGO_2F_FUNCTION("trackVehicleTurnLeftForward")\
	ADD_LEGO_2F_FUNCTION("trackVehicleTurnLeftReverse")\
	ADD_LEGO_2F_FUNCTION("trackVehicleTurnRightForward")\
	ADD_LEGO_2F_FUNCTION("trackVehicleTurnRightForward")\
	ADD_LEGO_0_FUNCTION("trackVehicleBrake") \
	ADD_LEGO_2F_FUNCTION("readSensor")\
	ADD_LEGO_1S1F_FUNCTION("isMotorRunning")\
	ADD_LEGO_1S1F_FUNCTION("getMotorSpeed");


#define ADD_ROBOT_AXIS(AXIS_NAME, UPPER_VALUE, LOWER_VALUE) \
robot_axis[axis_id] = new AxisData; \
robot_axis[axis_id]->axis_index = axis_id + 1; \
robot_axis[axis_id]->upper_value = UPPER_VALUE; \
robot_axis[axis_id]->lower_value = LOWER_VALUE; \
robot_axis[axis_id]->name = AXIS_NAME; \
axis_id++;

#define DEFINE_ALL_AXIS \
ADD_ROBOT_AXIS("locked", 1, 0)\
ADD_ROBOT_AXIS("speedMotorA", 100, -100)\
ADD_ROBOT_AXIS("speedMotorB", 100, -100)\
ADD_ROBOT_AXIS("speedMotorC", 100, -100)\
ADD_ROBOT_AXIS("speedMotorD", 100, -100)\
ADD_ROBOT_AXIS("moveMotorA", 1000, -1000)\
ADD_ROBOT_AXIS("moveMotorB", 1000, -1000)\
ADD_ROBOT_AXIS("moveMotorC", 1000, -1000)\
ADD_ROBOT_AXIS("moveMotorD", 1000, -1000)\
ADD_ROBOT_AXIS("straight", 100, -100)\
ADD_ROBOT_AXIS("rotation", 100, -100);


const char* LegoRobotModule::getUID() {
	return "Lego_EV3_Module";
};
FunctionData** LegoRobotModule::getFunctions(unsigned int *count_functions) {
	*count_functions = COUNT_LEGO_FUNCTIONS;
	return lego_functions;
};

LegoRobotModule::LegoRobotModule() {
	srand(time(NULL));
	lego_functions = new FunctionData*[COUNT_LEGO_FUNCTIONS];
	system_value function_id = 0;
	FunctionData::ParamTypes *Params = NULL;

	// define robot functions
	DEFINE_ALL_FUNCTIONS

	// define robot axis
	robot_axis = new AxisData*[COUNT_AXIS];
	system_value axis_id = 0;
	DEFINE_ALL_AXIS
};

inline void isSpeed(variable_value num){
	if ((num < (-100)) || (num > 100)) 
	{
		throw std::exception();
	}
};

inline void isPercent(variable_value num){
	if ((num < 0) || (num > 100))
	{
		throw std::exception();
	}
};

inline void isMotor(wchar_t num){
	switch (num)
	{
	case 'A':
	case 'B':
	case 'C':
	case 'D':{
		break;
	}
	default:
		throw std::exception();
	}
};

void LegoRobotModule::destroy() {
	for (unsigned int j = 0; j < COUNT_LEGO_FUNCTIONS; ++j) {
		if (lego_functions[j]->count_params) {
			delete[] lego_functions[j]->params;
		}
		delete lego_functions[j];
	}
	for (unsigned int j = 0; j < COUNT_AXIS; ++j) {
		delete robot_axis[j];
	}
	delete[] lego_functions;
	delete[] robot_axis;
	delete this;
};
int LegoRobotModule::init(){
	InitializeCriticalSection(&LRM_cs);
	CSimpleIniA ini;
	ini.SetMultiKey(true);

	HMODULE lr_handle;

	lr_handle = GetModuleHandleW(L"lego_module.dll");

	WCHAR DllPath[MAX_PATH] = { 0 };
	
	//GetModuleFileNameW((HINSTANCE)&__ImageBase, DllPath, _countof(DllPath));
	GetModuleFileNameW(lr_handle, DllPath, _countof(DllPath));
	WCHAR *tmp = wcsrchr(DllPath, L'\\');
	WCHAR ConfigPath[MAX_PATH] = { 0 };
{'fraction_non_alphanumeric': 0.1466866993515736, 'fraction_numerical': 0.027993041277874428, 'mean_word_length': 6.1451977401129945, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '6686474', 'n_tokens_mistral': 5257, 'n_tokens_neox': 4981, 'n_words': 774}