/*
 * Go2RangeDifference.c
 * 
 * Gocator system communication library
 * Copyright (C) 2013 by LMI Technologies Inc.
 * 
 * Licensed under The MIT License.
 * Redistributions of files must retain the above copyright notice.
 */

#include <z/Go2Measurements/zGo2RangeDifference.h>
#include <z/zGo2System.h>
#include <string.h>

/*
 * Go2RangeDifference Class 
 */

GO2_EXPORT(Go2Status) Go2RangeDifference_Construct(Go2RangeDifference* measurement, Go2UInt32 id, Go2Object system)
{
    Go2RangeDifference output = zNIL; 
    Go2Status status = zOK; 

    zCHECK(zCalloc(&output, 1, sizeof(Go2RangeDifferenceClass))); 

    if (!zSUCCESS(status = Go2RangeDifference_Init(output, id, system)))
    {
        zCHECK(Go2Object_Destroy(output)); 
        return status; 
    }

    *measurement = output; 

    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2RangeDifference_Init(Go2RangeDifference measurement, Go2UInt32 id, Go2Object system)
{
    Go2RangeDifferenceClass* obj = zHANDLE_POINTER(measurement);

    zCHECK(Go2Measurement_Init(measurement, GO2_TYPE_RANGE_DIFFERENCE, id, system)); 

    obj->Read = Go2RangeDifference_VRead; 
    obj->Write = Go2RangeDifference_VWrite; 
    obj->source = GO2_RANGE_SOURCE_BOTH;

    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2RangeDifference_VRead(Go2RangeDifference measurement, zXml xml, zXmlItem item)
{
    Go2RangeDifferenceClass* obj = zHANDLE_POINTER(measurement);
    zChar* text = zNULL;
    z32u textCapacity = GO2_MEASUREMENT_SOURCE_TEXT_CAPACITY; 

    zCHECK(Go2Measurement_VRead(measurement, xml, item)); 

    zCHECK(zCalloc(&text, textCapacity, sizeof(zChar)));
    zCHECK(zXml_ChildText(xml, item, "SourceOptions", text, textCapacity)); 
    zCHECK(Go2OptionList_ParseList(text, obj->sourceOptions));  

    zCHECK(zXml_Child32s(xml, item, "Source", &obj->source)); 

    zCHECK(zXml_Child32s(xml, item, "AbsoluteResult", &obj->absoluteResult)); 

    zCHECK(zFree(text));

    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2RangeDifference_VWrite(Go2RangeDifference  measurement, zXml xml, zXmlItem item)
{
    Go2RangeDifferenceClass* obj = zHANDLE_POINTER(measurement);

    zCHECK(Go2Measurement_VWrite(measurement, xml, item)); 

    zCHECK(zXml_SetChild32s(xml, item, "Source", obj->source)); 

    zCHECK(zXml_SetChild32s(xml, item, "AbsoluteResult", obj->absoluteResult)); 

    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2RangeDifference_SetId(Go2RangeDifference measurement, Go2UInt32 id)
{
    return Go2Measurement_SetId(measurement, id); 
}

GO2_EXPORT(Go2UInt32) Go2RangeDifference_Id(Go2RangeDifference measurement)
{
    return Go2Measurement_Id(measurement); 
}

GO2_EXPORT(Go2Status) Go2RangeDifference_SetName(Go2RangeDifference measurement, const Go2Char* name)
{
    return Go2Measurement_SetName(measurement, name); 
}

GO2_EXPORT(Go2Status) Go2RangeDifference_Name(Go2RangeDifference measurement, Go2Char* name, Go2UInt32 capacity)
{
    return Go2Measurement_Name(measurement, name, capacity); 
}

GO2_EXPORT(Go2UInt32) Go2RangeDifference_SourceOptionCount(Go2RangeDifference measurement)
{
    return Go2Measurement_SourceOptionCount(measurement);     
}

GO2_EXPORT(Go2RangeSource) Go2RangeDifference_SourceOptionAt(Go2RangeDifference measurement, Go2UInt32 index)
{
    return Go2Measurement_SourceOptionAt(measurement, index);     
}

GO2_EXPORT(Go2Status) Go2RangeDifference_SetSource(Go2RangeDifference measurement, Go2RangeSource source)
{
    return Go2Measurement_SetSource(measurement, source);     
}

GO2_EXPORT(Go2RangeSource) Go2RangeDifference_Source(Go2RangeDifference measurement)
{
    return Go2Measurement_Source(measurement);     
}

GO2_EXPORT(Go2Status) Go2RangeDifference_SetDecisionMin(Go2RangeDifference measurement, Go2Double min)
{
    return Go2Measurement_SetDecisionMin(measurement, min); 
}

GO2_EXPORT(Go2Double) Go2RangeDifference_DecisionMin(Go2RangeDifference measurement)
{
    return Go2Measurement_DecisionMin(measurement); 
}

GO2_EXPORT(Go2Status) Go2RangeDifference_SetDecisionMax(Go2RangeDifference measurement, Go2Double max)
{
    return Go2Measurement_SetDecisionMax(measurement, max); 
}

GO2_EXPORT(Go2Double) Go2RangeDifference_DecisionMax(Go2RangeDifference measurement)
{
    return Go2Measurement_DecisionMax(measurement); 
}

GO2_EXPORT(Go2Status) Go2RangeDifference_EnableHold(Go2RangeDifference measurement, Go2Bool enable)
{
    return Go2Measurement_EnableHold(measurement, enable);  
} 

GO2_EXPORT(Go2Bool) Go2RangeDifference_HoldEnabled(Go2RangeDifference measurement)
{
    return Go2Measurement_HoldEnabled(measurement);  
}

GO2_EXPORT(Go2Status) Go2RangeDifference_EnableSmoothing(Go2RangeDifference measurement, Go2Bool enable)
{
    return Go2Measurement_EnableSmoothing(measurement, enable);  
} 

GO2_EXPORT(Go2Bool) Go2RangeDifference_SmoothingEnabled(Go2RangeDifference measurement)
{
    return Go2Measurement_SmoothingEnabled(measurement);  
} 

GO2_EXPORT(Go2UInt32) Go2RangeDifference_SmoothingWindowMin(Go2RangeDifference measurement)
{
    return Go2Measurement_SmoothingWindowMin(measurement);  
} 

GO2_EXPORT(Go2UInt32) Go2RangeDifference_SmoothingWindowMax(Go2RangeDifference measurement)
{
    return Go2Measurement_SmoothingWindowMax(measurement);  
} 

GO2_EXPORT(Go2Status) Go2RangeDifference_SetSmoothingWindow(Go2RangeDifference measurement, Go2UInt32 window)
{
    return Go2Measurement_SetSmoothingWindow(measurement, window);  
} 

GO2_EXPORT(Go2UInt32) Go2RangeDifference_SmoothingWindow(Go2RangeDifference measurement)
{
    return Go2Measurement_SmoothingWindow(measurement);  
} 

GO2_EXPORT(Go2Status) Go2RangeDifference_SetAbsoluteResult(Go2RangeDifference measurement, Go2Bool absolute)
{
    Go2RangeDifferenceClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_CheckConfigurable(obj->system)); 
    obj->absoluteResult = absolute; 
    zCHECK(Go2System_SetModified(obj->system)); 

    return GO2_OK; 
}
 
GO2_EXPORT(Go2Bool) Go2RangeDifference_AbsoluteResult(Go2RangeDifference measurement)
{
    Go2RangeDifferenceClass* obj = zHANDLE_POINTER(measurement); 
    return obj->absoluteResult;   
}

GO2_EXPORT(Go2Status) Go2RangeDifference_SetScale(Go2RangeDifference measurement, Go2Double scale){
    return Go2Measurement_SetScale(measurement, scale);
}

GO2_EXPORT(Go2Double) Go2RangeDifference_Scale(Go2RangeDifference measurement){
    return Go2Measurement_Scale(measurement);
}

GO2_EXPORT(Go2Status) Go2RangeDifference_SetOffset(Go2RangeDifference measurement, Go2Double offset){
    return Go2Measurement_SetOffset(measurement, offset);
}

GO2_EXPORT(Go2Double) Go2RangeDifference_Offset(Go2RangeDifference measurement){
    return Go2Measurement_Offset(measurement);
}

GO2_EXPORT(Go2UInt32) Go2RangeDifference_LinkOptionCount(Go2RangeDifference measurement)
{
    return Go2Measurement_LinkOptionCount(measurement);
}

GO2_EXPORT(Go2UInt32) Go2RangeDifference_LinkOptionAt(Go2RangeDifference measurement, Go2UInt32 index)
{
    return Go2Measurement_LinkOptionAt(measurement, index);
}

GO2_EXPORT(Go2Status) Go2RangeDifference_EnableLink(Go2RangeDifference measurement, Go2Bool enable)  
{
    return Go2Measurement_EnableLink(measurement, enable);  
}

GO2_EXPORT(Go2Bool) Go2RangeDifference_LinkEnabled(Go2RangeDifference measurement)  
{
    return Go2Measurement_LinkEnabled(measurement);  
}

GO2_EXPORT(Go2Status) Go2RangeDifference_SetLink(Go2RangeDifference measurement, Go2UInt32 link) 
{
    return Go2Measurement_SetLink(measurement, link); 
}

GO2_EXPORT(Go2UInt32) Go2RangeDifference_Link(Go2RangeDifference measurement) 
{
    return Go2Measurement_Link(measurement); 
}
