If the protocol is not valid, return TELLSTICK_ERROR_CONFIG_SYNTAX instead of TELLSTICK_ERROR_UNKNOWN. Closes #119
This commit is contained in:
parent
12eb097ce4
commit
8babf9913d
1 changed files with 43 additions and 42 deletions
|
@ -139,49 +139,50 @@ int Device::getType(){
|
|||
|
||||
int Device::doAction(int action, unsigned char data, Controller *controller) {
|
||||
Protocol *p = this->retrieveProtocol();
|
||||
if(p){
|
||||
//Try to determine if we need to call another method due to masking
|
||||
int methods = p->methods();
|
||||
if ((action & methods) == 0) {
|
||||
//Loop all methods an see if any method masks to this one
|
||||
for(int i = 1; i <= methods; i<<=1) {
|
||||
if ((i & methods) == 0) {
|
||||
continue;
|
||||
}
|
||||
if (this->maskUnsupportedMethods(i, action)) {
|
||||
action = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((action & methods) == 0) {
|
||||
return TELLSTICK_ERROR_METHOD_NOT_SUPPORTED;
|
||||
}
|
||||
std::string code = p->getStringForMethod(action, data, controller);
|
||||
if (code == "") {
|
||||
return TELLSTICK_ERROR_METHOD_NOT_SUPPORTED;
|
||||
}
|
||||
if (code[0] != 'S' && code[0] != 'T' && code[0] != 'P' && code[0] != 'R') {
|
||||
//Try autodetect sendtype
|
||||
TellStick *tellstick = reinterpret_cast<TellStick *>(controller);
|
||||
if (!tellstick) {
|
||||
return TELLSTICK_ERROR_UNKNOWN;
|
||||
}
|
||||
unsigned int maxlength = 80;
|
||||
if (tellstick->pid() == 0x0c31) {
|
||||
maxlength = 512;
|
||||
}
|
||||
if (code.length() <= maxlength) {
|
||||
//S is enough
|
||||
code.insert(0, 1, 'S');
|
||||
code.append(1, '+');
|
||||
} else {
|
||||
code = TellStick::createTPacket(code);
|
||||
}
|
||||
}
|
||||
return controller->send(code);
|
||||
if (!p) {
|
||||
//Syntax error in configuration, no such protocol
|
||||
return TELLSTICK_ERROR_CONFIG_SYNTAX;
|
||||
}
|
||||
return TELLSTICK_ERROR_UNKNOWN;
|
||||
//Try to determine if we need to call another method due to masking
|
||||
int methods = p->methods();
|
||||
if ((action & methods) == 0) {
|
||||
//Loop all methods an see if any method masks to this one
|
||||
for(int i = 1; i <= methods; i<<=1) {
|
||||
if ((i & methods) == 0) {
|
||||
continue;
|
||||
}
|
||||
if (this->maskUnsupportedMethods(i, action)) {
|
||||
action = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((action & methods) == 0) {
|
||||
return TELLSTICK_ERROR_METHOD_NOT_SUPPORTED;
|
||||
}
|
||||
std::string code = p->getStringForMethod(action, data, controller);
|
||||
if (code == "") {
|
||||
return TELLSTICK_ERROR_METHOD_NOT_SUPPORTED;
|
||||
}
|
||||
if (code[0] != 'S' && code[0] != 'T' && code[0] != 'P' && code[0] != 'R') {
|
||||
//Try autodetect sendtype
|
||||
TellStick *tellstick = reinterpret_cast<TellStick *>(controller);
|
||||
if (!tellstick) {
|
||||
return TELLSTICK_ERROR_UNKNOWN;
|
||||
}
|
||||
unsigned int maxlength = 80;
|
||||
if (tellstick->pid() == 0x0c31) {
|
||||
maxlength = 512;
|
||||
}
|
||||
if (code.length() <= maxlength) {
|
||||
//S is enough
|
||||
code.insert(0, 1, 'S');
|
||||
code.append(1, '+');
|
||||
} else {
|
||||
code = TellStick::createTPacket(code);
|
||||
}
|
||||
}
|
||||
return controller->send(code);
|
||||
}
|
||||
|
||||
Protocol* Device::retrieveProtocol() const {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue