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 "DeviceIkea.h"
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -21,7 +21,7 @@ DeviceIkea::DeviceIkea(char *strSystem, char *strUnits, char *strFadeStyle)
|
|||
}
|
||||
if (strUnits != NULL && strlen(strUnits) > 0) {
|
||||
intUnits = 0; //Start without any units
|
||||
|
||||
|
||||
char *strTemp = strtok(strUnits, ",");
|
||||
do {
|
||||
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
|
||||
*/
|
||||
string DeviceIkea::getStringCode(unsigned char level){
|
||||
|
||||
|
||||
string strReturn = "STTTTTTª"; //Startcode, always like this;
|
||||
|
||||
try{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// #include "StdAfx.h"
|
||||
#include "DeviceNexa.h"
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <iostream>
|
||||
|
@ -19,7 +19,7 @@ DeviceNexa::DeviceNexa(char *strNewHouse, char *strNewCode)
|
|||
} else {
|
||||
intHouse = 0;
|
||||
}
|
||||
|
||||
|
||||
if (strNewCode != NULL && strlen(strNewCode) > 0) {
|
||||
intCode = atoi(strNewCode) - 1;
|
||||
} else {
|
||||
|
@ -45,10 +45,10 @@ void DeviceNexa::turnOn(void){
|
|||
string strCode = getStringCode(intHouse);
|
||||
string strUnit = getStringCode(intCode);
|
||||
strCode.append(strUnit);
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
char* strMessage = const_cast<char*>(strCode.c_str());
|
||||
|
||||
Device::send(strMessage);
|
||||
|
@ -62,17 +62,17 @@ void DeviceNexa::turnOn(void){
|
|||
* Turn off this device
|
||||
*/
|
||||
void DeviceNexa::turnOff(void){
|
||||
|
||||
|
||||
try{
|
||||
string strCode = getStringCode(intHouse);
|
||||
string strUnit = getStringCode(intCode);
|
||||
strCode.append(strUnit);
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
char* strMessage = const_cast<char*>(strCode.c_str());
|
||||
|
||||
|
||||
Device::send(strMessage);
|
||||
}
|
||||
catch(...){
|
||||
|
@ -84,16 +84,16 @@ void DeviceNexa::turnOff(void){
|
|||
* Send a bell
|
||||
*/
|
||||
void DeviceNexa::bell(void){
|
||||
|
||||
|
||||
try{
|
||||
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.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
|
||||
|
||||
|
||||
char* strMessage = const_cast<char*>(strCode.c_str());
|
||||
|
||||
|
||||
Device::send(strMessage);
|
||||
}
|
||||
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
|
||||
*/
|
||||
string DeviceNexa::getStringCode(int intToConvert){
|
||||
|
||||
|
||||
string strReturn = "";
|
||||
|
||||
try{
|
||||
bitset<4> bs ((long)intToConvert);
|
||||
|
||||
|
||||
strReturn = bs.to_string();
|
||||
reverse(strReturn.begin(), strReturn.end());
|
||||
|
||||
|
@ -125,7 +125,7 @@ string DeviceNexa::getStringCode(int intToConvert){
|
|||
strReturn.replace(intPos, 1, "k$");
|
||||
intPos = (int)strReturn.find("1", intPos + 1);
|
||||
}
|
||||
|
||||
|
||||
intPos = 0;
|
||||
while (intPos < (int)strReturn.length()){
|
||||
strReturn.insert(intPos, "$k");
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
void handleException(std::exception e);
|
||||
using namespace std;
|
||||
|
@ -22,13 +23,13 @@ using namespace std;
|
|||
//comment (just copy from the called methods)
|
||||
|
||||
bool WINAPI devTurnOn(int intDeviceId){
|
||||
|
||||
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
Device* dev = ts.getDevice(intDeviceId);
|
||||
if(dev != NULL){
|
||||
dev->turnOn();
|
||||
|
||||
|
||||
delete(dev);
|
||||
return true;
|
||||
}
|
||||
|
@ -43,13 +44,13 @@ bool WINAPI devTurnOn(int intDeviceId){
|
|||
}
|
||||
|
||||
bool WINAPI devTurnOff(int intDeviceId){
|
||||
|
||||
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
Device* dev = ts.getDevice(intDeviceId);
|
||||
if(dev != NULL){
|
||||
dev->turnOff();
|
||||
|
||||
|
||||
delete(dev);
|
||||
return true;
|
||||
}
|
||||
|
@ -64,13 +65,13 @@ bool WINAPI devTurnOff(int intDeviceId){
|
|||
}
|
||||
|
||||
bool WINAPI devBell(int intDeviceId){
|
||||
|
||||
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
Device* dev = ts.getDevice(intDeviceId);
|
||||
if(dev != NULL){
|
||||
dev->bell();
|
||||
|
||||
|
||||
delete(dev);
|
||||
return true;
|
||||
}
|
||||
|
@ -85,7 +86,7 @@ bool WINAPI devBell(int intDeviceId){
|
|||
}
|
||||
|
||||
bool WINAPI devDim(int intDeviceId, unsigned char level){
|
||||
|
||||
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
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){
|
||||
|
||||
|
||||
try{
|
||||
TelldusSettings ts;
|
||||
return ts.setArgument(intDeviceId, strName, strValue);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <iostream>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Send message to the USB dongle
|
||||
|
@ -9,11 +10,11 @@
|
|||
void Device::send(char* strMessage) {
|
||||
int fd = -1;
|
||||
struct termios tio;
|
||||
|
||||
|
||||
if( 0 > ( fd = open( strDevice, O_RDWR ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* adjust serial port parameters */
|
||||
bzero(&tio, sizeof(tio)); /* clear struct for new port settings */
|
||||
tio.c_cflag = B4800 | CS8 | CLOCAL | CREAD; /* CREAD not used yet */
|
||||
|
@ -23,7 +24,7 @@ void Device::send(char* strMessage) {
|
|||
tcsetattr(fd,TCSANOW,&tio);
|
||||
|
||||
write(fd, strMessage, strlen(strMessage));
|
||||
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "../DeviceWaveman.h"
|
||||
#include "../DeviceSartano.h"
|
||||
#include "../DeviceIkea.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Get the requested device
|
||||
|
@ -12,39 +12,39 @@
|
|||
Device* TelldusSettings::getDevice(int intDeviceId){
|
||||
|
||||
Device* dev = NULL;
|
||||
|
||||
|
||||
try{
|
||||
char* vendor = getVendor(intDeviceId);
|
||||
|
||||
|
||||
//each new brand must be added here
|
||||
if (strcmp(vendor, "Nexa") == 0){
|
||||
char *strHouse = getArgument(intDeviceId, "nexa_house");
|
||||
char *strCode = getArgument(intDeviceId, "nexa_unit");
|
||||
dev = new DeviceNexa(strHouse, strCode);
|
||||
|
||||
|
||||
} else if (strcmp(vendor, "Waveman") == 0) {
|
||||
char *strHouse = getArgument(intDeviceId, "nexa_house");
|
||||
char *strCode = getArgument(intDeviceId, "nexa_unit");
|
||||
dev = new DeviceWaveman(strHouse, strCode);
|
||||
|
||||
|
||||
} else if (strcmp(vendor, "Sartano") == 0) {
|
||||
char *strCode = getArgument(intDeviceId, "sartano_code");
|
||||
dev = new DeviceSartano(strCode);
|
||||
|
||||
|
||||
} else if (strcmp(vendor, "Ikea") == 0) {
|
||||
char *strSystem = getArgument(intDeviceId, "ikea_system");
|
||||
char *strUnits = getArgument(intDeviceId, "ikea_units");
|
||||
char *strFade = getArgument(intDeviceId, "ikea_fade");
|
||||
dev = new DeviceIkea(strSystem, strUnits, strFade);
|
||||
|
||||
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
#ifndef _WINDOWS
|
||||
dev->setDevice( getSetting("deviceNode") );
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
catch(...){
|
||||
throw;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue