<commit_before>// --------------------------------------------------------------------------
#include <string>
#include <sstream>
#include <getopt.h>
#include "Debug.h"
#include "modbus/ModbusRTUMaster.h"
#include "modbus/ModbusHelpers.h"
// --------------------------------------------------------------------------
using namespace UniSetTypes;
using namespace std;
// --------------------------------------------------------------------------
static struct option longopts[] = {
	{ "help", no_argument, 0, 'h' },
	{ "read01", required_argument, 0, 'c' },
	{ "read02", required_argument, 0, 'b' },
	{ "read03", required_argument, 0, 'r' },
	{ "read04", required_argument, 0, 'x' },
	{ "write05", required_argument, 0, 'f' }, 
	{ "write06", required_argument, 0, 'z' }, 
	{ "write0F", required_argument, 0, 'm' },
	{ "write10", required_argument, 0, 'w' },
//	{ "readfile14", required_argument, 0, 'g' },
//	{ "writefile15", required_argument, 0, 'p' },
	{ "filetransfer66", required_argument, 0, 'u' },
	{ "timeout", required_argument, 0, 't' },
	{ "autodetect-slave", no_argument, 0, 'q' },
	{ "autodetect-speed", required_argument, 0, 'n' },
	{ "device", required_argument, 0, 'd' },
	{ "verbose", no_argument, 0, 'v' },
	{ "myaddr", required_argument, 0, 'a' },
	{ "speed", required_argument, 0, 's' },
	{ "use485F", no_argument, 0, 'y' },
	{ "num-cycles", required_argument, 0, 'q' },
	{ NULL, 0, 0, 0 }
};
// --------------------------------------------------------------------------
static void print_help()
{
	printf("-h|--help 		- this message\n");
	printf("[--write05] slaveaddr reg val  - write val to reg for slaveaddr\n");
	printf("[--write06] slaveaddr reg val  - write val to reg for slaveaddr\n");
	printf("[--write0F] slaveaddr reg val  - write val to reg for slaveaddr\n");
	printf("[--write10] slaveaddr reg val count - write val to reg for slaveaddr\n");
	printf("[--read01] slaveaddr reg count   - read from reg (from slaveaddr). Default: count=1\n");
	printf("[--read02] slaveaddr reg count   - read from reg (from slaveaddr). Default: count=1\n");
	printf("[--read03] slaveaddr reg count   - read from reg (from slaveaddr). Default: count=1\n");
	printf("[--read04] slaveaddr reg count   - read from reg (from slaveaddr). Default: count=1\n");
//	printf("[--readfile14] slaveaddr fileID  - read file from slaveaddr).\n");
//	printf("[--writefile15] slaveaddr id filename  - write file to slaveaddr).\n");
	printf("[--filetransfer66] slaveaddr fileID [filename] - get file from slaveaddr. Default save to 'fileID.transfer'\n");

	printf("[--autodetect-speed] slaveaddr [reg fn]  - detect speed\n");
	printf("          reg - register of test. Default: 0\n");
	printf("          fn - function of test [0x01,0x02,0x03,0x04]. Default: 0x04\n");
	printf("[--autodetect-slave] [beg end reg fn]  - find slave\n");
	printf("          beg - start addres Default: 0\n");
	printf("          end - end addres Default: 255\n");
	printf("          reg - register of test. Default: 0\n");
	printf("          fn - function of test [0x01,0x02,0x03,0x04]. Default: 0x04\n");
	printf("[-y|--use485F]                    - use RS485 Fastwel.\n");
	printf("[-d|--device] dev                 - use device dev. Default: /dev/ttyS0\n");
	printf("[-a|--myaddr] addr                - Modbus address for master. Default: 0x01.\n");
	printf("[-s|--speed] speed                - 9600,14400,19200,38400,57600,115200. Default: 38400.\n");
	printf("[-t|--timeout] msec               - Timeout. Default: 2000.\n");
	printf("[-l|--num-cycles] num             - Number of cycles of exchange. Default: -1 - infinitely.\n");
	printf("[-v|--verbose]                    - Print all messages to stdout\n");
}
// --------------------------------------------------------------------------
enum Command
{
	cmdNOP,
	cmdRead01,
	cmdRead02,
	cmdRead03,
	cmdRead04,
	cmdWrite05,
	cmdWrite06,
	cmdWrite0F,
	cmdWrite10,
	cmdDetectSpeed,
	cmdDetectSlave,
	cmdReadFile,
	cmdWriteFile,
	cmdFileTransfer
};
// --------------------------------------------------------------------------
static char* checkArg( int ind, int argc, char* argv[] );
// --------------------------------------------------------------------------

int main( int argc, char **argv )
{   
	Command cmd = cmdNOP;
	int optindex = 0;
	int opt = 0;
	int verb = 0;
	string dev("/dev/ttyS0");
	string speed("38400");
	ModbusRTU::ModbusData reg = 0;
	int val = 0;
	ModbusRTU::ModbusData count = 1;
	ModbusRTU::ModbusAddr myaddr = 0x01;
	ModbusRTU::ModbusAddr slaveaddr = 0x00;
	ModbusRTU::SlaveFunctionCode fn = ModbusRTU::fnReadInputRegisters;
	ModbusRTU::ModbusAddr beg = 0;
	ModbusRTU::ModbusAddr end = 255;
	int tout = 2000;
	DebugStream dlog;
	string tofile("");
	int use485 = 0;
	int ncycles = -1;

	try
	{
		while( (opt = getopt_long(argc, argv, "hva:w:z:m:r:x:c:b:d:s:t:qn:u:yl:",longopts,&optindex)) != -1 )
		{
			switch (opt) 
			{
				case 'h':
					print_help();	
				return 0;

				case 'c':
					if( cmd == cmdNOP )
						cmd = cmdRead01;
				case 'b':
					if( cmd == cmdNOP )
						cmd = cmdRead02;
				case 'r':
					if( cmd == cmdNOP )
						cmd = cmdRead03;
				case 'x':
<commit_msg>(mbrtutester): исправил ошибку не обрабатывался ключ -t|--timeout<commit_after>// --------------------------------------------------------------------------
#include <string>
#include <sstream>
#include <getopt.h>
#include "Debug.h"
#include "modbus/ModbusRTUMaster.h"
#include "modbus/ModbusHelpers.h"
// --------------------------------------------------------------------------
using namespace UniSetTypes;
using namespace std;
// --------------------------------------------------------------------------
static struct option longopts[] = {
	{ "help", no_argument, 0, 'h' },
	{ "read01", required_argument, 0, 'c' },
	{ "read02", required_argument, 0, 'b' },
	{ "read03", required_argument, 0, 'r' },
	{ "read04", required_argument, 0, 'x' },
	{ "write05", required_argument, 0, 'f' }, 
	{ "write06", required_argument, 0, 'z' }, 
	{ "write0F", required_argument, 0, 'm' },
	{ "write10", required_argument, 0, 'w' },
//	{ "readfile14", required_argument, 0, 'g' },
//	{ "writefile15", required_argument, 0, 'p' },
	{ "filetransfer66", required_argument, 0, 'u' },
	{ "timeout", required_argument, 0, 't' },
	{ "autodetect-slave", no_argument, 0, 'q' },
	{ "autodetect-speed", required_argument, 0, 'n' },
	{ "device", required_argument, 0, 'd' },
	{ "verbose", no_argument, 0, 'v' },
	{ "myaddr", required_argument, 0, 'a' },
	{ "speed", required_argument, 0, 's' },
	{ "use485F", no_argument, 0, 'y' },
	{ "num-cycles", required_argument, 0, 'q' },
	{ NULL, 0, 0, 0 }
};
// --------------------------------------------------------------------------
static void print_help()
{
	printf("-h|--help 		- this message\n");
	printf("[--write05] slaveaddr reg val  - write val to reg for slaveaddr\n");
	printf("[--write06] slaveaddr reg val  - write val to reg for slaveaddr\n");
	printf("[--write0F] slaveaddr reg val  - write val to reg for slaveaddr\n");
	printf("[--write10] slaveaddr reg val count - write val to reg for slaveaddr\n");
	printf("[--read01] slaveaddr reg count   - read from reg (from slaveaddr). Default: count=1\n");
	printf("[--read02] slaveaddr reg count   - read from reg (from slaveaddr). Default: count=1\n");
	printf("[--read03] slaveaddr reg count   - read from reg (from slaveaddr). Default: count=1\n");
	printf("[--read04] slaveaddr reg count   - read from reg (from slaveaddr). Default: count=1\n");
//	printf("[--readfile14] slaveaddr fileID  - read file from slaveaddr).\n");
//	printf("[--writefile15] slaveaddr id filename  - write file to slaveaddr).\n");
	printf("[--filetransfer66] slaveaddr fileID [filename] - get file from slaveaddr. Default save to 'fileID.transfer'\n");

	printf("[--autodetect-speed] slaveaddr [reg fn]  - detect speed\n");
	printf("          reg - register of test. Default: 0\n");
	printf("          fn - function of test [0x01,0x02,0x03,0x04]. Default: 0x04\n");
	printf("[--autodetect-slave] [beg end reg fn]  - find slave\n");
	printf("          beg - start addres Default: 0\n");
	printf("          end - end addres Default: 255\n");
	printf("          reg - register of test. Default: 0\n");
	printf("          fn - function of test [0x01,0x02,0x03,0x04]. Default: 0x04\n");
	printf("[-y|--use485F]                    - use RS485 Fastwel.\n");
	printf("[-d|--device] dev                 - use device dev. Default: /dev/ttyS0\n");
	printf("[-a|--myaddr] addr                - Modbus address for master. Default: 0x01.\n");
	printf("[-s|--speed] speed                - 9600,14400,19200,38400,57600,115200. Default: 38400.\n");
	printf("[-t|--timeout] msec               - Timeout. Default: 2000.\n");
	printf("[-l|--num-cycles] num             - Number of cycles of exchange. Default: -1 - infinitely.\n");
	printf("[-v|--verbose]                    - Print all messages to stdout\n");
}
// --------------------------------------------------------------------------
enum Command
{
	cmdNOP,
	cmdRead01,
	cmdRead02,
	cmdRead03,
	cmdRead04,
	cmdWrite05,
	cmdWrite06,
	cmdWrite0F,
	cmdWrite10,
	cmdDetectSpeed,
	cmdDetectSlave,
	cmdReadFile,
	cmdWriteFile,
	cmdFileTransfer
};
// --------------------------------------------------------------------------
static char* checkArg( int ind, int argc, char* argv[] );
// --------------------------------------------------------------------------

int main( int argc, char **argv )
{   
	Command cmd = cmdNOP;
	int optindex = 0;
	int opt = 0;
	int verb = 0;
	string dev("/dev/ttyS0");
	string speed("38400");
	ModbusRTU::ModbusData reg = 0;
	int val = 0;
	ModbusRTU::ModbusData count = 1;
	ModbusRTU::ModbusAddr myaddr = 0x01;
	ModbusRTU::ModbusAddr slaveaddr = 0x00;
	ModbusRTU::SlaveFunctionCode fn = ModbusRTU::fnReadInputRegisters;
	ModbusRTU::ModbusAddr beg = 0;
	ModbusRTU::ModbusAddr end = 255;
	int tout = 2000;
	DebugStream dlog;
	string tofile("");
	int use485 = 0;
	int ncycles = -1;

	try
	{
		while( (opt = getopt_long(argc, argv, "hva:w:z:m:r:x:c:b:d:s:t:qn:u:yl:t:",longopts,&optindex)) != -1 )
		{
			switch (opt)
			{
				case 'h':
					print_help();	
				return 0;

				case 'c':
					if( cmd == cmdNOP )
						cmd = cmdRead01;
				case 'b':
					if( cmd == cmdNOP )
						cmd = cmdRead02;
				case 'r':
					if( cmd == cmdNOP )
						cmd = cmdRead03;
				case 'x':

{'fraction_non_alphanumeric': 0.25912656144088314, 'fraction_numerical': 0.041251089377360314, 'mean_word_length': 2.2004958165478774, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6591822', 'n_tokens_mistral': 3828, 'n_tokens_neox': 3446, 'n_words': 906}