Listing 2Heres the Analog Input Point class for the temperature and humidity sensors. The Explicit message handler allows the master to get any of the three attributes. They are read-only, so the Set Attribute service is not supported.
class ANALOG_INPUT_POINT{
private:
UCHAR value; // sensor value
UCHAR data_type; // data type of value
BOOL status; // alarm status
static UINT class_revision; // revision of object
public:
static void handle_class_inquiry(UCHAR*, UCHAR*);
void handle_explicit(UCHAR*, UCHAR*);
ANALOG_INPUT_POINT() {value = 0; status = 0; data_type = 2;}
};
// Handle explicit request to Analog Input Point
void ANALOG_INPUT_POINT::handle_explicit(UCHAR request[],
UCHAR response[])
{
UINT service, attrib, error;
service = request[1]; attrib = request[4]; error = 0;
memset(response, 0, BUFSIZE); // clear response buffer
switch(service){
case GET_REQUEST:
switch(attrib){ // return requested attribute
case 3: // value
response[0] = request[0] & NON_FRAGMENTED;
response[1] = service | SUCCESS_RESPONSE;
response[2] = value;
response[LENGTH] = 3;
break;
case 4: // status
response[0] = request[0] & NON_FRAGMENTED;
response[1] = service | SUCCESS_RESPONSE;
response[2] = (UCHAR)status;
response[LENGTH] = 3;
break;
case 8: // data type
response[0] = request[0] & NON_FRAGMENTED;
response[1] = service | SUCCESS_RESPONSE;
response[2] = data_type;
response[LENGTH] = 3;
break;
default: error = ATTRIB_NOT_SUPPORTED; break;
}
break;
default: error = SERVICE_NOT_SUPPORTED; break;
}
if (error) // return error response{
response[0] = request[0] & NON_FRAGMENTED;
response[1] = ERROR_RESPONSE;
response[2] = error;
response[3] = NO_ADDITIONAL_CODE;
response[LENGTH] = 4;
}
}