l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame^] | 1 | /*******************************************************
|
| 2 | *
|
| 3 | * @brief: none
|
| 4 | * @details: Add wakealrm and poweralarm api code
|
| 5 | * @author: l.yang
|
| 6 | * @date: 2023.8.17
|
| 7 | * @version: V1.0
|
| 8 | * @copyright: Copyright (c) MobileTek
|
| 9 | *
|
| 10 | *********************************************/
|
| 11 |
|
| 12 | #include<stdio.h>
|
| 13 | #include<stdlib.h>
|
| 14 | #include<unistd.h>
|
| 15 | #include<stdbool.h>
|
| 16 | #include<log/log.h>
|
| 17 | #include "liblog/lynq_deflog.h"
|
| 18 | #include <include/libpoweralarm.h>
|
| 19 | #include <pthread.h>
|
| 20 |
|
| 21 |
|
| 22 | #ifdef __cplusplus
|
| 23 | extern "C" {
|
| 24 | #endif
|
| 25 |
|
| 26 | #define USER_LOG_TAG "LYNQ_POWERALARM"
|
| 27 |
|
| 28 |
|
| 29 | static int wk_rtc_id = 1;
|
| 30 | static int pw_rtc_id = 2;
|
| 31 | static int wk_srcid = 0;
|
| 32 |
|
| 33 | typedef int (*sc_rtc_timer_exp_cb)(unsigned int src_id, int rtc_id);
|
| 34 | extern int sc_rtc_timer_init(void);
|
| 35 | extern int sc_rtc_timer_uninit(void );
|
| 36 | extern int sc_rtc_timer_add(int srcid, int rtc_id, unsigned long ulSec, sc_rtc_timer_exp_cb rtc_notify);
|
| 37 | extern int sc_rtc_timer_del(int srcid, int rtc_id);
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 | /*****************************************
|
| 42 | * @brief:sc_rtc_timer_add_cb
|
| 43 | * @param count [IN]:src_id, rtc_id,
|
| 44 | * @param sum [OUT]:NA
|
| 45 | * @return :0
|
| 46 | * @todo:
|
| 47 | * @see:NA
|
| 48 | * @warning:
|
| 49 | ******************************************/
|
| 50 | int sc_rtc_timer_add_cb(unsigned int src_id, int rtc_id)
|
| 51 | {
|
| 52 | return 0;
|
| 53 | }
|
| 54 |
|
| 55 |
|
| 56 | /*****************************************
|
| 57 | * @brief:Set wakealarm time
|
| 58 | * @param count [IN]:buffer,
|
| 59 | * @param sum [OUT]:NA
|
| 60 | * @return :success 0, failed -1
|
| 61 | * @todo:
|
| 62 | * @see:NA
|
| 63 | * @warning:
|
| 64 | ******************************************/
|
| 65 | ssize_t wakealarm(char *buffer)
|
| 66 | {
|
| 67 | unsigned long time_sec = 0;
|
| 68 | int ret = 0;
|
| 69 |
|
| 70 | LYLOGSET(LOG_INFO);
|
| 71 | LYLOGEINIT(USER_LOG_TAG);
|
| 72 |
|
| 73 | if(buffer == NULL)
|
| 74 | {
|
| 75 | LYINFLOG("Bad input parameter,exit!!!!");
|
| 76 | return -1;
|
| 77 | }
|
| 78 |
|
| 79 | time_sec = atol(buffer);
|
| 80 |
|
| 81 | LYINFLOG("Set wakealarm %ld seconds ",time_sec);
|
| 82 | wk_srcid = sc_rtc_timer_init();
|
| 83 | if (wk_srcid <= 0)
|
| 84 | {
|
| 85 | LYINFLOG("rtc_timer_init fail!");
|
| 86 | return -1;
|
| 87 | }
|
| 88 | ret = sc_rtc_timer_add(wk_srcid, wk_rtc_id, time_sec, sc_rtc_timer_add_cb);
|
| 89 | if(ret < 0)
|
| 90 | {
|
| 91 | LYINFLOG("Add rtc timer failed!!!!");
|
| 92 | return -1;
|
| 93 | }
|
| 94 |
|
| 95 | LYINFLOG("Set wakealarm success !!!");
|
| 96 |
|
| 97 | ret = sc_rtc_timer_uninit();
|
| 98 | if(ret != 0)
|
| 99 | {
|
| 100 | LYINFLOG("Deinit failed");
|
| 101 | }
|
| 102 |
|
| 103 | return 0;
|
| 104 |
|
| 105 | }
|
| 106 |
|
| 107 |
|
| 108 | /*****************************************
|
| 109 | * @brief:set poweralarm time
|
| 110 | * @param count [IN]:buffer,
|
| 111 | * @param sum [OUT]:NA
|
| 112 | * @return :success 0, failed -1
|
| 113 | * @todo:
|
| 114 | * @see:NA
|
| 115 | * @warning:
|
| 116 | ******************************************/
|
| 117 | ssize_t poweralarm(char *buffer)
|
| 118 | {
|
| 119 | int srcid = 0;
|
| 120 | unsigned long time_sec = 0;
|
| 121 | int ret = 0;
|
| 122 |
|
| 123 | LYLOGSET(LOG_INFO);
|
| 124 | LYLOGEINIT(USER_LOG_TAG);
|
| 125 |
|
| 126 | if(buffer == NULL)
|
| 127 | {
|
| 128 | LYINFLOG("Bad input parameter,exit!!!!");
|
| 129 | return -1;
|
| 130 | }
|
| 131 |
|
| 132 | time_sec = atol(buffer);
|
| 133 |
|
| 134 | LYINFLOG("Set poweralarm %ld seconds",time_sec);
|
| 135 | srcid = sc_rtc_timer_init();
|
| 136 | if (srcid <= 0)
|
| 137 | {
|
| 138 | LYINFLOG("rtc_timer_init fail!");
|
| 139 | return -1;
|
| 140 | }
|
| 141 | ret = sc_rtc_timer_add(srcid, pw_rtc_id, time_sec, sc_rtc_timer_add_cb);
|
| 142 | if(ret < 0)
|
| 143 | {
|
| 144 | LYINFLOG("Add rtc timer failed!!!!");
|
| 145 | return -1;
|
| 146 | }
|
| 147 |
|
| 148 | LYINFLOG("Set poweralarm success !!!");
|
| 149 |
|
| 150 | ret = sc_rtc_timer_uninit();
|
| 151 | if(ret != 0)
|
| 152 | {
|
| 153 | LYINFLOG("Deinit failed");
|
| 154 | }
|
| 155 |
|
| 156 | return 0;
|
| 157 |
|
| 158 | }
|
| 159 |
|
| 160 | /**********************************************
|
| 161 | * @brief:cancel_wakealarm,
|
| 162 | * @param count [IN]:void
|
| 163 | * @param sum [OUT]:NA
|
| 164 | * @return :success 0, failed -1
|
| 165 | * @todo:
|
| 166 | * @see:NA
|
| 167 | * @warning:
|
| 168 | ********************************************/
|
| 169 | ssize_t cancel_wakealarm(void)
|
| 170 | {
|
| 171 | int ret = 0;
|
| 172 |
|
| 173 | LYINFLOG("Enter cancel_wakealarm ");
|
| 174 | ret = sc_rtc_timer_del(wk_srcid, wk_rtc_id);
|
| 175 | if(ret < 0)
|
| 176 | {
|
| 177 | LYINFLOG("Del wakealarm failed!!!");
|
| 178 | return -1;
|
| 179 | }
|
| 180 |
|
| 181 | return 0;
|
| 182 |
|
| 183 | }
|
| 184 |
|
| 185 |
|
| 186 | /*****************************************
|
| 187 | * @brief:lynq_set_poweralarm
|
| 188 | * @param count [IN]:unsigned long time_sec
|
| 189 | * @param sum [OUT]:NA
|
| 190 | * @return :success 0, failed -1
|
| 191 | * @todo:
|
| 192 | * @see:NA
|
| 193 | * @warning:
|
| 194 | ******************************************/
|
| 195 | int lynq_set_poweralarm(unsigned long time_sec)
|
| 196 | {
|
| 197 |
|
| 198 | int ret = 0;
|
| 199 | int srcid = 0;
|
| 200 | LYINFLOG("lynq_set_poweralarm %ld seconds",time_sec);
|
| 201 | srcid = sc_rtc_timer_init();
|
| 202 | if (srcid <= 0)
|
| 203 | {
|
| 204 | LYINFLOG("rtc_timer_init fail!");
|
| 205 | return -1;
|
| 206 | }
|
| 207 | ret = sc_rtc_timer_add(srcid, pw_rtc_id, time_sec, sc_rtc_timer_add_cb);
|
| 208 | if(ret < 0)
|
| 209 | {
|
| 210 | LYINFLOG("Add rtc timer failed!!!!");
|
| 211 | return -1;
|
| 212 | }
|
| 213 |
|
| 214 | LYINFLOG("Set poweralarm success !!!");
|
| 215 |
|
| 216 | ret = sc_rtc_timer_uninit();
|
| 217 | if(ret != 0)
|
| 218 | {
|
| 219 | LYINFLOG("Deinit failed");
|
| 220 | }
|
| 221 |
|
| 222 | return 0;
|
| 223 |
|
| 224 | }
|
| 225 |
|
| 226 |
|
| 227 | /*****************************************
|
| 228 | * @brief:lynq_set_wakealarm
|
| 229 | * @param count [IN]:unsigned long time_sec
|
| 230 | * @param sum [OUT]:NA
|
| 231 | * @return :success 0, failed -1
|
| 232 | * @todo:
|
| 233 | * @see:NA
|
| 234 | * @warning:
|
| 235 | ******************************************/
|
| 236 | int lynq_set_wakealarm(unsigned long time_sec)
|
| 237 | {
|
| 238 | int ret = 0;
|
| 239 | LYINFLOG("lynq_set_wakealarm %ld seconds ",time_sec);
|
| 240 | wk_srcid = sc_rtc_timer_init();
|
| 241 | if (wk_srcid <= 0)
|
| 242 | {
|
| 243 | LYINFLOG("rtc_timer_init fail!");
|
| 244 | return -1;
|
| 245 | }
|
| 246 | ret = sc_rtc_timer_add(wk_srcid, wk_rtc_id, time_sec, sc_rtc_timer_add_cb);
|
| 247 | if(ret < 0)
|
| 248 | {
|
| 249 | LYINFLOG("Add rtc timer failed!!!!");
|
| 250 | return -1;
|
| 251 | }
|
| 252 |
|
| 253 | LYINFLOG("Set wakealarm success !!!");
|
| 254 |
|
| 255 | ret = sc_rtc_timer_uninit();
|
| 256 | if(ret != 0)
|
| 257 | {
|
| 258 | LYINFLOG("Deinit failed!!!");
|
| 259 | }
|
| 260 |
|
| 261 | return 0;
|
| 262 |
|
| 263 | }
|
| 264 |
|
| 265 |
|
| 266 | #ifdef __cplusplus
|
| 267 | }
|
| 268 | #endif
|
| 269 |
|