EvenAR / node-simconnect

A cross platform SimConnect client library for Node.JS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Subscribe to 'CustomMissionActionExecuted' event

Hegyusz opened this issue · comments

Hi Even!

I have some problem when calling the subscribeToSystemEvent('CustomMissionActionExecuted') function. I can get all the Crash, Start, Stop, Pause events, but not this one. I know, that there is a Custom Action in the mission, but this function never returns any value.

Here is an example of the function: https://www.prepar3d.com/SDKv4/sdk/simconnect_api/samples/mission_action.html.

My code looks like this:

simConnect.subscribeToSystemEvent('CustomMissionActionExecuted', (customAction) => {
  console.log('customAction', customAction);
});

Am I doing something wrong? Can you help me please?

Thanks!

Okay, I could solved half of this issue. I added the function above to the addon.cc file:

void handleReceived_CustomAction(Isolate* isolate, SIMCONNECT_RECV* pData, DWORD cbData) {
	SIMCONNECT_RECV_CUSTOM_ACTION* myEvent = (SIMCONNECT_RECV_CUSTOM_ACTION*)pData;

	const int argc = 1;
	Local<Value> argv[argc] = {
		String::NewFromUtf8(isolate, myEvent->szPayLoad)
	};

	systemEventCallbacks[myEvent->uEventID]->Call(isolate->GetCurrentContext()->Global(), argc, argv);
}

This is now returning the first letter of the payload. I have the same issue with C#. Can anybody help me to get the full string? I have no idea, what I am doing wrong...

Thanks!

Hi!

According to the SDK reference, szPayLoad is a variable length string. I beleive this must be retrieved using SimConnect_RetrieveString. An example of usage can be seen here.

Even

Hi!

Thank you for your answer. I tried you suggestion, but without success. Same error, I can only retrieve the first letter of the string.
Currently what I'm doing now to solve the issue, to get the GUID of the CustomAction and search in the xml file for the full length string. It's working, but it would much easier and better to get the string from the SDK.

Thanks,
Viktor

Hmm ok.. Did you try with
String::NewFromOneByte(..) instead of String::NewFromUtf8(..)?

Even

Yes, i tried both! Same response.

Viktor

I haven't been able to test this, but I was thinking of something like this:

void handleReceived_CustomAction(Isolate* isolate, SIMCONNECT_RECV* pData, DWORD cbData) {
	SIMCONNECT_RECV_CUSTOM_ACTION* myEvent = (SIMCONNECT_RECV_CUSTOM_ACTION*)pData;

	char *pOutString;
	DWORD cbString;
	char * pStringV = ((char*)(&myEvent->szPayLoad));

	HRESULT hr = SimConnect_RetrieveString(pData, cbData, pStringV, &pOutString, &cbString);
	v8::Local<v8::String> value = String::NewFromOneByte(isolate, (const uint8_t*)pOutString);

	const int argc = 1;
	Local<Value> argv[argc] = {
		value
	};

	systemEventCallbacks[myEvent->uEventID]->Call(isolate->GetCurrentContext()->Global(), argc, argv);
}

If the result is the same, try retrieving the string from pStringV + 8, like this:
HRESULT hr = SimConnect_RetrieveString(pData, cbData, pStringV+8, &pOutString, &cbString);
I don't understand why, but when handling SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE I had to do this to retreive strings correctly. This could also be the case for SIMCONNECT_RECV_ID_CUSTOM_ACTION.

This might have been fixed in v3.x. Closing this for now.