-
Notifications
You must be signed in to change notification settings - Fork 77
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 1 commit
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,7 @@ | ||
cmake_minimum_required(VERSION 3.2) | ||
project(read-rtc-battery) | ||
include_directories(.) | ||
add_executable(readrtcbattery readrtcbattery.c) | ||
set(CMAKE_INSTALL_PREFIX "/usr") | ||
# target_link_libraries(switchserialmode usb-1.0 gpiod) | ||
install(TARGETS readrtcbattery RUNTIME DESTINATION bin) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <sys/ioctl.h> | ||
nhahnetsrot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#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 | ||
printf("\nOpening Driver\n"); | ||
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. Too verbose 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. removed printf statement |
||
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) { | ||
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.
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 |
||
printf("Device file not found n\n"); | ||
return 0; | ||
} | ||
|
||
|
||
// 3rd step: Read out | ||
printf("Process ioctl access to read battery status\n"); | ||
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. same here 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. removed print statement |
||
retval = ioctl(fd, RTC_VL_DATA_INVALID, &batteryStatus); | ||
|
||
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 0; | ||
} else { | ||
// 5th step: Print battery status | ||
printf("Battery status (1 = Error) %d\n", batteryStatus); | ||
} | ||
// Close driver | ||
printf("Closing Driver\n"); | ||
close(fd); | ||
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. Inconsistent indention 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 |
||
} // main |
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.
Missing copyright header.
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.
corrected