Compare commits
20 Commits
9fcdfaf618
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3576461e03 | |||
| 9603093b62 | |||
| 20eda9fc42 | |||
| 516551f15d | |||
| aef92e33e8 | |||
| 2f9937867b | |||
| e8686cbe35 | |||
| 6249dd6074 | |||
| 4ea8ce944f | |||
| 790dcd2259 | |||
| 5043618bf8 | |||
| d8fb6cae01 | |||
| bc113e2015 | |||
| 31db3b78d6 | |||
| e314980c10 | |||
| 64a821bea1 | |||
| 09abf3e122 | |||
| 4d8ab68b81 | |||
| ebaf682151 | |||
| 9ee21ed8a8 |
@@ -16,4 +16,5 @@ target_link_libraries(usbserial-dw ${Boost_LIBRARIES})
|
|||||||
#target_link_libraries(usbserial-dw ${CMAKE_THREAD_LIBS_INIT})
|
#target_link_libraries(usbserial-dw ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
install(TARGETS usbserial-dw DESTINATION ${CMAKE_INSTALL_BINDIR})
|
install(TARGETS usbserial-dw
|
||||||
|
RUNTIME DESTINATION bin ${CMAKE_INSTALL_BINDIR})
|
||||||
@@ -268,7 +268,7 @@ Ymodem::Code Ymodem::receivePacket()
|
|||||||
BOOST_LOG_TRIVIAL(debug) << "RX = " << int(rxBuffer[0]);
|
BOOST_LOG_TRIVIAL(debug) << "RX = " << int(rxBuffer[0]);
|
||||||
if(rxBuffer[0] == CodeSoh)
|
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];
|
BOOST_LOG_TRIVIAL(debug) << "Len = " << len << " Start = " << rxBuffer[1];
|
||||||
|
|
||||||
@@ -286,7 +286,7 @@ Ymodem::Code Ymodem::receivePacket()
|
|||||||
}
|
}
|
||||||
else if(rxBuffer[0] == CodeStx)
|
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))
|
if(len < (YMODEM_PACKET_1K_SIZE + YMODEM_PACKET_OVERHEAD - 1))
|
||||||
{
|
{
|
||||||
@@ -315,7 +315,7 @@ Ymodem::Code Ymodem::receivePacket()
|
|||||||
{
|
{
|
||||||
if(code == CodeSoh)
|
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))
|
if(len < (YMODEM_PACKET_SIZE + YMODEM_PACKET_OVERHEAD - rxLength))
|
||||||
{
|
{
|
||||||
@@ -332,7 +332,7 @@ Ymodem::Code Ymodem::receivePacket()
|
|||||||
}
|
}
|
||||||
else if(code == CodeStx)
|
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))
|
if(len < (YMODEM_PACKET_1K_SIZE + YMODEM_PACKET_OVERHEAD - rxLength))
|
||||||
{
|
{
|
||||||
|
|||||||
80
main.cpp
80
main.cpp
@@ -30,6 +30,7 @@
|
|||||||
#include <boost/algorithm/string/split.hpp>
|
#include <boost/algorithm/string/split.hpp>
|
||||||
|
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
#include <boost/format.hpp>
|
||||||
|
|
||||||
#include "TimeoutSerial.h"
|
#include "TimeoutSerial.h"
|
||||||
#include "YmodemFileReceive.h"
|
#include "YmodemFileReceive.h"
|
||||||
@@ -38,11 +39,12 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
using boost::format;
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
typedef vector< string > split_vector_type;
|
typedef vector< string > split_vector_type;
|
||||||
|
|
||||||
static void init_log(void)
|
static void init_log(bool debug = false)
|
||||||
{
|
{
|
||||||
/* init boost log
|
/* init boost log
|
||||||
* 1. Add common attributes
|
* 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::min_free_space = 30 * 1024 * 1024,
|
||||||
boost::log::keywords::open_mode = std::ios_base::app);
|
boost::log::keywords::open_mode = std::ios_base::app);
|
||||||
fsSink->set_formatter(logFmt);
|
fsSink->set_formatter(logFmt);
|
||||||
|
if (!debug)
|
||||||
|
fsSink->set_filter(
|
||||||
|
boost::log::trivial::severity >= boost::log::trivial::warning
|
||||||
|
);
|
||||||
fsSink->locked_backend()->auto_flush(true);
|
fsSink->locked_backend()->auto_flush(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,23 +114,26 @@ int main(int argc, char* argv[])
|
|||||||
float pressure = NAN;
|
float pressure = NAN;
|
||||||
po::variables_map vm;
|
po::variables_map vm;
|
||||||
std::string port,path,filename;
|
std::string port,path,filename;
|
||||||
int speed;
|
int speed,brightness = 0,saturation = 0 ,contrast = 0;
|
||||||
|
|
||||||
init_log();
|
|
||||||
|
|
||||||
po::options_description desc("Allowed options");
|
po::options_description desc("Allowed options");
|
||||||
desc.add_options()
|
desc.add_options()
|
||||||
("help", "produce help message")
|
("help", "produce help message")
|
||||||
("measure", "get and print values")
|
("measure", "get and print values")
|
||||||
|
("debug", "debug output to file")
|
||||||
("verbose", po::value<string>()->implicit_value("0"), "verbosity level")
|
("verbose", po::value<string>()->implicit_value("0"), "verbosity level")
|
||||||
("file", po::value<string>(&filename)->default_value("camera.jpg"),"filename of capture filename")
|
("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")
|
("path", po::value<string>(&path)->default_value("/tmp"),"directory for file of capture")
|
||||||
("capture", "capture photo of camera")
|
("capture", "capture photo of camera")
|
||||||
("port", po::value<string>(&port)->default_value("/dev/ttyUSB0"), "port to read from")
|
("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")
|
("temperature", "get and print temprature")
|
||||||
("humidity", "get and print humidity")
|
("humidity", "get and print humidity")
|
||||||
("pressure", "get and print pressure")
|
("pressure", "get and print pressure")
|
||||||
|
("reboot", "reboot ESP32 CAM")
|
||||||
("noraw", "do not set raw mode")
|
("noraw", "do not set raw mode")
|
||||||
("noreset", "do not set zero on lines DTR a RST")
|
("noreset", "do not set zero on lines DTR a RST")
|
||||||
;
|
;
|
||||||
@@ -138,7 +147,9 @@ int main(int argc, char* argv[])
|
|||||||
cout << desc << "\n";
|
cout << desc << "\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init_log(vm.count("debug"));
|
||||||
|
|
||||||
} catch(std::exception& e) {
|
} catch(std::exception& e) {
|
||||||
cerr << "error: " << e.what() << "\n";
|
cerr << "error: " << e.what() << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
@@ -156,13 +167,28 @@ int main(int argc, char* argv[])
|
|||||||
serial.setDTR(false);
|
serial.setDTR(false);
|
||||||
serial.setRTS(false);
|
serial.setRTS(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! vm.count("noraw")) {
|
if (! vm.count("noraw")) {
|
||||||
serial.setRAW();
|
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));
|
boost::this_thread::sleep(posix_time::milliseconds(5000));
|
||||||
|
|
||||||
if (! vm.count("noreset")) {
|
if (! vm.count("noreset")) {
|
||||||
|
serial.writeString("\r\n\r\n");
|
||||||
|
boost::this_thread::sleep(posix_time::milliseconds(300));
|
||||||
line = serial.readStringUntil("\n");
|
line = serial.readStringUntil("\n");
|
||||||
trim(line);
|
trim(line);
|
||||||
BOOST_LOG_TRIVIAL(debug) << 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")) {
|
if (vm.count("measure") || vm.count("temperature") || vm.count("pressure") || vm.count("humidity")) {
|
||||||
serial.writeString("measure\r\n");
|
serial.writeString("measure\r\n");
|
||||||
|
boost::this_thread::sleep(posix_time::milliseconds(100));
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
line = serial.readStringUntil("\n");
|
line = serial.readStringUntil("\n");
|
||||||
@@ -195,6 +222,7 @@ int main(int argc, char* argv[])
|
|||||||
cout << "tlak = " << pressure << endl;
|
cout << "tlak = " << pressure << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (vm.count("temperature")) {
|
if (vm.count("temperature")) {
|
||||||
cout << temperature << endl;
|
cout << temperature << endl;
|
||||||
}
|
}
|
||||||
@@ -210,26 +238,46 @@ int main(int argc, char* argv[])
|
|||||||
return 0;
|
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")) {
|
if (vm.count("capture")) {
|
||||||
|
|
||||||
|
|
||||||
serial.writeString("capture\r\n");
|
serial.writeString("capture\r\n");
|
||||||
boost::this_thread::sleep(posix_time::milliseconds(100));
|
boost::this_thread::sleep(posix_time::milliseconds(100));
|
||||||
|
|
||||||
serial.setTimeout(posix_time::milliseconds(500));
|
serial.setTimeout(posix_time::milliseconds(500));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
line = serial.readStringUntil("\r\n");
|
line = serial.readStringUntil("\r\n");
|
||||||
if (line.rfind("[OK]",0) == 0)
|
if (line.rfind("[OK]",0) == 0)
|
||||||
cout << line << endl;
|
cout << line << endl;
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
serial.writeString("rb\r\n");
|
serial.writeString("rb\r\n");
|
||||||
boost::this_thread::sleep(posix_time::milliseconds(100));
|
boost::this_thread::sleep(posix_time::milliseconds(100));
|
||||||
//serial.readChar(1);
|
|
||||||
//serial.readChar(1);
|
|
||||||
|
|
||||||
modem.setSerialPort(&serial);
|
modem.setSerialPort(&serial);
|
||||||
modem.setFilePath(path);
|
modem.setFilePath(path);
|
||||||
|
|||||||
@@ -7,14 +7,14 @@
|
|||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=usbserial-dw
|
PKG_NAME:=usbserial-dw
|
||||||
PKG_VERSION:=0.2.4
|
PKG_VERSION:=0.3.7
|
||||||
PKG_RELEASE:=13
|
PKG_RELEASE:=2
|
||||||
|
|
||||||
PKG_SOURCE_PROTO:=git
|
PKG_SOURCE_PROTO:=git
|
||||||
PKG_SOURCE_URL:=https://git.bh.ttx.sk/jaro/usbserial-dw.git
|
PKG_SOURCE_URL:=https://git.bh.ttx.sk/jaro/usbserial-dw.git
|
||||||
PKG_MIRROR_HASH:=
|
PKG_MIRROR_HASH:=
|
||||||
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
|
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
|
||||||
PKG_SOURCE_VERSION:=9524e29a2c292bea2ffc0d7f5679905925c3d9a0
|
PKG_SOURCE_VERSION:=9603093b622b972c321e10982fa881f922dca690
|
||||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
|
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
|
||||||
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_SOURCE_VERSION)
|
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_SOURCE_VERSION)
|
||||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(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_BIN) $(PKG_INSTALL_DIR)/usr/bin/usbserial-dw $(1)/usr/bin/usbserial-dw
|
||||||
$(INSTALL_DIR) $(1)/etc/config
|
$(INSTALL_DIR) $(1)/etc/config
|
||||||
$(INSTALL_DATA) ./files/usbserial-dw.config $(1)/etc/config/usbserial
|
$(INSTALL_DATA) ./files/usbserial-dw.config $(1)/etc/config/usbserial
|
||||||
|
$(INSTALL_BIN) ./files/usbserial-dw.sh $(1)/usr/bin/usbserial.sh
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/usbserial-dw/conffiles
|
define Package/usbserial-dw/conffiles
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
config capture
|
config capture
|
||||||
option port /dev/ttyUSB0
|
option port /dev/ttyUSB0
|
||||||
option speed 115200
|
option speed 460800
|
||||||
option directory /tmp
|
option directory /tmp
|
||||||
option file camera.jpg
|
option file camera.jpg
|
||||||
option url https://meranie.bh.ttx.sk/upload/image
|
option url https://meranie.bh.ttx.sk/upload/image
|
||||||
|
|||||||
@@ -1,51 +1,62 @@
|
|||||||
#!/bin/sh /etc/rc.common
|
#!/bin/sh /etc/rc.common
|
||||||
# Copyright (C) 2018 wongsyrone
|
# Copyright (C) 2018 wongsyrone
|
||||||
|
|
||||||
. /lib/functions.sh
|
. /lib/functions.sh
|
||||||
|
|
||||||
PROG=/usr/bin/usbserial-dw
|
PROG=/usr/bin/usbserial-dw
|
||||||
CURL=/usr/bin/curl
|
CURL=/usr/bin/curl
|
||||||
|
|
||||||
parse_capture() {
|
parse_capture() {
|
||||||
local section="$1"
|
local section="$1"
|
||||||
local _port
|
local _port
|
||||||
local _speed
|
local _speed
|
||||||
local _dir
|
local _dir
|
||||||
local _file
|
local _file
|
||||||
|
|
||||||
config_get _port "$section" "port"
|
config_get _port "$section" "port"
|
||||||
config_get _speed "$section" "speed"
|
config_get _speed "$section" "speed"
|
||||||
config_get _dir "$section" "dir"
|
config_get _dir "$section" "directory"
|
||||||
config_get _file "$section" "file"
|
config_get _file "$section" "file"
|
||||||
config_get _url "$section" "url"
|
config_get _url "$section" "url"
|
||||||
|
|
||||||
$PROG --port $_port --speed $_speed --dir $_dir --file $_file
|
echo $PROG --port $_port --speed $_speed --path $_dir --file $_file --capture
|
||||||
cd $_dir
|
$PROG --port $_port --speed $_speed --path $_dir --file $_file --capture
|
||||||
$CURL -v -X POST -F "submit=OK" -F "file=@camera.jpg" $_url
|
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
|
rm $_file
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_post() {
|
parse_post() {
|
||||||
local section="$1"
|
local section="$1"
|
||||||
local _host
|
local _host
|
||||||
local _topic
|
local _topic
|
||||||
local _mqtt_prg
|
local _mqtt_prg
|
||||||
|
|
||||||
config_get _host "$section" "host"
|
config_get _host "$section" "host"
|
||||||
config_get _topic "$section" "topic"
|
config_get _topic "$section" "topic"
|
||||||
config_get _mqtt_prg "$section" "mqtt_prg"
|
config_get _mqtt_prg "$section" "mqtt_prg"
|
||||||
|
|
||||||
_tmp=`$PROG --temperature`
|
_tmp=`$PROG --temperature`
|
||||||
_hum=`$PROG --humidity`
|
_hum=`$PROG --humidity`
|
||||||
_pre=`$PROG --pressure`
|
_pre=`$PROG --pressure`
|
||||||
|
|
||||||
$_mqtt_prg -h $_host -t $_topic/temperature -m N:$_tmp
|
echo $_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/temperature -m N:${_tmp}
|
||||||
$_mqtt_prg -h $_host -t $_topic/pressure -m N:$_pre
|
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
|
start() {
|
||||||
config_foreach parse_capture capture
|
echo "[OK] Starting USB serial"
|
||||||
config_foreach parse_post post
|
config_load usbserial
|
||||||
|
config_foreach parse_capture capture
|
||||||
|
config_foreach parse_post post
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
echo "[OK] Stoping USB serial"
|
||||||
|
killall -9 $PROG
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user