Compare commits

...

37 Commits

Author SHA1 Message Date
3576461e03 Cid 2021-11-16 23:20:25 +01:00
9603093b62 brighrness, speed 460800 2021-11-16 23:18:32 +01:00
20eda9fc42 Cid 2021-10-15 21:29:08 +02:00
516551f15d CID 2021-10-15 21:28:33 +02:00
aef92e33e8 fix and log 2021-10-15 21:18:39 +02:00
2f9937867b CID 2021-10-15 18:58:29 +02:00
e8686cbe35 CID, pkg version 2021-10-15 18:57:47 +02:00
6249dd6074 speed, script update 2021-10-15 18:55:13 +02:00
4ea8ce944f format, str, contrast, saturation, brihtness, speed 2021-10-15 18:51:03 +02:00
790dcd2259 CID 2021-09-12 17:26:38 +02:00
5043618bf8 fix openwrt 18 2021-09-12 17:25:37 +02:00
d8fb6cae01 Fix cmake for openwrt 18 2021-09-12 17:24:00 +02:00
bc113e2015 CID 2021-09-12 09:19:44 +02:00
31db3b78d6 CID 2021-09-12 09:07:58 +02:00
e314980c10 First usable version on RS Pro 2021-09-12 09:06:44 +02:00
64a821bea1 cid 2021-09-12 00:36:20 +02:00
09abf3e122 debug messages to log file 2021-09-12 00:35:36 +02:00
4d8ab68b81 cid 2021-09-12 00:15:04 +02:00
ebaf682151 length 2021-09-12 00:11:13 +02:00
9ee21ed8a8 length unsigned 2021-09-12 00:11:03 +02:00
9fcdfaf618 error 158 2021-09-12 00:02:51 +02:00
aaf71e77c9 cid 2021-09-11 23:38:10 +02:00
9524e29a2c debug error 2021-09-11 23:37:15 +02:00
b6faa146fa cid 2021-09-11 23:27:17 +02:00
cd16fcc579 Test fixes 2021-09-11 23:25:52 +02:00
085c1a482e cid 2021-09-11 23:06:39 +02:00
bf7482317e more debug 2021-09-11 23:04:35 +02:00
f276d41f72 cid 2021-09-11 22:50:39 +02:00
155addc239 Makefile 2021-09-11 22:50:00 +02:00
ffaa44ceb4 Fix read final unsigned to signed retyped 2021-09-11 22:49:23 +02:00
5b0610cc44 cid 2021-09-11 21:32:29 +02:00
dbc6e38be7 More dump 2021-09-11 21:30:36 +02:00
8130f8e582 Cid 2021-09-11 20:38:26 +02:00
2a529f224a Fixes 2021-09-11 20:37:15 +02:00
1021893844 cid 2021-09-05 21:03:50 +02:00
7996cf50b0 fix timeout 2021-09-05 20:50:16 +02:00
7c2ad33e75 debug print 2021-09-05 20:48:34 +02:00
12 changed files with 146 additions and 69 deletions

View File

@@ -16,4 +16,5 @@ target_link_libraries(usbserial-dw ${Boost_LIBRARIES})
#target_link_libraries(usbserial-dw ${CMAKE_THREAD_LIBS_INIT})
## Install
install(TARGETS usbserial-dw DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS usbserial-dw
RUNTIME DESTINATION bin ${CMAKE_INSTALL_BINDIR})

3
TODO
View File

@@ -1 +1,2 @@
Code 0x41 A1 stage lookup in RS PRO problem
Pravdepodobne nejaky bug v TimeoutSerial read v tom ze cita s oneskorenim 1
Length 1 a potom este pise TimeoutSerial

View File

@@ -88,13 +88,21 @@ void TimeoutSerial::writeString(const std::string& s)
{
asio::write(port,asio::buffer(s.c_str(),s.size()));
}
void TimeoutSerial::dump(char *data, size_t size)
{
BOOST_LOG_TRIVIAL(debug) << "Size = " << size;
for (int i=0; i < size; i++) {
BOOST_LOG_TRIVIAL(debug) << i << "(" << int(data[i]) << ")";
}
}
size_t TimeoutSerial::read(char *data, size_t size)
{
size_t toRead = 0;
if(readData.size()>0)//If there is some data from a previous read
{
BOOST_LOG_TRIVIAL(debug) << "UNCONSUMED DATA " << readData.size();
istream is(&readData);
size_t toRead=min(readData.size(),size);//How many bytes to read?
toRead=min(readData.size(),size);//How many bytes to read?
is.read(data,toRead);
data+=toRead;
size-=toRead;
@@ -113,7 +121,7 @@ size_t TimeoutSerial::read(char *data, size_t size)
asio::placeholders::error));
result=resultInProgress;
bytesTransferred=0;
bytesTransferred=toRead;
for(;;)
{
io.run_one();
@@ -121,6 +129,7 @@ size_t TimeoutSerial::read(char *data, size_t size)
{
case resultSuccess:
timer.cancel();
dump(data,size);
return this->bytesTransferred;
case resultTimeoutExpired:
port.cancel();
@@ -235,10 +244,12 @@ void TimeoutSerial::timeoutExpired(const boost::system::error_code& error)
void TimeoutSerial::readCompleted(const boost::system::error_code& error,
const size_t bytesTransferred)
{
BOOST_LOG_TRIVIAL(debug) << "Error = " << error.value() << " Message = " << error.message();
if(!error)
{
result=resultSuccess;
this->bytesTransferred=bytesTransferred;
this->bytesTransferred+=bytesTransferred;
return;
}
@@ -257,7 +268,7 @@ void TimeoutSerial::readCompleted(const boost::system::error_code& error,
#else //Linux
if(error.value()==125) return; //Linux outputs error 125
if (error.value()==158) {
performReadSetup(setupParameters);
//performReadSetup(setupParameters);
return;
}
#endif

View File

@@ -127,7 +127,7 @@ public:
* \throws timeout_exception in case of timeout
*/
size_t read(char *data, size_t size);
void dump(char *data, size_t size);
/**
* Read some data, blocking
* \param size how much data to read

View File

@@ -268,7 +268,9 @@ Ymodem::Code Ymodem::receivePacket()
BOOST_LOG_TRIVIAL(debug) << "RX = " << int(rxBuffer[0]);
if(rxBuffer[0] == CodeSoh)
{
uint32_t len = read(&(rxBuffer[1]), YMODEM_PACKET_SIZE + YMODEM_PACKET_OVERHEAD - 1);
int32_t len = read(&(rxBuffer[1]), YMODEM_PACKET_SIZE + YMODEM_PACKET_OVERHEAD - 1);
BOOST_LOG_TRIVIAL(debug) << "Len = " << len << " Start = " << rxBuffer[1];
if(len < (YMODEM_PACKET_SIZE + YMODEM_PACKET_OVERHEAD - 1))
{
@@ -284,7 +286,7 @@ Ymodem::Code Ymodem::receivePacket()
}
else if(rxBuffer[0] == CodeStx)
{
uint32_t len = read(&(rxBuffer[1]), YMODEM_PACKET_1K_SIZE + YMODEM_PACKET_OVERHEAD - 1);
int32_t len = read(&(rxBuffer[1]), YMODEM_PACKET_1K_SIZE + YMODEM_PACKET_OVERHEAD - 1);
if(len < (YMODEM_PACKET_1K_SIZE + YMODEM_PACKET_OVERHEAD - 1))
{
@@ -305,6 +307,7 @@ Ymodem::Code Ymodem::receivePacket()
}
else
{
BOOST_LOG_TRIVIAL(debug) << "RET <= 0";
return CodeNone;
}
}
@@ -312,7 +315,7 @@ Ymodem::Code Ymodem::receivePacket()
{
if(code == CodeSoh)
{
uint32_t len = read(&(rxBuffer[rxLength]), YMODEM_PACKET_SIZE + YMODEM_PACKET_OVERHEAD - rxLength);
int32_t len = read(&(rxBuffer[rxLength]), YMODEM_PACKET_SIZE + YMODEM_PACKET_OVERHEAD - rxLength);
if(len < (YMODEM_PACKET_SIZE + YMODEM_PACKET_OVERHEAD - rxLength))
{
@@ -329,7 +332,7 @@ Ymodem::Code Ymodem::receivePacket()
}
else if(code == CodeStx)
{
uint32_t len = read(&(rxBuffer[rxLength]), YMODEM_PACKET_1K_SIZE + YMODEM_PACKET_OVERHEAD - rxLength);
int32_t len = read(&(rxBuffer[rxLength]), YMODEM_PACKET_1K_SIZE + YMODEM_PACKET_OVERHEAD - rxLength);
if(len < (YMODEM_PACKET_1K_SIZE + YMODEM_PACKET_OVERHEAD - rxLength))
{

View File

@@ -115,8 +115,8 @@ private:
virtual Code callback(Status status, uint8_t *buff, uint32_t *len) = 0;
virtual uint32_t read(uint8_t *buff, uint32_t len) = 0;
virtual uint32_t write(uint8_t *buff, uint32_t len) = 0;
virtual int32_t read(uint8_t *buff, uint32_t len) = 0;
virtual int32_t write(uint8_t *buff, uint32_t len) = 0;
uint32_t timeDivide;
uint32_t timeMax;

View File

@@ -253,12 +253,13 @@ Ymodem::Code YmodemFileReceive::callback(Status status, uint8_t *buff, uint32_t
}
}
uint32_t YmodemFileReceive::read(uint8_t *buff, uint32_t len)
int32_t YmodemFileReceive::read(uint8_t *buff, uint32_t len)
{
return serialPort->read((char *)buff, len);
}
uint32_t YmodemFileReceive::write(uint8_t *buff, uint32_t len)
int32_t YmodemFileReceive::write(uint8_t *buff, uint32_t len)
{
return serialPort->write((char *)buff, len);
}

View File

@@ -40,8 +40,8 @@ public:
private:
Code callback(Status status, uint8_t *buff, uint32_t *len);
uint32_t read(uint8_t *buff, uint32_t len);
uint32_t write(uint8_t *buff, uint32_t len);
int32_t read(uint8_t *buff, uint32_t len);
int32_t write(uint8_t *buff, uint32_t len);
ofstream file;
boost::asio::io_service io; ///< Io service object

View File

@@ -30,6 +30,7 @@
#include <boost/algorithm/string/split.hpp>
#include <boost/program_options.hpp>
#include <boost/format.hpp>
#include "TimeoutSerial.h"
#include "YmodemFileReceive.h"
@@ -38,11 +39,12 @@
using namespace std;
using namespace boost;
using boost::format;
namespace po = boost::program_options;
typedef vector< string > split_vector_type;
static void init_log(void)
static void init_log(bool debug = false)
{
/* init boost log
* 1. Add common attributes
@@ -89,6 +91,10 @@ static void init_log(void)
boost::log::keywords::min_free_space = 30 * 1024 * 1024,
boost::log::keywords::open_mode = std::ios_base::app);
fsSink->set_formatter(logFmt);
if (!debug)
fsSink->set_filter(
boost::log::trivial::severity >= boost::log::trivial::warning
);
fsSink->locked_backend()->auto_flush(true);
}
@@ -108,23 +114,26 @@ int main(int argc, char* argv[])
float pressure = NAN;
po::variables_map vm;
std::string port,path,filename;
int speed;
int speed,brightness = 0,saturation = 0 ,contrast = 0;
init_log();
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("measure", "get and print values")
("debug", "debug output to file")
("verbose", po::value<string>()->implicit_value("0"), "verbosity level")
("file", po::value<string>(&filename)->default_value("camera.jpg"),"filename of capture filename")
("path", po::value<string>(&path)->default_value("/tmp"),"directory for file of capture")
("capture", "capture photo of camera")
("port", po::value<string>(&port)->default_value("/dev/ttyUSB0"), "port to read from")
("speed", po::value<int>(&speed)->default_value(115200), "speed read from port")
("speed", po::value<int>(&speed)->default_value(460800), "speed read from port")
("brightness", po::value<int>(&brightness)->implicit_value(0), "set brightness")
("saturation", po::value<int>(&saturation)->implicit_value(0), "set saturation")
("contrast", po::value<int>(&contrast)->implicit_value(0), "set contrast")
("temperature", "get and print temprature")
("humidity", "get and print humidity")
("pressure", "get and print pressure")
("reboot", "reboot ESP32 CAM")
("noraw", "do not set raw mode")
("noreset", "do not set zero on lines DTR a RST")
;
@@ -138,7 +147,9 @@ int main(int argc, char* argv[])
cout << desc << "\n";
return 0;
}
init_log(vm.count("debug"));
} catch(std::exception& e) {
cerr << "error: " << e.what() << "\n";
return 1;
@@ -156,13 +167,28 @@ int main(int argc, char* argv[])
serial.setDTR(false);
serial.setRTS(false);
}
if (! vm.count("noraw")) {
serial.setRAW();
}
if (vm.count("reset")) {
serial.setDTR(true);
serial.setRTS(true);
serial.writeString("reboot\r\n");
boost::this_thread::sleep(posix_time::milliseconds(1000));
serial.setDTR(false);
serial.setRTS(false);
}
boost::this_thread::sleep(posix_time::milliseconds(5000));
if (! vm.count("noreset")) {
serial.writeString("\r\n\r\n");
boost::this_thread::sleep(posix_time::milliseconds(300));
line = serial.readStringUntil("\n");
trim(line);
BOOST_LOG_TRIVIAL(debug) << line;
@@ -170,6 +196,7 @@ int main(int argc, char* argv[])
if (vm.count("measure") || vm.count("temperature") || vm.count("pressure") || vm.count("humidity")) {
serial.writeString("measure\r\n");
boost::this_thread::sleep(posix_time::milliseconds(100));
for (;;) {
line = serial.readStringUntil("\n");
@@ -195,6 +222,7 @@ int main(int argc, char* argv[])
cout << "tlak = " << pressure << endl;
}
if (vm.count("temperature")) {
cout << temperature << endl;
}
@@ -210,26 +238,46 @@ int main(int argc, char* argv[])
return 0;
}
if (vm.count("brightness")) {
string s = str(format("bright %d\r\n") % brightness);
BOOST_LOG_TRIVIAL(debug) << "SET " << s ;
serial.writeString(s);
boost::this_thread::sleep(posix_time::milliseconds(100));
}
if (vm.count("saturation")) {
string s = str(format("satur %d\r\n") % saturation);
BOOST_LOG_TRIVIAL(debug) << "SET " << s ;
serial.writeString(s);
boost::this_thread::sleep(posix_time::milliseconds(100));
}
if (vm.count("contrast")) {
string s = str(format("contr %d\r\n") % contrast);
BOOST_LOG_TRIVIAL(debug) << "SET " << s ;
serial.writeString(s);
boost::this_thread::sleep(posix_time::milliseconds(100));
}
if (vm.count("capture")) {
serial.writeString("capture\r\n");
boost::this_thread::sleep(posix_time::milliseconds(100));
serial.setTimeout(posix_time::milliseconds(500));
try {
for (;;) {
line = serial.readStringUntil("\r\n");
if (line.rfind("[OK]",0) == 0)
cout << line << endl;
}
} catch (...) {
for (;;) {
line = serial.readStringUntil("\r\n");
if (line.rfind("[OK]",0) == 0)
cout << line << endl;
}
} catch (...) {
}
serial.writeString("rb\r\n");
boost::this_thread::sleep(posix_time::milliseconds(100));
//serial.readChar(1);
//serial.readChar(1);
modem.setSerialPort(&serial);
modem.setFilePath(path);

View File

@@ -7,14 +7,14 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=usbserial-dw
PKG_VERSION:=0.2.4
PKG_RELEASE:=5
PKG_VERSION:=0.3.7
PKG_RELEASE:=2
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://git.bh.ttx.sk/jaro/usbserial-dw.git
PKG_MIRROR_HASH:=
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=a6da98cf7f2e7d6c42799608b35a30eff207a992
PKG_SOURCE_VERSION:=9603093b622b972c321e10982fa881f922dca690
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_SOURCE_VERSION)
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_SOURCE_VERSION)
@@ -64,6 +64,7 @@ define Package/usbserial-dw/install
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/usbserial-dw $(1)/usr/bin/usbserial-dw
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DATA) ./files/usbserial-dw.config $(1)/etc/config/usbserial
$(INSTALL_BIN) ./files/usbserial-dw.sh $(1)/usr/bin/usbserial.sh
endef
define Package/usbserial-dw/conffiles

View File

@@ -1,6 +1,6 @@
config capture
option port /dev/ttyUSB0
option speed 115200
option speed 460800
option directory /tmp
option file camera.jpg
option url https://meranie.bh.ttx.sk/upload/image

View File

@@ -1,51 +1,62 @@
#!/bin/sh /etc/rc.common
#!/bin/sh /etc/rc.common
# Copyright (C) 2018 wongsyrone
. /lib/functions.sh
PROG=/usr/bin/usbserial-dw
CURL=/usr/bin/curl
parse_capture() {
parse_capture() {
local section="$1"
local _port
local _port
local _speed
local _dir
local _dir
local _file
config_get _port "$section" "port"
config_get _speed "$section" "speed"
config_get _dir "$section" "dir"
config_get _port "$section" "port"
config_get _speed "$section" "speed"
config_get _dir "$section" "directory"
config_get _file "$section" "file"
config_get _url "$section" "url"
$PROG --port $_port --speed $_speed --dir $_dir --file $_file
cd $_dir
$CURL -v -X POST -F "submit=OK" -F "file=@camera.jpg" $_url
echo $PROG --port $_port --speed $_speed --path $_dir --file $_file --capture
$PROG --port $_port --speed $_speed --path $_dir --file $_file --capture
cd $_dir
echo $CURL -X POST -F "submit=OK" -F "file=@camera.jpg" $_url
$CURL -X POST -F "submit=OK" -F "file=@camera.jpg" $_url
rm $_file
}
parse_post() {
parse_post() {
local section="$1"
local _host
local _topic
local _host
local _topic
local _mqtt_prg
config_get _host "$section" "host"
config_get _topic "$section" "topic"
config_get _host "$section" "host"
config_get _topic "$section" "topic"
config_get _mqtt_prg "$section" "mqtt_prg"
_tmp=`$PROG --temperature`
_hum=`$PROG --humidity`
_pre=`$PROG --pressure`
$_mqtt_prg -h $_host -t $_topic/temperature -m N:$_tmp
$_mqtt_prg -h $_host -t $_topic/humidity -m N:$_hum
$_mqtt_prg -h $_host -t $_topic/pressure -m N:$_pre
echo $_mqtt_prg -h $_host -t $_topic/temperature -m N:${_tmp}
$_mqtt_prg -h $_host -t $_topic/temperature -m N:${_tmp}
echo $_mqtt_prg -h $_host -t $_topic/humidity -m N:${_hum}
$_mqtt_prg -h $_host -t $_topic/humidity -m N:${_hum}
echo $_mqtt_prg -h $_host -t $_topic/pressure -m N:${_pre}
$_mqtt_prg -h $_host -t $_topic/pressure -m N:${_pre}}
}
config_load usbserial
config_foreach parse_capture capture
config_foreach parse_post post
start() {
echo "[OK] Starting USB serial"
config_load usbserial
config_foreach parse_capture capture
config_foreach parse_post post
}
stop() {
echo "[OK] Stoping USB serial"
killall -9 $PROG
}