Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions recipes-app/read-rtc-battery/files/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyright header.

Copy link
Author

Choose a reason for hiding this comment

The 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")
# target_link_libraries(switchserialmode usb-1.0 gpiod)
install(TARGETS readrtcbattery RUNTIME DESTINATION bin)
47 changes: 47 additions & 0 deletions recipes-app/read-rtc-battery/files/src/readrtcbattery.c
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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too verbose

Copy link
Author

Choose a reason for hiding this comment

The 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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if is not a function, therefore if (...

Copy link
Author

Choose a reason for hiding this comment

The 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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Author

Choose a reason for hiding this comment

The 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indention

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected

} // main
30 changes: 30 additions & 0 deletions recipes-app/read-rtc-battery/read-rtc-battery_0.1.bb
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

1 change: 1 addition & 0 deletions recipes-core/images/iot2050-image-example.bb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ IMAGE_INSTALL += " \
libteec1 \
optee-client-dev \
tee-supplicant \
read-rtc-battery \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to test it?

"

IOT2050_CORAL_SUPPORT ?= "1"
Expand Down