29.04.2014 - Version 0.4.0_prealpha. PICodeParser, namespace PICodeInfo, new tool "pip_cmg" in dir "code_model_generator". New feature in PIIODevice - "createFromFullPath", all parameters of all I/O devices now works with PIObjects`s properties.
This commit is contained in:
40
piserial.h
40
piserial.h
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
COM
|
||||
Copyright (C) 2013 Ivan Pelipenko peri4ko@gmail.com, Bychkov Andrey wapmobil@gmail.com
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com, Bychkov Andrey wapmobil@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -91,7 +91,9 @@
|
||||
#endif
|
||||
|
||||
|
||||
class PIP_EXPORT PISerial: public PIIODevice {
|
||||
class PIP_EXPORT PISerial: public PIIODevice
|
||||
{
|
||||
PIIODEVICE(PISerial)
|
||||
public:
|
||||
|
||||
//! Contructs an empty %PISerial
|
||||
@@ -134,36 +136,36 @@ public:
|
||||
|
||||
|
||||
//! Set both input and output speed to "speed"
|
||||
void setSpeed(PISerial::Speed speed) {ospeed = ispeed = speed; applySettings();}
|
||||
void setSpeed(PISerial::Speed speed) {setProperty("outSpeed", (int)speed); setProperty("inSpeed", (int)speed); applySettings();}
|
||||
|
||||
//! Set output speed to "speed"
|
||||
void setOutSpeed(PISerial::Speed speed) {ospeed = speed; applySettings();}
|
||||
void setOutSpeed(PISerial::Speed speed) {setProperty("outSpeed", (int)speed); applySettings();}
|
||||
|
||||
//! Set input speed to "speed"
|
||||
void setInSpeed(PISerial::Speed speed) {ispeed = speed; applySettings();}
|
||||
void setInSpeed(PISerial::Speed speed) {setProperty("inSpeed", (int)speed); applySettings();}
|
||||
|
||||
//! Set device name to "dev"
|
||||
void setDevice(const PIString & dev) {path_ = dev; if (isOpened()) {close(); open();};}
|
||||
void setDevice(const PIString & dev) {setPath(dev); if (isOpened()) {close(); open();};}
|
||||
|
||||
|
||||
//! Set parameters to "parameters_"
|
||||
void setParameters(PIFlags<PISerial::Parameters> parameters_) {params = parameters_; applySettings();}
|
||||
void setParameters(PIFlags<PISerial::Parameters> parameters_) {setProperty("parameters", (int)parameters_); applySettings();}
|
||||
|
||||
//! Set parameter "parameter" to "on" state
|
||||
void setParameter(PISerial::Parameters parameter, bool on = true) {params.setFlag(parameter, on); applySettings();}
|
||||
void setParameter(PISerial::Parameters parameter, bool on = true);
|
||||
|
||||
//! Returns if parameter "parameter" is set
|
||||
bool isParameterSet(PISerial::Parameters parameter) const {return params[parameter];}
|
||||
bool isParameterSet(PISerial::Parameters parameter) const;
|
||||
|
||||
//! Returns parameters
|
||||
PIFlags<PISerial::Parameters> parameters() const {return params;}
|
||||
PIFlags<PISerial::Parameters> parameters() const {return (PIFlags<Parameters>)(property("parameters").toInt());}
|
||||
|
||||
|
||||
//! Set data bits count. Valid range is from 5 to 8, befault is 8
|
||||
void setDataBitsCount(int bits) {dbits = bits; applySettings();}
|
||||
void setDataBitsCount(int bits) {setProperty("dataBitsCount", bits); applySettings();}
|
||||
|
||||
//! Returns data bits count
|
||||
int dataBitsCount() const {return dbits;}
|
||||
int dataBitsCount() const {return property("dataBitsCount").toInt();}
|
||||
|
||||
|
||||
//! Set pin number "number" to logic level "on". Valid numbers are 4 (DTR) and 7 (RTS)
|
||||
@@ -200,13 +202,13 @@ public:
|
||||
|
||||
|
||||
//! Returns device name
|
||||
const PIString & device() const {return path_;}
|
||||
PIString device() const {return path();}
|
||||
|
||||
//! Returns output speed
|
||||
PISerial::Speed outSpeed() const {return ospeed;}
|
||||
PISerial::Speed outSpeed() const {return (PISerial::Speed)(property("outSpeed").toInt());}
|
||||
|
||||
//! Returns input speed
|
||||
PISerial::Speed inSpeed() const {return ispeed;}
|
||||
PISerial::Speed inSpeed() const {return (PISerial::Speed)(property("inSpeed").toInt());}
|
||||
|
||||
int VTime() const {return vtime;}
|
||||
|
||||
@@ -271,17 +273,19 @@ public:
|
||||
//! \}
|
||||
|
||||
protected:
|
||||
PIString fullPathPrefix() const {return "ser";}
|
||||
void configureFromFullPath(const PIString & full_path);
|
||||
bool configureDevice(const void * e_main, const void * e_parent = 0);
|
||||
int write(const void * data, int max_size) {return write(data, max_size, true);}
|
||||
|
||||
//! Executes when any read function was successful. Default implementation does nothing
|
||||
virtual void received(const void * data, int size) {;}
|
||||
|
||||
void _init();
|
||||
void applySettings();
|
||||
int convertSpeed(PISerial::Speed speed);
|
||||
bool setBit(int bit, bool on, const PIString & bname);
|
||||
bool isBit(int bit, const PIString & bname) const;
|
||||
static bool headerValidate(void * d, uchar * src, uchar * rec, int size) {for (int i = 0; i < size; ++i) if (src[i] != rec[i]) return false; return true;}
|
||||
|
||||
bool openDevice();
|
||||
bool closeDevice();
|
||||
@@ -295,11 +299,9 @@ protected:
|
||||
termios desc, sdesc;
|
||||
uint readed;
|
||||
#endif
|
||||
int fd, vtime, dbits;
|
||||
int fd, vtime;
|
||||
bool block_read;
|
||||
PISerial::Speed ospeed, ispeed;
|
||||
PITimer timer;
|
||||
PIFlags<PISerial::Parameters> params;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user