Commit dd9fe9fb authored by Pavel Vainerman's avatar Pavel Vainerman

Более точно "выразил" применение типов,

а также чистка от лишних коментариев
parent 12454b9d
......@@ -258,7 +258,6 @@ namespace uniset
uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
const std::string& prefix = "mbtcp" );
/*! глобальная функция для вывода help-а */
static void help_print( int argc, const char* const* argv );
virtual uniset::SimpleInfo* getInfo( const char* userparam = 0 ) override;
......
......@@ -296,7 +296,6 @@ namespace uniset
uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
const std::string& prefix = "mbtcp" );
/*! глобальная функция для вывода help-а */
static void help_print( int argc, const char* const* argv );
virtual uniset::SimpleInfo* getInfo( const char* userparam = 0 ) override;
......
......@@ -41,7 +41,6 @@ namespace uniset
uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
const std::string& prefix = "rs" );
/*! глобальная функция для вывода help-а */
static void help_print( int argc, const char* const* argv );
protected:
......
......@@ -208,12 +208,12 @@ namespace uniset
}
}
// -----------------------------------------------------------------------------
long RTUStorage::getInt( RTUJack jack, unsigned short int chan, UniversalIO::IOType t )
long RTUStorage::getInt( RTUJack jack, uint16_t chan, UniversalIO::IOType t )
{
return lroundf( getFloat(jack, chan, t) );
}
// -----------------------------------------------------------------------------
float RTUStorage::getFloat( RTUJack jack, unsigned short int chan, UniversalIO::IOType t )
float RTUStorage::getFloat( RTUJack jack, uint16_t chan, UniversalIO::IOType t )
{
if( t == UniversalIO::AI )
{
......@@ -270,7 +270,7 @@ namespace uniset
return 0;
}
// -----------------------------------------------------------------------------
bool RTUStorage::getState( RTUJack jack, unsigned short int chan, UniversalIO::IOType t )
bool RTUStorage::getState( RTUJack jack, uint16_t chan, UniversalIO::IOType t )
{
if( t == UniversalIO::DI )
{
......@@ -321,7 +321,7 @@ namespace uniset
return false;
}
// -----------------------------------------------------------------------------
ModbusRTU::ModbusData RTUStorage::getRegister( RTUJack jack, unsigned short chan, UniversalIO::IOType t )
ModbusRTU::ModbusData RTUStorage::getRegister( RTUJack jack, uint16_t chan, UniversalIO::IOType t )
{
if( t == UniversalIO::AI )
{
......@@ -424,7 +424,7 @@ namespace uniset
return -1;
}
// -----------------------------------------------------------------------------
ModbusRTU::SlaveFunctionCode RTUStorage::getFunction( RTUJack jack, unsigned short chan, UniversalIO::IOType t )
ModbusRTU::SlaveFunctionCode RTUStorage::getFunction( RTUJack jack, uint16_t chan, UniversalIO::IOType t )
{
if( t == UniversalIO::AI )
{
......
......@@ -18,6 +18,7 @@
#define _RTUSTORAGE_H_
// -----------------------------------------------------------------------------
#include <ostream>
#include <cstdint>
#include <string>
#include <memory>
#include "modbus/ModbusTypes.h"
......@@ -78,13 +79,13 @@ namespace uniset
static RTUJack s2j( const std::string& jack );
static std::string j2s( RTUJack j );
long getInt( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
float getFloat( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
bool getState( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
long getInt( RTUJack jack, uint16_t channel, UniversalIO::IOType t );
float getFloat( RTUJack jack, uint16_t channel, UniversalIO::IOType t );
bool getState( RTUJack jack, uint16_t channel, UniversalIO::IOType t );
static ModbusRTU::ModbusData getRegister( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
static ModbusRTU::ModbusData getRegister( RTUJack jack, uint16_t channel, UniversalIO::IOType t );
static ModbusRTU::SlaveFunctionCode getFunction( RTUJack jack, unsigned short channel, UniversalIO::IOType t );
static ModbusRTU::SlaveFunctionCode getFunction( RTUJack jack, uint16_t channel, UniversalIO::IOType t );
// ДОДЕЛАТЬ: setState, setValue
void print();
......
......@@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// -------------------------------------------------------------------------
#include <cstdint>
#include <iostream>
#include <iomanip>
#include "UniSetTypes.h"
......@@ -30,8 +31,8 @@ static void print_help()
int main( int argc, const char** argv )
{
// std::ios::sync_with_stdio(false);
unsigned short v1 = 0;
unsigned short v2 = 0;
uint16_t v1 = 0;
uint16_t v2 = 0;
const char* type = "";
if( argc < 2 )
......
......@@ -74,7 +74,7 @@ int main( int argc, const char** argv )
// return 0;
*/
unsigned short v[4];
uint16_t v[4];
memset(v, 0, sizeof(v));
const char* type = "";
......
......@@ -1712,7 +1712,7 @@ namespace uniset
if( ret == ModbusRTU::erNoError )
{
for( unsigned int i = 0; i < query.count; i++ )
for( uint16_t i = 0; i < query.count; i++ )
reply.addData( buf[i] );
}
......@@ -1916,12 +1916,12 @@ namespace uniset
}
else if( p->vtype == VTypes::vtUnsigned )
{
long val = (unsigned short)(mbval);
long val = (uint16_t)(mbval);
IOBase::processingAsAI( p, val, shm, force );
}
else if( p->vtype == VTypes::vtSigned )
{
long val = (signed short)(mbval);
long val = (int16_t)(mbval);
IOBase::processingAsAI( p, val, shm, force );
}
else if( p->vtype == VTypes::vtI2 )
......@@ -2515,7 +2515,7 @@ namespace uniset
if( ret == ModbusRTU::erNoError )
{
for( unsigned int i = 0; i < query.count; i++ )
for( uint16_t i = 0; i < query.count; i++ )
reply.addData( buf[i] );
}
......
......@@ -341,7 +341,6 @@ namespace uniset
uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
const std::string& prefix = "mbs" );
/*! глобальная функция для вывода help-а */
static void help_print( int argc, const char* const* argv );
static const int NoSafetyState = -1;
......
......@@ -19,6 +19,7 @@
// -----------------------------------------------------------------------------
#include <string>
#include <map>
#include <cstdint>
#include <unordered_map>
#include <list>
#include <ostream>
......@@ -57,7 +58,7 @@ namespace uniset
// -------------------------------------------------------------------------
std::string type2str( MTRType t ); /*!< преоразование строки в тип */
MTRType str2type( const std::string& s ); /*!< преобразование названия в строку */
size_t wsize( MTRType t ); /*!< длина данных в словах */
size_t wsize( MTRType t ); /*!< длина данных в словах */
// -------------------------------------------------------------------------
// Информация
const ModbusRTU::ModbusData regModelNumber = 0x01;
......@@ -138,7 +139,7 @@ namespace uniset
{
public:
T1(): val(0) {}
T1( unsigned short v ): val(v) {}
T1( uint16_t v ): val(v) {}
T1( const ModbusRTU::ModbusData* data ): val(data[0]) {}
~T1() {}
// ------------------------------------------
......@@ -153,7 +154,7 @@ namespace uniset
return mtT1;
}
// ------------------------------------------
unsigned short val;
uint16_t val;
};
std::ostream& operator<<(std::ostream& os, T1& t );
// -------------------------------------------------------------------------
......@@ -161,7 +162,7 @@ namespace uniset
{
public:
T2(): val(0) {}
T2( signed short v ): val(v) {}
T2( int16_t v ): val(v) {}
T2( const ModbusRTU::ModbusData* data ): val(data[0]) {}
~T2() {}
// ------------------------------------------
......@@ -176,7 +177,7 @@ namespace uniset
return mtT2;
}
// ------------------------------------------
signed short val;
int16_t val;
};
std::ostream& operator<<(std::ostream& os, T2& t );
// -------------------------------------------------------------------------
......@@ -187,8 +188,8 @@ namespace uniset
/*! тип хранения в памяти */
typedef union
{
unsigned short v[u2size];
signed int val; // :32
uint16_t v[u2size];
int32_t val; // :32
} T3mem;
// ------------------------------------------
// конструкторы на разные случаи...
......@@ -197,12 +198,12 @@ namespace uniset
memset(raw.v, 0, sizeof(raw.v));
}
T3( signed int i )
T3( int32_t i )
{
raw.val = i;
}
T3( unsigned short v1, unsigned short v2 )
T3( uint16_t v1, uint16_t v2 )
{
raw.v[0] = v1;
raw.v[1] = v2;
......@@ -278,7 +279,7 @@ namespace uniset
}
// ------------------------------------------
std::string sval;
unsigned short raw;
uint16_t raw;
};
std::ostream& operator<<(std::ostream& os, T4& t );
// --------------------------------------------------------------------------
......@@ -289,11 +290,11 @@ namespace uniset
/*! тип хранения в памяти */
typedef union
{
unsigned short v[u2size];
uint16_t v[u2size];
struct u_T5
{
unsigned int val: 24;
signed char exp; // :8
uint32_t val: 24;
int8_t exp; // :8
} __attribute__( ( packed ) ) u2;
long lval;
} T5mem;
......@@ -303,7 +304,7 @@ namespace uniset
{
memset(raw.v, 0, sizeof(raw.v));
}
T5( unsigned short v1, unsigned short v2 )
T5( uint16_t v1, uint16_t v2 )
{
raw.v[0] = v1;
raw.v[1] = v2;
......@@ -352,11 +353,11 @@ namespace uniset
/*! тип хранения в памяти */
typedef union
{
unsigned short v[u2size];
uint16_t v[u2size];
struct u_T6
{
signed int val: 24;
signed char exp; // :8
int32_t val: 24;
int8_t exp; // :8
} u2;
long lval;
} T6mem;
......@@ -366,7 +367,7 @@ namespace uniset
{
memset(raw.v, 0, sizeof(raw.v));
}
T6( unsigned short v1, unsigned short v2 )
T6( uint16_t v1, uint16_t v2 )
{
raw.v[0] = v1;
raw.v[1] = v2;
......@@ -415,12 +416,12 @@ namespace uniset
/*! тип хранения в памяти */
typedef union
{
unsigned short v[u2size];
uint16_t v[u2size];
struct u_T7
{
unsigned int val: 16;
unsigned char ic; // :8 - Inductive/capacitive
unsigned char ie; // :8 - Import/export
uint32_t val: 16;
uint8_t ic; // :8 - Inductive/capacitive
uint8_t ie; // :8 - Import/export
} __attribute__( ( packed ) ) u2;
long lval;
} T7mem;
......@@ -430,7 +431,7 @@ namespace uniset
{
memset(raw.v, 0, sizeof(raw.v));
}
T7( unsigned short v1, unsigned short v2 )
T7( uint16_t v1, uint16_t v2 )
{
raw.v[0] = v1;
raw.v[1] = v2;
......@@ -478,13 +479,13 @@ namespace uniset
/*! тип хранения в памяти */
typedef union
{
unsigned short v[u2size];
uint16_t v[u2size];
struct u_T8
{
unsigned short mon: 8;
unsigned short day: 8;
unsigned short hour: 8;
unsigned short min: 8;
uint16_t mon: 8;
uint16_t day: 8;
uint16_t hour: 8;
uint16_t min: 8;
} __attribute__( ( packed ) ) u2;
} T8mem;
// ------------------------------------------
......@@ -493,7 +494,7 @@ namespace uniset
{
memset(raw.v, 0, sizeof(raw.v));
}
T8( unsigned short v1, unsigned short v2 )
T8( uint16_t v1, uint16_t v2 )
{
raw.v[0] = v1;
raw.v[1] = v2;
......@@ -509,19 +510,19 @@ namespace uniset
}
}
inline unsigned short day()
inline uint16_t day()
{
return raw.u2.day;
}
inline unsigned short mon()
inline uint16_t mon()
{
return raw.u2.mon;
}
inline unsigned short hour()
inline uint16_t hour()
{
return raw.u2.hour;
}
inline unsigned short min()
inline uint16_t min()
{
return raw.u2.min;
}
......@@ -550,13 +551,13 @@ namespace uniset
/*! тип хранения в памяти */
typedef union
{
unsigned short v[u2size];
uint16_t v[u2size];
struct u_T9
{
unsigned short hour: 8;
unsigned short min: 8;
unsigned short sec: 8;
unsigned short ssec: 8;
uint16_t hour: 8;
uint16_t min: 8;
uint16_t sec: 8;
uint16_t ssec: 8;
} __attribute__( ( packed ) ) u2;
} T9mem;
// ------------------------------------------
......@@ -565,7 +566,7 @@ namespace uniset
{
memset(raw.v, 0, sizeof(raw.v));
}
T9( unsigned short v1, unsigned short v2 )
T9( uint16_t v1, uint16_t v2 )
{
raw.v[0] = v1;
raw.v[1] = v2;
......@@ -581,19 +582,19 @@ namespace uniset
}
}
inline unsigned short hour()
inline uint16_t hour()
{
return raw.u2.hour;
}
inline unsigned short min()
inline uint16_t min()
{
return raw.u2.min;
}
inline unsigned short sec()
inline uint16_t sec()
{
return raw.u2.sec;
}
inline unsigned short ssec()
inline uint16_t ssec()
{
return raw.u2.ssec;
}
......@@ -622,12 +623,12 @@ namespace uniset
/*! тип хранения в памяти */
typedef union
{
unsigned short v[u2size];
uint16_t v[u2size];
struct u_T10
{
unsigned short year: 16;
unsigned short mon: 8;
unsigned short day: 8;
uint16_t year: 16;
uint16_t mon: 8;
uint16_t day: 8;
} __attribute__( ( packed ) ) u2;
} T10mem;
// ------------------------------------------
......@@ -636,7 +637,7 @@ namespace uniset
{
memset(raw.v, 0, sizeof(raw.v));
}
T10( unsigned short v1, unsigned short v2 )
T10( uint16_t v1, uint16_t v2 )
{
raw.v[0] = v1;
raw.v[1] = v2;
......@@ -652,15 +653,15 @@ namespace uniset
}
}
inline unsigned short year()
inline uint16_t year()
{
return raw.u2.year;
}
inline unsigned short mon()
inline uint16_t mon()
{
return raw.u2.mon;
}
inline unsigned short day()
inline uint16_t day()
{
return raw.u2.day;
}
......@@ -687,7 +688,7 @@ namespace uniset
{
public:
T16(): val(0) {}
T16( unsigned short v ): val(v)
T16( uint16_t v ): val(v)
{
fval = (float)(val) / 100.0;
}
......@@ -717,12 +718,12 @@ namespace uniset
{
return fval;
}
operator unsigned short()
operator uint16_t()
{
return val;
}
unsigned short val = { 0 };
uint16_t val = { 0 };
float fval = { 0.0 };
};
std::ostream& operator<<(std::ostream& os, T16& t );
......@@ -731,13 +732,13 @@ namespace uniset
{
public:
T17(): val(0) {}
T17( signed short v ): val(v)
T17( int16_t v ): val(v)
{
fval = (float)(v) / 100.0;
}
T17( unsigned short v ): val(v)
T17( uint16_t v ): val(v)
{
fval = (float)( (signed short)(v) ) / 100.0;
fval = (float)( (int16_t)(v) ) / 100.0;
}
T17( const ModbusRTU::ModbusData* data ): val(data[0])
......@@ -765,12 +766,12 @@ namespace uniset
{
return fval;
}
operator signed short()
operator int16_t()
{
return val;
}
signed short val = { 0 };
int16_t val = { 0 };
float fval = { 0 };
};
std::ostream& operator<<(std::ostream& os, T17& t );
......@@ -782,7 +783,7 @@ namespace uniset
/*! тип хранения в памяти */
typedef union
{
unsigned short v[2];
uint16_t v[2];
float val; //
} F1mem;
// ------------------------------------------
......@@ -791,7 +792,7 @@ namespace uniset
{
memset(raw.v, 0, sizeof(raw.v));
}
F1( unsigned short v1, unsigned short v2 )
F1( uint16_t v1, uint16_t v2 )
{
raw.v[0] = v1;
raw.v[1] = v2;
......
......@@ -38,25 +38,25 @@ TEST_CASE("VTypes: I2", "[vtypes][I2]")
SECTION("Default constructor")
{
I2 v;
REQUIRE( (int)v == 0 );
REQUIRE( (int32_t)v == 0 );
}
SECTION("'int' constructor")
{
I2 v(100);
REQUIRE( (int)v == 100 );
REQUIRE( (int32_t)v == 100 );
I2 v2(-1000000);
REQUIRE( (int)v2 == -1000000 );
REQUIRE( (int32_t)v2 == -1000000 );
}
SECTION("Modbus constructor")
{
ModbusRTU::ModbusData data[2] = {0, 0xFFFF};
I2 v1(data, 2);
REQUIRE( (int)v1 == -65536 );
REQUIRE( (int32_t)v1 == -65536 );
ModbusRTU::ModbusData data3[3] = {0, 0xFFFF, 0xFFFF};
I2 v2(data3, 3);
REQUIRE( (int)v2 == -65536 );
REQUIRE( (int32_t)v2 == -65536 );
}
}
// -----------------------------------------------------------------------------
......@@ -65,32 +65,32 @@ TEST_CASE("VTypes: I2r", "[vtypes][I2r]")
SECTION("Default constructor")
{
I2r v;
REQUIRE( (int)v == 0 );
REQUIRE( (int32_t)v == 0 );
}
SECTION("'int' constructor")
{
I2r v(100);
REQUIRE( (int)v == 100 );
REQUIRE( (int32_t)v == 100 );
I2r v1(-1000000);
REQUIRE( (int)v1 == -1000000 );
REQUIRE( (int32_t)v1 == -1000000 );
}
SECTION("Modbus constructor")
{
ModbusRTU::ModbusData data[2] = {0, 0xFFFF};
I2r v1(data, 2);
REQUIRE( (int)v1 == 65535 );
REQUIRE( (int32_t)v1 == 65535 );
ModbusRTU::ModbusData data3[3] = {0, 0xFFFF, 0xFFFF};
I2r v2(data3, 3);
REQUIRE( (int)v2 == 65535 );
REQUIRE( (int32_t)v2 == 65535 );
I2r tmp(-100000);
ModbusRTU::ModbusData d2[2];
d2[0] = tmp.raw.v[1];
d2[1] = tmp.raw.v[0];
I2r v3(d2, 2);
REQUIRE( (int)v3 == -100000 );
REQUIRE( (int32_t)v3 == -100000 );
}
}
......@@ -100,31 +100,31 @@ TEST_CASE("VTypes: U2", "[vtypes][U2]")
SECTION("Default constructor")
{
U2 v;
REQUIRE( (unsigned int)v == 0 );
REQUIRE( (uint32_t)v == 0 );
}
SECTION("'unsigned int' constructor")
{
{
U2 v( numeric_limits<unsigned int>::max() );
REQUIRE( (unsigned int)v == numeric_limits<unsigned int>::max() );
U2 v( numeric_limits<uint32_t>::max() );
REQUIRE( (uint32_t)v == numeric_limits<uint32_t>::max() );
REQUIRE( v.raw.v[0] == 0xffff );
REQUIRE( v.raw.v[1] == 0xffff );
}
{
U2 v(-1);
REQUIRE( (unsigned int)v == 4294967295 );
REQUIRE( (uint32_t)v == numeric_limits<uint32_t>::max() );
}
}
SECTION("Modbus constructor")
{
ModbusRTU::ModbusData data[2] = {0, 0xFFFF};
U2 v1(data, 2);
REQUIRE( (unsigned int)v1 == 0xffff0000 );
ModbusRTU::ModbusData data2[] = {0, 0xFFFF};
U2 v1(data2, 2);
REQUIRE( (uint32_t)v1 == 0xffff0000 );
ModbusRTU::ModbusData data3[3] = {0, 0xFFFF, 0xFFFF};
ModbusRTU::ModbusData data3[] = {0, 0xFFFF, 0xFFFF};
U2 v2(data3, 3);
REQUIRE( (unsigned int)v2 == 0xffff0000 );
REQUIRE( (uint32_t)v2 == 0xffff0000 );
}
}
// -----------------------------------------------------------------------------
......@@ -133,22 +133,22 @@ TEST_CASE("VTypes: U2r", "[vtypes][U2r]")
SECTION("Default constructor")
{
U2r v;
REQUIRE( (unsigned int)v == 0 );
REQUIRE( (uint32_t)v == 0 );
}
SECTION("'unsigned int' constructor")
{
U2r v( numeric_limits<unsigned int>::max() );
REQUIRE( (unsigned int)v == numeric_limits<unsigned int>::max() );
U2r v( numeric_limits<uint32_t>::max() );
REQUIRE( (uint32_t)v == numeric_limits<uint32_t>::max() );
}
SECTION("Modbus constructor")
{
ModbusRTU::ModbusData data[2] = {0, 0xFFFF};
U2r v1(data, 2);
REQUIRE( (unsigned int)v1 == 0x0000ffff );
REQUIRE( (uint32_t)v1 == 0x0000ffff );
ModbusRTU::ModbusData data3[3] = {0, 0xFFFF, 0xFFFF};
U2r v2(data3, 3);
REQUIRE( (unsigned int)v2 == 0x0000ffff );
REQUIRE( (uint32_t)v2 == 0x0000ffff );
}
}
......@@ -298,13 +298,13 @@ TEST_CASE("VTypes: Unsigned", "[vtypes][unsigned]")
{
long l = 0xffff;
Unsigned v(l);
REQUIRE( (unsigned short)v == 0xffff );
REQUIRE( (uint16_t)v == 0xffff );
}
SECTION("Modbus constructor")
{
ModbusRTU::ModbusData d = 65535;
Unsigned v(d);
REQUIRE( (unsigned short)v == 65535 );
REQUIRE( (uint16_t)v == 65535 );
}
}
// -----------------------------------------------------------------------------
......@@ -319,13 +319,13 @@ TEST_CASE("VTypes: Signed", "[vtypes][signed]")
{
long l = -32766;
Signed v(l);
REQUIRE( (signed short)v == l );
REQUIRE( (int16_t)v == l );
}
SECTION("Modbus constructor")
{
ModbusRTU::ModbusData d = 65535;
Signed v(d);
REQUIRE( (signed short)v == (signed short)d );
REQUIRE( (int16_t)v == (int16_t)d );
}
}
// -----------------------------------------------------------------------------
......@@ -14,8 +14,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// --------------------------------------------------------------------------
#ifndef _COMPORT_H_
#define _COMPORT_H_
#ifndef COMPORT_H_
#define COMPORT_H_
// --------------------------------------------------------------------------
#include <termios.h>
#include <fcntl.h>
......@@ -112,8 +112,8 @@ namespace uniset
virtual unsigned char receiveByte();
virtual void sendByte(unsigned char x);
virtual size_t receiveBlock(unsigned char* msg, size_t len);
virtual size_t sendBlock(unsigned char* msg, size_t len);
virtual size_t receiveBlock( unsigned char* msg, size_t len );
virtual ssize_t sendBlock( unsigned char* msg, size_t len );
void setBlocking(bool blocking);
......@@ -125,8 +125,8 @@ namespace uniset
static const size_t BufSize = 8192;
unsigned char buf[BufSize];
size_t curSym = { 0 };
size_t bufLength = { 0 };
ssize_t curSym = { 0 };
ssize_t bufLength = { 0 };
int fd = { -1 };
timeout_t uTimeout = { 0 };
bool waiting = { false };
......@@ -136,10 +136,10 @@ namespace uniset
virtual unsigned char m_receiveByte( bool wait );
private:
struct termios oldTermios = { 0 };
struct termios oldTermios;
};
// -------------------------------------------------------------------------
} // end of uniset namespace
// --------------------------------------------------------------------------
#endif // _COMPORT_H_
#endif // COMPORT_H_
// --------------------------------------------------------------------------
......@@ -39,11 +39,11 @@ namespace uniset
{
public:
ComPort485F( const std::string& comDevice, int gpio_num, bool tmit_ctrl = false );
ComPort485F( const std::string& comDevice, char gpio_num, bool tmit_ctrl = false );
virtual void sendByte( unsigned char x ) override;
virtual void setTimeout( timeout_t timeout ) override;
virtual size_t sendBlock( unsigned char* msg, size_t len ) override;
virtual ssize_t sendBlock( unsigned char* msg, size_t len ) override;
virtual void cleanupChannel() override;
virtual void reopen() override;
......@@ -51,8 +51,8 @@ namespace uniset
protected:
virtual unsigned char m_receiveByte( bool wait ) override;
void save2queue(unsigned char* msg, size_t len, size_t bnum );
bool remove_echo( unsigned char tb[], size_t len );
void save2queue( unsigned char* msg, size_t len, size_t bnum );
bool remove_echo( unsigned char tb[], ssize_t len );
void m_read( timeout_t tmsec );
/*! просто временный буфер для считывания данных */
......@@ -61,7 +61,7 @@ namespace uniset
std::queue<unsigned char> wq; /*!< хранилище байтов записанных в канал */
std::queue<unsigned char> rq; /*!< очередь для чтения */
int gpio_num;
char gpio_num;
bool tmit_ctrl_on;
PassiveTimer ptRecv;
timeout_t tout_msec = { 2000 };
......
......@@ -3,6 +3,7 @@
#define ModbusTypes_H_
// -------------------------------------------------------------------------
#include <ostream>
#include <cstdint>
#include <bitset>
#include <string>
#include <list>
......@@ -218,7 +219,7 @@ namespace uniset
return mbaphead.len;
}
unsigned char* buf();
u_int8_t* buf();
ModbusRTU::ModbusData len() const;
void swapHead();
void makeMBAPHeader( ModbusRTU::ModbusData tID, bool noCRC = true, ModbusRTU::ModbusData pID = 0 );
......
......@@ -220,7 +220,7 @@ void ComPort::setWaiting(bool waiting)
// Lav: сделать корректное определение таймаута
unsigned char ComPort::m_receiveByte( bool wait )
{
if(curSym >= bufLength)
if( curSym >= bufLength )
{
curSym = 0;
......@@ -246,7 +246,7 @@ unsigned char ComPort::m_receiveByte( bool wait )
else
bufLength = ::read(fd, buf, BufSize);
if(bufLength <= 0)
if( bufLength <= 0 )
{
throw uniset::TimeOut();
}
......@@ -305,7 +305,7 @@ timeout_t ComPort::getTimeout() const
// --------------------------------------------------------------------------------
// Lav: ситуация, когда отправлено меньше запрошенного, не типична и должна
// генерировать исключение
size_t ComPort::sendBlock(unsigned char* msg, size_t len)
ssize_t ComPort::sendBlock( unsigned char* msg, size_t len )
{
// fcntl(fd,F_SETFL,0);
......@@ -368,7 +368,7 @@ void ComPort::cleanupChannel()
while( k>0 );
*/
unsigned char tmpbuf[100];
int k = 0;
ssize_t k = 0;
bool old_waiting = waiting;
waiting = false;
int mask = fcntl(fd, F_GETFL);
......
......@@ -44,19 +44,19 @@ static void gpio_low_out_en( char gpio_num )
// --------------------------------------------------------------------------------
static void gpio_low_set_value( char gpio_num, char value )
{
unsigned long val;
unsigned int val;
val = inl(GPIO_BA);
if (value)
{
val |= (((unsigned long)1) << gpio_num);
val &= ~(((unsigned long)1) << (gpio_num + 16));
val |= (((unsigned int)1) << gpio_num);
val &= ~(((unsigned int)1) << (gpio_num + 16));
}
else
{
val &= ~(((unsigned long)1) << gpio_num);
val |= (((unsigned long)1) << (gpio_num + 16));
val &= ~(((unsigned int)1) << gpio_num);
val |= (((unsigned int)1) << (gpio_num + 16));
}
outl(val, GPIO_BA);
......@@ -77,7 +77,7 @@ static void setRTS(int fd, int state)
ioctl(fd, TIOCMSET, &status);
}
// --------------------------------------------------------------------------------
ComPort485F::ComPort485F( const string& dev, int gpio_num, bool tmit_ctrl ):
ComPort485F::ComPort485F( const string& dev, char gpio_num, bool tmit_ctrl ):
ComPort(dev, false),
gpio_num(gpio_num),
tmit_ctrl_on(tmit_ctrl)
......@@ -107,7 +107,7 @@ unsigned char ComPort485F::m_receiveByte( bool wait )
if( rq.empty() )
{
int rc = 0;
ssize_t rc = 0;
if( wait )
{
......@@ -163,7 +163,7 @@ unsigned char ComPort485F::m_receiveByte( bool wait )
return x;
}
// --------------------------------------------------------------------------------
size_t ComPort485F::sendBlock(unsigned char* msg, size_t len )
ssize_t ComPort485F::sendBlock(unsigned char* msg, size_t len )
{
if( tmit_ctrl_on )
{
......@@ -171,7 +171,7 @@ size_t ComPort485F::sendBlock(unsigned char* msg, size_t len )
gpio_low_set_value(gpio_num, 1);
}
size_t r = 0;
ssize_t r = 0;
try
{
......@@ -191,7 +191,7 @@ size_t ComPort485F::sendBlock(unsigned char* msg, size_t len )
m_read(2000);
}
}
catch( const uniset::Exception& ex )
catch( const uniset::Exception& )
{
if( tmit_ctrl_on )
{
......@@ -234,7 +234,7 @@ void ComPort485F::sendByte( unsigned char x )
wq.push(x);
m_read(2000);
}
catch( const uniset::Exception& ex )
catch( const uniset::Exception& )
{
if( tmit_ctrl_on )
{
......@@ -259,9 +259,9 @@ void ComPort485F::save2queue( unsigned char* msg, size_t len, size_t bnum )
wq.push(msg[i]);
}
// --------------------------------------------------------------------------------
bool ComPort485F::remove_echo( unsigned char tb[], size_t len )
bool ComPort485F::remove_echo( unsigned char tb[], ssize_t len )
{
size_t i = 0;
ssize_t i = 0;
while( !wq.empty() )
{
......
......@@ -119,7 +119,7 @@ namespace uniset
// Lav: отключил, раз не используем
#if 0
// -------------------------------------------------------------------------
static int get_crc_ccitt( uint16_t crc, uint8_t* buf, size_t size )
static int32_t get_crc_ccitt( uint16_t crc, uint8_t* buf, size_t size )
{
while( size-- )
{
......@@ -127,7 +127,7 @@ namespace uniset
crc = (crc << 8) ^ crc_ccitt_tab[ (crc >> 8) ^ * (buf++) ];
#else
register int i;
crc ^= (unsigned short)(*(buf++)) << 8;
crc ^= (uint16_t)(*(buf++)) << 8;
for (i = 0; i < 8; i++)
{
......@@ -146,7 +146,7 @@ namespace uniset
// -------------------------------------------------------------------------
/* CRC-16 is based on the polynomial x^16 + x^15 + x^2 + 1. Bits are */
/* sent LSB to MSB. */
static int get_crc_16( uint16_t crc, uint8_t* buf, size_t size )
static int32_t get_crc_16( uint16_t crc, uint8_t* buf, size_t size )
{
while( size-- )
......@@ -180,7 +180,7 @@ namespace uniset
*/
ModbusCRC ModbusRTU::checkCRC( ModbusByte* buf, size_t len )
{
unsigned short crc = 0xffff;
uint16_t crc = 0xffff;
crc = get_crc_16(crc, (uint8_t*)(buf), len);
// crc = SWAPSHORT(crc);
......@@ -219,7 +219,7 @@ namespace uniset
s << hex << showbase << setfill('0'); // << showbase;
for( size_t i = 0; i < len; i++ )
s << setw(2) << (short)(m[i]) << " ";
s << setw(2) << (int16_t)(m[i]) << " ";
return os << s.str();
}
......@@ -243,12 +243,12 @@ namespace uniset
memset(data, 0, sizeof(data));
}
// -------------------------------------------------------------------------
unsigned char* ModbusMessage::buf()
u_int8_t* ModbusMessage::buf()
{
if( mbaphead.len == 0 )
return (unsigned char*)&pduhead;
return (uint8_t*)&pduhead;
return (unsigned char*)&mbaphead;
return (uint8_t*)&mbaphead;
}
// -------------------------------------------------------------------------
ModbusData ModbusMessage::len() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment