1
/***************************************************************************
2
knutnet.cpp - description
5
copyright : (C) 2003 by Daniel Prynych
6
email : Daniel.Prynych@alo.cz
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
20
#include <qtextstream.h>
26
#include <sys/socket.h>
27
#include <sys/types.h>
29
#include <arpa/inet.h>
31
#include <netinet/in.h>
37
/****** KONSTANTY ***********/
39
const int rBufferLen = 1024;
43
KNutNet::KNutNet (const QString netAddress, const QString netName, const bool netProtocol, const unsigned short port, unsigned int countRepeat, const unsigned int delay, QObject *parent, const char *name) : QObject(parent,name), protocol(netProtocol) {
54
description = false; // popis neni natazen
56
upsAddress = netAddress;
59
if (upsAddress.isEmpty()) {
60
error = NullAddress; // jestlize addresa neexistuje koncime
66
// zjistime IP adresu - vynulujeme strukturu
67
bzero ((char *) &upsAddrServer, sizeof (upsAddrServer));
68
upsAddrServer.sin_family = AF_INET;
70
upsAddrServer.sin_port = htons(port);
71
QCString netAddress = upsAddress.local8Bit();
74
if ((returnAddress = inet_addr(netAddress.data())) == -1) {
75
// neni to teckova adresa zkusime jmenou
77
if ((phe = gethostbyname(netAddress.data())) != 0L)
78
bcopy(phe->h_addr,(char *)&upsAddrServer.sin_addr,phe->h_length); // adresa nalezena - prevedeme adresu
85
else upsAddrServer.sin_addr.s_addr = (unsigned long)returnAddress; // prevedeme adresu
86
// v upsAddrServer.sin_addr.s_addr mame ulozenou prevedenou adresu
88
// spojime se se serverem a vytvorime socket
89
if (protocol) socAddr = socket (AF_INET,SOCK_STREAM,0);
90
else socAddr = socket (AF_INET,SOCK_DGRAM,0);
96
// zkusime nekolikrat pripojit
97
countRepeat++; // maximalni pocet cyklu je pocet opakovani + 1
100
retVal = makeConnect(countRepeat, delay);
105
state = ConnectError;
108
int n = version (countRepeat, delay);
111
// pokud server pro pouziti UDP neodpovi zkusime jeste TCP
114
socAddr = socket (AF_INET,SOCK_STREAM,0);
115
countRepeat++; // maximalni pocet cyklu je pocet opakovani + 1
118
retVal = makeConnect(countRepeat, delay);
123
state = ConnectError;
126
protocol = !protocol;
128
// promena error je nastavena v procedure version
129
int n = version (countRepeat, delay);
132
state = ConnectError;
138
state = ConnectError;
143
if ((nutProtocol == 0) || (nutVariables == 0)) { // ansfer from upsd (VER) is unknown
145
error=NutProtocolVarErr;
146
state = ConnectError;
150
if ((nutProtocol == 2) && !protocol) { //ups > 1.3 doesn't support udp
152
socAddr = socket (AF_INET,SOCK_STREAM,0);
153
countRepeat++; // maximalni pocet cyklu je pocet opakovani + 1
156
retVal = makeConnect(countRepeat, delay);
161
state = ConnectError;
164
protocol = !protocol;
168
if ((nutProtocol == 2) && upsName.isEmpty()) {
169
if ((error =KNutNet::getFirstUpsName (upsName))) { // reading first upsName
171
state = ConnectError;
185
if (state == Connected) {
187
getUpsData (inBuffer,outBuffer);
194
int KNutNet::getError ( void ) { return error; }
196
int KNutNet::getState ( void ){ return state; }
198
bool KNutNet::isDescription ( void ){ return description; }
200
int KNutNet::getNutProtocol ( void ) { return nutProtocol; }
202
int KNutNet::getNutVariables ( void ) { return nutVariables; }
204
bool KNutNet::switchedToTCP ( void ) { return switchToTCP; }
207
int KNutNet::getUpsVars ( void) {
209
if (state == Connected) {
211
// init vars and lists
216
switch (nutProtocol) {
218
return getUpsVars1();
221
return getUpsVars2();
228
return NotConnection;
233
int KNutNet::getUpsValues (const bool allVars ) {// allVars = true vse; allVars = false jen activate
235
error=0; // vynulujeme chyby
236
if (state == Connected) {
237
// init vars and lists
238
switch (nutProtocol) {
240
return getUpsValues1(allVars);
243
return getUpsValues2(allVars);
250
return NotConnection;
256
int KNutNet::getDescription (bool always) {
258
error=0; // vynulujeme chyby
259
if (state == Connected) {
260
switch (nutProtocol) {
262
return getDescription1 (always);
265
return getDescription2 (always);
271
else return NotConnection;
275
int KNutNet::instantCommand (const QString command, const QString userName, const QString password, const bool onlyCommand) {
276
error=0; // vynulujeme chyby
277
if (state == Connected) {
278
// tuto cast pouzijem az uz nebudeme podporovat starsi verze KDE
279
// if (netMutex.locked()) {
280
// // proces bezi pockame na dokonceni
281
// netMutex.lock(); // cekame na volny pristup
285
if (netMutex) while (netMutex) {};
289
// funkce sendComm sama mastavi promenou error
291
if (!(error = sendComm("INSTCMD", command, "",true))) {
295
else { netMutex=false; return error;}
298
if (!(error = sendComm ("USERNAME", userName, ""))) {
299
if (!(error = sendComm("PASSWORD", password, ""))) {
300
if (!(error = sendComm("INSTCMD", command, "",true))) {
304
else { netMutex=false; return error;}
306
else { netMutex=false; return error;}
308
else { netMutex=false; return error;}
311
else return NotConnection;
315
int KNutNet::setVariable (const QString variable, const QString value, const QString userName, const QString password, const bool onlyVariable) {
316
error=0; // vynulujeme chyby
317
if (state == Connected) {
318
// tuto cast pouzijem az uz nebudeme podporovat starsi verze KDE
319
// if (netMutex.locked()) {
320
// // proces bezi pockame na dokonceni
321
// netMutex.lock(); // cekame na volny pristup
325
if (netMutex) while (netMutex) {};
330
switch (nutProtocol) {
331
case 1: setCommand = "SET";
333
case 2: setCommand = "SET VAR";
336
if (!(error = sendComm(setCommand, variable, value, true))) {
340
else { netMutex=false; return error;}
343
if (!(error = sendComm ("USERNAME", userName, ""))) {
344
if (!(error = sendComm("PASSWORD", password, ""))) {
345
if (!(error = sendComm(setCommand, variable, value, true))) {
349
else { netMutex=false; return error;}
351
else { netMutex=false; return error;}
353
else { netMutex=false; return error;}
356
else return NotConnection;
360
int KNutNet::readNumberVars (typeOfVar typVar) {
361
// Vraci pocet promenych
363
if (state == Connected) {
369
return numberVars - numberRWVars;
381
int KNutNet::readNumberComms (void) {
382
// Vraci pocet prikazu
384
if (state == Connected) return numberIComms;
389
int KNutNet::readIComm (const int seqNumber, struct upsIComm& iComm) {
391
if (state == Connected) {
392
#if defined (KDE_VERSION_MAJOR)
393
#if KDE_VERSION_MAJOR >= 3
394
if ((seqNumber < 1) || ((unsigned int)seqNumber > listIComms.size())) {
396
if ((seqNumber < 1) || ((unsigned int)seqNumber > listIComms.count())) {
399
if ((seqNumber < 1) || ((unsigned int)seqNumber > listIComms.count())) {
404
iComm = listIComms[seqNumber-1];
407
else return NotConnection;
411
int KNutNet::readVars (const QString name, struct upsVar& allVar) {
413
if (state == Connected) {
414
#if defined (KDE_VERSION_MAJOR)
415
#if KDE_VERSION_MAJOR >= 3
416
QValueVector<upsVar>::const_iterator it;
418
QValueList<upsVar>::ConstIterator it;
421
QValueList<upsVar>::ConstIterator it;
423
for (it = listVars.begin(); it != listVars.end(); it++) {
424
if ((*it).upsVarName == name) {
432
else return NotConnection;
435
int KNutNet::readVars (const int seqNumber, struct upsVar& allVar, const typeOfVar typVar) {
437
if (state == Connected) {
439
#if defined (KDE_VERSION_MAJOR)
440
#if KDE_VERSION_MAJOR >= 3
441
QValueVector<upsVar>::const_iterator it;
443
QValueList<upsVar>::ConstIterator it;
446
QValueList<upsVar>::ConstIterator it;
449
for (it = listVars.begin(); it != listVars.end(); it++) {
450
if ((typVar== AllVars) || ((typVar==ROVars) && ((*it).upsVarType)) ||
451
((typVar==RWVars) && (!(*it).upsVarType))) {
452
if (n == seqNumber) {
462
else return NotConnection;
466
QString KNutNet::readStringVar (const QString name) {
468
if (state == Connected) {
469
#if defined (KDE_VERSION_MAJOR)
470
#if KDE_VERSION_MAJOR >= 3
471
QValueVector<upsVar>::const_iterator it;
473
QValueList<upsVar>::ConstIterator it;
476
QValueList<upsVar>::ConstIterator it;
480
for (it = listVars.begin(); it != listVars.end(); it++) {
481
if ((*it).upsVarName == name) return (*it).upsValue;
490
QString KNutNet::readEnumValueVar (const QString name, const int valueNumber) {
492
if (state == Connected) {
493
#if defined (KDE_VERSION_MAJOR)
494
#if KDE_VERSION_MAJOR >= 3
495
QValueVector<upsVar>::const_iterator it;
497
QValueList<upsVar>::ConstIterator it;
500
QValueList<upsVar>::ConstIterator it;
504
for (it = listVars.begin(); it != listVars.end(); it++) {
505
if ((*it).upsVarName == name) {
506
if ((valueNumber < 1) || (valueNumber > (*it).upsVarMax)) {
507
error=EnumValueNotFind;
511
return (*(*it).upsEnumValues)[valueNumber-1];
521
int KNutNet::readStatus(void) {
527
int KNutNet::setActivate ( const QString name ) {
528
return activate (name,true);
532
int KNutNet::unSetActivate ( const QString name ) {
533
return activate (name,false);
537
int KNutNet::unSetActivateAll ( void ) {
538
return activateAll (false);
542
int KNutNet::existName ( const QString name ) {
544
if (state == Connected) {
545
#if defined (KDE_VERSION_MAJOR)
546
#if KDE_VERSION_MAJOR >= 3
547
QValueVector<upsVar>::const_iterator it;
549
QValueList<upsVar>::ConstIterator it;
552
QValueList<upsVar>::ConstIterator it;
554
for (it = listVars.begin(); it != listVars.end(); it++) {
555
if ((*it).upsVarName == name) return 0;
560
else return NotConnection;
563
/*************************************************************************/
565
/* PRIVATE FUNCTIONS */
567
/*************************************************************************/
569
int KNutNet::makeConnect (int countRepeat, const int delay) {
574
if (!( retVal = ::connect (socAddr,(struct sockaddr *)&upsAddrServer,sizeof(upsAddrServer)))) break;
576
if (countRepeat) sleep (delay);
578
while ((countRepeat));
583
int KNutNet::version (int countRepeat, const int delay) {
590
if (!(error=getUpsData (inBuffer,outBuffer))) {
591
outBuffer.stripWhiteSpace ();
593
if (outBuffer.length() > 0) {
594
outBuffer = outBuffer.mid(outBuffer.find("upsd")+4);
595
int n = outBuffer.find(".");
597
QString firstNumber= outBuffer.left(n);
598
QString secondNumber= outBuffer.mid(n+1);
599
int n = secondNumber.find(".");
602
secondNumber = secondNumber.left(n);
603
int secondInt = secondNumber.toInt(&ok);
604
if (!ok) {error = UnknownFormatVer; return error;}
605
int firstInt = firstNumber.toInt(&ok);
606
if (!ok) {error = UnknownFormatVer; return error;}
607
if ((firstInt == 0) || ((firstInt == 1) && (secondInt < 3))) {
617
else error = UnknownFormatVer;
619
else error = UnknownFormatVer;
621
error = UnknownAnswer;
625
if (countRepeat) sleep (delay);
627
while ((countRepeat));
633
int KNutNet::getFirstUpsName (QString& firstUpsName) {
636
QString varOutBuffer;
640
inBuffer = "LIST UPS\n";
641
if (!(error=getUpsData (inBuffer,outBuffer,"END LIST UPS"))) {
643
QString inLine, upsNameRet, varName, value;
645
bool beginList = false;
646
QTextIStream varInputStream(&outBuffer);
647
while (!(inLine = varInputStream.readLine()).isNull()) {
648
key = parseLine (inLine, upsNameRet, varName, value, typeValue, lenString);
650
case BEGIN_LIST_UPS: {
656
firstUpsName = upsNameRet;
664
error = upsTranslateError(value);
672
else {error=NoData; return error; }
678
int KNutNet::setKey (const QString line) {
679
line.stripWhiteSpace();
680
if (line == "OK") return OK;
681
if (line == "ERR") return ERR;
682
if (line == "BEGIN") return BEGIN;
683
if (line == "END") return END;
684
if (line == "VAR") return VAR;
685
if (line == "TYPE") return TYPE;
686
if (line == "DESC") return DESC;
687
if (line == "CMDDESC") return CMDDESC;
688
if (line == "UPSDESC") return CMDDESC;
689
if (line == "UPS") return UPS;
690
if (line == "LIST") return LIST;
691
if (line == "RW") return RW;
692
if (line == "CMD") return CMD;
693
if (line == "ENUM") return ENUM;
694
if (line == "STARTTLS") return STARTTLS;
698
QString KNutNet::parseValue (const QString line) {
699
line.stripWhiteSpace();
700
if (line.isEmpty()) return "";
701
if (line[0] != "\"") {
702
if ((posChar=line.find(' ')) == -1) return line;
703
else return line.left(posChar+1);
706
int len = line.length();
707
QString outString = "";
708
for (int i=1; i < len; i++) {
709
if ( line[i] == "\\") {
711
if ((line[i+1] == "\"") || (line[i+1] == "\"")) {
712
outString +=line[i+1];
720
if (line [i] == "\"") {
723
outString += line[i];
730
int KNutNet::parseTypeValue (QString line, int& lenString ) {
735
if (line.isEmpty()) return 0;
736
QTextIStream inputStream(&line);
737
while (!inputStream.atEnd()) {
739
if (word == "RW") ret += RW_FLAG;
740
if (word == "ENUM") ret += ENUM_FLAG;
741
if (word.find("STRING:") != -1) {
744
lenString = word.toInt();
751
int KNutNet::parseLine(QString& line, QString& upsName ,QString& varName, QString& value, int& typeValue, int& lenString) {
753
QString word1, word2, word3;
754
int key1, key2, key3;
756
line = line.stripWhiteSpace();
763
if (line.isEmpty()) return NONE;
765
if ((posChar=line.find(' ')) == -1) {
766
if (setKey(line) == OK) return OK;
770
key1 = setKey( line.left(posChar));
771
line = line.mid(posChar+1);
780
value = parseValue(line);
783
if ((posChar=line.find(' ')) == -1) return NONE;
784
word2 = line.left(posChar);
785
key2 = setKey( word2);
786
line = line.mid(posChar+1);
790
if ((key2 == LIST) && (setKey(line) == UPS)) return BEGIN_LIST_UPS;
793
if ((key2 == LIST) && (setKey(line) == UPS)) return END_LIST_UPS;
797
value = parseValue(line);
801
varName = parseValue(line);
805
if ((posChar=line.find(' ')) == -1) return NONE;
807
word3 = line.left(posChar);
808
key3 = setKey( word3);
809
line = line.mid(posChar+1);
815
value = parseValue(line);
820
typeValue = parseTypeValue(line,lenString);
825
value = parseValue(line);
830
value = parseValue(line);
835
value = parseValue(line);
838
if (key2 != LIST) return NONE;
840
upsName=line.stripWhiteSpace();
841
return BEGIN_LIST_VAR;
844
upsName=line.stripWhiteSpace();
845
return BEGIN_LIST_RW;
848
upsName=line.stripWhiteSpace();
849
return BEGIN_LIST_CMD;
852
if ((posChar=line.find(' ')) == -1) return NONE;
853
upsName = line.left(posChar);
854
line=line.mid(posChar+1);
855
varName = line.stripWhiteSpace();
856
return BEGIN_LIST_ENUM;
860
if (key2 != LIST) return NONE;
862
upsName=line.stripWhiteSpace();
866
upsName=line.stripWhiteSpace();
870
upsName=line.stripWhiteSpace();
874
if ((posChar=line.find(' ')) == -1) return NONE;
875
upsName = line.left(posChar);
876
line=line.mid(posChar+1);
877
varName = line.stripWhiteSpace();
878
return END_LIST_ENUM;
889
int KNutNet::newDescription (const QCString inBuffer, QString& upsDescription) {
892
if (!(error=getUpsData (inBuffer,outBuffer))) {
893
outBuffer.stripWhiteSpace ();
894
QString word1, word2, word3;
896
if ((posChar = outBuffer.find(' ')) == -1)
899
word1 = outBuffer.left(posChar);
900
word2 = outBuffer.mid(posChar+1);
902
if (word1 == "DESC") {
903
if ((posChar = word2.find('\"')) == -1) word3="";
906
word3 = word2.mid(posChar+1);
907
if ((posChar = word3.find('\"')) != -1) word3=word3.left(posChar);
909
if (!word3.isEmpty()) upsDescription=word3;
912
if (word1 == "ERR" ) return upsTranslateError(word2);
913
else return UnknownAnswer;
923
int KNutNet::getUpsData (const QCString sBuffer, QString& rBuffer, const QCString endString) {
925
//rbuffer_len a sbuffer_len udavaji maximalni velikost bufferu
926
int selectReturn; // navratova hodnota selectu
927
struct timeval upsTimeout; // struktura pro cas cekani na ukazatel
928
QCString recvBuffer(rBufferLen);
933
// nastavime vsechny ukazatele na nulu
935
// nastavime reakci na nas socket
936
FD_SET (socAddr,&fdUps);
938
upsTimeout.tv_usec=0;
941
while ((sr = select (socAddr+1,(fd_set *)&fdUps,(fd_set *)0L,(fd_set *)0L,&upsTimeout)) >0) {
942
recv (socAddr,recvBuffer.data(),rBufferLen, 0);
943
if (recvBuffer.length() == 0) break;
944
if (n > 20) break; else n++;
945
// obslouzime dve varianty: -1 data neprisla a 0 delka dat je nule
946
// Nikdy necteme vice nez 20 polozek
949
if (send(socAddr,sBuffer.data(),sBuffer.length(),0) < 0 ) return SendErr;
951
rBuffer=""; // vycistime buffer;
953
int numberOfEINTR = 0;
955
// nastavime vsechny ukazatele na nulu
957
// nastavime reakci na nas socket
958
FD_SET (socAddr,&fdUps);
960
upsTimeout.tv_sec=upsGetTimeout1;
961
upsTimeout.tv_usec=0;
962
if ((selectReturn = select (socAddr+1,(fd_set *)&fdUps,(fd_set *)0L,(fd_set *)0L,&upsTimeout)) <0 )
964
if ((errno == EINTR) && (numberOfEINTR < 10)) {
968
else return SelectErr;
971
while (selectReturn < 0);
973
if (( ! protocol ) && ( ! selectReturn )) {
974
// zajima nas selectReturn = 0 zaporne hodnoty jsme uz odfiltrovali
975
// posleme jeste jeden paket
976
if (send (socAddr,sBuffer.data(),sBuffer.length(), 0)<0) return SendErr;
977
int numberOfEINTR = 0;
979
// nastavime vsechny ukazatele na nulu
981
// nastavime reakci na nas socket
982
FD_SET (socAddr,&fdUps);
984
upsTimeout.tv_sec=upsGetTimeout2;
985
upsTimeout.tv_usec=0;
986
if ((selectReturn = select (socAddr+1,(fd_set *)&fdUps,(fd_set *)0L,(fd_set *)0L,&upsTimeout)) <0 )
988
if ((errno == EINTR) && (numberOfEINTR < 10)) {
992
else return SelectErr;
995
while (selectReturn < 0);
996
} // end if (( ! protocol........
997
if ( !selectReturn) return NoServerData; // opet neprisli zadna data
999
bool endRecv = false;
1001
recvBuffer.fill('\0',rBufferLen); // vyplnime string mezarami
1002
if (recv (socAddr,recvBuffer.data(),rBufferLen, 0) <0 ) return RecvErr;
1003
rBuffer.append(recvBuffer.data()); // pripojime
1004
if (endString.isEmpty()) endRecv = false;
1006
if (recvBuffer.findRev(endString) == -1) {
1007
// nastavime vsechny ukazatele na nulu
1009
// nastavime reakci na nas socket
1010
FD_SET (socAddr,&fdUps);
1011
// nastavime timeout
1012
upsTimeout.tv_sec=upsGetTimeout3;
1013
upsTimeout.tv_usec=0;
1014
selectReturn = select (socAddr+1,(fd_set *)&fdUps,(fd_set *)0L,(fd_set *)0L,&upsTimeout);
1015
if (selectReturn < 0) return SelectErr;
1017
if (selectReturn==0) endRecv=false; //select vraci 0 kdyz nic neprislo
1021
else endRecv = false; // nalezen ocekavany konec
1027
// nastavime vsechny ukazatele na nulu
1028
// FD_ZERO (&fdUps);
1029
// nastavime reakci na nas socket
1030
// FD_SET (socAddr,&fdUps);
1031
// upsTimeout.tv_sec=0;
1032
// upsTimeout.tv_usec=0;
1033
// while (select (socAddr+1,(fd_set *)&fdUps,(fd_set *)0L,(fd_set *)0L,&upsTimeout) >0) {
1034
// recv (socAddr,recvBuffer.data(),rBufferLen, 0);
1039
// definice setRWVVars
1040
#if defined (KDE_VERSION_MAJOR)
1041
#if KDE_VERSION_MAJOR >= 3
1042
void KNutNet::setRWVars (const QString varName, const bool valueType, const int varMax, QValueVector<QString>* enumValues) {
1044
void KNutNet::setRWVars (const QString varName, const bool valueType, const int varMax, QValueList<QString>* enumValues) {
1047
void KNutNet::setRWVars (const QString varName, const bool valueType, const int varMax, QValueList<QString>* enumValues) {
1049
#if defined (KDE_VERSION_MAJOR)
1050
#if KDE_VERSION_MAJOR >= 3
1051
QValueVector<upsVar>::iterator it;
1053
QValueList<upsVar>::Iterator it;
1056
QValueList<upsVar>::Iterator it;
1058
for (it = listVars.begin(); it != listVars.end(); it++) {
1059
if ((*it).upsVarName == varName) {
1060
(*it).upsVarMax = varMax;
1061
(*it).upsValueType=valueType;
1062
(*it).upsEnumValues=enumValues;
1063
(*it).upsVarType=false;
1069
void KNutNet::upsSetType (struct upsVar& uVar, const QString name, const QString value) {
1070
if (((nutVariables = 2) && (name == "STATUS")) || ((nutVariables = 2) && (name == "ups.status")))
1071
uVar.upsVarActivate=true;
1072
else uVar.upsVarActivate=false;
1073
uVar.upsVarName = name;
1074
uVar.upsVarType=true;
1075
uVar.upsValueType=true;
1077
uVar.upsValue=value;
1078
uVar.upsDescription="";
1079
uVar.upsEnumValues=0L;
1083
void KNutNet::deleteVars (void) {
1084
#if defined (KDE_VERSION_MAJOR)
1085
#if KDE_VERSION_MAJOR >= 3
1086
QValueVector<upsVar>::iterator it;
1088
QValueList<upsVar>::Iterator it;
1091
QValueList<upsVar>::Iterator it;
1093
for (it = listVars.begin(); it != listVars.end(); it++) {
1094
if ((*it).upsEnumValues != 0) {
1095
(*it).upsEnumValues->clear();
1096
delete (*it).upsEnumValues;
1103
void KNutNet::genStatusFlags (QString value) {
1105
QTextIStream inputStream(&value);
1107
while (!inputStream.atEnd()) {
1108
inputStream >> word;
1109
if (word == "OFF") upsStatusVar +=OFF;
1110
if (word == "OL") upsStatusVar +=OL;
1111
if (word == "OB") upsStatusVar +=OB;
1112
if (word == "LB") upsStatusVar +=LB;
1113
if (word == "CAL") upsStatusVar +=CAL;
1114
if (word == "TRIM") upsStatusVar +=TRIM;
1115
if (word == "BOOST") upsStatusVar +=BOOST;
1116
if (word == "OVER") upsStatusVar +=OVER;
1117
if (word == "RB") upsStatusVar +=RB;
1118
//OFF - 1 ups je vypnuta
1119
//OL - 2 ups je bezi na sit
1120
//OB - 4 ups bezi na baterie
1121
//LB - 8 baterie je vybyta (pokud je zaroven OB dojde k shutdownu)
1122
//CAL - 16 je spustena kalibrace
1123
//OVER -128 ups je pretizena
1124
//RB -256 ups pozaduje vymenu baterie
1129
int KNutNet::getDescription1 (bool always) {
1131
if (always || (! description)) {
1132
// tuto cast pouzijem az uz nebudeme podporovat starsi verze KDE
1133
// if (netMutex.locked()) {
1134
// // proces bezi pockame na dokonceni
1135
// // nema vyznam ho znovu cist
1136
// netMutex.lock(); // cekame na volny pristup
1137
// netMutex.unlock();
1142
if (netMutex) while (netMutex) {};
1147
#if defined (KDE_VERSION_MAJOR)
1148
#if KDE_VERSION_MAJOR >= 3
1149
QValueVector<upsVar>::iterator itv;
1150
QValueVector<upsIComm>::iterator itc;
1152
QValueList<upsVar>::Iterator itv;
1153
QValueList<upsIComm>::Iterator itc;
1156
QValueList<upsVar>::Iterator itv;
1157
QValueList<upsIComm>::Iterator itc;
1159
for (itv = listVars.begin(); itv != listVars.end(); itv++) {
1161
inBuffer = "VARDESC " + (*itv).upsVarName + "\n";
1162
if ((error = newDescription (inBuffer, (*itv).upsDescription))) {
1163
//netMutex.unlock();
1168
for (itc = listIComms.begin(); itc != listIComms.end(); itc++) {
1170
inBuffer = "INSTCMDDESC "+(*itc).upsCommName+"\n";
1171
if ((error = newDescription (inBuffer, (*itc).upsDescription))) {
1172
//netMutex.unlock();
1185
int KNutNet::getDescription2 (bool always) {
1187
if (always || (! description)) {
1188
// tuto cast pouzijem az uz nebudeme podporovat starsi verze KDE
1189
// if (netMutex.locked()) {
1190
// // proces bezi pockame na dokonceni
1191
// // nema vyznam ho znovu cist
1192
// netMutex.lock(); // cekame na volny pristup
1193
// netMutex.unlock();
1198
if (netMutex) while (netMutex) {};
1208
#if defined (KDE_VERSION_MAJOR)
1209
#if KDE_VERSION_MAJOR >= 3
1210
QValueVector<upsVar>::iterator itv;
1211
QValueVector<upsIComm>::iterator itc;
1213
QValueList<upsVar>::Iterator itv;
1214
QValueList<upsIComm>::Iterator itc;
1217
QValueList<upsVar>::Iterator itv;
1218
QValueList<upsIComm>::Iterator itc;
1220
for (itv = listVars.begin(); itv != listVars.end(); itv++) {
1222
inBuffer = "GET DESC " + upsName + " " + (*itv).upsVarName+"\n";
1224
if (!(error=getUpsData (inBuffer,outBuffer))) {
1225
outBuffer.stripWhiteSpace ();
1226
if ( !outBuffer.isEmpty() ) {
1227
int key = parseLine(outBuffer, upsNameRet, varName, value, typeValue, lenString);
1230
(*itv).upsDescription = value;
1233
error=upsTranslateError(value);
1234
//netMutex.unlock();
1238
error=UnknownAnswer;
1239
//netMutex.unlock();
1244
else {error = NoData; netMutex=false; return error;}
1246
else {netMutex=false; return error;}
1248
for (itc = listIComms.begin(); itc != listIComms.end(); itc++) {
1250
inBuffer = "GET CMDDESC " + upsName + " " + (*itc).upsCommName+"\n";
1251
if (!(error=getUpsData (inBuffer,outBuffer))) {
1252
outBuffer.stripWhiteSpace ();
1253
if ( !outBuffer.isEmpty() ) {
1254
int key = parseLine(outBuffer, upsNameRet, varName, value, typeValue, lenString);
1257
(*itc).upsDescription = value;
1260
error=upsTranslateError(value);
1261
//netMutex.unlock();
1265
error=UnknownAnswer;
1266
//netMutex.unlock();
1271
else {error = NoData; netMutex=false; return error;}
1273
else {netMutex=false; return error;}
1283
int KNutNet::getUpsVars1 ( void) {
1284
// getUpsVars nacte promene a jejich typ
1285
// vraci kod chyby nebo 0 pokud je vse v poradku
1288
QString varOutBuffer;
1289
struct upsVar uVars;
1292
// init vars and lists
1293
if (!upsName.isEmpty()) { // pokud upsName neni je vzdy nastaveno na null
1294
inBuffer="LISTVARS ";
1295
inBuffer.append(upsName);
1296
inBuffer.append("\n");
1298
else inBuffer ="LISTVARS\n";
1300
if (!(error=getUpsData (inBuffer,outBuffer))) {
1301
outBuffer.stripWhiteSpace ();
1302
if (outBuffer.length() > 0) {
1304
QTextIStream inputStream(&outBuffer);
1307
while (!inputStream.atEnd()) {
1308
inputStream >> word;
1311
// vyndame prvni polozku
1312
if (word == "VARS") count++;
1314
if (word == "ERR") {
1315
inputStream >> word;
1316
error = upsTranslateError(word);
1318
else error=UnknownAnswer;
1324
if ((word.length() > 0) && word.startsWith("@")) break;
1326
// pridame polozku do tabulky
1327
upsSetType(uVars, word);
1328
#if defined (KDE_VERSION_MAJOR)
1329
#if KDE_VERSION_MAJOR >= 3
1330
listVars.push_back(uVars);
1332
listVars.append(uVars);
1335
listVars.append(uVars);
1342
else { error=NoData; return error; }
1346
if ((error = getUpsValues1(true))) return error;
1348
// *********** RW VARIABLES
1349
if (!upsName.isEmpty()) { // pokud upsName neni je vzdy nastaveno na null
1351
inBuffer.append(upsName);
1352
inBuffer.append("\n");
1354
else inBuffer ="LISTRW\n";
1356
if (!(error=getUpsData (inBuffer,outBuffer))) {
1357
outBuffer.stripWhiteSpace();
1358
if (!outBuffer.isEmpty()) {
1360
QTextIStream inputStream(&outBuffer);
1365
while (!inputStream.atEnd()) {
1366
inputStream >> word;
1369
// vyndame prvni polozku
1370
if (word == "RW") count++;
1372
if (word == "ERR") {
1373
inputStream >> word;
1374
error = upsTranslateError(word);
1376
else error=UnknownAnswer;
1382
if ((word.length() > 0) && word.startsWith("@")) break;
1384
// Zpracujeme polozku v tabulce
1385
// zjistime informaci o promene
1386
inBuffer="VARTYPE ";
1387
inBuffer.append(word);
1388
if (!upsName.isEmpty()) {
1389
inBuffer.append("@"); // pokud upsName neni je vzdy nastaveno na null
1390
inBuffer.append(upsName);
1392
inBuffer.append("\n");
1393
if (!(error=getUpsData (inBuffer,varOutBuffer))) {
1394
varOutBuffer.stripWhiteSpace();
1395
if ( !outBuffer.isEmpty() ) {
1396
QTextIStream varInputStream(&varOutBuffer);
1397
QString word1, word2, word3;
1398
varInputStream >> word1;
1399
varInputStream >> word2;
1400
varInputStream >> word3;
1401
if (word1 == "TYPE") {
1402
if ((word2.isEmpty()) || (word3.isEmpty())) {
1403
error=UnknownFormat;
1406
if (word2 == "ENUM") valueType=false;
1408
if (word2 =="STRING") valueType=true;
1410
error=UnknownFormat;
1415
varMax=word3.toInt(&ok);
1416
if (!ok) {error=UnknownFormat; return error;};
1420
error = upsTranslateError(word2);
1424
error = UnknownAnswer;
1429
else { error=NoData; return error; }
1432
// ********** ENUM / STRING ******************
1434
#if defined (KDE_VERSION_MAJOR)
1435
#if KDE_VERSION_MAJOR >= 3
1436
QValueVector<QString>* enumString=0;
1438
QValueList<QString>* enumString=0;
1441
QValueList<QString>* enumString=0;
1445
// nacteme enum hodnoty
1447
inBuffer.append(word);
1448
// pokud existuje pridame jmeno UPS-ky
1449
if (!upsName.isEmpty()) {
1450
inBuffer.append("@");
1451
inBuffer.append(upsName);
1453
inBuffer.append("\n");
1454
if (!(error=getUpsData (inBuffer,varOutBuffer,"END\n"))) {
1455
// varOutBuffer.stripWhiteSpace(); nemuze provest protoze bychom si odstranili konce radek
1456
if (!varOutBuffer.isEmpty()) {
1457
QString inLine, word1, word2;
1458
QTextIStream varInputStream(&varOutBuffer);
1460
while (!(inLine = varInputStream.readLine()).isNull()) {
1461
inLine.stripWhiteSpace();
1463
if ((posChar=inLine.find(' ')) == -1) word1=inLine;
1465
word1=inLine.left(posChar);
1466
inLine = inLine.mid(posChar+1);
1468
if (word1.isEmpty()) { error = UnknownFormat; return error; }
1469
if (inCountLine == 1) {
1470
if ((posChar=inLine.find(' ')) == -1) word2=inLine;
1471
else word2=inLine.left(posChar);
1472
if (word1 =="ENUM") {
1473
if (word2 != word) { error = UnknownFormat; return error; }
1476
#if defined (KDE_VERSION_MAJOR)
1477
#if KDE_VERSION_MAJOR >= 3
1478
enumString = new QValueVector<QString>;
1480
enumString = new QValueList<QString>;
1483
enumString = new QValueList<QString>;
1485
enumString->clear();
1489
error=upsTranslateError(word2); // prevede chybu na jeji kod
1490
else error=UnknownAnswer;
1495
if (word1 == "END") break;
1496
if (word1 != "OPTION") { error = UnknownFormat; return error; }
1497
if ((posChar = inLine.find('\"')) == -1) word2 = "";
1499
word2 = inLine.mid(posChar+1);
1500
if ((posChar=word2.find('\"')) != -1) word2 = word2.left(posChar);
1502
#if defined (KDE_VERSION_MAJOR)
1503
#if KDE_VERSION_MAJOR >= 3
1504
enumString->push_back(word2);
1506
enumString->append(word2);
1509
enumString->append(word2);
1514
} // buffer is not empty
1515
else { error = NoData ; return error; }
1519
else enumString = 0l;
1520
// nacteme stringovou promenou
1522
setRWVars (word,valueType,varMax,enumString);
1526
} // end while (!inputStream.atEnd())
1528
else { error = NoData ; return error; }
1532
// *************** INSTANT COMMAND
1533
if (!upsName.isEmpty()) { // pokud upsName neni je vzdy nastaveno na null
1534
inBuffer="LISTINSTCMD ";
1535
inBuffer.append(upsName);
1536
inBuffer.append("\n");
1538
else inBuffer ="LISTINSTCMD\n";
1540
if (!(error=getUpsData (inBuffer,outBuffer))) {
1541
outBuffer.stripWhiteSpace ();
1542
if ( !outBuffer.isEmpty() ) {
1544
QTextIStream inputStream(&outBuffer);
1547
while (!inputStream.atEnd()) {
1548
inputStream >> word;
1551
// vyndame prvni polozku
1552
if (word == "INSTCMDS") count++;
1554
if (word == "ERR") {
1555
inputStream >> word;
1556
error = upsTranslateError(word);
1558
else error=UnknownAnswer;
1564
if ((word.length() > 0) && word.startsWith("@")) break;
1566
// Zpracujeme polozku v tabulky
1567
uIComm.upsCommName=word;
1568
uIComm.upsDescription="";
1569
#if defined (KDE_VERSION_MAJOR)
1570
#if KDE_VERSION_MAJOR >= 3
1571
listIComms.push_back(uIComm);
1573
listIComms.append(uIComm);
1576
listIComms.append(uIComm);
1583
else { error=NoData; return error; }
1591
int KNutNet::getUpsVars2 ( void) {
1594
QString varOutBuffer;
1595
struct upsVar uVars;
1602
#if defined (KDE_VERSION_MAJOR)
1603
#if KDE_VERSION_MAJOR >= 3
1604
QValueVector<QString>* enumString=0;
1606
QValueList<QString>* enumString=0;
1609
QValueList<QString>* enumString=0;
1611
inBuffer = "LIST VAR " + upsName + "\n";
1612
if (!(error=getUpsData (inBuffer,outBuffer,"END LIST VAR"))) {
1613
QString inLine, upsNameRet, varName, varNameRet, value;
1614
bool beginList = false;
1615
QTextIStream varInputStream(&outBuffer);
1616
while (!(inLine = varInputStream.readLine()).isNull()) {
1617
key = parseLine (inLine, upsNameRet, varName, value, typeValue, lenString);
1619
case BEGIN_LIST_VAR:
1620
if (upsNameRet == upsName) beginList = true;
1624
upsSetType(uVars, varName, value);
1626
if (varName == "ups.status") genStatusFlags(value);
1627
inBuffer = "GET TYPE " + upsName + " " + varName +"\n";
1628
if (!(error=getUpsData (inBuffer,varOutBuffer))) {
1629
key = parseLine (varOutBuffer, upsNameRet, varNameRet, value, typeValue, lenString);
1632
if (typeValue & RW_FLAG) {
1633
uVars.upsVarMax = 0;
1634
uVars.upsEnumValues=0L;
1635
if (typeValue & ENUM_FLAG) {
1636
uVars.upsValueType=false;
1637
// nacteme enumValues
1638
inBuffer = "LIST ENUM " + upsName + " " + varName +"\n";
1639
if (!(error=getUpsData (inBuffer,varOutBuffer,"END LIST ENUM"))) {
1640
bool beginEnumList = false;
1641
QTextIStream varInputStream(&varOutBuffer);
1642
while (!(inLine = varInputStream.readLine()).isNull()) {
1643
key = parseLine (inLine, upsNameRet, varName, value, typeValue, lenString);
1645
case BEGIN_LIST_ENUM:
1646
beginEnumList = true;
1648
#if defined (KDE_VERSION_MAJOR)
1649
#if KDE_VERSION_MAJOR >= 3
1650
enumString = new QValueVector<QString>;
1652
enumString = new QValueList<QString>;
1655
enumString = new QValueList<QString>;
1657
enumString->clear();
1658
uVars.upsEnumValues=enumString;
1662
#if defined (KDE_VERSION_MAJOR)
1663
#if KDE_VERSION_MAJOR >= 3
1664
enumString->push_back(value);
1666
enumString->append(value);
1669
enumString->append(value);
1675
error = upsTranslateError(value);
1678
error=UnknownAnswer;
1681
uVars.upsVarMax=varMax;
1688
// Vse co nenini ENUM je STRING
1689
uVars.upsValueType=true;
1690
uVars.upsVarMax=lenString;
1692
uVars.upsVarType=false;
1697
error = upsTranslateError(value);
1700
error=UnknownAnswer;
1704
else { return error; }
1705
#if defined (KDE_VERSION_MAJOR)
1706
#if KDE_VERSION_MAJOR >= 3
1707
listVars.push_back(uVars);
1709
listVars.append(uVars);
1712
listVars.append(uVars);
1720
error = upsTranslateError(value);
1723
error=UnknownAnswer;
1728
else { return error; }
1731
inBuffer = "LIST CMD " + upsName + "\n";
1732
if (!(error=getUpsData (inBuffer,outBuffer,"END LIST CMD"))) {
1734
QString inLine, upsNameRet, varName, value;
1736
bool beginList = false;
1737
QTextIStream varInputStream(&outBuffer);
1738
while (!(inLine = varInputStream.readLine()).isNull()) {
1739
key = parseLine (inLine, upsNameRet, varName, value, typeValue, lenString);
1741
case BEGIN_LIST_CMD: {
1742
if (upsNameRet == upsName) beginList = true;
1747
// Zpracujeme polozku v tabulky
1748
uIComm.upsCommName=varName;
1749
uIComm.upsDescription="";
1750
#if defined (KDE_VERSION_MAJOR)
1751
#if KDE_VERSION_MAJOR >= 3
1752
listIComms.push_back(uIComm);
1754
listIComms.append(uIComm);
1757
listIComms.append(uIComm);
1765
error = upsTranslateError(value);
1768
error=UnknownAnswer;
1773
else { return error; }
1779
int KNutNet::getUpsValues1 (const bool allVars ) {// allVars = true vse; allVars = false jen activate
1780
// Nacte hodnotu promenych
1781
// tuto cast pouzijem az uz nebudeme podporovat starsi verze KDE
1782
// if (netMutex.locked()) {
1783
// // proces bezi pockame na dokonceni
1784
// // nema vyznam ho znovu cist
1785
// netMutex.lock(); // cekame na volny pristup
1786
// netMutex.unlock();
1791
if (netMutex) while (netMutex) {};
1795
#if defined (KDE_VERSION_MAJOR)
1796
#if KDE_VERSION_MAJOR >= 3
1797
QValueVector<upsVar>::iterator it;
1799
QValueList<upsVar>::Iterator it;
1802
QValueList<upsVar>::Iterator it;
1804
emit getVarDesc (numberVars, 0);
1807
for (it = listVars.begin(); it != listVars.end(); it++) {
1809
if ((allVars) || ((*it).upsVarActivate)) {
1812
inBuffer.append((*it).upsVarName);
1813
if (!upsName.isEmpty()) { // pokud upsName neni je vzdy nastaveno na null
1814
inBuffer.append("@");
1815
inBuffer.append(upsName);
1817
inBuffer.append("\n");
1818
if (!(error=getUpsData (inBuffer,outBuffer))) {
1819
outBuffer.stripWhiteSpace ();
1821
emit getVarDesc (numberVars, numberVar);
1823
if ( !outBuffer.isEmpty() ) {
1824
QTextIStream inputStream(&outBuffer);
1825
QString word1, word2, word3 ;
1826
inputStream >> word1;
1827
inputStream >> word2;
1828
if (inputStream.atEnd()) { // neexistuje treti cast VALUE
1829
if (word1 == "ERR") {
1831
error=upsTranslateError(word2);
1832
//netMutex.unlock();
1837
error=UnknownFormat;
1838
//netMutex.unlock();
1843
inputStream >> word3;
1844
if (word1 == "ANS") {
1846
// odstranime pripadne jmeno upsky
1847
if ((posChar = word2.find('@')) != -1) word2 = word2.left(posChar);
1848
if ( word2 != (*it).upsVarName ) {
1849
error=UnknownAnswer;
1850
//netMutex.unlock();
1852
return error;// neni to odpoved na spravnou promenou
1854
// test pro starsi format modulu vraceli chybu v hodnote promene
1855
if ((error=upsOldTranslateError(word3))) {
1856
//netMutex.unlock();
1860
// zalozime hodnotu do vectoru;
1861
(*it).upsValue=word3;
1862
if ((*it).upsVarName == "STATUS") {
1863
// dogenerujeme dalsi slova pro status
1864
word3 += inputStream.readLine();
1865
genStatusFlags(word3);
1869
// neznama odpoved - neni ANS ani ERR
1870
error=UnknownAnswer;
1871
//netMutex.unlock();
1876
else {netMutex=false; error=NoData; return error; }
1878
else { netMutex=false; return error;}
1881
//netMutex.unlock();
1888
int KNutNet::getUpsValues2 (const bool allVars ) {// allVars = true vse; allVars = false jen activate
1895
// Nacte hodnotu promenych
1896
// tuto cast pouzijem az uz nebudeme podporovat starsi verze KDE
1897
// if (netMutex.locked()) {
1898
// // proces bezi pockame na dokonceni
1899
// // nema vyznam ho znovu cist
1900
// netMutex.lock(); // cekame na volny pristup
1901
// netMutex.unlock();
1906
if (netMutex) while (netMutex) {};
1910
#if defined (KDE_VERSION_MAJOR)
1911
#if KDE_VERSION_MAJOR >= 3
1912
QValueVector<upsVar>::iterator it;
1914
QValueList<upsVar>::Iterator it;
1917
QValueList<upsVar>::Iterator it;
1919
emit getVarDesc (numberVars, 0);
1921
for (it = listVars.begin(); it != listVars.end(); it++) {
1923
if ((allVars) || ((*it).upsVarActivate)) {
1925
inBuffer = "GET VAR "+upsName+" "+(*it).upsVarName+"\n";
1926
if (!(error=getUpsData (inBuffer,outBuffer))) {
1927
outBuffer.stripWhiteSpace ();
1928
emit getVarDesc (numberVars, numberVar);
1929
if ( !outBuffer.isEmpty() ) {
1930
int key = parseLine(outBuffer, upsNameRet, varName, value, typeValue, lenString);
1933
if ( varName != (*it).upsVarName ) {
1934
error=UnknownAnswer;
1935
//netMutex.unlock();
1937
return error;// neni to odpoved na spravnou promenou
1939
(*it).upsValue=value;
1940
if ((((*it).upsVarName == "STATUS") && (nutVariables == 1)) || (((*it).upsVarName == "ups.status") && (nutVariables == 2))) {
1941
// dogenerujeme dalsi slova pro status
1942
genStatusFlags(value);
1946
error=upsTranslateError(value);
1947
//netMutex.unlock();
1951
error=UnknownAnswer;
1952
//netMutex.unlock();
1957
else {netMutex=false; error=NoData; return error; }
1959
else { netMutex=false; return error;}
1962
//netMutex.unlock();
1968
int KNutNet::sendComm (const QString command, const QString arg1, const QString arg2, const bool useUpsName) {
1970
// nenastavi promenou error ale nenuluje ji
1974
switch (nutProtocol) {
1976
inBuffer=command + " " + arg1;
1977
if (useUpsName && (!upsName.isEmpty())) // pokud upsName neni je vzdy prazdne
1978
inBuffer += "@"+upsName;
1979
if (!arg2.isEmpty()) inBuffer += " " + arg2;
1982
inBuffer = command + " ";
1983
if (useUpsName) inBuffer += upsName + " ";
1984
inBuffer.append(arg1);
1985
if (!arg2.isEmpty()) inBuffer += " \"" + arg2 +"\"";
1988
inBuffer.append("\n");
1990
if (!(localError=getUpsData (inBuffer,outBuffer))) {
1991
outBuffer.stripWhiteSpace ();
1992
QTextIStream inputStream(&outBuffer);
1993
QString word1, word2;
1994
inputStream >> word1;
1995
inputStream >> word2;
1996
if (word1.isEmpty()) return UnknownAnswer; // zadna odpoved
1997
if (word1 != "OK") {
1999
if (word1 == "ERR") return upsTranslateError (word2);
2000
else return UnknownAnswer;
2004
else return localError;
2008
int KNutNet::activate ( const QString name, const bool setActivate ) {
2010
if (state == Connected) {
2011
#if defined (KDE_VERSION_MAJOR)
2012
#if KDE_VERSION_MAJOR >= 3
2013
QValueVector<upsVar>::iterator it;
2015
QValueList<upsVar>::Iterator it;
2018
QValueList<upsVar>::Iterator it;
2020
for (it = listVars.begin(); it != listVars.end(); it++) {
2021
if ((*it).upsVarName == name) {
2022
(*it).upsVarActivate = setActivate;
2029
else return NotConnection;
2032
int KNutNet::activateAll ( const bool setActivate ) {
2034
if (state == Connected) {
2035
#if defined (KDE_VERSION_MAJOR)
2036
#if KDE_VERSION_MAJOR >= 3
2037
QValueVector<upsVar>::iterator it;
2039
QValueList<upsVar>::Iterator it;
2042
QValueList<upsVar>::Iterator it;
2044
for (it = listVars.begin(); it != listVars.end(); it++) {
2045
(*it).upsVarActivate = setActivate;
2049
else return NotConnection;
2053
int KNutNet::upsTranslateError (const QString string) {
2054
if (string == "VAR-NOT-SUPPORTED") return VarNotSupported;
2055
if (string == "VAR-UNKNOWN") return VarUnknown;
2057
if (string == "ACCESS-DENIED") return AccessDenied;
2058
if (string == "PASSWORD-REQUIRED") return PasswordRequired;
2059
if (string == "PASSWORD-INCORRECT") return PasswordIncorrect;
2060
if (string == "UNKNOWN-UPS") return UnknownUps;
2061
if (string == "ALREADY-LOGGED_IN") return AlreadyLoggedIn;
2062
if (string == "ALREADY-SET-PASSWORD") return AlreadySetPassword;
2063
if (string == "UNKNOWN-COMMAND") return UnknownCommand;
2065
if (string == "UNKNOWN-INSTCMD") return UnknownInstCmd;
2066
if (string == "CMD-NOT-SUPPORTED") return CmdNotSupported;
2068
if (string == "INVALID-VALUE") return InvalidValue;
2070
if (string == "NO-RESPONSE") return NoResponse;
2071
if (string == "UNKNOWN-REPLY") return UnknownReply;
2072
if (string == "NOT-IMPLEMENTED") return NotImplemented;
2073
if (string == "COMMAND-FAILED") return CommandFailed;
2075
if (string == "MISSING-ARGUMENT") return MissingArgument;
2076
if (string == "DATA-STALE") return DataStale;
2077
if (string == "UNKNOWN-TYPE") return UnknownType;
2079
if (string == "DRIVER-NOT-CONNECTED") return DriverNotConnected;
2081
if (string == "") return UnknownFormat;
2086
int KNutNet::upsOldTranslateError (const QString string) {
2087
if (string == "NOT-SUPPORTED") return VarNotSupported;
2088
if (string == "UNKNOWN") return VarUnknown;
2089
if (string == "DATA-STALE") return DataStale;
2090
return 0; // nebylo nalezeno
2094
#include "knutnet.moc"