blob: 79629a747e207bafc79ab4ece5c3b7bf0ade05dc [file] [log] [blame]
/*******************************************************
*
* @brief: none
* @details: Add wakealrm and poweralarm api code
* @author: l.yang
* @date: 2023.8.17
* @version: V1.0
* @copyright: Copyright (c) MobileTek
*
*********************************************/
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<stdbool.h>
#include<log/log.h>
#include "liblog/lynq_deflog.h"
#include <include/libpoweralarm.h>
#include <pthread.h>
#ifdef __cplusplus
extern "C" {
#endif
#define USER_LOG_TAG "LYNQ_POWERALARM"
static int wk_rtc_id = 1;
static int pw_rtc_id = 2;
static int wk_srcid = 0;
typedef int (*sc_rtc_timer_exp_cb)(unsigned int src_id, int rtc_id);
extern int sc_rtc_timer_init(void);
extern int sc_rtc_timer_uninit(void );
extern int sc_rtc_timer_add(int srcid, int rtc_id, unsigned long ulSec, sc_rtc_timer_exp_cb rtc_notify);
extern int sc_rtc_timer_del(int srcid, int rtc_id);
/*****************************************
* @brief:sc_rtc_timer_add_cb
* @param count [IN]:src_id, rtc_id,
* @param sum [OUT]:NA
* @return :0
* @todo:
* @see:NA
* @warning:
******************************************/
int sc_rtc_timer_add_cb(unsigned int src_id, int rtc_id)
{
return 0;
}
/*****************************************
* @brief:Set wakealarm time
* @param count [IN]:buffer,
* @param sum [OUT]:NA
* @return :success 0, failed -1
* @todo:
* @see:NA
* @warning:
******************************************/
ssize_t wakealarm(char *buffer)
{
unsigned long time_sec = 0;
int ret = 0;
LYLOGSET(LOG_INFO);
LYLOGEINIT(USER_LOG_TAG);
if(buffer == NULL)
{
LYINFLOG("Bad input parameter,exit!!!!");
return -1;
}
time_sec = atol(buffer);
LYINFLOG("Set wakealarm %ld seconds ",time_sec);
wk_srcid = sc_rtc_timer_init();
if (wk_srcid <= 0)
{
LYINFLOG("rtc_timer_init fail!");
return -1;
}
ret = sc_rtc_timer_add(wk_srcid, wk_rtc_id, time_sec, sc_rtc_timer_add_cb);
if(ret < 0)
{
LYINFLOG("Add rtc timer failed!!!!");
return -1;
}
LYINFLOG("Set wakealarm success !!!");
ret = sc_rtc_timer_uninit();
if(ret != 0)
{
LYINFLOG("Deinit failed");
}
return 0;
}
/*****************************************
* @brief:set poweralarm time
* @param count [IN]:buffer,
* @param sum [OUT]:NA
* @return :success 0, failed -1
* @todo:
* @see:NA
* @warning:
******************************************/
ssize_t poweralarm(char *buffer)
{
int srcid = 0;
unsigned long time_sec = 0;
int ret = 0;
LYLOGSET(LOG_INFO);
LYLOGEINIT(USER_LOG_TAG);
if(buffer == NULL)
{
LYINFLOG("Bad input parameter,exit!!!!");
return -1;
}
time_sec = atol(buffer);
LYINFLOG("Set poweralarm %ld seconds",time_sec);
srcid = sc_rtc_timer_init();
if (srcid <= 0)
{
LYINFLOG("rtc_timer_init fail!");
return -1;
}
ret = sc_rtc_timer_add(srcid, pw_rtc_id, time_sec, sc_rtc_timer_add_cb);
if(ret < 0)
{
LYINFLOG("Add rtc timer failed!!!!");
return -1;
}
LYINFLOG("Set poweralarm success !!!");
ret = sc_rtc_timer_uninit();
if(ret != 0)
{
LYINFLOG("Deinit failed");
}
return 0;
}
/**********************************************
* @brief:cancel_wakealarm,
* @param count [IN]:void
* @param sum [OUT]:NA
* @return :success 0, failed -1
* @todo:
* @see:NA
* @warning:
********************************************/
ssize_t cancel_wakealarm(void)
{
int ret = 0;
LYINFLOG("Enter cancel_wakealarm ");
ret = sc_rtc_timer_del(wk_srcid, wk_rtc_id);
if(ret < 0)
{
LYINFLOG("Del wakealarm failed!!!");
return -1;
}
return 0;
}
/*****************************************
* @brief:lynq_set_poweralarm
* @param count [IN]:unsigned long time_sec
* @param sum [OUT]:NA
* @return :success 0, failed -1
* @todo:
* @see:NA
* @warning:
******************************************/
int lynq_set_poweralarm(unsigned long time_sec)
{
int ret = 0;
int srcid = 0;
LYINFLOG("lynq_set_poweralarm %ld seconds",time_sec);
srcid = sc_rtc_timer_init();
if (srcid <= 0)
{
LYINFLOG("rtc_timer_init fail!");
return -1;
}
ret = sc_rtc_timer_add(srcid, pw_rtc_id, time_sec, sc_rtc_timer_add_cb);
if(ret < 0)
{
LYINFLOG("Add rtc timer failed!!!!");
return -1;
}
LYINFLOG("Set poweralarm success !!!");
ret = sc_rtc_timer_uninit();
if(ret != 0)
{
LYINFLOG("Deinit failed");
}
return 0;
}
/*****************************************
* @brief:lynq_set_wakealarm
* @param count [IN]:unsigned long time_sec
* @param sum [OUT]:NA
* @return :success 0, failed -1
* @todo:
* @see:NA
* @warning:
******************************************/
int lynq_set_wakealarm(unsigned long time_sec)
{
int ret = 0;
LYINFLOG("lynq_set_wakealarm %ld seconds ",time_sec);
wk_srcid = sc_rtc_timer_init();
if (wk_srcid <= 0)
{
LYINFLOG("rtc_timer_init fail!");
return -1;
}
ret = sc_rtc_timer_add(wk_srcid, wk_rtc_id, time_sec, sc_rtc_timer_add_cb);
if(ret < 0)
{
LYINFLOG("Add rtc timer failed!!!!");
return -1;
}
LYINFLOG("Set wakealarm success !!!");
ret = sc_rtc_timer_uninit();
if(ret != 0)
{
LYINFLOG("Deinit failed!!!");
}
return 0;
}
#ifdef __cplusplus
}
#endif