Page 1 of 1

Way to send Bogus Callback event?

Posted: Fri Mar 17, 2023 9:45 am
by peec
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.

Re: Way to send Bogus Callback event?

Posted: Fri Mar 17, 2023 9:45 am
by micke.prag
Try:

Code: Select all

$ tdtool --on 1
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.

Re: Way to send Bogus Callback event?

Posted: Fri Mar 17, 2023 9:45 am
by hekj
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.
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).

/Henrik

Re: Way to send Bogus Callback event?

Posted: Fri Mar 17, 2023 9:45 am
by micke.prag
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:

Code: Select all

void __stdcall deviceChangeEvent(int deviceId, int eventId, int changeType, int, void *context);
I hope this helps you.

Re: Way to send Bogus Callback event?

Posted: Fri Mar 17, 2023 9:45 am
by peec
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 );

		

Re: Way to send Bogus Callback event?

Posted: Fri Mar 17, 2023 9:45 am
by hekj
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 );
I have tested your code and the result is the same, why do you declare the variable data as a Pointer instead of String?

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);
}
If I get this to work shall I call the method tdReleaseString(String txt) at some point to get rid of the string?

/Henrik

Re: Way to send Bogus Callback event?

Posted: Fri Mar 17, 2023 9:45 am
by micke.prag
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.

Re: Way to send Bogus Callback event?

Posted: Fri Mar 17, 2023 9:45 am
by micke.prag
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);