Permalink
Browse files

Mainly code cleanup ...

- minor update (error checking) in check_incoming
- removed unused codes, info
- updated info
  • Loading branch information...
1 parent c85740f commit 86f40b4c3a94e1f2d13fe5a3985238624a70a5b2 @azman committed Mar 29, 2013
Showing with 32 additions and 183 deletions.
  1. +11 −0 CHANGELOG
  2. +5 −6 README
  3. +0 −11 TODO
  4. +1 −1 makefile
  5. +6 −35 src/my1comlib.c
  6. +3 −3 src/my1comlib.h
  7. +0 −103 src/my1comport.c
  8. +0 −24 src/my1comport.h
  9. +6 −0 src/my1termu.c
View
@@ -1,3 +1,14 @@
+****************
+my1termu-current
+****************
+
+- added error checking during check_incoming (e.g. USBSerial removed!)
+- my1termu will now exit on this error!
+- removed deprecated my1comport module...
+- removed previous code attempts related to ftdi usb port
+- removed TODO
+- updated README
+
**************
my1termu-1.4.1
**************
View
11 README
@@ -15,13 +15,12 @@ a common interface for both systems - thus, becoming a simple cross-platform
solution for small embedded projects that frequently require access to
the RS232 serial port.
-The my1comport module is deprecated but kept to provide transition time
-for other applications that is using it (e.g. my1nxpflash). It will be
-permanently removed in the future!
-
The my1cons module provides functions for console keys and parameter
-extraction for console-based applications. A test program for my1cons
-module, my1console, is also available.
+extraction for console-based applications. A test program for my1cons module,
+my1console, is also available. A couple of conio.h-compatible functions
+(getch/kbhit) for Linux are also available in conio_lin.h header file (these
+are actually based on codes I found on the internet - kudos to the original
+coders!).
This code is written for Linux platform but can be compiled with MinGW
cross-compiler for Win32 target machine.
View
11 TODO
@@ -1,11 +0,0 @@
-2012113
-- [DONE] add DTR/RTS/DSR/CTS utility in my1termu
-
-20111006
-- [NOT] define ALL keystrokes
-- [NOT] detect SHIFT/CTRL/ALT/CAPS/NUM keys as well?
-
-20110318
-- [DONE] rewrite everything to use pure c library (no c++)
-- [NOT] consider thread (or maybe use signal for linux?)
-- [DONE] recheck and test windows code...
View
@@ -9,7 +9,7 @@ TESTPRO = $(TESTBIN)
TESTOBJ = my1cons.o $(TESTBIN).o
PACKDIR = $(PROJECT)-$(shell cat VERSION)
-PACKDAT = README TODO CHANGELOG VERSION
+PACKDAT = README CHANGELOG VERSION
PLATBIN ?= $(shell uname -m)
VERSION = -DMY1APP_PROGVERS=\"$(shell date +%Y%m%d)\"
View
@@ -33,7 +33,7 @@ void initialize_serial(ASerialPort_t* aPort)
/* reset handler/flag */
aPort->mHandle = INVALID_HANDLE_VALUE;
aPort->mPortIndex = INVALID_PORT_INDEX;
- aPort->mPortType = MY1PORT_HARDWARE;
+ aPort->mPortStat = MY1PORT_STATUS_OK;
sprintf(aPort->mPortName,"%s",COM_PORT_NAME);
#ifdef DO_MINGW
/* configure 9600,N81 for COM */
@@ -151,38 +151,6 @@ int open_serial(ASerialPort_t* aPort)
aPort->mHandle = INVALID_HANDLE_VALUE;
return 0;
}
- /* for FTDI-based usb to serial? pl2303 doesn't support hi-speed */
- speed_t cBaudRate = cfgetispeed(&aPort->mTIO);
- if(aPort->mPortType==MY1PORT_FTDIUSB&&cBaudRate>B38400)
- {
- speed_t cBaudDumb = B38400;
- cfsetispeed(&aPort->mTIO, cBaudDumb);
- cfsetospeed(&aPort->mTIO, cBaudDumb);
- purge_serial(aPort);
- tcsetattr(aPort->mHandle, TCSANOW, &aPort->mTIO);
- struct serial_struct sio;
- ioctl(aPort->mHandle, TIOCGSERIAL, &sio);
- sio.flags=(sio.flags&(~ASYNC_SPD_MASK));
- sio.custom_divisor=0;
- switch(cBaudRate)
- {
- case B57600: sio.flags=(sio.flags&ASYNC_SPD_HI); break;
- case B115200: sio.flags=(sio.flags&ASYNC_SPD_VHI); break;
- case B230400: sio.flags=(sio.flags&ASYNC_SPD_SHI); break;
- case B460800: sio.flags=(sio.flags&ASYNC_SPD_WARP); break;
- case B921600: /* not supported?! */
- {
- sio.flags=(sio.flags&ASYNC_SPD_CUST);
- sio.custom_divisor = sio.baud_base / 921600;
- /** sio.reserved_char[0]=0; */
- break;
- }
- }
- ioctl(aPort->mHandle, TIOCSSERIAL, &sio);
- /* in case changed by ftdi thingy */
- cfsetispeed(&aPort->mTIO, cBaudRate);
- cfsetospeed(&aPort->mTIO, cBaudRate);
- }
#endif
}
return serial_opened(aPort);
@@ -653,10 +621,13 @@ int check_incoming(ASerialPort_t* aPort)
if(aPort->mHandle==INVALID_HANDLE_VALUE)
return 0;
#ifdef DO_MINGW
- ClearCommError(aPort->mHandle,&cDummy,&cTestStat);
+ aPort->mPortStat = ClearCommError(aPort->mHandle,&cDummy,&cTestStat);
+ if(!aPort->mPortStat) aPort->mPortStat = MY1PORT_STATUS_EIO;
return cTestStat.cbInQue; /* just check input queue buffer */
#else
- ioctl(aPort->mHandle, FIONREAD, &cCount); /* TIOCOUTQ for output */
+ /* use TIOCOUTQ instead of FIONREAD for output */
+ aPort->mPortStat = ioctl(aPort->mHandle, FIONREAD, &cCount);
+ if(aPort->mPortStat) aPort->mPortStat = MY1PORT_STATUS_EIO;
return cCount;
#endif
}
View
@@ -25,8 +25,8 @@
#define MY1BAUD460800 6
#define MY1BAUD921600 7
/*----------------------------------------------------------------------------*/
-#define MY1PORT_HARDWARE 0
-#define MY1PORT_FTDIUSB 1
+#define MY1PORT_STATUS_OK 0
+#define MY1PORT_STATUS_EIO 5
/*----------------------------------------------------------------------------*/
#define MY1PIN_RTS 1
#define MY1PIN_CTS 2
@@ -53,7 +53,7 @@ typedef struct __ASerialPort
struct termios mTIO, mTIOsave;
long mHandle;
#endif
- int mPortIndex, mPortType;
+ int mPortIndex, mPortStat;
char mPortName[MAX_COM_CHAR];
}
ASerialPort_t;
View
@@ -1,103 +0,0 @@
-/*----------------------------------------------------------------------------*/
-#include "my1comport.h"
-#include <stdio.h>
-/*----------------------------------------------------------------------------*/
-#define VERSIONSTR "2012.2"
-#define AUTHORSTR "azman@my1matrix.net"
-/*----------------------------------------------------------------------------*/
-void print_portscan(ASerialPort_t* aPort)
-{
- int test, cCount = 0;
- printf("\n--------------------\n");
- printf("COM Port Scan Result\n");
- printf("--------------------\n");
- for(test=1;test<=MAX_COM_PORT;test++)
- {
- if(check_serial(aPort,test))
- {
- printf("%s%d: ",aPort->mPortName,COM_PORT(test));
- cCount++;
- printf("Ready.\n");
- }
- }
- printf("\nDetected Port(s): %d\n\n",cCount);
-}
-/*----------------------------------------------------------------------------*/
-int initialize_port(ASerialPort_t* aPort, int anIndex)
-{
- initialize_serial(aPort);
- if(anIndex==0) return 0;
- return prepare_port(aPort,anIndex);
-}
-/*----------------------------------------------------------------------------*/
-int prepare_port(ASerialPort_t* aPort, int anIndex)
-{
- printf("\nSerial Port (%s) Library %s - by %s\n\n",
- aPort->mPortName, VERSIONSTR, AUTHORSTR);
- if(anIndex==0) anIndex = find_serial(aPort,0x0);
- return set_serial(aPort,anIndex);
-}
-/*----------------------------------------------------------------------------*/
-int isready_port(ASerialPort_t* aPort)
-{
- return serial_ready(aPort);
-}
-/*----------------------------------------------------------------------------*/
-int isopened_port(ASerialPort_t* aPort)
-{
- return serial_opened(aPort);
-}
-/*----------------------------------------------------------------------------*/
-int open_port(ASerialPort_t* aPort)
-{
- return open_serial(aPort);
-}
-/*----------------------------------------------------------------------------*/
-int close_port(ASerialPort_t* aPort)
-{
- return close_serial(aPort);
-}
-/*----------------------------------------------------------------------------*/
-int refresh_ports(ASerialPort_t* aPort, int *pCount)
-{
- return find_serial(aPort,pCount);
-}
-/*----------------------------------------------------------------------------*/
-int check_portindex(ASerialPort_t* aPort, int anIndex)
-{
- return set_serial(aPort,anIndex);
-}
-/*----------------------------------------------------------------------------*/
-int check_fastport(ASerialPort_t* aPort, int fast)
-{
- ASerialConf_t thisConfig = { 0,8,0,0 } ;
- if(fast)
- thisConfig.mBaudRate = 4;
- return set_serialconfig(aPort,&thisConfig);
-}
-/*----------------------------------------------------------------------------*/
-int check_inbuffer(ASerialPort_t* aPort)
-{
- return check_incoming(aPort);
-}
-/*----------------------------------------------------------------------------*/
-void put_byte_port(ASerialPort_t* aPort, byte_t aData)
-{
- put_byte_serial(aPort, aData);
-}
-/*----------------------------------------------------------------------------*/
-byte_t get_byte_port(ASerialPort_t* aPort)
-{
- return get_byte_serial(aPort);
-}
-/*----------------------------------------------------------------------------*/
-void clear_ibuffer(ASerialPort_t* aPort)
-{
- purge_serial(aPort);
-}
-/*----------------------------------------------------------------------------*/
-void clear_obuffer(ASerialPort_t* aPort)
-{
- flush_serial(aPort);
-}
-/*----------------------------------------------------------------------------*/
View
@@ -1,24 +0,0 @@
-/*----------------------------------------------------------------------------*/
-#ifndef __MY1COMPORTH
-#define __MY1COMPORTH
-/*----------------------------------------------------------------------------*/
-#include "my1comlib.h"
-/*----------------------------------------------------------------------------*/
-void print_portscan(ASerialPort_t* aPort);
-int initialize_port(ASerialPort_t* aPort, int anIndex);
-int prepare_port(ASerialPort_t* aPort, int anIndex);
-int isready_port(ASerialPort_t* aPort);
-int isopened_port(ASerialPort_t* aPort);
-int open_port(ASerialPort_t* aPort);
-int close_port(ASerialPort_t* aPort);
-int refresh_ports(ASerialPort_t* aPort, int *pCount);
-int check_portindex(ASerialPort_t* aPort, int anIndex);
-int check_fastport(ASerialPort_t* aPort, int fast);
-int check_inbuffer(ASerialPort_t* aPort);
-void put_byte_port(ASerialPort_t* aPort, byte_t aData);
-byte_t get_byte_port(ASerialPort_t* aPort);
-void clear_ibuffer(ASerialPort_t* aPort);
-void clear_obuffer(ASerialPort_t* aPort);
-/*----------------------------------------------------------------------------*/
-#endif
-/*----------------------------------------------------------------------------*/
View
@@ -500,6 +500,12 @@ int main(int argc, char* argv[])
if(options&OPT_SHOWHEX) printf("[%02X]",cTemp);
else putchar(cTemp);
}
+ /* check port status? */
+ if(cPort.mPortStat!=MY1PORT_STATUS_OK)
+ {
+ printf("Port Error! Aborting!\n");
+ break;
+ }
}
/* close port */
close_serial(&cPort);

0 comments on commit 86f40b4

Please sign in to comment.