From 6010dafe066e4b04e7f64820a010b8f4e9e1c719 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Fri, 23 Sep 2011 11:43:42 -0400 Subject: [PATCH] Add SerialPort.sendBreak() Change-Id: If25ba7724cf69489f2b04fc995baa9c164b5ea58 Signed-off-by: Mike Lockwood --- api/current.txt | 1 + core/java/android/hardware/SerialPort.java | 8 ++++++++ core/jni/android_hardware_SerialPort.cpp | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/api/current.txt b/api/current.txt index a8265fc38ebf4..70dad79aef63c 100644 --- a/api/current.txt +++ b/api/current.txt @@ -9614,6 +9614,7 @@ package android.hardware { method public void close() throws java.io.IOException; method public java.lang.String getName(); method public int read(java.nio.ByteBuffer) throws java.io.IOException; + method public void sendBreak(); method public void write(java.nio.ByteBuffer, int) throws java.io.IOException; } diff --git a/core/java/android/hardware/SerialPort.java b/core/java/android/hardware/SerialPort.java index 5aee0f69cf90a..d3bcbdd0c1006 100644 --- a/core/java/android/hardware/SerialPort.java +++ b/core/java/android/hardware/SerialPort.java @@ -113,10 +113,18 @@ public class SerialPort { } } + /** + * Sends a stream of zero valued bits for 0.25 to 0.5 seconds + */ + public void sendBreak() { + native_send_break(); + } + private native void native_open(FileDescriptor pfd, int speed) throws IOException; private native void native_close(); private native int native_read_array(byte[] buffer, int length) throws IOException; private native int native_read_direct(ByteBuffer buffer, int length) throws IOException; private native void native_write_array(byte[] buffer, int length) throws IOException; private native void native_write_direct(ByteBuffer buffer, int length) throws IOException; + private native void native_send_break(); } diff --git a/core/jni/android_hardware_SerialPort.cpp b/core/jni/android_hardware_SerialPort.cpp index 792211595f2d7..728bd7bfe3f81 100644 --- a/core/jni/android_hardware_SerialPort.cpp +++ b/core/jni/android_hardware_SerialPort.cpp @@ -234,6 +234,13 @@ android_hardware_SerialPort_write_direct(JNIEnv *env, jobject thiz, jobject buff jniThrowException(env, "java/io/IOException", NULL); } +static void +android_hardware_SerialPort_send_break(JNIEnv *env, jobject thiz) +{ + int fd = env->GetIntField(thiz, field_context); + tcsendbreak(fd, 0); +} + static JNINativeMethod method_table[] = { {"native_open", "(Ljava/io/FileDescriptor;I)V", (void *)android_hardware_SerialPort_open}, @@ -246,6 +253,7 @@ static JNINativeMethod method_table[] = { (void *)android_hardware_SerialPort_write_array}, {"native_write_direct", "(Ljava/nio/ByteBuffer;I)V", (void *)android_hardware_SerialPort_write_direct}, + {"native_send_break", "()V", (void *)android_hardware_SerialPort_send_break}, }; int register_android_hardware_SerialPort(JNIEnv *env)