|
@@ -31,6 +31,7 @@ int page(struct http_request *);
|
|
|
int handle_time(struct http_request *);
|
|
|
int handle_wkalrm(struct http_request *);
|
|
|
int detect_device(struct http_request *);
|
|
|
+int handle_nvmem(struct http_request *);
|
|
|
|
|
|
int
|
|
|
page(struct http_request *req)
|
|
@@ -263,3 +264,38 @@ int detect_device(struct http_request *req) {
|
|
|
return (KORE_RESULT_OK);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+int handle_nvmem(struct http_request *req) {
|
|
|
+ int fdesc, bytes_read;
|
|
|
+ unsigned char buf[56];
|
|
|
+ char result_string[113];
|
|
|
+ char buf2[3];
|
|
|
+ char * result_object;
|
|
|
+ cJSON *json_response, *json_string;
|
|
|
+ if(req->method == HTTP_METHOD_GET) {
|
|
|
+ fdesc = open("/sys/bus/nvmem/devices/ds1307_nvram0/nvmem", O_RDONLY);
|
|
|
+ bytes_read = read(fdesc, &buf, 56);
|
|
|
+ if(bytes_read == 56) {
|
|
|
+ result_string[112] = '\0';
|
|
|
+ for(int i=0; i<56; i++) {
|
|
|
+ if (buf[i] <= 15) {
|
|
|
+ sprintf(buf2, "0%x", buf[i]);
|
|
|
+ } else {
|
|
|
+ sprintf(buf2, "%x", buf[i]);
|
|
|
+ }
|
|
|
+ strcpy(result_string + i*2, buf2);
|
|
|
+ }
|
|
|
+ json_response = cJSON_CreateObject();
|
|
|
+ json_string = cJSON_CreateString(result_string);
|
|
|
+ cJSON_AddItemToObject(json_response, "content", json_string);
|
|
|
+ result_object = cJSON_Print(json_response);
|
|
|
+ cJSON_Delete(json_response);
|
|
|
+ http_response_header(req, "Content-Type", "application/json");
|
|
|
+ http_response(req, 200, result_object, strlen(result_object));
|
|
|
+ }
|
|
|
+ return KORE_RESULT_OK;
|
|
|
+ } else {
|
|
|
+ http_response(req, HTTP_STATUS_METHOD_NOT_ALLOWED, NULL, 0);
|
|
|
+ return (KORE_RESULT_OK);
|
|
|
+ }
|
|
|
+}
|