[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Uisp-dev] RFC: use uisp as terminal/pty
From: |
Ph. Marek |
Subject: |
Re: [Uisp-dev] RFC: use uisp as terminal/pty |
Date: |
Mon, 9 Jan 2006 07:41:40 +0100 |
User-agent: |
KMail/1.8.3 |
Hello everyone,
here's the version I'm using. I know the implementation is not pretty, but it
works and didn't take too long.
I call it with
$ src/uisp -v=3 -dlpt=/dev/parports/0 -dprog=dapa --console=1
-dt_sck=3000 -dt_reset=20 -dno-enable=1
The AVR part is mostly finished; I'm only looking for a bug, where a character
sent
from PC to AVR causes a character lost from AVR to PC.
But for "sparse" communication it already works fine.
(Someone who likes to help debugging?)
Regards,
Phil
=== src/AvrDummy.C
==================================================================
--- src/AvrDummy.C (revision 8)
+++ src/AvrDummy.C (revision 19)
@@ -622,7 +622,7 @@
/* Device Command line options ... */
if (GetCmdParam("-dno-poll", false)){use_data_polling=false;}
- EnableAvr();
+ if (!GetCmdParam("-dno-enable", false)) EnableAvr();
}
#endif
=== src/DAPA.h
==================================================================
--- src/DAPA.h (revision 8)
+++ src/DAPA.h (revision 19)
@@ -69,7 +69,6 @@
private:
int SendRecv(int);
/* low level access to parallel port lines */
- void OutReset(int);
void OutSck(int);
void OutData(int);
void SckDelay();
@@ -89,6 +88,7 @@
/* If enable command 0x53 did not echo back, give a positive SCK
pulse and retry again.
*/
+ void OutReset(int);
void PulseSck();
void PulseReset();
void Init();
=== src/Main.C
==================================================================
--- src/Main.C (revision 8)
+++ src/Main.C (revision 19)
@@ -36,6 +36,8 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
+#include <signal.h>
#include "Terminal.h"
#include "MotIntl.h"
#include "AvrAtmel.h"
@@ -56,6 +58,8 @@
TMotIntl motintl;
TTerminal terminal;
+volatile int quit=0;
+
const char* version = "uisp version %s\n"
"(C) 1997-1999 Uros Platise, 2000-2003 Marek Michalkiewicz\n"
"\nuisp is free software, covered by the GNU General Public License.\n"
@@ -230,6 +234,12 @@
}
+void SigHandler(int sig)
+{
+ quit=1;
+}
+
+
int main(int _argc, const char* _argv[]){
int return_val=0;
argc = _argc;
@@ -288,7 +298,72 @@
#ifndef NO_DAPA
else if (val) {
/* The TDAPA() constructor will drop setuid privileges after
- opening the lpt ioport. */
+ opening the lpt ioport. */
+ if (GetCmdParam("--console", false))
+ {
+ unsigned char buffer[2];
+ fd_set set;
+ struct timeval tv;
+ int l;
+ TDAPA *ad=new TDAPA;
+ struct termios tios, tios2;
+ int hex_out;
+
+
+ signal(SIGQUIT, SigHandler);
+ signal(SIGINT, SigHandler);
+ signal(SIGTERM, SigHandler);
+ signal(SIGPIPE, SigHandler);
+
+ hex_out=!!GetCmdParam("--hex-out", false);
+
+ printf("Connection established.\n");
+ if (tcgetattr(0, &tios) == -1)
+ throw Error_Device("Cannot get terminal
attributes");
+ memcpy(&tios2, &tios, sizeof(tios));
+ tios2.c_cc[VMIN]=0;
+ tios2.c_lflag &= ~(ICANON | ECHO);
+ if (tcsetattr(0, TCSANOW, &tios2) == -1)
+ throw Error_Device("Cannot get terminal
attributes");
+ ad->OutReset(1);
+
+ while(!quit)
+ {
+ FD_ZERO(&set);
+ FD_SET(0,&set);
+ tv.tv_sec=0;
+ tv.tv_usec=100000;
+ if (select(1,&set, NULL,NULL, &tv))
+ {
+ l=read(0, buffer+1,
sizeof(buffer)-1);
+ if (l <= 0) break;
+ }
+ else
+ l=0;
+
+ buffer[0]=0x7f;
+ ad->Send(buffer, l+1, sizeof(buffer));
+ if (buffer[0])
+ {
+ if (hex_out)
+ {
+ printf("'%c' = hex %02X
= dez %d = bin ",
+
isprint(buffer[0]) ? buffer[0] : ' ',
+
buffer[0], buffer[0]);
+ for(l=7; l>=0; l--)
putchar((buffer[0] & (1 << l)) ? '1' : '0');
+ putchar('\n');
+ }
+ else
+ putchar(buffer[0]);
+ fflush(stdout);
+ }
+ }
+
+ if (tcsetattr(0, TCSANOW, &tios) == -1)
+ throw Error_Device("Cannot get terminal
attributes");
+ return 0;
+ }
+
device = new TAvrDummy();
}
#endif