Skip to content

Commit

Permalink
Fix dynamic buffer handling
Browse files Browse the repository at this point in the history
Fix dynamic buffer handling
  • Loading branch information
arendst committed Nov 27, 2018
1 parent eaa7acd commit e1d3dca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sonoff/xdrv_08_serial_bridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void SerialBridgeInput(void)
return;
}
if (serial_in_byte) {
if ((serial_in_byte_counter < sizeof(serial_bridge_buffer) -1) && (serial_in_byte != Settings.serial_delimiter)) { // add char to string if it still fits
if ((serial_in_byte_counter < SERIAL_BRIDGE_BUFFER_SIZE -1) && (serial_in_byte != Settings.serial_delimiter)) { // add char to string if it still fits
serial_bridge_buffer[serial_bridge_in_byte_counter++] = serial_in_byte;
serial_bridge_polling_window = millis(); // Wait for more data
} else {
Expand Down
2 changes: 1 addition & 1 deletion sonoff/xdrv_16_tuyadimmer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void TuyaInit(void)
if (!Settings.param[P_TUYA_DIMMER_ID]) {
Settings.param[P_TUYA_DIMMER_ID] = TUYA_DIMMER_ID;
}
tuya_buffer = reinterpret_cast<char*>(malloc(TUYA_BUFFER_SIZE));
tuya_buffer = (char*)(malloc(TUYA_BUFFER_SIZE));
if (tuya_buffer != NULL) {
TuyaSerial = new TasmotaSerial(pin[GPIO_TUYA_RX], pin[GPIO_TUYA_TX], 2);
if (TuyaSerial->begin(9600)) {
Expand Down
18 changes: 9 additions & 9 deletions sonoff/xdrv_19_ps16dz_dimmer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int ps16dz_byte_counter = 0;

void printTimestamp(void)
{
snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s%d%03d"), ps16dz_tx_buffer, LocalTime(), millis()%1000);
snprintf_P(ps16dz_tx_buffer, PS16DZ_BUFFER_SIZE, PSTR( "%s%d%03d"), ps16dz_tx_buffer, LocalTime(), millis()%1000);
}

boolean PS16DZSetPower(void)
Expand All @@ -55,9 +55,9 @@ boolean PS16DZSetPower(void)

if (source != SRC_SWITCH && PS16DZSerial) { // ignore to prevent loop from pushing state from faceplate interaction

snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+UPDATE=\"sequence\":\""));
snprintf_P(ps16dz_tx_buffer, PS16DZ_BUFFER_SIZE, PSTR( "AT+UPDATE=\"sequence\":\""));
printTimestamp();
snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"switch\":\"%s\""), ps16dz_tx_buffer, rpower?"on":"off");
snprintf_P(ps16dz_tx_buffer, PS16DZ_BUFFER_SIZE, PSTR( "%s\",\"switch\":\"%s\""), ps16dz_tx_buffer, rpower?"on":"off");
snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send serial command: %s"), ps16dz_tx_buffer );
AddLog(LOG_LEVEL_DEBUG);

Expand All @@ -77,9 +77,9 @@ void PS16DZSerialDuty(uint8_t duty)
duty = 25; // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself
}

snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+UPDATE=\"sequence\":\""));
snprintf_P(ps16dz_tx_buffer, PS16DZ_BUFFER_SIZE, PSTR( "AT+UPDATE=\"sequence\":\""));
printTimestamp();
snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "%s\",\"bright\":%d"), ps16dz_tx_buffer, round(duty * (100. / 255.)));
snprintf_P(ps16dz_tx_buffer, PS16DZ_BUFFER_SIZE, PSTR( "%s\",\"bright\":%d"), ps16dz_tx_buffer, round(duty * (100. / 255.)));
snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send serial command: %s"), ps16dz_tx_buffer );
AddLog(LOG_LEVEL_DEBUG);

Expand Down Expand Up @@ -117,9 +117,9 @@ boolean PS16DZModuleSelected(void)

void PS16DZInit(void)
{
ps16dz_tx_buffer = reinterpret_cast<char*>(malloc(PS16DZ_BUFFER_SIZE));
ps16dz_tx_buffer = (char*)(malloc(PS16DZ_BUFFER_SIZE));
if (ps16dz_tx_buffer != NULL) {
ps16dz_rx_buffer = reinterpret_cast<char*>(malloc(PS16DZ_BUFFER_SIZE));
ps16dz_rx_buffer = (char*)(malloc(PS16DZ_BUFFER_SIZE));
if (ps16dz_rx_buffer != NULL) {
PS16DZSerial = new TasmotaSerial(pin[GPIO_RXD], pin[GPIO_TXD], 2);
if (PS16DZSerial->begin(19200)) {
Expand Down Expand Up @@ -189,10 +189,10 @@ void PS16DZSerialInput(void)
AddLog(LOG_LEVEL_DEBUG);
PS16DZResetWifi();
}
memset(ps16dz_rx_buffer, 0, sizeof(ps16dz_rx_buffer));
memset(ps16dz_rx_buffer, 0, PS16DZ_BUFFER_SIZE);
ps16dz_byte_counter = 0;

snprintf_P(ps16dz_tx_buffer, sizeof(ps16dz_tx_buffer), PSTR( "AT+SEND=ok"));
snprintf_P(ps16dz_tx_buffer, PS16DZ_BUFFER_SIZE, PSTR( "AT+SEND=ok"));
snprintf_P(log_data, sizeof(log_data), PSTR( "PSZ: Send serial command: %s"), ps16dz_tx_buffer );
AddLog(LOG_LEVEL_DEBUG);

Expand Down

0 comments on commit e1d3dca

Please sign in to comment.