diff --git a/DMRCSBK.cpp b/DMRCSBK.cpp index f530f5b..97a4268 100644 --- a/DMRCSBK.cpp +++ b/DMRCSBK.cpp @@ -96,7 +96,9 @@ bool CDMRCSBK::put(const unsigned char* bytes) default: CUtils::dump("Unhandled CSBK type", m_data, 12U); - return false; + m_srcId = 0U; + m_dstId = 0U; + return true; } return true; diff --git a/Nextion/MMDVM_2.4.tft b/Nextion/MMDVM_2.4.tft index d5b0df5..f1c0f29 100644 Binary files a/Nextion/MMDVM_2.4.tft and b/Nextion/MMDVM_2.4.tft differ diff --git a/Nextion/MMDVM_2.8.tft b/Nextion/MMDVM_2.8.tft index 5b2c6d9..f6b5354 100644 Binary files a/Nextion/MMDVM_2.8.tft and b/Nextion/MMDVM_2.8.tft differ diff --git a/Nextion/MMDVM_3.2.tft b/Nextion/MMDVM_3.2.tft index 159053b..2b04ca1 100644 Binary files a/Nextion/MMDVM_3.2.tft and b/Nextion/MMDVM_3.2.tft differ diff --git a/Nextion/MMDVM_3.5.tft b/Nextion/MMDVM_3.5.tft index 62a3fdf..3651c2a 100644 Binary files a/Nextion/MMDVM_3.5.tft and b/Nextion/MMDVM_3.5.tft differ diff --git a/Nextion/nextion.py b/Nextion/nextion.py new file mode 100644 index 0000000..f15299e --- /dev/null +++ b/Nextion/nextion.py @@ -0,0 +1,115 @@ +''' + * Copyright (C) 2016 Alex Koren + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +''' + +import serial +import time +import sys +import os + +e = "\xff\xff\xff" +deviceName = '/dev/ttyUSB0' #MAKE SURE THIS IS THE CORRECT DEVICE +CHECK_MODEL = 'NX3224T024' + +def getBaudrate(ser, fSize=None): + for baudrate in (2400, 4800, 9600, 19200, 38400, 57600, 115200): + ser.baudrate = baudrate + ser.timeout = 3000 / baudrate + .2 + print 'Trying with baudrate: ' + str(baudrate) + '...' + ser.write("\xff\xff\xff") + ser.write('connect') + ser.write("\xff\xff\xff") + r = ser.read(128) + if 'comok' in r: + print 'Connected with baudrate: ' + str(baudrate) + '...' + noConnect = False + status, unknown1, model, unknown2, version, serial, flashSize = r.strip("\xff\x00").split(',') + print 'Status: ' + status + print 'Model: ' + model + print 'Version: ' + version + print 'Serial: ' + serial + print 'Flash size: ' + flashSize + if fSize and fSize > flashSize: + print 'File too big!' + return False + if not CHECK_MODEL in model: + print 'Wrong Display!' + return False + return True + return False + +def setDownloadBaudrate(ser, fSize, baudrate): + ser.write("") + ser.write("whmi-wri " + str(fSize) + "," + str(baudrate) + ",0" + e) + time.sleep(.05) + ser.baudrate = baudrate + ser.timeout = .5 + r = ser.read(1) + if "\x05" in r: + return True + return False + +def transferFile(ser, filename, fSize): + with open(filename, 'rb') as hmif: + dcount = 0 + while True: + data = hmif.read(4096) + if len(data) == 0: + break + dcount += len(data) + ser.timeout = 5 + ser.write(data) + sys.stdout.write('\rDownloading, %3.1f%%...'% (dcount / float(fSize) * 100.0)) + sys.stdout.flush() + ser.timeout = .5 + time.sleep(.5) + r = ser.read(1) + if "\x05" in r: + continue + else: + break + print + return True + +def upload(ser, filename): + if not getBaudrate(ser, os.path.getsize(filename)): + print 'could not find baudrate' + exit(1) + + if not setDownloadBaudrate(ser, os.path.getsize(filename), 115200): + print 'could not set download baudrate' + exit(1) + + if not transferFile(ser, filename, os.path.getsize(filename)): + print 'could not transfer file' + exit(1) + + exit(0) + +if __name__ == "__main__": + if len(sys.argv) != 2: + print 'usage:\npython nextion.py file_to_upload.tft' + exit(1) + + ser = serial.Serial(deviceName, 9600, timeout=5) + if not ser: + print 'could not open device' + exit(1) + if not ser.is_open: + ser.open() + + upload(ser, sys.argv[1]) diff --git a/OLED.h b/OLED.h index e6490c6..baeb8f2 100644 --- a/OLED.h +++ b/OLED.h @@ -37,7 +37,7 @@ class COLED : public CDisplay { public: - COLED(unsigned char displayType, unsigned char displayBrighness, unsigned char displayInvert); + COLED(unsigned char displayType, unsigned char displayBrighness, bool displayInvert); virtual ~COLED(); virtual bool open(); diff --git a/UMP.cpp b/UMP.cpp index 0df27c2..8eff25a 100644 --- a/UMP.cpp +++ b/UMP.cpp @@ -41,6 +41,7 @@ const unsigned int BUFFER_LENGTH = 255U; CUMP::CUMP(const std::string& port) : m_serial(port, SERIAL_115200), +m_open(false), m_buffer(NULL), m_length(0U), m_offset(0U), @@ -58,6 +59,9 @@ CUMP::~CUMP() bool CUMP::open() { + if (m_open) + return true; + bool ret = m_serial.open(); if (!ret) return false; @@ -76,6 +80,8 @@ bool CUMP::open() return false; } + m_open = true; + return true; } @@ -243,5 +249,10 @@ void CUMP::clock(unsigned int ms) void CUMP::close() { + if (!m_open) + return; + m_serial.close(); + + m_open = false; } diff --git a/UMP.h b/UMP.h index 17a1e97..2be9447 100644 --- a/UMP.h +++ b/UMP.h @@ -48,6 +48,7 @@ public: private: CSerialController m_serial; + bool m_open; unsigned char* m_buffer; unsigned int m_length; unsigned int m_offset; diff --git a/UMP/UMP.ino b/UMP/UMP.ino index b3d00e8..8de2d98 100644 --- a/UMP/UMP.ino +++ b/UMP/UMP.ino @@ -144,13 +144,13 @@ void loop() m_count++; if (m_started) { - if (m_count > 32000U) { + if (m_count > 3200U) { digitalWrite(PIN_LED, m_led ? LOW : HIGH); m_led = !m_led; m_count = 0U; } } else { - if (m_count > 320000U) { + if (m_count > 32000U) { digitalWrite(PIN_LED, m_led ? LOW : HIGH); m_led = !m_led; m_count = 0U;