Skip to content

Commit

Permalink
Merge branch 'development' into pre-release-12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Aug 18, 2022
2 parents f5b2216 + 6bc0e8d commit 806c576
Show file tree
Hide file tree
Showing 23 changed files with 888 additions and 2,164 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ All notable changes to this project will be documented in this file.

## [Released]

## [12.1.0] 20220817
## [12.1.0] 20220818
- Release Patricia

## [12.0.2.4] 20220817
## [12.0.2.4] 20220818
### Added
- Command ``SetOption45 1..250`` to change default bistable latching relay pulse length of 40 milliseconds
- Support for Modbus bridge adding commands ``ModbusSend``, ``ModbusBaudrate`` and ``ModbusSerialConfig`` (#16013)
Expand All @@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
### Changed
- ESP32 LVGL library from v8.2.0 to v8.3.0 (#16019)
- Tasmota ESP32 Arduino core from v2.0.4 to v2.0.4.1 (#16110)
- TasmotaModbus library from v3.4.0 to v3.5.0 (#16245)

### Fixed
- Restore EnergyToday after using command ``restart 2`` and power cycle (#16118)
Expand Down
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
### Breaking Changed

### Changed
- TasmotaModbus library from v3.4.0 to v3.5.0 [#16245](https://github.com/arendst/Tasmota/issues/16245)
- ESP32 Arduino core from v2.0.3 to v2.0.4.1 [#15940](https://github.com/arendst/Tasmota/issues/15940)
- ESP32 LVGL library from v8.2.0 to v8.3.0 [#16019](https://github.com/arendst/Tasmota/issues/16019)
- Driver DHT v6 consolidation for both ESP8266 and ESP32 to support SI7021, THS01 and MS01 on ESP32 [#15856](https://github.com/arendst/Tasmota/issues/15856)
Expand Down
7 changes: 0 additions & 7 deletions lib/lib_basic/TasmotaModbus-3.4.0/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "TasmotaModbus",
"version": "3.4.0",
"version": "3.5.0",
"keywords": [
"serial", "io", "TasmotaModbus"
],
"description": "Basic modbus wrapper for TasmotaSerial for ESP8266.",
"description": "Modbus wrapper for TasmotaSerial.",
"repository":
{
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=TasmotaModbus
version=3.4.0
version=3.5.0
author=Theo Arends
maintainer=Theo Arends <theo@arends.com>
sentence=Basic modbus wrapper for TasmotaSerial for ESP8266.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
TasmotaModbus.cpp - Basic modbus wrapper for TasmotaSerial for Tasmota
Copyright (C) 2021 Theo Arends
Expand All @@ -15,6 +15,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Documentation about modbus protocol: https://www.modbustools.com/modbus.html
*/

#include "TasmotaModbus.h"
Expand Down Expand Up @@ -53,36 +55,94 @@ int TasmotaModbus::Begin(long speed, uint32_t config)
return result;
}

void TasmotaModbus::Send(uint8_t device_address, uint8_t function_code, uint16_t start_address, uint16_t register_count)
uint8_t TasmotaModbus::Send(uint8_t device_address, uint8_t function_code, uint16_t start_address, uint16_t register_count, uint16_t *registers)
{
uint8_t frame[8];
uint8_t *frame;
uint8_t framepointer = 0;

if (function_code < 7)
{
frame = (uint8_t *)malloc(8); // Addres(1), Function(1), Start/Coil Address(2), Registercount or Data (2), CRC(2)
}
else
{
frame = (uint8_t *)malloc(9 + (register_count * 2)); // Addres(1), Function(1), Start/Coil Address(2),Quantity of registers (2), Bytecount(1), Data(1..n), CRC(2)
}

mb_address = device_address; // Save address for receipt check

frame[0] = mb_address; // 0xFE default device address or dedicated like 0x01
frame[1] = function_code;
frame[2] = (uint8_t)(start_address >> 8); // MSB
frame[3] = (uint8_t)(start_address); // LSB
frame[4] = (uint8_t)(register_count >> 8); // MSB
frame[5] = (uint8_t)(register_count); // LSB
uint16_t crc = CalculateCRC(frame, 6);
frame[6] = (uint8_t)(crc);
frame[7] = (uint8_t)(crc >> 8);
frame[framepointer++] = mb_address; // 0xFE default device address or dedicated like 0x01
frame[framepointer++] = function_code;
frame[framepointer++] = (uint8_t)(start_address >> 8); // MSB
frame[framepointer++] = (uint8_t)(start_address); // LSB
if (function_code < 5)
{
frame[framepointer++] = (uint8_t)(register_count >> 8); // MSB
frame[framepointer++] = (uint8_t)(register_count); // LSB
}
else if ((function_code == 5) || (function_code == 6))
{
if (registers == NULL)
{
free(frame);
return 13; // Register data not specified
}
if (register_count != 1)
{
free(frame);
return 12; // Wrong register count
}
frame[framepointer++] = (uint8_t)(registers[0] >> 8); // MSB
frame[framepointer++] = (uint8_t)(registers[0]); // LSB
}
else if ((function_code == 15) || (function_code == 16))
{
frame[framepointer++] = (uint8_t)(register_count >> 8); // MSB
frame[framepointer++] = (uint8_t)(register_count); // LSB
frame[framepointer++] = register_count * 2;
if (registers == NULL)
{
free(frame);
return 13; // Register data not specified
}
if (register_count == 0)
{
free(frame);
return 12; // Wrong register count
}
for (int registerpointer = 0; registerpointer < register_count; registerpointer++)
{
frame[framepointer++] = (uint8_t)(registers[registerpointer] >> 8); // MSB
frame[framepointer++] = (uint8_t)(registers[registerpointer]); // LSB
}
}
else
{
free(frame);
return 1; // Wrong function code
}

uint16_t crc = CalculateCRC(frame, framepointer);
frame[framepointer++] = (uint8_t)(crc);
frame[framepointer++] = (uint8_t)(crc >> 8);

flush();
write(frame, sizeof(frame));
write(frame, framepointer);
free(frame);
return 0;
}

bool TasmotaModbus::ReceiveReady()
{
return (available() > 4);
}

uint8_t TasmotaModbus::ReceiveBuffer(uint8_t *buffer, uint8_t register_count)
uint8_t TasmotaModbus::ReceiveBuffer(uint8_t *buffer, uint8_t data_count)
{
mb_len = 0;
uint32_t timeout = millis() + 10;
while ((mb_len < (register_count *2) + 5) && (millis() < timeout)) {
uint8_t header_length = 3;
while ((mb_len < (data_count * 2) + header_length + 2) && (millis() < timeout)) {
if (available()) {
uint8_t data = (uint8_t)read();
if (!mb_len) { // Skip leading data as provided by hardware serial
Expand All @@ -106,6 +166,7 @@ uint8_t TasmotaModbus::ReceiveBuffer(uint8_t *buffer, uint8_t register_count)
// 10 = Gateway Path Unavailable
// 11 = Gateway Target device failed to respond
}
if ((buffer[1] == 5) || (buffer[1] == 6) || (buffer[1] == 15) || (buffer[1] == 16)) header_length = 4; // Addr, Func, StartAddr
}
}

Expand All @@ -114,7 +175,7 @@ uint8_t TasmotaModbus::ReceiveBuffer(uint8_t *buffer, uint8_t register_count)
}
}

if (mb_len < 7) { return 7; } // 7 = Not enough data
if (mb_len < 6) { return 7; } // 7 = Not enough data

/*
if (mb_len != buffer[2] + 5) {
Expand All @@ -131,6 +192,22 @@ uint8_t TasmotaModbus::ReceiveBuffer(uint8_t *buffer, uint8_t register_count)
return 0; // 0 = No error
}

uint8_t TasmotaModbus::Receive8BitRegister(uint8_t *value)
{
// 0 1 2 3 4 5
// 01 04 02 43 HH LL
// Id Cc Sz Regis Crc--

uint8_t buffer[6];

uint8_t error = ReceiveBuffer(buffer, 1); // 1 x 16bit register
if (!error) {
*value = buffer[3];
}

return error;
}

uint8_t TasmotaModbus::Receive16BitRegister(uint16_t *value)
{
// 0 1 2 3 4 5 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class TasmotaModbus : public TasmotaSerial {

uint16_t CalculateCRC(uint8_t *frame, uint8_t num);

void Send(uint8_t device_address, uint8_t function_code, uint16_t start_address, uint16_t register_count);

bool ReceiveReady();

/* Return codes:
Expand All @@ -51,8 +49,13 @@ class TasmotaModbus : public TasmotaSerial {
* 9 = Crc error
* 10 = Gateway Path Unavailable
* 11 = Gateway Target device failed to respond
* 12 = Wrong number of registers
* 13 = Register data not specified
* 14 = To many registers
*/
uint8_t Send(uint8_t device_address, uint8_t function_code, uint16_t start_address, uint16_t register_count, uint16_t *registers = NULL);
uint8_t ReceiveBuffer(uint8_t *buffer, uint8_t register_count);
uint8_t Receive8BitRegister(uint8_t *value);
uint8_t Receive16BitRegister(uint16_t *value);
uint8_t Receive32BitRegister(float *value);

Expand Down
22 changes: 8 additions & 14 deletions lib/lib_ssl/bearssl-esp8266/src/ec/ec_p256_m15.c
Original file line number Diff line number Diff line change
Expand Up @@ -2026,12 +2026,13 @@ api_mul(unsigned char *G, size_t Glen,
p256_jacobian P;

(void)curve;
if (Glen != 65) {
return 0;
}
r = p256_decode(&P, G, Glen);
p256_mul(&P, x, xlen);
if (Glen >= 65) {
p256_to_affine(&P);
p256_encode(G, &P);
}
p256_to_affine(&P);
p256_encode(G, &P);
return r;
}

Expand All @@ -2046,16 +2047,6 @@ api_mulgen(unsigned char *R,
p256_to_affine(&P);
p256_encode(R, &P);
return 65;

/*
const unsigned char *G;
size_t Glen;
G = api_generator(curve, &Glen);
memcpy(R, G, Glen);
api_mul(R, Glen, x, xlen, curve);
return Glen;
*/
}

static uint32_t
Expand All @@ -2068,6 +2059,9 @@ api_muladd(unsigned char *A, const unsigned char *B, size_t len,
int i;

(void)curve;
if (len != 65) {
return 0;
}
r = p256_decode(&P, A, len);
p256_mul(&P, x, xlen);
if (B == NULL) {
Expand Down
10 changes: 7 additions & 3 deletions lib/lib_ssl/bearssl-esp8266/src/ec/ec_prime_i15.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,12 @@ api_mul(unsigned char *G, size_t Glen,
jacobian P;

cc = id_to_curve(curve);
if (Glen != cc->point_len) {
return 0;
}
r = point_decode(&P, G, Glen, cc);
point_mul(&P, x, xlen, cc);
if (Glen == cc->point_len) {
point_encode(G, &P, cc);
}
point_encode(G, &P, cc);
return r;
}

Expand Down Expand Up @@ -772,6 +773,9 @@ api_muladd(unsigned char *A, const unsigned char *B, size_t len,
*/

cc = id_to_curve(curve);
if (len != cc->point_len) {
return 0;
}
r = point_decode(&P, A, len, cc);
if (B == NULL) {
size_t Glen;
Expand Down
Loading

0 comments on commit 806c576

Please sign in to comment.