I am currently working on javatellstick ( http://code.google.com/p/javatellstick/ )
I am currently implementing the callbacks with JNA.
However, now i have come to the stage where I need to check if it recieves events as it should.
Is there a way to send a bogus signal or do you got to have the Tellstick DUO to do this ?
The reason is that i don't got the DUO, and I have to test it someway (or wait for that sake, but i like to work fast
It's like the python script in your SVN, but in java, so I just need to check if I get signals in some way.
Way to send Bogus Callback event?
Moderator: Telldus
-
- Site Admin
- Posts: 2243
- Joined: Fri Mar 17, 2023 9:45 am
- Location: Lund
- Contact:
Re: Way to send Bogus Callback event?
Try:
Even other applications will trigger DeviceEvent when the status of a device changes.
If you change the name in TelldusCenter a DeviceChangeEvent will be triggered.
Please note that you must run our beta software for the callback to work. Currently the latest version is 2.0.104.
Code: Select all
$ tdtool --on 1
If you change the name in TelldusCenter a DeviceChangeEvent will be triggered.
Please note that you must run our beta software for the callback to work. Currently the latest version is 2.0.104.
Micke Prag
Software
Telldus Technologies
Software
Telldus Technologies
Re: Way to send Bogus Callback event?
I have implemented callbacks in NexaHome using JNA, but it's not yet activated... when I set a breakpoint in the JNA source code I can see that NexaHome shuts down when the callback thread exits (don't know if there is a bug in JNA or NexaHome).peec wrote:I am currently working on javatellstick ( http://code.google.com/p/javatellstick/ )
I am currently implementing the callbacks with JNA.
However, now i have come to the stage where I need to check if it recieves events as it should.
/Henrik
-
- Site Admin
- Posts: 2243
- Joined: Fri Mar 17, 2023 9:45 am
- Location: Lund
- Contact:
Re: Way to send Bogus Callback event?
I don't know if it is the case but, in the windows world there is 3 different calling conventions used for functions. If you declare your functions with wrong calling convention strange things can happen. We use "stdcall" so make sure you declare you callback like this:
I hope this helps you.
Code: Select all
void __stdcall deviceChangeEvent(int deviceId, int eventId, int changeType, int, void *context);
Micke Prag
Software
Telldus Technologies
Software
Telldus Technologies
Re: Way to send Bogus Callback event?
I have now implemented callbacks in Java, (JNA) seems to work just fine.
Snippet for the callbacks:
Snippet for the callbacks:
Code: Select all
// typedef void (WINAPI *TDDeviceEvent)(int deviceId, int method, const char *data, int callbackId, void *context);
interface TDDeviceEvent extends Callback{
void invoke(int deviceId, int method, Pointer data, int callbackId, Pointer context);
}
// TELLSTICK_API int WINAPI tdRegisterDeviceEvent( TDDeviceEvent eventFunction, void *context );
public int tdRegisterDeviceEvent( TDDeviceEvent eventFunction, Pointer context );
// typedef void (WINAPI *TDDeviceChangeEvent)(int deviceId, int changeEvent, int changeType, int callbackId, void *context);
interface TDDeviceChangeEvent extends Callback{
void invoke(int deviceId, int changeEvent, int changeType, int callbackId, Pointer context);
}
// TELLSTICK_API int WINAPI tdRegisterDeviceChangeEvent( TDDeviceChangeEvent eventFunction, void *context);
public int tdRegisterDeviceChangeEvent( TDDeviceChangeEvent eventFunction, Pointer context);
// typedef void (WINAPI *TDRawDeviceEvent)(const char *data, int controllerId, int callbackId, void *context);
interface TDRawDeviceEvent extends Callback{
void invoke(Pointer data, int controllerId, int callbackId, Pointer context);
}
// TELLSTICK_API int WINAPI tdRegisterRawDeviceEvent( TDRawDeviceEvent eventFunction, void *context );
public int tdRegisterRawDeviceEvent( TDRawDeviceEvent eventFunction, Pointer context );
Re: Way to send Bogus Callback event?
I have tested your code and the result is the same, why do you declare the variable data as a Pointer instead of String?peec wrote:I have now implemented callbacks in Java, (JNA) seems to work just fine.
Snippet for the callbacks:Code: Select all
// typedef void (WINAPI *TDDeviceEvent)(int deviceId, int method, const char *data, int callbackId, void *context); interface TDDeviceEvent extends Callback{ void invoke(int deviceId, int method, Pointer data, int callbackId, Pointer context); } // TELLSTICK_API int WINAPI tdRegisterDeviceEvent( TDDeviceEvent eventFunction, void *context ); public int tdRegisterDeviceEvent( TDDeviceEvent eventFunction, Pointer context ); // typedef void (WINAPI *TDDeviceChangeEvent)(int deviceId, int changeEvent, int changeType, int callbackId, void *context); interface TDDeviceChangeEvent extends Callback{ void invoke(int deviceId, int changeEvent, int changeType, int callbackId, Pointer context); } // TELLSTICK_API int WINAPI tdRegisterDeviceChangeEvent( TDDeviceChangeEvent eventFunction, void *context); public int tdRegisterDeviceChangeEvent( TDDeviceChangeEvent eventFunction, Pointer context); // typedef void (WINAPI *TDRawDeviceEvent)(const char *data, int controllerId, int callbackId, void *context); interface TDRawDeviceEvent extends Callback{ void invoke(Pointer data, int controllerId, int callbackId, Pointer context); } // TELLSTICK_API int WINAPI tdRegisterRawDeviceEvent( TDRawDeviceEvent eventFunction, void *context ); public int tdRegisterRawDeviceEvent( TDRawDeviceEvent eventFunction, Pointer context );
Code: Select all
TDRawDeviceEvent
public void invoke(Pointer data, int controllerId, int callbackId, Pointer context) {
System.out.println(data.getString(0));
}
public void invoke(String data, int controllerId, int callbackId, Pointer context) {
System.out.println(data);
}
/Henrik
-
- Site Admin
- Posts: 2243
- Joined: Fri Mar 17, 2023 9:45 am
- Location: Lund
- Contact:
Re: Way to send Bogus Callback event?
No, don't call tdRelaseString() on strings passed on to a callback. They are declared const.
tdRelaseString() must be called on all strings returned from telldus-core, where telldus-core no longer have the possibility to release them when not needed anymore.
Strings passed on to a callback will be released when the callback returns. If you want to store it longer you must copy them yourself and take care of the release.
tdRelaseString() must be called on all strings returned from telldus-core, where telldus-core no longer have the possibility to release them when not needed anymore.
Strings passed on to a callback will be released when the callback returns. If you want to store it longer you must copy them yourself and take care of the release.
Micke Prag
Software
Telldus Technologies
Software
Telldus Technologies
-
- Site Admin
- Posts: 2243
- Joined: Fri Mar 17, 2023 9:45 am
- Location: Lund
- Contact:
Re: Way to send Bogus Callback event?
See these examples:
Code: Select all
void WINAPI deviceEvent(int deviceId, int method, const char *data, int callbackId, void *context) {
//variable data must not be released here. It is released by telldus-core when this function returns
}
Code: Select all
//telldus-core doesn't know when "name" is not used anymore and must be released
char *name = tdGetName(1);
tdReleaseString(name);
Micke Prag
Software
Telldus Technologies
Software
Telldus Technologies