开发者

Android - Read "device attribute" fails with error "invalid length"

开发者 https://www.devze.com 2023-04-02 05:40 出处:网络
I am working on the TI OMAP platform with Android as the operating system. For one UseCase, we have to toggle one of the LED\'s in the device. The LED has number of \"Device Attributes\" and from the

I am working on the TI OMAP platform with Android as the operating system. For one UseCase, we have to toggle one of the LED's in the device. The LED has number of "Device Attributes" and from the Application Layer [.java], we want to read a "Device Attribute".

When we do run the cat command on the adb prompt:

# cat /sys/devices/device_name/device_attribute
# device_attribute:invalid length

We get the error "invalid length". Hence, I wanted to know is there a way to read a "Device Property" such that it is accessible to the App Layer as well.

I found a similar question on another forum http://android.modaco.com/topic/312770-possible-solution-for-lack-of-notification-light-developers-needed but it was also unanswered.

Thanks for the replies !!!

Solu开发者_Go百科tion The device was only having "set_device_attribute" but since "get_device_attribute" was missing, we were getting "invalid length" issue when "read" command to that device property was issued.

I added a new API named:

static ssize_t get_device_attribute(struct device *dev, struct device_attribute *attr,
char *buf)
{
 .........................
 .........................
 .........................
}

and updated the device attribute

static DEVICE_ATTR(device_property, 0777,get_device_attribute, set_device_attribute);


invalid length often indicates a directory. Try to cd into the last "device_attribute".

Alternativeley you can also search for device info in "/proc".


You probably have the Linux kernel source code, search the particular sysfs implementation of the device, see how it was programmed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号