PDA

View Full Version : Plugin inconsistent behavior - firecracker



Ron
October 13th, 2002, 12:55 PM
There is one error that I tend to make over and over and over again in plugins. I'm just guessing that you made the same error :

In gir_event a variable called command is passed, this is the command that the plugin should execute. However in all the rest of the plugin we are working with CurCommand (or something similar). Most of the time these two are the same, especially if you actually selected the command in the tree ( that is when girder updates this variable in the plugin ). However if you trigger a multigroup this variable does not get updated and thus your plugin is trying to trigger the multigroup!!

In short: Make sure that in gir_event you are using the correct local p_command variable and not the global one.

mflaster
October 13th, 2002, 12:55 PM
Hi,

I tried to take Mark's X10 plugin, and convert it to 3.2 format. I thought I had succeeded. But there seems to be an odd problem.

If I have a command which just uses the plugin to send an X10 command, it works fine. But if I put it in a multigroup, it does *not* do anything.

For example:
MultiGroup
-- Firecracker send A3 on
-- Wait 5 seconds

If I right-click on the firecracker command, and do "test command", I see "X10 sent" in the lower left of the status bar, and everything works fine - my lights go on.

I then clear that status area.

If I then right click on "MultiGroup", and do test command, I see it scroll through both commands, and I see "X10 sent" in the lower left of the status bar - but no X10 gets transmitted!

Is there some obvious mistake that I could have made in converting the plugin that would cause this problem? Is this a race condition between this plugin and the rest of Girder? Has anyone seen this problem before?

Keep in mind I was practicing "zero knowledge programming", so I definitely might have done something stupid! :) I saw there are locks in 3.2 plugins, and I copied the way they were used, to the best of my ability. Maybe that's what I screwed up?

Thanks!

Mike

mflaster
October 13th, 2002, 12:55 PM
OK, I have the following code:


int gir_event(p_command command, PCHAR eventstring, void *payload, int len, PCHAR status, int statuslen)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return theApp.PluginEvent(command, eventstring, payload, len, status, statuslen);
}

int CX10App::PluginEvent(p_command command, PCHAR eventstring, void *payload, int len,
PCHAR status, int statuslen)
{
int ret = retStopProcessing;

UINT Action, SubAction, DeviceID, UserData;
CString str;
*** [i]m_pGirder->GetCurCommandData(Action, SubAction, DeviceID, UserData, str);[/i]

if (command->actiontype == PlgDeviceID)
{
ret = m_pCommand->ExecuteCommand(command->actionsubtype);
// send string to firecracker device
m_X10Device.SendData(UserData);
// set return buffer to show in status bar
strncpy(status,"X10 Sent",statuslen);
}
else
{
strncpy(status,"X10 FAILURE",statuslen);
}
return ret;
}

It seems like the line with the *** the problem you're describing? Where am I supposed to get UserData from instead?

Mike

mflaster
October 13th, 2002, 12:55 PM
Thanks guys! That did the trick. I knew I wouldn't have to think! :)

Ron - I'll mail you an updated version, 2.0.1. I guess I can mail you the source code too?

Mike

Mark F
October 13th, 2002, 12:55 PM
command will have the data you want.

The old code used to set the current command variable before calling the execute method.