telldus-core

Defines

#define TELLSTICK_TURNON   1
#define TELLSTICK_TURNOFF   2
#define TELLSTICK_BELL   4
#define TELLSTICK_TOGGLE   8
#define TELLSTICK_DIM   16
#define TELLSTICK_EXECUTE   64
#define TELLSTICK_UP   128
#define TELLSTICK_DOWN   256
#define TELLSTICK_STOP   512
#define TELLSTICK_LEARN   32
#define TELLSTICK_TYPE_DEVICE   1
#define TELLSTICK_TYPE_GROUP   2
#define TELLSTICK_TYPE_SCENE   3
#define TELLSTICK_SUCCESS   0
#define TELLSTICK_ERROR_BROKEN_PIPE   -9
#define TELLSTICK_ERROR_NOT_FOUND   -1
#define TELLSTICK_ERROR_PERMISSION_DENIED   -2
#define TELLSTICK_ERROR_DEVICE_NOT_FOUND   -3
#define TELLSTICK_ERROR_METHOD_NOT_SUPPORTED   -4
#define TELLSTICK_ERROR_COMMUNICATION   -5
#define TELLSTICK_ERROR_CONNECTING_SERVICE   -6
#define TELLSTICK_ERROR_UNKNOWN_RESPONSE   -7
#define TELLSTICK_ERROR_SYNTAX   -8
#define TELLSTICK_ERROR_COMMUNICATING_SERVICE   -10
#define TELLSTICK_ERROR_UNKNOWN   -99

Functions

void tdClose (void)
void tdReleaseString (char *string)
int tdTurnOn (int intDeviceId)
int tdTurnOff (int intDeviceId)
int tdBell (int intDeviceId)
int tdDim (int intDeviceId, unsigned char level)
int tdExecute (int intDeviceId)
int tdUp (int intDeviceId)
int tdDown (int intDeviceId)
int tdStop (int intDeviceId)
int tdLearn (int intDeviceId)
int tdLastSentCommand (int intDeviceId, int methodsSupported)
char * tdLastSentValue (int intDeviceId)
int tdGetNumberOfDevices (void)
int tdGetDeviceId (int intDeviceIndex)
int tdGetDeviceType (int intDeviceId)
char * tdGetName (int intDeviceId)
char tdSetName (int intDeviceId, const char *strNewName)
char * tdGetProtocol (int intDeviceId)
char tdSetProtocol (int intDeviceId, const char *strProtocol)
char * tdGetModel (int intDeviceId)
char tdSetModel (int intDeviceId, const char *strModel)
char tdSetDeviceParameter (int intDeviceId, const char *strName, const char *strValue)
char * tdGetDeviceParameter (int intDeviceId, const char *strName, const char *defaultValue)
int tdAddDevice ()
char tdRemoveDevice (int intDeviceId)
int tdMethods (int id, int methodsSupported)
char * tdGetErrorString (int intErrorNo)
int tdSendRawCommand (const char *command, int reserved)
int tdSensor (char *protocol, int protocolLen, char *model, int modelLen, int *id, int *dataTypes)
int tdSensorValue (const char *protocol, const char *model, int id, int dataType, char *value, int len, int *timestamp)

Detailed Description

Telldus Core is the base module used to interface a Telldus TellStick.


Define Documentation

#define TELLSTICK_BELL   4

Device-flag for devices supporting the tdBell() call.

#define TELLSTICK_DIM   16

Device-flag for devices supporting the tdDim() call.

#define TELLSTICK_DOWN   256

Device-flag for devices supporting the tdDown() call.

#define TELLSTICK_ERROR_BROKEN_PIPE   -9

Error code. Pipe broken during communication.

#define TELLSTICK_ERROR_COMMUNICATING_SERVICE   -10

Error code. Timeout waiting for response from the Telldus Service.

#define TELLSTICK_ERROR_COMMUNICATION   -5

Error code. An error occurred when communicating with TellStick.

#define TELLSTICK_ERROR_CONNECTING_SERVICE   -6

Error code. The client library could not connect to the service. Maybe it is not running?

#define TELLSTICK_ERROR_DEVICE_NOT_FOUND   -3

Error code. The supplied device id was not found.

#define TELLSTICK_ERROR_METHOD_NOT_SUPPORTED   -4

Error code. The requested method is not supported by the device. This should be avoided by a call to tdMethods().

#define TELLSTICK_ERROR_NOT_FOUND   -1

Error code. Returned if a TellStick was not found on the system.

#define TELLSTICK_ERROR_PERMISSION_DENIED   -2

Error code. Returned if the user doesn't have privileges to open the TellStick device.

#define TELLSTICK_ERROR_SYNTAX   -8

Error code. Input/command could not be parsed or didn't follow input rules.

#define TELLSTICK_ERROR_UNKNOWN   -99

Error code. An unkown error has occurred.

#define TELLSTICK_ERROR_UNKNOWN_RESPONSE   -7

Error code. The client library received a response from the service it did not understand.

#define TELLSTICK_EXECUTE   64

Device-flag for devices (scenes) supporting the tdExecute() call.

#define TELLSTICK_LEARN   32

Device-flag for devices supporting the tdLearn() call.

#define TELLSTICK_STOP   512

Device-flag for devices supporting the tdStop() call.

#define TELLSTICK_SUCCESS   0

Error code. Returned when the command succeeded.

#define TELLSTICK_TOGGLE   8

This method is currently unimplemented.

#define TELLSTICK_TURNOFF   2

Device-flag for devices supporting the tdTurnOff() call.

#define TELLSTICK_TURNON   1

Device-flag for devices supporting the tdTurnOn() call.

#define TELLSTICK_TYPE_DEVICE   1

Device type of a single device.

#define TELLSTICK_TYPE_GROUP   2

Device type of a device which contains other devices.

#define TELLSTICK_TYPE_SCENE   3

Device type of a device which contains other devices that are sent different commands when executed (i.e. one device turns on, another turns off).

#define TELLSTICK_UP   128

Device-flag for devices supporting the tdUp() call.


Function Documentation

int tdAddDevice (  ) 

Add a new device to the global database of devices. This function must be called first before any call to tdSetName(), tdSetProtocol() and similar functions.

Returns:
the new device id for the newly created device. If the creation fails it returnes a negative value.
int tdBell ( int  intDeviceId  ) 

Sends bell command to devices supporting this. Make sure the device supports this by calling tdMethods() before any call to this function.

Parameters:
intDeviceId The device id to send bell to
void tdClose ( void   ) 

Close the library and clean up the cache it uses. This should be called when the library is not supposed to be used anymore

int tdDim ( int  intDeviceId,
unsigned char  level 
)

Dims a device. Make sure the device supports this by calling tdMethods() before any call to this function.

Parameters:
intDeviceId The device id to dim
level The level the device should dim to. This value should be 0-255
int tdDown ( int  intDeviceId  ) 

Send "down" command to device. Make sure the device supports this by calling tdMethods() before any call to this function.

Parameters:
intDeviceId The device id to send the command to
int tdExecute ( int  intDeviceId  ) 

Execute a scene action. Make sure the device supports this by calling tdMethods() before any call to this function.

Parameters:
intDeviceId The id to execute
int tdGetDeviceId ( int  intDeviceIndex  ) 

This function returns the unique id of a device with a specific index. To get all the id numbers you should loop over all the devices:

 int intNumberOfDevices = tdGetNumberOfDevices();
 for (int i = 0; i < intNumberOfDevices; i++) {
   int id = tdGetDeviceId( i );
   // id now contains the id number of the device with index of i
 }
Parameters:
intDeviceIndex The device index to query. The index starts from 0.
Returns:
the unique id for the device or -1 if the device is not found.
char* tdGetDeviceParameter ( int  intDeviceId,
const char *  strName,
const char *  defaultValue 
)
Returns:
any protocol specific parameter specified by strName
Parameters:
intDeviceId The device to query.
strName The name of the parameter to query.
defaultValue A defaultValue to return if the current parameter hasn't previously been set.
int tdGetDeviceType ( int  intDeviceId  ) 

Returns which type the device is. The device could be either TELLSTICK_TYPE_DEVICE, TELLSTICK_TYPE_GROUP or TELLSTICK_TYPE_SCENE

char* tdGetErrorString ( int  intErrorNo  ) 
char* tdGetModel ( int  intDeviceId  ) 
Returns:
the model for a device. Not all protocols uses this.
Parameters:
intDeviceId The device to query.
char* tdGetName ( int  intDeviceId  ) 

Query a device for it's name.

Parameters:
intDeviceId The unique id of the device to query
Returns:
The name of the device or an empty string if the device is not found.
int tdGetNumberOfDevices ( void   ) 

This function returns the number of devices configured

Returns:
an integer of the total number of devices configured
char* tdGetProtocol ( int  intDeviceId  ) 
Returns:
the protocol used by a specific device.
Parameters:
intDeviceId The device id to query.
int tdLastSentCommand ( int  intDeviceId,
int  methodsSupported 
)

Returns the last sent command to a specific device

Parameters:
intDeviceId The device id to query
methodsSupported The methods supported by the client. See tdMethods() for more information.
Returns:
the last sent command as integer, example TELLSTICK_TURNON or TELLSTICK_TURNOFF
char* tdLastSentValue ( int  intDeviceId  ) 

If the last sent command it TELLSTICK_DIM this returns the dimmed value.

Parameters:
intDeviceId The device id to query
Returns:
the the value as a human readable string, example "128" for 50%
int tdLearn ( int  intDeviceId  ) 

Sends a special learn command to some devices that need a special learn-command to be used from TellStick Make sure the device supports this by calling tdMethods() before any call to this function.

Parameters:
intDeviceId The device id to learn.
int tdMethods ( int  id,
int  methodsSupported 
)

Query a device for which methods it supports. By supplying the methods you support the library could remap the methods a device support for better fit the application. Example of querying a device supporting TELLSTICK_BELL:

 int methods = tdMethods(id, TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_BELL);
 //methods is now TELLSTICK_BELL
 int methods = tdMethods(idm TELLSTICK_TURNON | TELLSTICK_TURNOFF);
 //methods is now TELLSTICK_TURNON because the client application doesn't support TELLSTICK_BELL
Parameters:
id The device id to query
methodsSupported The methods the client application supports
Returns:
The method-flags OR'ed into an integer.
See also:
TELLSTICK_TURNON
TELLSTICK_TURNOFF
TELLSTICK_BELL
TELLSTICK_TOGGLE
TELLSTICK_DIM
TELLSTICK_EXECUTE
TELLSTICK_UP
TELLSTICK_DOWN
TELLSTICK_STOP
void tdReleaseString ( char *  string  ) 

This method releases resources allocated by telldus-core. It should be called on the returned value from all functions return char *

char tdRemoveDevice ( int  intDeviceId  ) 

Removes a device.

Returns:
true on success, false otherwise.
int tdSendRawCommand ( const char *  command,
int  reserved 
)

Send a raw command to TellStick. Please read the TellStick protocol definition on how the command should be constructed.

Parameters:
command The command for TellStick in its native format
Returns:
TELLSTICK_SUCCESS on success or one of the errorcodes on failure
int tdSensor ( char *  protocol,
int  protocolLen,
char *  model,
int  modelLen,
int *  id,
int *  dataTypes 
)

Use this function to iterate over all sensors. Iterate until TELLSTICK_SUCCESS is not returned

Parameters:
protocol A byref string where the protocol of the sensor will be placed
protocolLen The length of the protocol parameter
model A byref string where the model of the sensor will be placed
modelLen The length of the model parameter
id A byref int where the id of the sensor will be placed
dataTypes A byref int with flags for the supported sensor values
Returns:
TELLSTICK_SUCCESS if there is more sensors to be fetched
int tdSensorValue ( const char *  protocol,
const char *  model,
int  id,
int  dataType,
char *  value,
int  len,
int *  timestamp 
)

Get one of the supported sensor values from a sensor. Make sure it support the value type first by calling tdSensor(). The triplet protocol, model, and id together identifies a sensor.

Parameters:
protocol The protocol for the sensor
model The model for the sensor
id The id of the sensor
dataType One of the datatype to retrieve
value A byref string where the value will be places
len The length of the value parameter
timestamp A byref int where the timestamp of the value will be placed
Returns:
TELLSTICK_SUCCESS if the value could be fetched or one of the errorcodes on failure
char tdSetDeviceParameter ( int  intDeviceId,
const char *  strName,
const char *  strValue 
)

Sets a new protocol specific parameter. Please see the documentation of the protocols before setting any parameter.

Parameters:
intDeviceId The device to change.
strName The parameter to change.
strValue The new value for the parameter.
Returns:
true on success, false otherwise.
char tdSetModel ( int  intDeviceId,
const char *  strModel 
)

Sets a new model for a device. Which model to set depends on the current protocol.

Parameters:
intDeviceId The device to change
strModel The new model
Returns:
true on success, false otherwise.
char tdSetName ( int  intDeviceId,
const char *  strNewName 
)

Sets a new name for a device. The devices are global for all application, changing this will change the name for other applications aswell.

Parameters:
intDeviceId The device id to change the name for
strNewName The new name for the devices
Returns:
true on success, false otherwise.
char tdSetProtocol ( int  intDeviceId,
const char *  strProtocol 
)

This changes the current protocol used by a device. After changing the protocol, setting new parameters is required.

Parameters:
intDeviceId The device to change.
strProtocol The new protocol to use.
Returns:
true on success, false otherwise.
See also:
tdSetModel()
tdSetDeviceParameter()
int tdStop ( int  intDeviceId  ) 

Send "stop" command to device. Make sure the device supports this by calling tdMethods() before any call to this function.

Parameters:
intDeviceId The device id to stop
int tdTurnOff ( int  intDeviceId  ) 

Turns a device off. Make sure the device supports this by calling tdMethods() before any call to this function.

Parameters:
intDeviceId The device id to turn off.
int tdTurnOn ( int  intDeviceId  ) 

Turns a device on. Make sure the device supports this by calling tdMethods() before any call to this function.

Parameters:
intDeviceId The device id to turn on.
int tdUp ( int  intDeviceId  ) 

Send "up" command to device. Make sure the device supports this by calling tdMethods() before any call to this function.

Parameters:
intDeviceId The device id to send the command to