Added #include <string.h> to a lot of files
This commit is contained in:
parent
c93df293e2
commit
57e74dd496
5 changed files with 39 additions and 37 deletions
|
@ -1,10 +1,10 @@
|
||||||
// #include "StdAfx.h" //Needed?
|
// #include "StdAfx.h" //Needed?
|
||||||
#include "DeviceIkea.h"
|
#include "DeviceIkea.h"
|
||||||
#include <string>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ DeviceIkea::DeviceIkea(char *strSystem, char *strUnits, char *strFadeStyle)
|
||||||
}
|
}
|
||||||
if (strUnits != NULL && strlen(strUnits) > 0) {
|
if (strUnits != NULL && strlen(strUnits) > 0) {
|
||||||
intUnits = 0; //Start without any units
|
intUnits = 0; //Start without any units
|
||||||
|
|
||||||
char *strTemp = strtok(strUnits, ",");
|
char *strTemp = strtok(strUnits, ",");
|
||||||
do {
|
do {
|
||||||
int intUnit = atoi(strTemp);
|
int intUnit = atoi(strTemp);
|
||||||
|
@ -100,7 +100,7 @@ void DeviceIkea::dim(unsigned char level){
|
||||||
* Convert an integer to byte string where 0 is represented by ª and 1 by TT
|
* Convert an integer to byte string where 0 is represented by ª and 1 by TT
|
||||||
*/
|
*/
|
||||||
string DeviceIkea::getStringCode(unsigned char level){
|
string DeviceIkea::getStringCode(unsigned char level){
|
||||||
|
|
||||||
string strReturn = "STTTTTTª"; //Startcode, always like this;
|
string strReturn = "STTTTTTª"; //Startcode, always like this;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// #include "StdAfx.h"
|
// #include "StdAfx.h"
|
||||||
#include "DeviceNexa.h"
|
#include "DeviceNexa.h"
|
||||||
#include <string>
|
#include <string.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -19,7 +19,7 @@ DeviceNexa::DeviceNexa(char *strNewHouse, char *strNewCode)
|
||||||
} else {
|
} else {
|
||||||
intHouse = 0;
|
intHouse = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strNewCode != NULL && strlen(strNewCode) > 0) {
|
if (strNewCode != NULL && strlen(strNewCode) > 0) {
|
||||||
intCode = atoi(strNewCode) - 1;
|
intCode = atoi(strNewCode) - 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -45,10 +45,10 @@ void DeviceNexa::turnOn(void){
|
||||||
string strCode = getStringCode(intHouse);
|
string strCode = getStringCode(intHouse);
|
||||||
string strUnit = getStringCode(intCode);
|
string strUnit = getStringCode(intCode);
|
||||||
strCode.append(strUnit);
|
strCode.append(strUnit);
|
||||||
|
|
||||||
strCode.insert(0, "S");
|
strCode.insert(0, "S");
|
||||||
strCode.append("$k$k$kk$$kk$$kk$$k+"); //the "turn on"-code, keeps it like this, doesn't have to be regenerated each time
|
strCode.append("$k$k$kk$$kk$$kk$$k+"); //the "turn on"-code, keeps it like this, doesn't have to be regenerated each time
|
||||||
|
|
||||||
char* strMessage = const_cast<char*>(strCode.c_str());
|
char* strMessage = const_cast<char*>(strCode.c_str());
|
||||||
|
|
||||||
Device::send(strMessage);
|
Device::send(strMessage);
|
||||||
|
@ -62,17 +62,17 @@ void DeviceNexa::turnOn(void){
|
||||||
* Turn off this device
|
* Turn off this device
|
||||||
*/
|
*/
|
||||||
void DeviceNexa::turnOff(void){
|
void DeviceNexa::turnOff(void){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
string strCode = getStringCode(intHouse);
|
string strCode = getStringCode(intHouse);
|
||||||
string strUnit = getStringCode(intCode);
|
string strUnit = getStringCode(intCode);
|
||||||
strCode.append(strUnit);
|
strCode.append(strUnit);
|
||||||
|
|
||||||
strCode.insert(0, "S");
|
strCode.insert(0, "S");
|
||||||
strCode.append("$k$k$kk$$kk$$k$k$k+"); //the "turn off"-code, keeps it like this, doesn't have to be regenerated each time
|
strCode.append("$k$k$kk$$kk$$k$k$k+"); //the "turn off"-code, keeps it like this, doesn't have to be regenerated each time
|
||||||
|
|
||||||
char* strMessage = const_cast<char*>(strCode.c_str());
|
char* strMessage = const_cast<char*>(strCode.c_str());
|
||||||
|
|
||||||
Device::send(strMessage);
|
Device::send(strMessage);
|
||||||
}
|
}
|
||||||
catch(...){
|
catch(...){
|
||||||
|
@ -84,16 +84,16 @@ void DeviceNexa::turnOff(void){
|
||||||
* Send a bell
|
* Send a bell
|
||||||
*/
|
*/
|
||||||
void DeviceNexa::bell(void){
|
void DeviceNexa::bell(void){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
string strCode = getStringCode(intHouse);
|
string strCode = getStringCode(intHouse);
|
||||||
|
|
||||||
strCode.append("$kk$$kk$$kk$$k$k"); //the unit-code is always 7, doesn't have to be regenerated each time
|
strCode.append("$kk$$kk$$kk$$k$k"); //the unit-code is always 7, doesn't have to be regenerated each time
|
||||||
strCode.insert(0, "S");
|
strCode.insert(0, "S");
|
||||||
strCode.append("$kk$$kk$$kk$$kk$$k+"); //the "bell"-code, keeps it like this, doesn't have to be regenerated each time
|
strCode.append("$kk$$kk$$kk$$kk$$k+"); //the "bell"-code, keeps it like this, doesn't have to be regenerated each time
|
||||||
|
|
||||||
char* strMessage = const_cast<char*>(strCode.c_str());
|
char* strMessage = const_cast<char*>(strCode.c_str());
|
||||||
|
|
||||||
Device::send(strMessage);
|
Device::send(strMessage);
|
||||||
}
|
}
|
||||||
catch(...){
|
catch(...){
|
||||||
|
@ -105,12 +105,12 @@ void DeviceNexa::bell(void){
|
||||||
* Convert an integer to byte string where 0 is represented by $k and 1 by k$, reversed and padded with 0's as needed
|
* Convert an integer to byte string where 0 is represented by $k and 1 by k$, reversed and padded with 0's as needed
|
||||||
*/
|
*/
|
||||||
string DeviceNexa::getStringCode(int intToConvert){
|
string DeviceNexa::getStringCode(int intToConvert){
|
||||||
|
|
||||||
string strReturn = "";
|
string strReturn = "";
|
||||||
|
|
||||||
try{
|
try{
|
||||||
bitset<4> bs ((long)intToConvert);
|
bitset<4> bs ((long)intToConvert);
|
||||||
|
|
||||||
strReturn = bs.to_string();
|
strReturn = bs.to_string();
|
||||||
reverse(strReturn.begin(), strReturn.end());
|
reverse(strReturn.begin(), strReturn.end());
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ string DeviceNexa::getStringCode(int intToConvert){
|
||||||
strReturn.replace(intPos, 1, "k$");
|
strReturn.replace(intPos, 1, "k$");
|
||||||
intPos = (int)strReturn.find("1", intPos + 1);
|
intPos = (int)strReturn.find("1", intPos + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
intPos = 0;
|
intPos = 0;
|
||||||
while (intPos < (int)strReturn.length()){
|
while (intPos < (int)strReturn.length()){
|
||||||
strReturn.insert(intPos, "$k");
|
strReturn.insert(intPos, "$k");
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
void handleException(std::exception e);
|
void handleException(std::exception e);
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -22,13 +23,13 @@ using namespace std;
|
||||||
//comment (just copy from the called methods)
|
//comment (just copy from the called methods)
|
||||||
|
|
||||||
bool WINAPI devTurnOn(int intDeviceId){
|
bool WINAPI devTurnOn(int intDeviceId){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
TelldusSettings ts;
|
TelldusSettings ts;
|
||||||
Device* dev = ts.getDevice(intDeviceId);
|
Device* dev = ts.getDevice(intDeviceId);
|
||||||
if(dev != NULL){
|
if(dev != NULL){
|
||||||
dev->turnOn();
|
dev->turnOn();
|
||||||
|
|
||||||
delete(dev);
|
delete(dev);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -43,13 +44,13 @@ bool WINAPI devTurnOn(int intDeviceId){
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WINAPI devTurnOff(int intDeviceId){
|
bool WINAPI devTurnOff(int intDeviceId){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
TelldusSettings ts;
|
TelldusSettings ts;
|
||||||
Device* dev = ts.getDevice(intDeviceId);
|
Device* dev = ts.getDevice(intDeviceId);
|
||||||
if(dev != NULL){
|
if(dev != NULL){
|
||||||
dev->turnOff();
|
dev->turnOff();
|
||||||
|
|
||||||
delete(dev);
|
delete(dev);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -64,13 +65,13 @@ bool WINAPI devTurnOff(int intDeviceId){
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WINAPI devBell(int intDeviceId){
|
bool WINAPI devBell(int intDeviceId){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
TelldusSettings ts;
|
TelldusSettings ts;
|
||||||
Device* dev = ts.getDevice(intDeviceId);
|
Device* dev = ts.getDevice(intDeviceId);
|
||||||
if(dev != NULL){
|
if(dev != NULL){
|
||||||
dev->bell();
|
dev->bell();
|
||||||
|
|
||||||
delete(dev);
|
delete(dev);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +86,7 @@ bool WINAPI devBell(int intDeviceId){
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WINAPI devDim(int intDeviceId, unsigned char level){
|
bool WINAPI devDim(int intDeviceId, unsigned char level){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
TelldusSettings ts;
|
TelldusSettings ts;
|
||||||
Device* dev = ts.getDevice(intDeviceId);
|
Device* dev = ts.getDevice(intDeviceId);
|
||||||
|
@ -225,7 +226,7 @@ bool WINAPI devSetModel(int intDeviceId, const char* strNewModel){
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WINAPI devSetArgument(int intDeviceId, const char *strName, const char *strValue){
|
bool WINAPI devSetArgument(int intDeviceId, const char *strName, const char *strValue){
|
||||||
|
|
||||||
try{
|
try{
|
||||||
TelldusSettings ts;
|
TelldusSettings ts;
|
||||||
return ts.setArgument(intDeviceId, strName, strValue);
|
return ts.setArgument(intDeviceId, strName, strValue);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send message to the USB dongle
|
* Send message to the USB dongle
|
||||||
|
@ -9,11 +10,11 @@
|
||||||
void Device::send(char* strMessage) {
|
void Device::send(char* strMessage) {
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
struct termios tio;
|
struct termios tio;
|
||||||
|
|
||||||
if( 0 > ( fd = open( strDevice, O_RDWR ) ) ) {
|
if( 0 > ( fd = open( strDevice, O_RDWR ) ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* adjust serial port parameters */
|
/* adjust serial port parameters */
|
||||||
bzero(&tio, sizeof(tio)); /* clear struct for new port settings */
|
bzero(&tio, sizeof(tio)); /* clear struct for new port settings */
|
||||||
tio.c_cflag = B4800 | CS8 | CLOCAL | CREAD; /* CREAD not used yet */
|
tio.c_cflag = B4800 | CS8 | CLOCAL | CREAD; /* CREAD not used yet */
|
||||||
|
@ -23,7 +24,7 @@ void Device::send(char* strMessage) {
|
||||||
tcsetattr(fd,TCSANOW,&tio);
|
tcsetattr(fd,TCSANOW,&tio);
|
||||||
|
|
||||||
write(fd, strMessage, strlen(strMessage));
|
write(fd, strMessage, strlen(strMessage));
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "../DeviceWaveman.h"
|
#include "../DeviceWaveman.h"
|
||||||
#include "../DeviceSartano.h"
|
#include "../DeviceSartano.h"
|
||||||
#include "../DeviceIkea.h"
|
#include "../DeviceIkea.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the requested device
|
* Get the requested device
|
||||||
|
@ -12,39 +12,39 @@
|
||||||
Device* TelldusSettings::getDevice(int intDeviceId){
|
Device* TelldusSettings::getDevice(int intDeviceId){
|
||||||
|
|
||||||
Device* dev = NULL;
|
Device* dev = NULL;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
char* vendor = getVendor(intDeviceId);
|
char* vendor = getVendor(intDeviceId);
|
||||||
|
|
||||||
//each new brand must be added here
|
//each new brand must be added here
|
||||||
if (strcmp(vendor, "Nexa") == 0){
|
if (strcmp(vendor, "Nexa") == 0){
|
||||||
char *strHouse = getArgument(intDeviceId, "nexa_house");
|
char *strHouse = getArgument(intDeviceId, "nexa_house");
|
||||||
char *strCode = getArgument(intDeviceId, "nexa_unit");
|
char *strCode = getArgument(intDeviceId, "nexa_unit");
|
||||||
dev = new DeviceNexa(strHouse, strCode);
|
dev = new DeviceNexa(strHouse, strCode);
|
||||||
|
|
||||||
} else if (strcmp(vendor, "Waveman") == 0) {
|
} else if (strcmp(vendor, "Waveman") == 0) {
|
||||||
char *strHouse = getArgument(intDeviceId, "nexa_house");
|
char *strHouse = getArgument(intDeviceId, "nexa_house");
|
||||||
char *strCode = getArgument(intDeviceId, "nexa_unit");
|
char *strCode = getArgument(intDeviceId, "nexa_unit");
|
||||||
dev = new DeviceWaveman(strHouse, strCode);
|
dev = new DeviceWaveman(strHouse, strCode);
|
||||||
|
|
||||||
} else if (strcmp(vendor, "Sartano") == 0) {
|
} else if (strcmp(vendor, "Sartano") == 0) {
|
||||||
char *strCode = getArgument(intDeviceId, "sartano_code");
|
char *strCode = getArgument(intDeviceId, "sartano_code");
|
||||||
dev = new DeviceSartano(strCode);
|
dev = new DeviceSartano(strCode);
|
||||||
|
|
||||||
} else if (strcmp(vendor, "Ikea") == 0) {
|
} else if (strcmp(vendor, "Ikea") == 0) {
|
||||||
char *strSystem = getArgument(intDeviceId, "ikea_system");
|
char *strSystem = getArgument(intDeviceId, "ikea_system");
|
||||||
char *strUnits = getArgument(intDeviceId, "ikea_units");
|
char *strUnits = getArgument(intDeviceId, "ikea_units");
|
||||||
char *strFade = getArgument(intDeviceId, "ikea_fade");
|
char *strFade = getArgument(intDeviceId, "ikea_fade");
|
||||||
dev = new DeviceIkea(strSystem, strUnits, strFade);
|
dev = new DeviceIkea(strSystem, strUnits, strFade);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WINDOWS
|
#ifndef _WINDOWS
|
||||||
dev->setDevice( getSetting("deviceNode") );
|
dev->setDevice( getSetting("deviceNode") );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(...){
|
catch(...){
|
||||||
throw;
|
throw;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue