Set device driver xmit buffer size
This commit is contained in:
parent
7412d8b9cc
commit
4ca5fb0337
|
@ -2,7 +2,7 @@
|
||||||
* SerialPort_Android.c
|
* SerialPort_Android.c
|
||||||
*
|
*
|
||||||
* Created on: Mar 13, 2015
|
* Created on: Mar 13, 2015
|
||||||
* Last Updated on: Oct 07, 2018
|
* Last Updated on: Oct 08, 2018
|
||||||
* Author: Will Hedgecock
|
* Author: Will Hedgecock
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012-2018 Fazecast, Inc.
|
* Copyright (C) 2012-2018 Fazecast, Inc.
|
||||||
|
@ -38,6 +38,7 @@
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <linux/usbdevice_fs.h>
|
#include <linux/usbdevice_fs.h>
|
||||||
|
#include <linux/serial.h>
|
||||||
#include <asm/byteorder.h>
|
#include <asm/byteorder.h>
|
||||||
#include "com_fazecast_jSerialComm_SerialPort.h"
|
#include "com_fazecast_jSerialComm_SerialPort.h"
|
||||||
#include "AndroidHelperFunctions.h"
|
#include "AndroidHelperFunctions.h"
|
||||||
|
@ -62,6 +63,8 @@ jfieldID dataBitsField;
|
||||||
jfieldID stopBitsField;
|
jfieldID stopBitsField;
|
||||||
jfieldID parityField;
|
jfieldID parityField;
|
||||||
jfieldID flowControlField;
|
jfieldID flowControlField;
|
||||||
|
jfieldID sendDeviceQueueSizeField;
|
||||||
|
jfieldID receiveDeviceQueueSizeField;
|
||||||
jfieldID timeoutModeField;
|
jfieldID timeoutModeField;
|
||||||
jfieldID readTimeoutField;
|
jfieldID readTimeoutField;
|
||||||
jfieldID writeTimeoutField;
|
jfieldID writeTimeoutField;
|
||||||
|
@ -115,6 +118,8 @@ JNIEXPORT void JNICALL Java_com_fazecast_jSerialComm_SerialPort_initializeLibrar
|
||||||
stopBitsField = (*env)->GetFieldID(env, serialCommClass, "stopBits", "I");
|
stopBitsField = (*env)->GetFieldID(env, serialCommClass, "stopBits", "I");
|
||||||
parityField = (*env)->GetFieldID(env, serialCommClass, "parity", "I");
|
parityField = (*env)->GetFieldID(env, serialCommClass, "parity", "I");
|
||||||
flowControlField = (*env)->GetFieldID(env, serialCommClass, "flowControl", "I");
|
flowControlField = (*env)->GetFieldID(env, serialCommClass, "flowControl", "I");
|
||||||
|
sendDeviceQueueSizeField = (*env)->GetFieldID(env, serialCommClass, "sendDeviceQueueSize", "I");
|
||||||
|
receiveDeviceQueueSizeField = (*env)->GetFieldID(env, serialCommClass, "receiveDeviceQueueSize", "I");
|
||||||
timeoutModeField = (*env)->GetFieldID(env, serialCommClass, "timeoutMode", "I");
|
timeoutModeField = (*env)->GetFieldID(env, serialCommClass, "timeoutMode", "I");
|
||||||
readTimeoutField = (*env)->GetFieldID(env, serialCommClass, "readTimeout", "I");
|
readTimeoutField = (*env)->GetFieldID(env, serialCommClass, "readTimeout", "I");
|
||||||
writeTimeoutField = (*env)->GetFieldID(env, serialCommClass, "writeTimeout", "I");
|
writeTimeoutField = (*env)->GetFieldID(env, serialCommClass, "writeTimeout", "I");
|
||||||
|
@ -168,33 +173,11 @@ JNIEXPORT jlong JNICALL Java_com_fazecast_jSerialComm_SerialPort_openPortNative(
|
||||||
return serialPortFD;
|
return serialPortFD;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_associateNativeHandle(JNIEnv *env, jobject obj, jlong serialPortFD)
|
|
||||||
{
|
|
||||||
// TODO: SET A FLAG SAYING THAT WE ARE USING USBFS
|
|
||||||
// Attempt to determine which serial port file this descriptor belongs to
|
|
||||||
char serialPortFdChars[16];
|
|
||||||
sprintf(serialPortFdChars, "%d", (int)serialPortFD);
|
|
||||||
char* fileDescriptorName = (char*)malloc(256), *portName = (char*)malloc(256);
|
|
||||||
strcpy(fileDescriptorName, "/proc/self/fd/");
|
|
||||||
strcat(fileDescriptorName, serialPortFdChars);
|
|
||||||
ssize_t result = readlink(fileDescriptorName, portName, 256);
|
|
||||||
free(fileDescriptorName);
|
|
||||||
if (result < 0)
|
|
||||||
{
|
|
||||||
free(portName);
|
|
||||||
return JNI_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the port name in the Java object
|
|
||||||
(*env)->SetObjectField(env, obj, comPortField, (*env)->NewStringUTF(env, portName));
|
|
||||||
free(portName);
|
|
||||||
return JNI_TRUE;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(JNIEnv *env, jobject obj, jlong serialPortFD)
|
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||||
{
|
{
|
||||||
if (serialPortFD <= 0)
|
if (serialPortFD <= 0)
|
||||||
return JNI_FALSE;
|
return JNI_FALSE;
|
||||||
|
struct serial_struct serInfo;
|
||||||
struct termios options = { 0 };
|
struct termios options = { 0 };
|
||||||
|
|
||||||
// Get port parameters from Java class
|
// Get port parameters from Java class
|
||||||
|
@ -203,6 +186,8 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
||||||
int stopBitsInt = (*env)->GetIntField(env, obj, stopBitsField);
|
int stopBitsInt = (*env)->GetIntField(env, obj, stopBitsField);
|
||||||
int parityInt = (*env)->GetIntField(env, obj, parityField);
|
int parityInt = (*env)->GetIntField(env, obj, parityField);
|
||||||
int flowControl = (*env)->GetIntField(env, obj, flowControlField);
|
int flowControl = (*env)->GetIntField(env, obj, flowControlField);
|
||||||
|
int sendDeviceQueueSize = (*env)->GetIntField(env, obj, sendDeviceQueueSizeField);
|
||||||
|
int receiveDeviceQueueSize = (*env)->GetIntField(env, obj, receiveDeviceQueueSizeField);
|
||||||
unsigned char configDisabled = (*env)->GetBooleanField(env, obj, disableConfigField);
|
unsigned char configDisabled = (*env)->GetBooleanField(env, obj, disableConfigField);
|
||||||
unsigned char isDtrEnabled = (*env)->GetBooleanField(env, obj, isDtrEnabledField);
|
unsigned char isDtrEnabled = (*env)->GetBooleanField(env, obj, isDtrEnabledField);
|
||||||
unsigned char isRtsEnabled = (*env)->GetBooleanField(env, obj, isRtsEnabledField);
|
unsigned char isRtsEnabled = (*env)->GetBooleanField(env, obj, isRtsEnabledField);
|
||||||
|
@ -261,7 +246,12 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
||||||
requestWrapper.data = &options;
|
requestWrapper.data = &options;
|
||||||
retVal = ioctl(serialPortFD, USBDEVFS_IOCTL, &requestWrapper);
|
retVal = ioctl(serialPortFD, USBDEVFS_IOCTL, &requestWrapper);
|
||||||
}*/
|
}*/
|
||||||
if (baudRateCode == 0) // Set custom baud rate
|
|
||||||
|
// Attempt to set the transmit buffer size and any necessary custom baud rates
|
||||||
|
ioctl(serialPortFD, TIOCGSERIAL, &serInfo);
|
||||||
|
serInfo.xmit_fifo_size = sendDeviceQueueSize;
|
||||||
|
ioctl(serialPortFD, TIOCSSERIAL, &serInfo);
|
||||||
|
if (baudRateCode == 0)
|
||||||
setBaudRate(serialPortFD, baudRate);
|
setBaudRate(serialPortFD, baudRate);
|
||||||
return ((retVal == 0) && Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD) ? JNI_TRUE : JNI_FALSE);
|
return ((retVal == 0) && Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD) ? JNI_TRUE : JNI_FALSE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* SerialPort_Linux.c
|
* SerialPort_Linux.c
|
||||||
*
|
*
|
||||||
* Created on: Feb 25, 2012
|
* Created on: Feb 25, 2012
|
||||||
* Last Updated on: Oct 07, 2018
|
* Last Updated on: Oct 08, 2018
|
||||||
* Author: Will Hedgecock
|
* Author: Will Hedgecock
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012-2018 Fazecast, Inc.
|
* Copyright (C) 2012-2018 Fazecast, Inc.
|
||||||
|
@ -55,6 +55,8 @@ jfieldID dataBitsField;
|
||||||
jfieldID stopBitsField;
|
jfieldID stopBitsField;
|
||||||
jfieldID parityField;
|
jfieldID parityField;
|
||||||
jfieldID flowControlField;
|
jfieldID flowControlField;
|
||||||
|
jfieldID sendDeviceQueueSizeField;
|
||||||
|
jfieldID receiveDeviceQueueSizeField;
|
||||||
jfieldID timeoutModeField;
|
jfieldID timeoutModeField;
|
||||||
jfieldID readTimeoutField;
|
jfieldID readTimeoutField;
|
||||||
jfieldID writeTimeoutField;
|
jfieldID writeTimeoutField;
|
||||||
|
@ -109,6 +111,8 @@ JNIEXPORT void JNICALL Java_com_fazecast_jSerialComm_SerialPort_initializeLibrar
|
||||||
stopBitsField = (*env)->GetFieldID(env, serialCommClass, "stopBits", "I");
|
stopBitsField = (*env)->GetFieldID(env, serialCommClass, "stopBits", "I");
|
||||||
parityField = (*env)->GetFieldID(env, serialCommClass, "parity", "I");
|
parityField = (*env)->GetFieldID(env, serialCommClass, "parity", "I");
|
||||||
flowControlField = (*env)->GetFieldID(env, serialCommClass, "flowControl", "I");
|
flowControlField = (*env)->GetFieldID(env, serialCommClass, "flowControl", "I");
|
||||||
|
sendDeviceQueueSizeField = (*env)->GetFieldID(env, serialCommClass, "sendDeviceQueueSize", "I");
|
||||||
|
receiveDeviceQueueSizeField = (*env)->GetFieldID(env, serialCommClass, "receiveDeviceQueueSize", "I");
|
||||||
timeoutModeField = (*env)->GetFieldID(env, serialCommClass, "timeoutMode", "I");
|
timeoutModeField = (*env)->GetFieldID(env, serialCommClass, "timeoutMode", "I");
|
||||||
readTimeoutField = (*env)->GetFieldID(env, serialCommClass, "readTimeout", "I");
|
readTimeoutField = (*env)->GetFieldID(env, serialCommClass, "readTimeout", "I");
|
||||||
writeTimeoutField = (*env)->GetFieldID(env, serialCommClass, "writeTimeout", "I");
|
writeTimeoutField = (*env)->GetFieldID(env, serialCommClass, "writeTimeout", "I");
|
||||||
|
@ -164,6 +168,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
||||||
{
|
{
|
||||||
if (serialPortFD <= 0)
|
if (serialPortFD <= 0)
|
||||||
return JNI_FALSE;
|
return JNI_FALSE;
|
||||||
|
struct serial_struct serInfo;
|
||||||
struct termios options = { 0 };
|
struct termios options = { 0 };
|
||||||
|
|
||||||
// Get port parameters from Java class
|
// Get port parameters from Java class
|
||||||
|
@ -172,6 +177,8 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
||||||
int stopBitsInt = (*env)->GetIntField(env, obj, stopBitsField);
|
int stopBitsInt = (*env)->GetIntField(env, obj, stopBitsField);
|
||||||
int parityInt = (*env)->GetIntField(env, obj, parityField);
|
int parityInt = (*env)->GetIntField(env, obj, parityField);
|
||||||
int flowControl = (*env)->GetIntField(env, obj, flowControlField);
|
int flowControl = (*env)->GetIntField(env, obj, flowControlField);
|
||||||
|
int sendDeviceQueueSize = (*env)->GetIntField(env, obj, sendDeviceQueueSizeField);
|
||||||
|
int receiveDeviceQueueSize = (*env)->GetIntField(env, obj, receiveDeviceQueueSizeField);
|
||||||
unsigned char configDisabled = (*env)->GetBooleanField(env, obj, disableConfigField);
|
unsigned char configDisabled = (*env)->GetBooleanField(env, obj, disableConfigField);
|
||||||
unsigned char isDtrEnabled = (*env)->GetBooleanField(env, obj, isDtrEnabledField);
|
unsigned char isDtrEnabled = (*env)->GetBooleanField(env, obj, isDtrEnabledField);
|
||||||
unsigned char isRtsEnabled = (*env)->GetBooleanField(env, obj, isRtsEnabledField);
|
unsigned char isRtsEnabled = (*env)->GetBooleanField(env, obj, isRtsEnabledField);
|
||||||
|
@ -205,10 +212,15 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
||||||
cfsetospeed(&options, baudRateCode);
|
cfsetospeed(&options, baudRateCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply changes
|
// Apply changes and block non-root users from opening this port
|
||||||
int retVal = configDisabled ? 0 : tcsetattr(serialPortFD, TCSANOW, &options);
|
int retVal = configDisabled ? 0 : tcsetattr(serialPortFD, TCSANOW, &options);
|
||||||
ioctl(serialPortFD, TIOCEXCL); // Block non-root users from opening this port
|
ioctl(serialPortFD, TIOCEXCL);
|
||||||
if (baudRateCode == 0) // Set custom baud rate
|
|
||||||
|
// Attempt to set the transmit buffer size and any necessary custom baud rates
|
||||||
|
ioctl(serialPortFD, TIOCGSERIAL, &serInfo);
|
||||||
|
serInfo.xmit_fifo_size = sendDeviceQueueSize;
|
||||||
|
ioctl(serialPortFD, TIOCSSERIAL, &serInfo);
|
||||||
|
if (baudRateCode == 0)
|
||||||
setBaudRate(serialPortFD, baudRate);
|
setBaudRate(serialPortFD, baudRate);
|
||||||
return ((retVal == 0) && Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD) ? JNI_TRUE : JNI_FALSE);
|
return ((retVal == 0) && Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD) ? JNI_TRUE : JNI_FALSE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* SerialPort_OSX.c
|
* SerialPort_OSX.c
|
||||||
*
|
*
|
||||||
* Created on: Feb 25, 2012
|
* Created on: Feb 25, 2012
|
||||||
* Last Updated on: Oct 07, 2018
|
* Last Updated on: Oct 08, 2018
|
||||||
* Author: Will Hedgecock
|
* Author: Will Hedgecock
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012-2018 Fazecast, Inc.
|
* Copyright (C) 2012-2018 Fazecast, Inc.
|
||||||
|
@ -57,6 +57,8 @@ jfieldID dataBitsField;
|
||||||
jfieldID stopBitsField;
|
jfieldID stopBitsField;
|
||||||
jfieldID parityField;
|
jfieldID parityField;
|
||||||
jfieldID flowControlField;
|
jfieldID flowControlField;
|
||||||
|
jfieldID sendDeviceQueueSizeField;
|
||||||
|
jfieldID receiveDeviceQueueSizeField;
|
||||||
jfieldID timeoutModeField;
|
jfieldID timeoutModeField;
|
||||||
jfieldID readTimeoutField;
|
jfieldID readTimeoutField;
|
||||||
jfieldID writeTimeoutField;
|
jfieldID writeTimeoutField;
|
||||||
|
@ -159,6 +161,8 @@ JNIEXPORT void JNICALL Java_com_fazecast_jSerialComm_SerialPort_initializeLibrar
|
||||||
stopBitsField = (*env)->GetFieldID(env, serialCommClass, "stopBits", "I");
|
stopBitsField = (*env)->GetFieldID(env, serialCommClass, "stopBits", "I");
|
||||||
parityField = (*env)->GetFieldID(env, serialCommClass, "parity", "I");
|
parityField = (*env)->GetFieldID(env, serialCommClass, "parity", "I");
|
||||||
flowControlField = (*env)->GetFieldID(env, serialCommClass, "flowControl", "I");
|
flowControlField = (*env)->GetFieldID(env, serialCommClass, "flowControl", "I");
|
||||||
|
sendDeviceQueueSizeField = (*env)->GetFieldID(env, serialCommClass, "sendDeviceQueueSize", "I");
|
||||||
|
receiveDeviceQueueSizeField = (*env)->GetFieldID(env, serialCommClass, "receiveDeviceQueueSize", "I");
|
||||||
timeoutModeField = (*env)->GetFieldID(env, serialCommClass, "timeoutMode", "I");
|
timeoutModeField = (*env)->GetFieldID(env, serialCommClass, "timeoutMode", "I");
|
||||||
readTimeoutField = (*env)->GetFieldID(env, serialCommClass, "readTimeout", "I");
|
readTimeoutField = (*env)->GetFieldID(env, serialCommClass, "readTimeout", "I");
|
||||||
writeTimeoutField = (*env)->GetFieldID(env, serialCommClass, "writeTimeout", "I");
|
writeTimeoutField = (*env)->GetFieldID(env, serialCommClass, "writeTimeout", "I");
|
||||||
|
@ -222,6 +226,8 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
||||||
int stopBitsInt = (*env)->GetIntField(env, obj, stopBitsField);
|
int stopBitsInt = (*env)->GetIntField(env, obj, stopBitsField);
|
||||||
int parityInt = (*env)->GetIntField(env, obj, parityField);
|
int parityInt = (*env)->GetIntField(env, obj, parityField);
|
||||||
int flowControl = (*env)->GetIntField(env, obj, flowControlField);
|
int flowControl = (*env)->GetIntField(env, obj, flowControlField);
|
||||||
|
int sendDeviceQueueSize = (*env)->GetIntField(env, obj, sendDeviceQueueSizeField);
|
||||||
|
int receiveDeviceQueueSize = (*env)->GetIntField(env, obj, receiveDeviceQueueSizeField);
|
||||||
unsigned char configDisabled = (*env)->GetBooleanField(env, obj, disableConfigField);
|
unsigned char configDisabled = (*env)->GetBooleanField(env, obj, disableConfigField);
|
||||||
unsigned char isDtrEnabled = (*env)->GetBooleanField(env, obj, isDtrEnabledField);
|
unsigned char isDtrEnabled = (*env)->GetBooleanField(env, obj, isDtrEnabledField);
|
||||||
unsigned char isRtsEnabled = (*env)->GetBooleanField(env, obj, isRtsEnabledField);
|
unsigned char isRtsEnabled = (*env)->GetBooleanField(env, obj, isRtsEnabledField);
|
||||||
|
@ -255,10 +261,12 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
||||||
cfsetospeed(&options, baudRateCode);
|
cfsetospeed(&options, baudRateCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply changes
|
// Apply changes and block non-root users from opening this port
|
||||||
int retVal = configDisabled ? 0 : tcsetattr(serialPortFD, TCSANOW, &options);
|
int retVal = configDisabled ? 0 : tcsetattr(serialPortFD, TCSANOW, &options);
|
||||||
ioctl(serialPortFD, TIOCEXCL); // Block non-root users from opening this port
|
ioctl(serialPortFD, TIOCEXCL);
|
||||||
if (baudRateCode == 0) // Set custom baud rate
|
|
||||||
|
// Attempt to set any necessary custom baud rates
|
||||||
|
if (baudRateCode == 0)
|
||||||
{
|
{
|
||||||
speed_t speed = (speed_t)baudRate;
|
speed_t speed = (speed_t)baudRate;
|
||||||
ioctl(serialPortFD, IOSSIOSPEED, &speed);
|
ioctl(serialPortFD, IOSSIOSPEED, &speed);
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue