-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add commandline tool to check rtc battery status #438
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# | ||
# Copyright (c) Siemens AG, 2019-2023 | ||
# | ||
# Authors: | ||
# Torsten Hahn <[email protected]> | ||
# | ||
# This file is subject to the terms and conditions of the MIT License. See | ||
# COPYING.MIT file in the top-level directory. | ||
# | ||
cmake_minimum_required(VERSION 3.2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing copyright header. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. corrected |
||
project(read-rtc-battery) | ||
include_directories(.) | ||
add_executable(readrtcbattery readrtcbattery.c) | ||
set(CMAKE_INSTALL_PREFIX "/usr") | ||
install(TARGETS readrtcbattery RUNTIME DESTINATION bin) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright (c) Siemens AG, 2019-2023 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use |
||
* | ||
* Authors: | ||
* Torsten Hahn <[email protected]> | ||
* | ||
* This file is subject to the terms and conditions of the MIT License. See | ||
* COPYING.MIT file in the top-level directory. | ||
* | ||
**/ | ||
#include <sys/ioctl.h> | ||
#include <stdio.h> | ||
#include <linux/rtc.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
|
||
int main() | ||
{ | ||
int fd; // Device file path | ||
int batteryStatus; // Status of battery | ||
int retval = 0; // Return value of ioctl function (-1 = Error) | ||
|
||
// 1st step: Open Driver | ||
fd = open("/dev/rtc", O_RDONLY); | ||
|
||
// 2nd step: Display error in command line if the device | ||
// file wasn't found and close application | ||
if (fd < 0) { | ||
printf("Device file not found\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
// 3rd step: Read out | ||
retval = ioctl(fd, RTC_VL_DATA_INVALID, &batteryStatus); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not correct, please read https://support.industry.siemens.com/forum/de/en/posts/check-rtc-battery-status-of-iot2050/291926 again. |
||
|
||
if (retval == -1) { | ||
// 4th step: Display error in command line if the ioctl function isn't able to access | ||
// the specific function | ||
printf("Error access ioctl function \n"); | ||
return EXIT_FAILURE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} else { | ||
// 5th step: Print battery status | ||
printf("Battery status (1 = Error) %d\n", batteryStatus); | ||
} | ||
Comment on lines
+47
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to wrap this print to the |
||
close(fd); | ||
|
||
return EXIT_SUCCESS; | ||
} // main | ||
Comment on lines
+25
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is simple and straight-forward enough to be self-explained, so most of the comments are unnecessary. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# | ||
# Copyright (c) Siemens AG, 2019-2023 | ||
# | ||
# Authors: | ||
# Torsten Hahn <[email protected]> | ||
# | ||
# This file is subject to the terms and conditions of the MIT License. See | ||
# COPYING.MIT file in the top-level directory. | ||
# | ||
|
||
inherit dpkg | ||
|
||
DESCRIPTION = "Commandline tool to read the state of the rtc battery" | ||
MAINTAINER = "[email protected]" | ||
|
||
SRC_URI = "file://src" | ||
|
||
S = "${WORKDIR}/src" | ||
|
||
DEBIAN_BUILD_DEPENDS = "cmake" | ||
DEBIAN_DEPENDS = "\${shlibs:Depends}" | ||
|
||
do_prepare_build[cleandirs] += "${S}/debian" | ||
|
||
do_prepare_build() { | ||
deb_debianize | ||
} | ||
|
||
# propably correct permissions | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ IMAGE_INSTALL += " \ | |
libteec1 \ | ||
optee-client-dev \ | ||
tee-supplicant \ | ||
read-rtc-battery \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How to test it? |
||
" | ||
|
||
IOT2050_CORAL_SUPPORT ?= "1" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here