264 views
in System Integration by

Hi Gents,

 I know this is a well worn path, and I've read https://doc.embedded-wizard.de/integrating-with-the-device#10. But I'm at a bit of a loss.

I call DeviceDriver_getProfiles() from a native() block. And in my DeviceDriver.c I have:

void DeviceDriver_getProfiles(XUInt8 profile_count, XUInt32 *profile_uid, XString* profile_desc, XUInt8* profile_mode)
{
    ApplicationDeviceClass device = EwGetAutoObject( &ApplicationDevice, ApplicationDeviceClass );

    if(g_SDcardFatfsInstance.mounted)
    {
        profile_count = MAX_CONFIG_FILES;
        for (uint8_t x = 0; x < MAX_CONFIG_FILES; x++)
        {
            profile_uid[x] = PROFILE_info->UID[x];
            profile_desc[x] = EwNewStringAnsi(PROFILE_info->Desc[x]);
            profile_mode[x] = PROFILE_info->Mode[x];
        }
    }

    ApplicationDeviceClass__PROFILE_update(device, profile_count, profile_uid, profile_desc, profile_mode);
}

 

This wont work because you cant specify an Array as an argument to a Method{} as with my PROFILE_update{} method. 

I'm able to pass arrays into DeviceDriver_getProfiles() but how do I get them out once stuffed? To then push into device.PROFILE_myproperty;
Is there a way to pass an array into ApplicationDeviceClass__PROFILE_update()? Or is there a way to directly stuff my device.PROFILE_myproperties within the DeviceDriver.c code?

by

Oh, I think I just realized what I can do:

void DeviceDriver_getProfiles(XUInt8 profile_count, XUInt32 *profile_uid, XString* profile_desc, XUInt8* profile_mode)
{
	ApplicationDeviceClass device = EwGetAutoObject( &ApplicationDevice, ApplicationDeviceClass );


	if(g_SDcardFatfsInstance.mounted)
	{
		device->PROFILE_count = MAX_CONFIG_FILES;
		for (uint8_t x = 0; x < MAX_CONFIG_FILES; x++)
		{
			
			//profile_desc[x] = EwNewStringAnsi(PROFILE_info->Desc[x]);
			//profile_mode[x] = PROFILE_info->Mode[x];
			device->PROFILE_uid[x] = PROFILE_info->UID[x];
			device->PROFILE_Mode[x] = PROFILE_info->Mode[x];
			EwRetainString( &device->PROFILE_desc[x], EwNewStringAnsi(PROFILE_info->Desc[x]));		
		}
	}
}

I can access device. properties directly like that and use EwRetainString() to keep the Strings happy. Forgoing the need to use localized variables. No?

1 Answer

0 votes
by

Hello Mike,

passing arrays directy as method parameters is not possible. Some possibilies how to exchange array contents is addressed in the section Exchange array contents.

In your concrete case, PROFILE_uid, PROFILE_Mode and PROFILE_desc are arrays embedded within the device obejct. These can be accessed even from the native code and initialized with other values. At the end of the initialization you can call some Update method of the device object to notify it about the just made modification. Although accessing object members from C code is possible, we avoid to recommend this approach. It expects some deeper knowledge of the underlying concepts. One of these aspects, for example, is to always use EwRetainString() when assigning a string to a variable or array item existing within the object.

You can also modify the implementation and pass the array values individually by invoking a method for each value. This could be the implementation:

void DeviceDriver_getProfiles(XUInt8 profile_count, XUInt32 *profile_uid, XString* profile_desc, XUInt8* profile_mode)
{
    ApplicationDeviceClass device = EwGetAutoObject( &ApplicationDevice, ApplicationDeviceClass );

    if(g_SDcardFatfsInstance.mounted)
    {
        profile_count = MAX_CONFIG_FILES;
        for (uint8_t x = 0; x < MAX_CONFIG_FILES; x++)
        {
           ApplicationDeviceClass__PROFILE_update_item(device, x, PROFILE_info->UID[x],
             EwNewStringAnsi(PROFILE_info->Desc[x]), PROFILE_info->Mode[x]);
        }
    }
}

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...