Skip to content

Commit 37646c6

Browse files
committed
Make MDDSerialPort.h ANSI C compliant
* Change third argument (input Integer) of MDD_serialPortSend from int* to int
1 parent d2de0bb commit 37646c6

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

Modelica_DeviceDrivers/Resources/Include/MDDSerialPort.h

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef struct {
6060
} MDDSerialPort;
6161

6262
void MDD_serialPortDestructor(void * p_udp);
63-
int MDD_serialPortReceivingThread(void * p_serial);
63+
void* MDD_serialPortReceivingThread(void * p_serial);
6464

6565

6666
int MDD_serialPortGetReceivedBytes(void * p_serial) {
@@ -78,8 +78,9 @@ int MDD_serialPortGetReceivedBytes(void * p_serial) {
7878
void MDD_serialPortSetBlocking (int fd, int should_block) {
7979

8080
struct termios ser;
81+
int ret;
8182
memset (&ser, 0, sizeof(ser));
82-
int ret = tcgetattr (fd, &ser);
83+
ret = tcgetattr (fd, &ser);
8384
if (ret != 0) {
8485
ModelicaFormatError("MDDSerialPort.h: Error %d from tcgetattr\n",ret);
8586
return;
@@ -106,43 +107,44 @@ void MDD_serialPortSetBlocking (int fd, int should_block) {
106107
void MDD_serialPortSetInterfaceAttributes (int fd, int speed, int parity) {
107108

108109
struct termios ser;
110+
int ret;
109111
memset (&ser, 0, sizeof(ser));
110-
int ret = tcgetattr (fd, &ser);
112+
ret = tcgetattr (fd, &ser);
111113
if (ret != 0) {
112114
ModelicaFormatError("MDDSerialPort.h: Error %d from tcgetattr\n",ret);
113115
return;
114116
}
115117

116-
cfsetospeed (&ser, speed); // set output speed
117-
cfsetispeed (&ser, speed); // set input speed
118+
cfsetospeed (&ser, speed); /* set output speed */
119+
cfsetispeed (&ser, speed); /* set input speed */
118120

119-
ser.c_cflag = ( ser.c_cflag & ~CSIZE) | CS8; // 8 bit characters shall be used
120-
ser.c_iflag &= ~IGNBRK; // ignore break signal
121-
//ser.c_iflag |= IGNBRK; // ignore break signal
122-
ser.c_lflag = 0; // no signaling characters, no echo
123-
ser.c_oflag = 0; // no remapping, no delays
124-
ser.c_cc[VMIN] = 0; // read does not block
125-
ser.c_cc[VTIME] = 5; // 0.5 second read timeout
126-
ser.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff control
127-
ser.c_cflag |= (CLOCAL | CREAD); //ignore modem controls, enable reading
121+
ser.c_cflag = ( ser.c_cflag & ~CSIZE) | CS8; /* 8 bit characters shall be used */
122+
ser.c_iflag &= ~IGNBRK; /* ignore break signal */
123+
/*ser.c_iflag |= IGNBRK; // ignore break signal*/
124+
ser.c_lflag = 0; /* no signaling characters, no echo */
125+
ser.c_oflag = 0; /* no remapping, no delays */
126+
ser.c_cc[VMIN] = 0; /* read does not block */
127+
ser.c_cc[VTIME] = 5; /* 0.5 second read timeout */
128+
ser.c_iflag &= ~(IXON | IXOFF | IXANY); /* shut off xon/xoff control */
129+
ser.c_cflag |= (CLOCAL | CREAD); /*ignore modem controls, enable reading*/
128130

129131
switch (parity) {
130132
case 1:
131133
/* even parity */
132-
ser.c_cflag |= PARENB; // enable parity
133-
ser.c_cflag &= ~PARODD; // set even parity
134+
ser.c_cflag |= PARENB; /* enable parity */
135+
ser.c_cflag &= ~PARODD; /* set even parity */
134136
ModelicaFormatMessage("Set even Parity of serial port handle: %d\n",fd);
135137
break;
136138
case 2:
137139
/* odd parity */
138-
ser.c_cflag |= PARENB; // enable parity
139-
ser.c_cflag |= PARODD; // set even parity
140+
ser.c_cflag |= PARENB; /* enable parity */
141+
ser.c_cflag |= PARODD; /* set even parity */
140142
ModelicaFormatMessage("Set odd Parity of serial port handle: %d\n",fd);
141143
break;
142144
default:
143145
/* no parity */
144-
ser.c_cflag &= ~(PARENB | PARODD); // switch off any parity
145-
ser.c_cflag |= parity; // set parity
146+
ser.c_cflag &= ~(PARENB | PARODD); /* switch off any parity */
147+
ser.c_cflag |= parity; /* set parity */
146148
ModelicaFormatMessage("Set no Parity of serial port handle: %d\n",fd);
147149
break;
148150
}
@@ -167,7 +169,7 @@ void MDD_serialPortSetInterfaceAttributes (int fd, int speed, int parity) {
167169
void * MDD_serialPortConstructor(const char * deviceName, int bufferSize, int parity, int receiver, int baud) {
168170
/* Allocation of data structure memory */
169171
MDDSerialPort* serial = (MDDSerialPort*) malloc(sizeof(MDDSerialPort));
170-
int i, ret;
172+
int ret;
171173
speed_t speed;
172174
serial->messageLength = bufferSize;
173175
serial->runReceive = 0;
@@ -226,7 +228,7 @@ void * MDD_serialPortConstructor(const char * deviceName, int bufferSize, int pa
226228
if (receiver) {
227229
/* Start dedicated receiver thread */
228230
serial->runReceive = 1;
229-
ret = pthread_create(&serial->thread, 0, (void *) MDD_serialPortReceivingThread, serial);
231+
ret = pthread_create(&serial->thread, 0, MDD_serialPortReceivingThread, serial);
230232
if (ret) {
231233
ModelicaFormatError("MDDSerialPort.h: pthread (MDD_serialPortReceivingThread) failed\n");
232234
}
@@ -239,7 +241,7 @@ void * MDD_serialPortConstructor(const char * deviceName, int bufferSize, int pa
239241
*
240242
* @param p_udp pointer address to the udp socket data structure
241243
*/
242-
int MDD_serialPortReceivingThread(void * p_serial) {
244+
void* MDD_serialPortReceivingThread(void * p_serial) {
243245
MDDSerialPort * serial = (MDDSerialPort *) p_serial;
244246

245247
struct pollfd serial_poll;
@@ -285,7 +287,7 @@ int MDD_serialPortReceivingThread(void * p_serial) {
285287
ModelicaFormatError("MDDSerialPort.h: Poll returned %d. That should not happen.\n", ret);
286288
}
287289
}
288-
return 0;
290+
return NULL;
289291
}
290292

291293

@@ -311,12 +313,11 @@ const char * MDD_serialPortRead(void * p_serial) {
311313
* @param data data to be sent
312314
* @param dataSize size of data
313315
*/
314-
void MDD_serialPortSend(void * p_serial, const char * data, int * dataSize) {
316+
void MDD_serialPortSend(void * p_serial, const char * data, int dataSize) {
315317

316318
MDDSerialPort * serial = (MDDSerialPort *) p_serial;
317319

318-
int ret;
319-
ret = write(serial->fd, data, dataSize); // write to serial port
320+
int ret = write(serial->fd, data, dataSize); /* write to serial port */
320321
if (ret < dataSize) {
321322
MDD_serialPortDestructor((void *) serial);
322323
ModelicaFormatError("MDDSerialPort.h: Expected to send: %d bytes, but was: %d\n"

0 commit comments

Comments
 (0)