Ensure all data structures are properly initialized
This commit is contained in:
parent
f06b03f186
commit
155ae7940c
|
@ -2,7 +2,7 @@
|
|||
* SerialPort_Android.c
|
||||
*
|
||||
* Created on: Mar 13, 2015
|
||||
* Last Updated on: Nov 07, 2019
|
||||
* Last Updated on: Nov 12, 2019
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* Copyright (C) 2012-2019 Fazecast, Inc.
|
||||
|
@ -154,7 +154,7 @@ JNIEXPORT jlong JNICALL Java_com_fazecast_jSerialComm_SerialPort_openPortNative(
|
|||
// Clear any serial port flags and set up raw, non-canonical port parameters
|
||||
if (isatty(serialPortFD))
|
||||
{
|
||||
struct termios options = { 0 };
|
||||
struct termios options = {0};
|
||||
fcntl(serialPortFD, F_SETFL, 0);
|
||||
ioctl(serialPortFD, TCGETS, &options);
|
||||
options.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
|
||||
|
@ -188,8 +188,8 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
{
|
||||
if (serialPortFD <= 0)
|
||||
return JNI_FALSE;
|
||||
struct serial_struct serInfo;
|
||||
struct termios options = { 0 };
|
||||
struct serial_struct serInfo = {0};
|
||||
struct termios options = {0};
|
||||
|
||||
// Get port parameters from Java class
|
||||
int baudRate = (*env)->GetIntField(env, obj, baudRateField);
|
||||
|
@ -267,13 +267,13 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
setBaudRate(serialPortFD, baudRate);
|
||||
|
||||
// Attempt to set the requested RS-485 mode
|
||||
struct serial_rs485 rs485Conf;
|
||||
struct serial_rs485 rs485Conf = {0};
|
||||
if (ioctl(serialPortFD, TIOCGRS485, &rs485Conf) == 0)
|
||||
{
|
||||
if (rs485ModeEnabled)
|
||||
rs485Conf.flags |= SER_RS485_ENABLED;
|
||||
rs485Conf.flags |= SER_RS485_ENABLED; // Set these too? SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND
|
||||
else
|
||||
rs485Conf.flags &= ~SER_RS485_ENABLED;
|
||||
rs485Conf.flags &= ~SER_RS485_ENABLED; // Clear these too? &= ~(SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND);
|
||||
rs485Conf.delay_rts_before_send = rs485DelayBefore;
|
||||
rs485Conf.delay_rts_after_send = rs485DelayAfter;
|
||||
ioctl(serialPortFD, TIOCSRS485, &rs485Conf);
|
||||
|
@ -292,7 +292,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configTimeou
|
|||
int readTimeout = (*env)->GetIntField(env, obj, readTimeoutField);
|
||||
|
||||
// Retrieve existing port configuration
|
||||
struct termios options = { 0 };
|
||||
struct termios options = {0};
|
||||
if (isatty(serialPortFD))
|
||||
ioctl(serialPortFD, TCGETS, &options);
|
||||
else
|
||||
|
@ -383,7 +383,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configEventF
|
|||
jboolean retVal;
|
||||
if ((eventsToMonitor & com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_RECEIVED) > 0)
|
||||
{
|
||||
struct termios options = { 0 };
|
||||
struct termios options = {0};
|
||||
ioctl(serialPortFD, TCGETS, &options);
|
||||
int flags = fcntl(serialPortFD, F_GETFL);
|
||||
if (flags == -1)
|
||||
|
@ -424,7 +424,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_closePortNat
|
|||
(*env)->SetBooleanField(env, obj, isOpenedField, JNI_FALSE);
|
||||
|
||||
// Force the port to enter non-blocking mode to ensure that any current reads return
|
||||
struct termios options;
|
||||
struct termios options = {0};
|
||||
ioctl(serialPortFD, TCGETS, &options);
|
||||
int flags = fcntl(serialPortFD, F_GETFL);
|
||||
flags |= O_NONBLOCK;
|
||||
|
@ -500,7 +500,7 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_readBytes(JNIEnv
|
|||
else if ((timeoutMode & com_fazecast_jSerialComm_SerialPort_TIMEOUT_READ_BLOCKING) > 0) // Blocking mode, but not indefinitely
|
||||
{
|
||||
// Get current system time
|
||||
struct timeval expireTime = { 0 }, currTime = { 0 };
|
||||
struct timeval expireTime = {0}, currTime = {0};
|
||||
gettimeofday(&expireTime, NULL);
|
||||
expireTime.tv_usec += (readTimeout * 1000);
|
||||
if (expireTime.tv_usec > 1000000)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* SerialPort_Posix.c
|
||||
*
|
||||
* Created on: Feb 25, 2012
|
||||
* Last Updated on: Nov 08, 2019
|
||||
* Last Updated on: Nov 12, 2019
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* Copyright (C) 2012-2019 Fazecast, Inc.
|
||||
|
@ -263,7 +263,7 @@ JNIEXPORT jlong JNICALL Java_com_fazecast_jSerialComm_SerialPort_openPortNative(
|
|||
else
|
||||
{
|
||||
// Clear any serial port flags and set up raw, non-canonical port parameters
|
||||
struct termios options = { 0 };
|
||||
struct termios options = {0};
|
||||
fcntl(serialPortFD, F_SETFL, 0);
|
||||
tcgetattr(serialPortFD, &options);
|
||||
#if defined(__sun__)
|
||||
|
@ -303,7 +303,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
{
|
||||
if (serialPortFD <= 0)
|
||||
return JNI_FALSE;
|
||||
struct termios options = { 0 };
|
||||
struct termios options = {0};
|
||||
|
||||
// Get port parameters from Java class
|
||||
baud_rate baudRate = (*env)->GetIntField(env, obj, baudRateField);
|
||||
|
@ -355,7 +355,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
|
||||
// Attempt to set the transmit buffer size and any necessary custom baud rates
|
||||
#if defined(__linux__)
|
||||
struct serial_struct serInfo;
|
||||
struct serial_struct serInfo = {0};
|
||||
if (ioctl(serialPortFD, TIOCGSERIAL, &serInfo) == 0)
|
||||
{
|
||||
serInfo.xmit_fifo_size = sendDeviceQueueSize;
|
||||
|
@ -370,13 +370,13 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
|
||||
// Attempt to set the requested RS-485 mode
|
||||
#if defined(__linux__)
|
||||
struct serial_rs485 rs485Conf;
|
||||
struct serial_rs485 rs485Conf = {0};
|
||||
if (ioctl(serialPortFD, TIOCGRS485, &rs485Conf) == 0)
|
||||
{
|
||||
if (rs485ModeEnabled)
|
||||
rs485Conf.flags |= SER_RS485_ENABLED;
|
||||
rs485Conf.flags |= SER_RS485_ENABLED; // Set these too? SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND
|
||||
else
|
||||
rs485Conf.flags &= ~SER_RS485_ENABLED;
|
||||
rs485Conf.flags &= ~SER_RS485_ENABLED; // Clear these too? &= ~(SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND);
|
||||
rs485Conf.delay_rts_before_send = rs485DelayBefore;
|
||||
rs485Conf.delay_rts_after_send = rs485DelayAfter;
|
||||
ioctl(serialPortFD, TIOCSRS485, &rs485Conf);
|
||||
|
@ -396,7 +396,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configTimeou
|
|||
int readTimeout = (*env)->GetIntField(env, obj, readTimeoutField);
|
||||
|
||||
// Retrieve existing port configuration
|
||||
struct termios options = { 0 };
|
||||
struct termios options = {0};
|
||||
tcgetattr(serialPortFD, &options);
|
||||
int flags = fcntl(serialPortFD, F_GETFL);
|
||||
if (flags == -1)
|
||||
|
@ -463,7 +463,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configEventF
|
|||
jboolean retVal;
|
||||
if ((eventsToMonitor & com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_RECEIVED) > 0)
|
||||
{
|
||||
struct termios options = { 0 };
|
||||
struct termios options = {0};
|
||||
tcgetattr(serialPortFD, &options);
|
||||
int flags = fcntl(serialPortFD, F_GETFL);
|
||||
if (flags == -1)
|
||||
|
@ -507,7 +507,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_closePortNat
|
|||
(*env)->SetBooleanField(env, obj, isOpenedField, JNI_FALSE);
|
||||
|
||||
// Force the port to enter non-blocking mode to ensure that any current reads return
|
||||
struct termios options = { 0 };
|
||||
struct termios options = {0};
|
||||
tcgetattr(serialPortFD, &options);
|
||||
int flags = fcntl(serialPortFD, F_GETFL);
|
||||
flags |= O_NONBLOCK;
|
||||
|
@ -586,7 +586,7 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_readBytes(JNIEnv
|
|||
else if ((timeoutMode & com_fazecast_jSerialComm_SerialPort_TIMEOUT_READ_BLOCKING) > 0) // Blocking mode, but not indefinitely
|
||||
{
|
||||
// Get current system time
|
||||
struct timeval expireTime = { 0 }, currTime = { 0 };
|
||||
struct timeval expireTime = {0}, currTime = {0};
|
||||
gettimeofday(&expireTime, NULL);
|
||||
expireTime.tv_usec += (readTimeout * 1000);
|
||||
if (expireTime.tv_usec > 1000000)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* SerialPort_Windows.c
|
||||
*
|
||||
* Created on: Feb 25, 2012
|
||||
* Last Updated on: Nov 07, 2019
|
||||
* Last Updated on: Nov 12, 2019
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* Copyright (C) 2012-2019 Fazecast, Inc.
|
||||
|
@ -408,7 +408,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||
return JNI_FALSE;
|
||||
DCB dcbSerialParams = {0};
|
||||
DCB dcbSerialParams{};
|
||||
dcbSerialParams.DCBlength = sizeof(DCB);
|
||||
|
||||
// Get port parameters from Java class
|
||||
|
@ -476,7 +476,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configTimeou
|
|||
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||
return JNI_FALSE;
|
||||
COMMTIMEOUTS timeouts = {0};
|
||||
COMMTIMEOUTS timeouts{};
|
||||
int timeoutMode = env->GetIntField(obj, timeoutModeField);
|
||||
DWORD readTimeout = (DWORD)env->GetIntField(obj, readTimeoutField);
|
||||
DWORD writeTimeout = (DWORD)env->GetIntField(obj, writeTimeoutField);
|
||||
|
@ -537,7 +537,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configEventF
|
|||
// Change read timeouts if we are monitoring data received
|
||||
if ((eventsToMonitor & com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_RECEIVED) > 0)
|
||||
{
|
||||
COMMTIMEOUTS timeouts = {0};
|
||||
COMMTIMEOUTS timeouts{};
|
||||
timeouts.ReadIntervalTimeout = MAXDWORD;
|
||||
timeouts.ReadTotalTimeoutMultiplier = MAXDWORD;
|
||||
timeouts.ReadTotalTimeoutConstant = 1000;
|
||||
|
@ -557,7 +557,7 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_waitForEvent(JNI
|
|||
HANDLE serialPortHandle = (HANDLE)serialPortFD;
|
||||
if (serialPortHandle == INVALID_HANDLE_VALUE)
|
||||
return 0;
|
||||
OVERLAPPED overlappedStruct = {0};
|
||||
OVERLAPPED overlappedStruct{};
|
||||
overlappedStruct.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (overlappedStruct.hEvent == NULL)
|
||||
{
|
||||
|
@ -607,7 +607,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_closePortNat
|
|||
PurgeComm(serialPortHandle, PURGE_RXABORT | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_TXCLEAR);
|
||||
|
||||
// Force the port to enter non-blocking mode to ensure that any current reads return
|
||||
COMMTIMEOUTS timeouts = {0};
|
||||
COMMTIMEOUTS timeouts{};
|
||||
timeouts.WriteTotalTimeoutMultiplier = 0;
|
||||
timeouts.ReadIntervalTimeout = MAXDWORD;
|
||||
timeouts.ReadTotalTimeoutMultiplier = 0;
|
||||
|
@ -689,7 +689,7 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_readBytes(JNIEnv
|
|||
}
|
||||
|
||||
// Create an asynchronous result structure
|
||||
OVERLAPPED overlappedStruct = {0};
|
||||
OVERLAPPED overlappedStruct{};
|
||||
overlappedStruct.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (overlappedStruct.hEvent == NULL)
|
||||
{
|
||||
|
@ -751,7 +751,7 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_writeBytes(JNIEn
|
|||
}
|
||||
|
||||
// Create an asynchronous result structure
|
||||
OVERLAPPED overlappedStruct = {0};
|
||||
OVERLAPPED overlappedStruct{};
|
||||
overlappedStruct.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (overlappedStruct.hEvent == NULL)
|
||||
{
|
||||
|
|
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.
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.
Binary file not shown.
Loading…
Reference in New Issue