Define an object and resources with a custom handler.
#include <string.h>
#include <stdio.h>
#define HEATER_INSTANCES 1
typedef struct
{
char Manufacturer[64];
} HeaterObject;
static HeaterObject heater[HEATER_INSTANCES];
void ** dataPointer, size_t * dataSize, bool * changed)
{
if ((objectID == 1000) && (objectInstanceID >= 0) && (objectInstanceID < HEATER_INSTANCES))
{
switch (operation)
{
{
memset(&heater[objectInstanceID], 0, sizeof(heater[objectInstanceID]));
break;
}
{
switch (resourceID)
{
case 101:
strcpy(heater[objectInstanceID].Manufacturer, "HotAir Systems Inc");
break;
case 104:
heater[objectInstanceID].Temperature = 0.0;
break;
default:
break;
}
break;
}
{
switch (resourceID)
{
case 101:
{
int currentLength = strlen(heater[objectInstanceID].Manufacturer) + 1;
if ((*dataSize != currentLength) || (memcmp(*dataPointer, heater[objectInstanceID].Manufacturer, currentLength) != 0))
{
*changed = true;
strcpy(heater[objectInstanceID].Manufacturer, "HotAir Systems Inc");
}
break;
}
case 104:
{
if (newTemperature != heater[objectInstanceID].Temperature)
{
*changed = true;
heater[objectInstanceID].Temperature = newTemperature;
}
break;
}
default:
break;
}
break;
}
{
switch (resourceID)
{
case 101:
{
*dataPointer = heater[objectInstanceID].Manufacturer;
*dataSize = strlen(heater[objectInstanceID].Manufacturer) + 1;
break;
}
case 104:
{
*dataPointer = &heater[objectInstanceID].Temperature;
*dataSize = sizeof(heater[objectInstanceID].Temperature);
break;
}
default:
break;
}
break;
}
default:
break;
}
}
return result;
}
{
}
{
int instance = 0;
}
int main(void)
{
DefineHeaterObject(awaClient);
CreateHeaterObject(awaClient);
while (1)
{
}
return 0;
}