1
0
mirror of https://github.com/mik3y/usb-serial-for-android.git synced 2026-08-11 08:22:52 +00:00

build tools update; instrumented device test

This commit is contained in:
Kai Morich
2018-03-09 22:37:06 +01:00
parent c89ca2c96a
commit adb22f718e
12 changed files with 1032 additions and 31 deletions
@@ -0,0 +1,64 @@
/*
bridge USB-serial to hardware-serial
for Arduinos based on ATmega32u4 (Leonardo and compatible Pro Micro, Micro)
hardware serial is configured with baud-rate, databits, stopbits, parity as send over USB
see https://github.com/arduino/Arduino/tree/master/hardware/arduino/avr/cores/arduino
-> CDC.cpp|HardwareSerial.cpp for serial implementation details
this sketch is mainly for demonstration / test of CDC communication
performance as real usb-serial bridge would be inacceptable as each byte is send in separate USB packet
*/
uint32_t baud = 9600;
uint8_t databits = 8;
uint8_t stopbits = 1;
uint8_t parity = 0;
void setup() {
Serial.begin(baud); // USB
Serial1.begin(baud, SERIAL_8N1);
}
void loop() {
// show USB connected state
if (Serial) TXLED1;
else TXLED0;
// configure hardware serial
if (Serial.baud() != baud ||
Serial.numbits() != databits ||
Serial.stopbits() != stopbits ||
Serial.paritytype() != parity) {
baud = Serial.baud();
databits = Serial.numbits();
stopbits = Serial.stopbits();
parity = Serial.paritytype();
uint8_t config = 0; // ucsrc register
switch (databits) {
case 5: break;
case 6: config |= 2; break;
case 7: config |= 4; break;
case 8: config |= 6; break;
default: config |= 6;
}
switch (stopbits) {
case 2: config |= 8;
// 1.5 stopbits not supported
}
switch (parity) {
case 1: config |= 0x30; break; // odd
case 2: config |= 0x20; break; // even
// mark, space not supported
}
Serial1.end();
Serial1.begin(baud, config);
}
// bridge
if (Serial.available() > 0)
Serial1.write(Serial.read());
if (Serial1.available() > 0)
Serial.write(Serial1.read());
}
+42
View File
@@ -0,0 +1,42 @@
*** /n/archiv/python/rfc2217_server.py 2018-03-10 09:02:07.613771600 +0100
--- rfc2217_server.py 2018-03-09 20:57:44.933717100 +0100
***************
*** 26,31 ****
--- 26,32 ----
self,
logger=logging.getLogger('rfc2217.server') if debug else None)
self.log = logging.getLogger('redirector')
+ self.dlog = logging.getLogger('data')
def statusline_poller(self):
self.log.debug('status line poll thread started')
***************
*** 55,60 ****
--- 56,62 ----
try:
data = self.serial.read(self.serial.in_waiting or 1)
if data:
+ self.dlog.debug("serial read: "+data.encode('hex'))
# escape outgoing data when needed (Telnet IAC (0xff) character)
self.write(b''.join(self.rfc2217.escape(data)))
except socket.error as msg:
***************
*** 76,81 ****
--- 78,84 ----
data = self.socket.recv(1024)
if not data:
break
+ self.dlog.debug("socket read: "+data.encode('hex'))
self.serial.write(b''.join(self.rfc2217.filter(data)))
except socket.error as msg:
self.log.error('{}'.format(msg))
***************
*** 132,137 ****
--- 135,141 ----
logging.basicConfig(level=logging.INFO)
#~ logging.getLogger('root').setLevel(logging.INFO)
logging.getLogger('rfc2217').setLevel(level)
+ logging.getLogger('data').setLevel(level)
# connect to serial port
ser = serial.serial_for_url(args.SERIALPORT, do_not_open=True)
+43
View File
@@ -0,0 +1,43 @@
/* Copyright 2012 Google Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* Project home page: http://code.google.com/p/usb-serial-for-android/
*/
// Sample Arduino sketch for use with usb-serial-for-android.
// Prints an ever-increasing counter, and writes back anything
// it receives.
static int counter = 0;
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.print("Tick #");
Serial.print(counter++, DEC);
Serial.print("\n");
if (Serial.peek() != -1) {
Serial.print("Read: ");
do {
Serial.print((char) Serial.read());
} while (Serial.peek() != -1);
Serial.print("\n");
}
delay(1000);
}