<commit_before>#include "legato.h"
#include "interfaces.h"

// [DeclareVariables]
#define APP_RUNNING_DURATION_SEC 600        //run this app for 10min
// [AssetDataPath]
//-------------------------------------------------------------------------------------------------
/**
 * Declare asset data path
 */
//-------------------------------------------------------------------------------------------------

/* variables */
// string - room name
#define ROOM_NAME_VAR_RES   "/home1/room1/roomName"

// bool - status of air conditioning in the room ON or OFF
#define IS_AC_ON_VAR_RES   "/home1/room1/AC/IsACOn"

// float - room temperature reading
#define ROOM_TEMP_READING_VAR_RES "/home1/room1/thermostat/roomTemp"

/* settings*/

//float - target temperature setting
#define TARGET_TEMP_SET_RES "/home1/room1/thermostat/targetTemp"

/* commands */

// commands to turn off the air conditioning
#define AC_CMD_TURN_OFF_RES              "/home1/room1/AC/ACControl"
// [AssetDataPath]
//-------------------------------------------------------------------------------------------------
/**
 * AVC related variable and update timer
 */
//-------------------------------------------------------------------------------------------------
// reference timer for app session
le_timer_Ref_t sessionTimer;
//reference to AVC event handler
le_avdata_SessionStateHandlerRef_t  avcEventHandlerRef = NULL;
//reference to AVC Session handler
le_avdata_RequestSessionObjRef_t sessionRef = NULL;
//reference to temperature update timer
le_timer_Ref_t tempUpdateTimerRef = NULL;
//reference to push asset data timer
le_timer_Ref_t serverUpdateTimerRef = NULL;

//-------------------------------------------------------------------------------------------------
/**
 * Counters recording the number of times certain hardwares are accessed.
 */
//-------------------------------------------------------------------------------------------------
static int ReadTempVarCounter = 0;
static int WriteTempSettingCounter = 0;
static int ExecACCmd = 0;

//-------------------------------------------------------------------------------------------------
/**
 * Target temperature related declarations.
 */
//-------------------------------------------------------------------------------------------------
static char* RoomNameVar;
static double RoomTempVar = 0.0;
static int TargetTempSet = 0;
static bool IsACOn = false;
static int OutsideTemp = 30;

// [DeclareVariables]

//-------------------------------------------------------------------------------------------------
/**
 * Asset data handlers
 */
//-------------------------------------------------------------------------------------------------

// [VariableDataHandler]
//-------------------------------------------------------------------------------------------------
/**
 * Variable data handler.
 * This function is returned whenever AirVantage performs a read on the room's temperature
 */
//-------------------------------------------------------------------------------------------------
static void ReadTempVarHandler
(
    const char* path,
    le_avdata_AccessType_t accessType,
    le_avdata_ArgumentListRef_t argumentList,
    void* contextPtr
)
{
    ReadTempVarCounter++;

    LE_INFO("------------------- Server reads room temperature [%d] times ------------",
            ReadTempVarCounter);
}
// [VariableDataHandler]
// [DataHandlerFunction]
//-------------------------------------------------------------------------------------------------
/**
 * Setting data handler.
 * This function is returned whenever AirVantage performs a read or write on the target temperature
 */
//-------------------------------------------------------------------------------------------------
// [TempSettingHandler]
static void TempSettingHandler
(
    const char* path,
    le_avdata_AccessType_t accessType,
    le_avdata_ArgumentListRef_t argumentList,
    void* contextPtr
)
// TempSettingHandler
{
    WriteTempSettingCounter++;

    LE_INFO("------------------- Server writes temperature setting [%d] times ------------",
                WriteTempSettingCounter);
    int targetTempLatest = 0;
    le_result_t resultGetInt = le_avdata_GetInt(TARGET_TEMP_SET_RES, &targetTempLatest);
    if (LE_FAULT == resultGetInt)
    {
        LE_ERROR("Error in getting latest TARGET_TEMP_SET_RES");
    }
    // if targetTempLatest from server is not the same as the current TargetTempSet
    // ,then set to the latest one
    if (targetTempLatest != TargetTempSet){
        TargetTempSet=targetTempLatest;
        le_result_t resultSetTargetTemp = le_avdata_SetInt(TARGET_TEMP_SET_RES, TargetTempSet);
        if (LE_FAULT == resultSetTargetTemp)
        {
            LE_ERROR("Error in getting latest TARGET_TEMP_SET_RES");
        }
        LE_INFO("Setting Write target temperature request: %s is %d C°",
                                            "TARGET_TEMP_SET_RES", TargetTempSet);
    }
    // turn on the air conditioning if room temperature is higher than target temperature
    if (TargetTempSet < RoomTempVar)
    {
        le_result_t resultSetAC = le_avdata_SetBool(IS_AC_ON_VAR_RES, true);
        if (LE_FAULT == resultSetAC)
        {
            LE_ERROR("Error in setting IS_AC_ON_VAR_RES");
        }
        LE_INFO("Setting Write turning on AC variable request: %s", "IS_AC_ON_VAR_RES");
    }else{
        le_result_t resultSetAC = le_avdata_SetBool(IS_AC_ON_VAR_RES, true);
        if (LE_FAULT == resultSetAC)
        {
            LE_ERROR("Error in setting IS_AC_ON_VAR_RES");
        }
        LE_INFO("Setting Write turning on AC variable request: %s", "IS_AC_ON_VAR_RES");
    }
}
// [DataHandlerFunction]<commit_msg>Update sample app<commit_after>#include "legato.h"
#include "interfaces.h"

// [DeclareVariables]
#define APP_RUNNING_DURATION_SEC 600        //run this app for 10min
// [AssetDataPath]
//-------------------------------------------------------------------------------------------------
/**
 * Declare asset data path
 */
//-------------------------------------------------------------------------------------------------

/* variables */
// string - room name
#define ROOM_NAME_VAR_RES   "/home1/room1/roomName"

// bool - status of air conditioning in the room ON or OFF
#define IS_AC_ON_VAR_RES   "/home1/room1/AC/IsACOn"

// float - room temperature reading
#define ROOM_TEMP_READING_VAR_RES "/home1/room1/thermostat/roomTemp"

/* settings*/

//float - target temperature setting
#define TARGET_TEMP_SET_RES "/home1/room1/thermostat/targetTemp"

/* commands */

// commands to turn off the air conditioning
#define AC_CMD_TURN_OFF_RES              "/home1/room1/AC/ACControl"
// [AssetDataPath]
//-------------------------------------------------------------------------------------------------
/**
 * AVC related variable and update timer
 */
//-------------------------------------------------------------------------------------------------
// reference timer for app session
le_timer_Ref_t sessionTimer;
//reference to AVC event handler
le_avdata_SessionStateHandlerRef_t  avcEventHandlerRef = NULL;
//reference to AVC Session handler
le_avdata_RequestSessionObjRef_t sessionRef = NULL;
//reference to temperature update timer
le_timer_Ref_t tempUpdateTimerRef = NULL;
//reference to push asset data timer
le_timer_Ref_t serverUpdateTimerRef = NULL;

//-------------------------------------------------------------------------------------------------
/**
 * Counters recording the number of times certain hardwares are accessed.
 */
//-------------------------------------------------------------------------------------------------
static int ReadTempVarCounter = 0;
static int WriteTempSettingCounter = 0;
static int ExecACCmd = 0;

//-------------------------------------------------------------------------------------------------
/**
 * Target temperature related declarations.
 */
//-------------------------------------------------------------------------------------------------
static char* RoomNameVar;
static double RoomTempVar = 0.0;
static int TargetTempSet = 0;
static bool IsACOn = false;
static int OutsideTemp = 30;

// [DeclareVariables]

//-------------------------------------------------------------------------------------------------
/**
 * Asset data handlers
 */
//-------------------------------------------------------------------------------------------------

// [VariableDataHandler]
//-------------------------------------------------------------------------------------------------
/**
 * Variable data handler.
 * This function is returned whenever AirVantage performs a read on the room's temperature
 */
//-------------------------------------------------------------------------------------------------
static void ReadTempVarHandler
(
    const char* path,
    le_avdata_AccessType_t accessType,
    le_avdata_ArgumentListRef_t argumentList,
    void* contextPtr
)
{
    ReadTempVarCounter++;

    LE_INFO("------------------- Server reads room temperature [%d] times ------------",
            ReadTempVarCounter);
}
// [VariableDataHandler]
// [DataHandlerFunction]
//-------------------------------------------------------------------------------------------------
/**
 * Setting data handler.
 * This function is returned whenever AirVantage performs a read or write on the target temperature
 */
//-------------------------------------------------------------------------------------------------
// [TempSettingHandler]
static void TempSettingHandler
(
    const char* path,
    le_avdata_AccessType_t accessType,
    le_avdata_ArgumentListRef_t argumentList,
    void* contextPtr
)
// TempSettingHandler
{
    WriteTempSettingCounter++;

    LE_INFO("------------------- Server writes temperature setting [%d] times ------------",
                WriteTempSettingCounter);
    le_result_t resultGetInt = le_avdata_GetInt(TARGET_TEMP_SET_RES, &TargetTempSet);
    if (LE_FAULT == resultGetInt)
    {
        LE_ERROR("Error in getting latest TARGET_TEMP_SET_RES");
    }

    // turn on the air conditioning if room temperature is higher than target temperature
    if (TargetTempSet < RoomTempVar)
    {
        le_result_t resultSetAC = le_avdata_SetBool(IS_AC_ON_VAR_RES, true);
        if (LE_FAULT == resultSetAC)
        {
            LE_ERROR("Error in setting IS_AC_ON_VAR_RES");
        }
        LE_INFO("Setting Write turning on AC variable request: %s", "IS_AC_ON_VAR_RES");
    }else{
        le_result_t resultSetAC = le_avdata_SetBool(IS_AC_ON_VAR_RES, true);
        if (LE_FAULT == resultSetAC)
        {
            LE_ERROR("Error in setting IS_AC_ON_VAR_RES");
        }
        LE_INFO("Setting Write turning on AC variable request: %s", "IS_AC_ON_VAR_RES");
    }
}
// [DataHandlerFunction]
{'fraction_non_alphanumeric': 0.3326198231735691, 'fraction_numerical': 0.0043741275011633315, 'mean_word_length': 1.3104708664803268, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3099264', 'n_tokens_mistral': 2502, 'n_tokens_neox': 2468, 'n_words': 673}