Skip to content

Commit

Permalink
if STATE = null
Browse files Browse the repository at this point in the history
  • Loading branch information
elkinvg committed Dec 29, 2021
1 parent 222a096 commit 0171bdc
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 55 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# История изменений

- Выставление DevState = UNKNOWN, если значение DevState выходит за пределы, например, если не была инициализирована.

### 1.0.8 (20.07.2021)

- В случае ошибки при подписке на события, возвращаются отдельно сообщения об успешных, и отдельно об ошибочных. Для сообщений об ошибках используется структура ErrorInfo
Expand Down
9 changes: 0 additions & 9 deletions server_mode/WebSocketDS.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@

#include <tango.h>

// TODO: DELETE
//#include <chrono>

// TODO: WSTangoConn
//#include "common.h"
//#include "WSTangoConn.h"

#include "WSTangoConnSer.h"

/*----- PROTECTED REGION END -----*/ // WebSocketDS.h
Expand Down Expand Up @@ -99,8 +92,6 @@ class WebSocketDS : public TANGO_BASE_CLASS
private:
WSTangoConnSer* wsTangoConn;

// TODO: DELETE
//std::chrono::seconds timeFromUpdateData;
/*----- PROTECTED REGION END -----*/ // WebSocketDS::Data Members

// Device property data members
Expand Down
3 changes: 0 additions & 3 deletions src/wstangoproc_cli/EventProcCli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,6 @@ namespace WebSocketDS_ns {
return true;
}

// TODO: Может давать в аргументах по ссылке вместо
// const string & deviceName, const string & attrName,
// const string & precOpt, Tango::EventType eventType
ResponseFromEventReq EventProcCli::_addCallback(websocketpp::connection_hdl hdl, const string & deviceName, const string & attrName, const string & precOpt, Tango::EventType eventType)
{
ResponseFromEventReq resp;
Expand Down
43 changes: 24 additions & 19 deletions src/wstangoproc_common/TangoProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,17 +696,6 @@ namespace WebSocketDS_ns
json << "{";
auto attBegin = devAttrList->begin();
for (auto att = attBegin; att != devAttrList->end(); ++att) {
// Если задан niter для данного атрибута
// Вывод будет только если iterator кратно nIters
//Tango::DeviceAttribute att = attrList->at(i);

// TODO: FOR NITER Доделать, или убрать
//if (nIters.find(att.get_name()) != nIters.end()) {
// if (nIters[att.get_name()].first != 0) {
// if ((iterator + (nIters[att.get_name()].first - nIters[att.get_name()].second)) % nIters[att.get_name()].first != 0)
// continue;
// }
//}
if (att != attBegin)
json << ", ";

Expand Down Expand Up @@ -929,7 +918,7 @@ namespace WebSocketDS_ns
_extractFromPipeTmpl<string>(json, devPipe, precOpt, false);
}
break;
case Tango::DEVVAR_CHARARRAY: // ??? why not DEVVAR_CHARARRAY
case Tango::DEVVAR_CHARARRAY: // TODO: why not DEVVAR_CHARARRAY
{
json << NONE;
}
Expand Down Expand Up @@ -983,7 +972,14 @@ namespace WebSocketDS_ns
{
Tango::DevState state;
devPipe >> state;
json << "\"" << Tango::DevStateName[state] << "\"";
string stateStr;
if (state < Tango::DevState::ON || state > Tango::DevState::UNKNOWN) {
stateStr = Tango::DevStateName[Tango::DevState::UNKNOWN];
}
else {
stateStr = Tango::DevStateName[state];
}
json << "\"" << stateStr << "\"";
}
break;
case Tango::DEVVAR_BOOLEANARRAY:
Expand All @@ -994,7 +990,7 @@ namespace WebSocketDS_ns
case Tango::DEV_UCHAR:
{
json << NONE;
// ??? _extractFromPipeTmpl<Tango::DevUChar>(pipe, json, false);
// TODO: _extractFromPipeTmpl<Tango::DevUChar>(pipe, json, false);
}
break;
case Tango::DEV_LONG64:
Expand Down Expand Up @@ -1054,7 +1050,7 @@ namespace WebSocketDS_ns
{
case Tango::DEV_VOID:
break;
case Tango::DEV_BOOLEAN: // ??? not boolean?
case Tango::DEV_BOOLEAN: // TODO: not boolean?
{
deviceData = _getDeviceDataTmpl<Tango::DevBoolean>(inpStr);
}
Expand Down Expand Up @@ -1094,10 +1090,10 @@ namespace WebSocketDS_ns
deviceData = _generateDeviceDataFromArgin(inpStr);
}
break;
case Tango::DEVVAR_CHARARRAY: // ??? why not DEVVAR_CHARARRAY
case Tango::DEVVAR_CHARARRAY: // TODO: why not DEVVAR_CHARARRAY
{
// ??? !!! FOR DEVVAR_CHARARRAY
// ??? WHY unsigned char
// TODO: !!! FOR DEVVAR_CHARARRAY
// TODO: WHY unsigned char
deviceData = _getDeviceDataTmpl<unsigned char>(inpVecStr);
}
break;
Expand Down Expand Up @@ -1518,9 +1514,18 @@ namespace WebSocketDS_ns
json << noneComm;
break;
case Tango::DEV_STATE:
{
Tango::DevState stateIn;
string stateStr;
deviceData >> stateIn;
json << " \"" << Tango::DevStateName[stateIn] << "\"";
if (stateIn < Tango::DevState::ON || stateIn > Tango::DevState::UNKNOWN) {
stateStr = Tango::DevStateName[Tango::DevState::UNKNOWN];
}
else {
stateStr = Tango::DevStateName[stateIn];
}
json << " \"" << stateStr << "\"";
}
break;
case Tango::DEVVAR_BOOLEANARRAY:
// {
Expand Down
21 changes: 13 additions & 8 deletions src/wstangoproc_common/TangoProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ namespace WebSocketDS_ns
int type = devAttr->get_type();
std::vector<T> dataVector, dataVectorFromSet;
T data;
Tango::DevState stateIn;
string stateStr;

if (format == Tango::AttrDataFormat::SPECTRUM || format == Tango::AttrDataFormat::IMAGE)
json << "\"dimX\": " << devAttr->dim_x << ", ";
Expand All @@ -94,8 +92,15 @@ namespace WebSocketDS_ns
json << "\"data\": ";
if (format == Tango::AttrDataFormat::SCALAR) {
if (type == Tango::DEV_STATE) {
Tango::DevState stateIn;
string stateStr;
(*devAttr) >> stateIn;
stateStr = Tango::DevStateName[stateIn];
if (stateIn < Tango::DevState::ON || stateIn > Tango::DevState::UNKNOWN) {
stateStr = Tango::DevStateName[Tango::DevState::UNKNOWN];
}
else {
stateStr = Tango::DevStateName[stateIn];
}
_dataValueToStr(json, stateStr, precOpt);
}
else {
Expand Down Expand Up @@ -152,7 +157,7 @@ namespace WebSocketDS_ns
// default streamsize.
std::streamsize srsz = std::stringstream().precision();

// Ëÿìáäà-ôóíêöèÿ äëÿ ïîëó÷åíèÿ ÷èñëà äëÿ std::setprecision
// Лямбда-функция для получения числа для std::setprecision
auto get_srsz = [=](string fromOptStr) {
std::streamsize tmpsz = srsz;
if (fromOptStr != "") {
Expand Down Expand Up @@ -258,7 +263,7 @@ namespace WebSocketDS_ns
static Tango::DeviceData _getDeviceDataTmpl(const string& inputStr) {
T inp;
if (std::is_same<T, bool>::value) {
// åñëè íå òî è íå äðóãîå áóäåò êèíóòî èñêëþ÷åíèå
// если не то и не другое будет кинуто исключение
if (inputStr == "0" || inputStr == "false")
inp = false;
else if (inputStr == "1" || inputStr == "true")
Expand All @@ -277,7 +282,7 @@ namespace WebSocketDS_ns
inpVec.reserve(inputVecStr.size());
for (auto &val : inputVecStr) {
if (std::is_same<T, bool>::value) {
// åñëè íå òî è íå äðóãîå áóäåò êèíóòî èñêëþ÷åíèå
// если не то и не другое будет кинуто исключение
T inp;
if (val == "0" || val == "false") {
inp = false;
Expand All @@ -300,7 +305,7 @@ namespace WebSocketDS_ns
static void _getDataForDeviceAttribute(Tango::DeviceAttribute& devAttr, const string& inputStr) {
T inp;
if (std::is_same<T, bool>::value) {
// åñëè íå òî è íå äðóãîå áóäåò êèíóòî èñêëþ÷åíèå
// если не то и не другое будет кинуто исключение
if (inputStr == "0" || inputStr == "false")
inp = false;
else if (inputStr == "1" || inputStr == "true")
Expand All @@ -319,7 +324,7 @@ namespace WebSocketDS_ns
inpVec.reserve(inputVecStr.size());
for (auto &val : inputVecStr) {
if (std::is_same<T, bool>::value) {
// åñëè íå òî è íå äðóãîå áóäåò êèíóòî èñêëþ÷åíèå
// если не то и не другое будет кинуто исключение
T inp;
if (val == "0" || val == "false") {
inp = false;
Expand Down
1 change: 0 additions & 1 deletion src/wstangoproc_common/UserControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace WebSocketDS_ns
class UserControl
{
public:
// TODO: DELETE UserControl(string authDS, TYPE_OF_IDENT toi, bool isLogActive);
UserControl(string authDS);
~UserControl(){};

Expand Down
10 changes: 1 addition & 9 deletions src/wstangoproc_common/WSTangoConn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,13 @@ namespace WebSocketDS_ns
if (opt == "uselog") {
uc->setLogActive();
}
// TODO: ADD TO README
// TODO: Доделать и проверить useoldjson

if (opt == "useoldjson") {
_isOldVersionOfJson = true;
}
if (opt.find("tident") != string::npos) {
auto gettedIdentOpt = StringProc::parseInputString(opt, "=", true);
if (gettedIdentOpt.size() > 1) {
//if (gettedIdentOpt[1] == "rndid")
// typeOfIdent = TYPE_OF_IDENT::RANDIDENT;
if (gettedIdentOpt[1] == "smpl")
typeOfIdent = TYPE_OF_IDENT::SIMPLE;
// Для аутентификации в Егоровом AuthDS в check_permissions_www
Expand All @@ -83,31 +80,27 @@ namespace WebSocketDS_ns
}
}

// TODO: ADD TO README
if (opt.find("command_name_for_check_user") != string::npos) {
auto gettedIdentOpt = StringProc::parseInputString(opt, "=", true);
if (gettedIdentOpt.size() > 1) {
uc->setCommandNameForCheckUser(gettedIdentOpt[1]);
}
}

// TODO: ADD TO README
if (opt.find("command_name_for_check_permission") != string::npos) {
auto gettedIdentOpt = StringProc::parseInputString(opt, "=", true);
if (gettedIdentOpt.size() > 1) {
uc->setCommandNameForCheckPermission(gettedIdentOpt[1]);
}
}

// TODO: ADD TO README
if (opt.find("command_name_for_log") != string::npos) {
auto gettedIdentOpt = StringProc::parseInputString(opt, "=", true);
if (gettedIdentOpt.size() > 1) {
uc->setCommandNameForLog(gettedIdentOpt[1]);
}
}

// TODO: ADD TO README
if (opt.find("maxnconn") != string::npos) {
auto gettedIdentOpt = StringProc::parseInputString(opt, "=", true);
if (gettedIdentOpt.size() > 1) {
Expand All @@ -121,7 +114,6 @@ namespace WebSocketDS_ns
}
}

// TODO: ADD TO README
if (opt.find("maxbuffsize") != string::npos) {
auto gettedIdentOpt = StringProc::parseInputString(opt, "=", true);
if (gettedIdentOpt.size() > 1) {
Expand Down
4 changes: 1 addition & 3 deletions src/wstangoproc_common/WSThread_plain.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ namespace WebSocketDS_ns
#ifdef CLIENT_MODE
WSThread_plain(WSTangoConnCli *tc, int portNumber);
#endif
// TODO: DELETE WSThread_plain(WSTangoConn *tc, int portNumber);

~WSThread_plain();
virtual void *run_undetached(void *) override;
virtual void stop() override;
virtual void send_all(std::string msg) override;
virtual void send(websocketpp::connection_hdl hdl, std::string msg) override;
// Äëÿ áèíàðíûõ äàííûõ. Ïîêà íå èñïîëüçóåòñÿ.
// Для бинарных данных. Пока не используется.
// TODO: NOT USED virtual void send(websocketpp::connection_hdl hdl, const void *data, size_t len) override;
virtual bool on_validate(websocketpp::connection_hdl hdl) override;
private:
Expand Down
4 changes: 1 addition & 3 deletions src/wstangoproc_common/WSThread_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ namespace WebSocketDS_ns
#ifdef CLIENT_MODE
WSThread_tls(WSTangoConnCli *tc, int portNumber, string cert, string key);
#endif
// TODO: DELETE WSThread_tls(WSTangoConn *tc, int portNumber, string cert, string key);

~WSThread_tls();
virtual void *run_undetached(void *) override;

virtual void stop() override;
virtual void send_all(std::string msg) override;
virtual void send(websocketpp::connection_hdl hdl, std::string msg) override;
// Äëÿ áèíàðíûõ äàííûõ. Ïîêà íå èñïîëüçóåòñÿ.
// Для бинарных данных. Пока не используется.
// TODO: NOT USED virtual void send(websocketpp::connection_hdl hdl, const void *data, size_t len) override;
virtual bool on_validate(websocketpp::connection_hdl hdl) override;
private:
Expand Down

0 comments on commit 0171bdc

Please sign in to comment.