Commit Graph

3923 Commits

Author SHA1 Message Date
1e201d6be4 fix mem leaks in sim (#1665)
* Update drv_spiLED.c

* Update drv_spiLED.c

* Update drv_spiLED.c

* Update asan.suppressions

* Update drv_spiLED.c

* try

* mcu clear

* return cmd

* free alias leak
1.18.109
2025-06-01 10:06:09 +02:00
92ea9cd8ab Ability to run linux tests with AddressSanitizer (#1651)
* Ability to run linux tests with AddressSanitizer

This makes it possible to compile and run the tests with Address
Sanitizer (ASAN) [1].

The command is:
```
make -f custom.mk clean; ASAN=1 make -f custom.mk && ./build/win_main -runUnitTests 2
```

Building without ASAN works without change.

Address Sanitizer saves a lot of time debugging memory issues, for
example for a bug where we index in an array with negative index it
gives this nice error message:
```
=================================================================
==2532658==ERROR: AddressSanitizer: global-buffer-overflow on address 0x5642389c5e37 at pc 0x564237e67492 bp 0x7fff17726e50 sp 0x7fff17726e40
READ of size 1 at 0x5642389c5e37 thread T0
    #0 0x564237e67491 in CHANNEL_GetType src/new_cfg.c:427
    #1 0x564237dfc933 in TuyaMCU_ApplyMapping src/driver/drv_tuyaMCU.c:1126
    #2 0x564237dff92f in TuyaMCU_ParseStateMessage src/driver/drv_tuyaMCU.c:1632
    #3 0x564237e019fa in TuyaMCU_ProcessIncoming src/driver/drv_tuyaMCU.c:1977
    #4 0x564237e027ee in TuyaMCU_RunReceive src/driver/drv_tuyaMCU.c:2178
    #5 0x564237e02dc2 in TuyaMCU_RunFrame src/driver/drv_tuyaMCU.c:2335
    #6 0x564237dd2ce6 in DRV_RunQuickTick src/driver/drv_main.c:536
    #7 0x564237ec4037 in QuickTick src/user_main.c:946
    #8 0x564237eca8a5 in Sim_RunFrame src/win_main.c:106
    #9 0x564237eca993 in Sim_RunFrames src/win_main.c:134
    #10 0x564237ebce4a in Test_TuyaMCU_Basic src/selftest/selftest_tuyaMCU.c:369
    #11 0x564237ecab1f in Win_DoUnitTests src/win_main.c:194
    #12 0x564237ecba57 in main src/win_main.c:535
    #13 0x7fb55312ed8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #14 0x7fb55312ee3f in __libc_start_main_impl ../csu/libc-start.c:392
    #15 0x564237cb16b4 in _start (/home/niteria/tmp/broken-realloc/OpenBK7231T_App/build/win_main+0xcf6b4)

0x5642389c5e37 is located 51 bytes to the right of global variable 'stat_deduper_culled_tooFast' defined in 'src/mqtt/new_mqtt_deduper.c:40:12' (0x5642389c5e00) of size 4
0x5642389c5e37 is located 9 bytes to the left of global variable 'g_mutex' defined in 'src/mqtt/new_mqtt_deduper.c:42:26' (0x5642389c5e40) of size 4
SUMMARY: AddressSanitizer: global-buffer-overflow src/new_cfg.c:427 in CHANNEL_GetType
Shadow bytes around the buggy address:
  0x0ac8c7130b70: 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0ac8c7130b80: 00 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0ac8c7130b90: 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0ac8c7130ba0: 00 00 00 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9
  0x0ac8c7130bb0: 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
=>0x0ac8c7130bc0: 04 f9 f9 f9 f9 f9[f9]f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0ac8c7130bd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac8c7130be0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac8c7130bf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac8c7130c00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac8c7130c10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==2532658==ABORTING
```

[1] https://github.com/google/sanitizers/wiki/addresssanitizer

* disable tests broken on linux

* add a suppression file for known leaks

* attempt at adding an ASAN workflow

* fix autogen

* Update workflow.yaml

---------

Co-authored-by: openshwprojects <85486843+openshwprojects@users.noreply.github.com>
2025-05-31 14:27:02 +02:00
b1b41f4a66 channel type - Percent 1.18.108 2025-05-31 01:18:37 +02:00
d6f7678dc6 TCL AC driver progress + LowMidHigh etc channels HA discovery
* Buzzer

* Update obk_config.h

* Display

* uart test stub

* unfinished TCL_DoDiscovery

* ha

* Update drv_tclAC.c

* ha mode send

* unfinished not working

* Update drv_tclAC.c

* Update hass.h

* better discovery

* Update obk_config.h
1.18.107
2025-05-30 16:10:36 +02:00
a2c9d19147 Fix a memory leak in http_fns.c (#1653) 1.18.106 2025-05-26 17:35:45 +02:00
cbf0d459fd Fix tests on linux (#1640)
The tests were segfaulting on linux, I don't know how they work on
Windows, perhaps casting `void*` to `int` happens to work there.
Generally it's not portable.

Berry has a dedicated `comptr` type, so let's use that and be portable.

Also makes `run_closure` handle arbitrary number of arguments, see
https://berry.readthedocs.io/en/latest/source/en/Chapter-5.html#function-with-variable-number-of-arguments-vararg
for docs.

Test Plan:
* CI
* make -f custom.mk, ./build/win_main -runUnitTests 2
2025-05-25 18:12:56 +02:00
e1456181e8 berry workaround for broken realloc on OpenBK7231N (#1649)
* berry workaround for broken realloc on OpenBK7231N

I ran `addRepeatingEvent 1 -1 testRealloc 100` on a OpenBK7231N device
and it failed. This is the same problem as #1563.

This might be related to mysterious crashes I was getting while
importing big modules like this:
`addRepeatingEvent 1 1 berry import modulename`.

* fix
1.18.105
2025-05-25 17:44:06 +02:00
46fe6736ca Fix out-of-bounds access on g_cfg.pins.channelTypes (#1652)
This place expected -1 for "unmapped", but -999 can come from this line:
fe51ee8f47/src/driver/drv_tuyaMCU.c (L883)

This was detected with ASAN (#1651), the error message:
```
=================================================================
==2532658==ERROR: AddressSanitizer: global-buffer-overflow on address 0x5642389c5e37 at pc 0x564237e67492 bp 0x7fff17726e50 sp 0x7fff17726e40
READ of size 1 at 0x5642389c5e37 thread T0
    #0 0x564237e67491 in CHANNEL_GetType src/new_cfg.c:427
    #1 0x564237dfc933 in TuyaMCU_ApplyMapping src/driver/drv_tuyaMCU.c:1126
    #2 0x564237dff92f in TuyaMCU_ParseStateMessage src/driver/drv_tuyaMCU.c:1632
    #3 0x564237e019fa in TuyaMCU_ProcessIncoming src/driver/drv_tuyaMCU.c:1977
    #4 0x564237e027ee in TuyaMCU_RunReceive src/driver/drv_tuyaMCU.c:2178
    #5 0x564237e02dc2 in TuyaMCU_RunFrame src/driver/drv_tuyaMCU.c:2335
    #6 0x564237dd2ce6 in DRV_RunQuickTick src/driver/drv_main.c:536
    #7 0x564237ec4037 in QuickTick src/user_main.c:946
    #8 0x564237eca8a5 in Sim_RunFrame src/win_main.c:106
    #9 0x564237eca993 in Sim_RunFrames src/win_main.c:134
    #10 0x564237ebce4a in Test_TuyaMCU_Basic src/selftest/selftest_tuyaMCU.c:369
    #11 0x564237ecab1f in Win_DoUnitTests src/win_main.c:194
    #12 0x564237ecba57 in main src/win_main.c:535
    #13 0x7fb55312ed8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #14 0x7fb55312ee3f in __libc_start_main_impl ../csu/libc-start.c:392
    #15 0x564237cb16b4 in _start (/home/niteria/tmp/broken-realloc/OpenBK7231T_App/build/win_main+0xcf6b4)

0x5642389c5e37 is located 51 bytes to the right of global variable 'stat_deduper_culled_tooFast' defined in 'src/mqtt/new_mqtt_deduper.c:40:12' (0x5642389c5e00) of size 4
0x5642389c5e37 is located 9 bytes to the left of global variable 'g_mutex' defined in 'src/mqtt/new_mqtt_deduper.c:42:26' (0x5642389c5e40) of size 4
SUMMARY: AddressSanitizer: global-buffer-overflow src/new_cfg.c:427 in CHANNEL_GetType
Shadow bytes around the buggy address:
  0x0ac8c7130b70: 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0ac8c7130b80: 00 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0ac8c7130b90: 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0ac8c7130ba0: 00 00 00 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9
  0x0ac8c7130bb0: 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
=>0x0ac8c7130bc0: 04 f9 f9 f9 f9 f9[f9]f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0ac8c7130bd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac8c7130be0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac8c7130bf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac8c7130c00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ac8c7130c10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==2532658==ABORTING
```
2025-05-25 17:42:08 +02:00
5899b0c7e5 CSE stub (unfinished)
* test1

* Update CMakeLists.txt

* Update drv_cse7761.c

* tr

* dbg

* Update hal_uart_espidf.c

* Update hal_uart_espidf.c

* Update hal_uart_espidf.c

* cmnt
1.18.104
2025-05-23 10:23:01 +02:00
529bf00170 cse test stub 1.18.103 2025-05-22 12:33:13 +02:00
d07c72a0ca AC TCL driver - part 1
* ac t1

* test

* fx

* fx

* p

* build_set_cmd

* try enable

* makefile

* make

* header

* self test

* parsing - not tested

* rename for easier testing

* add src

* print len

* parity

* FIX PARITY - 2

* SwingH and SwingV

* w

* files

* Update drv_tclAC.c

* display vals

* few berry tests

* disable
1.18.102
2025-05-18 18:24:21 +02:00
acd46ad682 add PIR driver
* tt

* Update selftest_berry.c

* Update obk_config.h

* some more fixes

* fixes

* IOR_PWM_ScriptOnly_n

* fx

* Update OpenBeken.mk

* disable
1.18.101
2025-05-16 10:07:38 +02:00
5ea78582e0 fix header 1.18.100 2025-05-15 23:55:04 +02:00
4196afda4d unfinished PIR code 2025-05-15 18:08:53 +02:00
fe51ee8f47 Update hal_flashConfig_xr809.c 1.18.99 2025-05-06 09:50:27 +02:00
754aca5c01 BL602 powersave workaround (#1630) 1.18.98 2025-05-04 09:54:59 +02:00
3597eec24d Remove powersave for BL602 (#1628)
Apparently breaks connecting to wifi. Maybe something like ln882 should be done
1.18.97
2025-05-03 12:32:21 +02:00
4cc458f014 update OpenBL602 and XR872 SDKs to latest commits 1.18.96 2025-05-02 15:31:39 +02:00
5916fbd8a7 Update BL602 code to work with latest sdk. (#1487)
* Support new BL602 SDK

* Update .gitmodules

---------

Co-authored-by: openshwprojects <85486843+openshwprojects@users.noreply.github.com>
1.18.95
2025-05-02 14:42:14 +02:00
0274993d7f Update OpenXR872 1.18.94 2025-04-25 17:26:25 +02:00
162e4df354 Update workflow.yaml 1.18.93 2025-04-23 00:28:35 +02:00
782d478b87 fix xr806
* Update http_tcp_server.c

* Update http_tcp_server.c

* better naming

* debug print

* TRY TO CLEAR UP A BIT

* Update http_tcp_server.c

* Update http_tcp_server.c

* Update http_tcp_server.c

* Update http_tcp_server.c

* Update new_http.c

* XR auth disabled

* clear log

* Update OpenXR806

* Update OpenXR806

* Update new_http.c
1.18.92
2025-04-19 20:33:08 +02:00
5d09349b9d also add XR806 to online builds (it boots but there is some issue with WiFi?)
* Update .gitmodules

* w

* Manually added submodule OpenXR

* Update Makefile

* Update Makefile

* Update Makefile

* Update OpenXR806

* Update OpenXR806

* Update OpenXR806

* Update hal_wifi_xr809.c
1.18.91
2025-04-19 11:58:35 +02:00
379f7cb00e XR872 online builds (#1609)
* Update workflow.yaml

* Update Makefile

* Update .gitmodules

* Update .gitmodules

* Manually added submodule OpenXR872

* Update workflow.yaml

* Update .gitmodules

* Update OpenXR872

* Update OpenXR872

* Update OpenXR872

* Update OpenXR872

* Update OpenXR872

* Update workflow.yaml

* Update OpenXR872
1.18.90
2025-04-19 08:17:56 +02:00
fd853eb203 Merge branch 'main' of https://github.com/openshwprojects/OpenBK7231T_App 1.18.89 2025-04-18 20:29:43 +02:00
d70e9e93e1 xr fixes 2025-04-18 20:29:23 +02:00
3fd49d4fae Merge branch 'main' of https://github.com/openshwprojects/OpenBK7231T_App 1.18.88 2025-04-18 18:35:12 +02:00
5b763e3194 Update hal_pins_xr809.c 2025-04-18 18:32:27 +02:00
0ea1983049 add IRRemoteESP8266 IR alternate version to online builds (vfonov PR)
* add IRRemoteSP

* fx

* Update IRsend.cpp

* f

* fix

* s

* irRemoteESP

* Update obk_config_irRemoteESP.h

* w
1.18.87
2025-04-18 18:24:13 +02:00
a5a5b4b7b9 xr872 (A9 camera) 1.18.86 2025-04-18 18:05:04 +02:00
64ec573482 EXPERIMENT: allow alternate build permutations (with berry), should not break anything
* Update obk_config.h

* Update workflow.yaml

* Update obk_config.h

* v2

* Update workflow.yaml

* test

* tr3

* ffs

* save fx

* Update workflow.yaml

* APP NAME FX?

* Update workflow.yaml

* Update workflow.yaml

* Update workflow.yaml

* Update workflow.yaml

* test

* Update obk_config.h

* Update win_main.c

* Update Makefile

* test

* Update obk_config_berry.h

* test

* test

* matrix

* Update workflow.yaml

* Update obk_config.h
1.18.85
2025-04-17 22:51:58 +02:00
9a7447fd4b Fix T build (#1607) 1.18.84 2025-04-16 09:11:50 +02:00
ac3c5d6da6 Faster wifi connecting (up to 2sec restart -> connected) (#1297)
* Wifi fast connect + extra

* --
2025-04-15 16:38:10 +02:00
714d9c9ab1 Update cmd_public.h (#1605) 1.18.83 2025-04-14 16:41:04 +02:00
5a78713c90 add missing prestate check 1.18.82 2025-04-13 19:34:37 +02:00
00890d1cf4 API CHANGE - extend http callback for drivers so it includes bPreState boolean so we can add HTML either before state div (without refresh) or in state div (refreshing) 1.18.81 2025-04-13 19:18:30 +02:00
db1942c10c fix Berry - add missing be_pop 1.18.80 2025-04-13 15:38:09 +02:00
b21ca34812 Berry stack size test - part 1 2025-04-13 14:13:54 +02:00
dc6ced4102 Merge branch 'main' of https://github.com/openshwprojects/OpenBK7231T_App 1.18.79 2025-04-13 10:04:16 +02:00
9922aec8df add prestate for berry 2025-04-13 09:45:19 +02:00
f2c1133b47 futher berry fixes 1.18.78 2025-04-12 17:55:52 +02:00
eadba42f9f Berry integration part 1
* t

* fx

* split closure handler

* setTimeout, setInterval

* split berry frm SVM, but I need to move event waiter to separate struct?

* fx

* fx

* split relations

* remvoe ode duplciaton

* POC - pass value to berry

* POC - pass str to berry

* berry preps + lfs test

* lfs test + bytes

* save

* remove code duplication

* try dpid calls

* working test for bytes

* tyuamcu to file in eberry

* str for berry test

* tuyamcu to berry glue

* fx1

* fixes

* try berry http

* fix

* tests

* test  vaar lifespan

* test

* test

* test if

* berry in html

* #if ENABLE_OBK_BERRY

* fx

* better

* fx

* test nested loop

* free mem

* simpler

* split lfs run

* arg

* fx

* fix

* #if ENABLE_OBK_BERRY

* comamnd hook

* vars access, ntp

* finalize?

* unfinished
1.18.77
2025-04-12 16:56:24 +02:00
8ac653b89a Update safeMode.md (#1599) 1.18.76 2025-04-11 08:51:52 +02:00
4973295415 tuyaMCU: avoid state machine interfering with reset AP mode (#1597)
Don't continue with the state machine if the device is in Open WiFi mode
based on a user button press.

This avoids the device shutting down itself when in recovery mode. The
MCU will reset the device after 90 seconds automatically.

Communicate to the MCU the device is in configuration mode. This will
change the status LED blink pattern to reflect the state.

Signed-off-by: David Bauer <mail@david-bauer.net>
1.18.75
2025-04-06 09:10:26 +02:00
9e3bcf72af tuyaMCU: replace network state magic values (#1596)
Replace magic values present in the code with the more descriptive
macros.

As these macros are redundant with the comments, drop the repsective
comments.

Signed-off-by: David Bauer <mail@david-bauer.net>
1.18.74
2025-04-05 21:51:03 +02:00
f43f5238be ecr6600 gh actions hack (#1589) 1.18.73 2025-04-02 22:25:23 +02:00
e96097debf Update README.md 2025-04-02 08:58:15 +02:00
8fad535e4e typos + releaserc update (#1575)
* Update drv_tuyaMCU.c

* Update drv_spi.c

* Update drv_spi.h

* Update .releaserc.yaml
1.18.72
2025-03-31 00:27:31 +02:00
XJ
be5aca62b3 ENABLE_BL_TWIN mode - reset energy_today also for channel B (#1587) 1.18.71 2025-03-30 21:03:19 +02:00
7e1afd0fdf [POC] Run berry-lang (#1544)
* setChannel(ch, v) in Berry

* try

* t2

* b

* fx

* update to berry with autogenerated files

* Add debug to find out whether the submodule is really checked out

* Revert "Add debug to find out whether the submodule is really checked out"

This reverts commit 40ec2f6677.

* Add src/berry checkout to every build

* berry separate file p1

* #define ENABLE_OBK_BERRY 1 on Beken only

* Compile in obkSimulator

Compiles, but crashes in parser.
Seems like the Berry code has not been tested under MSVC2017.

* Checkout with submodules in obkSimulator workflow

* berry with ffs msvc fix

* berry autogen fiasco fix

* OpenBK7231T compiles from official berry, handle prebuild

Breaks obkSimulator

* Fix botched rebase on .gitmodules

* Build in msvc with a berry prebuild step (requires python)

* MSVC: also extend include directories for Release

* Fix BK723x build, extract common berry build rules into berry.mk

* Fix OpenBL602 build

This doesn't actually compile berry for OpenBL602, but makes compile
errors go away and marks where further work will be needed.

* working delayMs

Test Plan:
```
berry state = 1; var tick; def tick() state = 1 - state; channelSet(1, state); delayMs(1000, tick); end; tick();
```
can be stopped with `stopAllScripts`

* only use os_realloc on PLATFORM_BK7231T

* Move as much berry logic as possible out of cmd_script

* Guard more with ENABLE_OBK_BERRY

* upload script

* file operations & working import

* enough to implement "Advanced turn off after time with timer on UI and timer setting on UI and kept in flash"

* experiments

* clang-format -i src/berry/be_*.{h,c} src/cmnds/cmd_berry.c

* Remove redundant hfile != NULL

Calling with hfile == NULL would be bug in some other part of the code

* Don't checkout other submodules for simulator build

* remove stray debug & .user files

* Use be_newcomobj

* Build sim on linux

* build linux sim [2]

* threads & tests

* Leave enabled on Windows, disable on BEKEN

* SIM_RunWindow fix?

* allow "startScript test.be" as a shorthand for "berry import test" ??

* test?

* fix /

* test arg

* test2

* test

* test add

* fx

* test

* just checking if i can use import without module?

* test with module

* CMD_StopBerry fix?

* run obk command from berry? probably not good idea due to the stack size, will delay execution later?

* str arg

* test to see if i have to repeat import

* submit unfinished code

* concat tst

* more tests

* fix copy/paste mistake, add fib test

* fx

* channelSet

* fx

* try

* tester.fib(11)

* rename

---------

Co-authored-by: Tester23 <85486843+openshwprojects@users.noreply.github.com>
Co-authored-by: NonPIayerCharacter <18557343+NonPIayerCharacter@users.noreply.github.com>
2025-03-30 20:37:37 +02:00