xj | 3d6eec7 | 2022-05-26 14:45:57 +0800 | [diff] [blame^] | 1 | #include<stdio.h> |
| 2 | #include<stdlib.h> |
| 3 | #include<unistd.h> |
| 4 | #include<stdbool.h> |
| 5 | #include<log/log.h> |
| 6 | #include"./include/format_change.h" |
| 7 | |
| 8 | |
| 9 | #define LOG_TAG "libpoweralarm" |
| 10 | #define RTCFILE_POWERALARM "/sys/class/rtc/rtc0/poweralarm" |
| 11 | |
| 12 | #define RTCFILE_WAKEALARM "/sys/class/rtc/rtc0/wakealarm" |
| 13 | |
| 14 | extern "C" ssize_t wakealarm(char *buffer); |
| 15 | |
| 16 | |
| 17 | extern "C" ssize_t poweralarm(char *buffer); |
| 18 | |
| 19 | ssize_t poweralarm(char *buffer); |
| 20 | |
| 21 | ssize_t wakealarm(char *buffer); |
| 22 | /***************************************************************************** |
| 23 | * |
| 24 | * Prototype : poweralarm |
| 25 | * Description : set shutdown wake-up alarm clock |
| 26 | * Input : char *buffer ; input format : 04-23-15-30-00 ( Mon-Day-Hour-Min-Sec ) Or 1200 ( seconds ) |
| 27 | * Output : None |
| 28 | * Return Value : -1: error ; >0: set to wake up the devices after seconds |
| 29 | * |
| 30 | *****************************************************************************/ |
| 31 | ssize_t poweralarm(char *buffer) |
| 32 | { |
| 33 | ssize_t sec; |
| 34 | char *time_buff = NULL; |
| 35 | |
| 36 | sec = format_change(buffer); //computing seconds for shutdown alarm |
| 37 | if(sec < 0) |
| 38 | { |
| 39 | ALOGI("No Mattch\n"); |
| 40 | return -1; |
| 41 | } |
| 42 | |
| 43 | time_buff = (char*)malloc(100); |
| 44 | bzero(time_buff,100); |
| 45 | |
| 46 | sprintf(time_buff,"echo +%ld > %s",sec,RTCFILE_POWERALARM); //write formatted data into time_buff |
| 47 | system(time_buff); |
| 48 | ALOGI(time_buff); |
| 49 | |
| 50 | free(time_buff); |
| 51 | |
| 52 | return sec; // wake-up devices after sec seconds |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /***************************************************************************** |
| 57 | * Prototype : wakealarm |
| 58 | * Description : set the wake-up alarm clock in low power mode |
| 59 | * Input : char *buffer ; input format : 04-23-15-30-00 ( Mon-Day-Hour-Min-Sec ) Or 1200 ( seconds ) |
| 60 | * Output : None |
| 61 | * Return Value : -1: error ; >0: set to wake up the devices after seconds |
| 62 | * |
| 63 | *****************************************************************************/ |
| 64 | ssize_t wakealarm(char *buffer) |
| 65 | { |
| 66 | ssize_t sec; |
| 67 | char *time_buff = NULL; |
| 68 | |
| 69 | sec = format_change(buffer); //computing seconds for lowpower alarm |
| 70 | if(sec < 0) |
| 71 | { |
| 72 | ALOGI("No Mattch\n"); |
| 73 | return -1; |
| 74 | } |
| 75 | |
| 76 | time_buff = (char*)malloc(100); |
| 77 | bzero(time_buff,100); |
| 78 | |
| 79 | sprintf(time_buff,"echo +%ld > %s",sec,RTCFILE_WAKEALARM); //write formatted data into time_buff |
| 80 | system(time_buff); |
| 81 | ALOGI(time_buff); |
| 82 | |
| 83 | free(time_buff); |
| 84 | |
| 85 | return sec; // wake-up devices after sec seconds |
| 86 | } |