|
@@ -11,6 +11,8 @@
|
|
|
|
|
|
int page(struct http_request *);
|
|
|
int handle_time(struct http_request *);
|
|
|
+int handle_wkalrm(struct http_request *);
|
|
|
+
|
|
|
int
|
|
|
page(struct http_request *req)
|
|
|
{
|
|
@@ -54,7 +56,7 @@ int handle_time(struct http_request *req) {
|
|
|
}
|
|
|
cJSON_Delete(time_json);
|
|
|
msg = "Error: could not get time from /dev/rtc\n";
|
|
|
- http_response(req, 200, msg, strlen(msg));
|
|
|
+ http_response(req, 500, msg, strlen(msg));
|
|
|
return KORE_RESULT_OK;
|
|
|
} else if (req->method == HTTP_METHOD_POST) {
|
|
|
struct kore_buf * buf;
|
|
@@ -121,3 +123,50 @@ int handle_time(struct http_request *req) {
|
|
|
return (KORE_RESULT_OK);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+int handle_wkalrm(struct http_request *req) {
|
|
|
+ char *result_string;
|
|
|
+ struct rtc_wkalrm alarm;
|
|
|
+ int fdesc, ret;
|
|
|
+ cJSON *alarm_json, *json_min, *json_hour, *json_mday,
|
|
|
+ *json_mon, *json_year, *json_sec, *json_wday,
|
|
|
+ *json_enabled, *json_pending;
|
|
|
+ if(req->method == HTTP_METHOD_GET) {
|
|
|
+ alarm_json = cJSON_CreateObject();
|
|
|
+ fdesc = open("/dev/rtc", O_RDONLY);
|
|
|
+ ret = ioctl(fdesc, RTC_WKALM_RD, &alarm);
|
|
|
+ close(fdesc);
|
|
|
+ if (!ret) {
|
|
|
+ json_sec = cJSON_CreateNumber(alarm.time.tm_sec);
|
|
|
+ json_min = cJSON_CreateNumber(alarm.time.tm_min);
|
|
|
+ json_hour = cJSON_CreateNumber(alarm.time.tm_hour);
|
|
|
+ json_mday = cJSON_CreateNumber(alarm.time.tm_mday);
|
|
|
+ json_mon = cJSON_CreateNumber(alarm.time.tm_mon);
|
|
|
+ json_year = cJSON_CreateNumber(alarm.time.tm_year);
|
|
|
+ json_wday = cJSON_CreateNumber(alarm.time.tm_wday);
|
|
|
+ json_enabled = cJSON_CreateNumber(alarm.enabled);
|
|
|
+ json_pending = cJSON_CreateNumber(alarm.pending);
|
|
|
+ cJSON_AddItemToObject(alarm_json, "seconds", json_sec);
|
|
|
+ cJSON_AddItemToObject(alarm_json, "minutes", json_min);
|
|
|
+ cJSON_AddItemToObject(alarm_json, "hour", json_hour);
|
|
|
+ cJSON_AddItemToObject(alarm_json, "mday", json_mday);
|
|
|
+ cJSON_AddItemToObject(alarm_json, "month", json_mon);
|
|
|
+ cJSON_AddItemToObject(alarm_json, "year", json_year);
|
|
|
+ cJSON_AddItemToObject(alarm_json, "wday", json_wday);
|
|
|
+ cJSON_AddItemToObject(alarm_json, "enabled", json_enabled);
|
|
|
+ cJSON_AddItemToObject(alarm_json, "pending", json_pending);
|
|
|
+ result_string = cJSON_Print(alarm_json);
|
|
|
+ cJSON_Delete(alarm_json);
|
|
|
+ http_response_header(req, "Content-Type", "application/json");
|
|
|
+ http_response(req, 200, result_string, strlen(result_string));
|
|
|
+ return KORE_RESULT_OK;
|
|
|
+ }
|
|
|
+ cJSON_Delete(alarm_json);
|
|
|
+ result_string = "Error: could not get alarm from /dev/rtc\n";
|
|
|
+ http_response(req, 500, result_string, strlen(result_string));
|
|
|
+ return KORE_RESULT_OK;
|
|
|
+ } else {
|
|
|
+ http_response(req, HTTP_STATUS_METHOD_NOT_ALLOWED, NULL, 0);
|
|
|
+ return (KORE_RESULT_OK);
|
|
|
+ }
|
|
|
+}
|