Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Sep 21, 2024
2 parents 06ff166 + df8f810 commit 5fb7f75
Show file tree
Hide file tree
Showing 45 changed files with 986 additions and 881 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,49 @@ jobs:
echo "::set-output name=short_ref::${BRANCHTRANSLATED}"
echo "::set-output name=sha_short::SHA-$(git rev-parse --short=12 HEAD)"
echo "::set-output name=version::${VERSION}"
build2:
name: Build Simulator
needs: refs
runs-on: windows-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup MSBuild
uses: microsoft/[email protected]

- name: Checkout simulator repository
run: |
git clone https://github.com/openshwprojects/obkSimulator
mkdir -p ./libs_for_simulator
cp -r ./obkSimulator/simulator/libs_for_simulator/* ./libs_for_simulator
- name: Build project
run: msbuild openBeken_win32_mvsc2017.vcxproj /p:Configuration=Release /p:PlatformToolset=v143
- name: Flatten build assets
run: |
mkdir -p flat
cp ./Release/openBeken_win32.exe flat/
cp ./obkSimulator/simulator/*.dll flat/
cp ./run_*.bat flat/
mkdir -p flat/examples
cp -r ./obkSimulator/examples/* flat/examples/
- name: Run unit tests
run: |
./flat/openBeken_win32.exe -runUnitTests 2
- name: Compress build assets
run: |
Compress-Archive -Path flat/* -DestinationPath obkSimulator_win32_${{ needs.refs.outputs.version }}.zip
- name: Copy build assets
run: |
mkdir -Force output/${{ needs.refs.outputs.version }}
cp obkSimulator_win32_${{ needs.refs.outputs.version }}.zip output/${{ needs.refs.outputs.version }}/obkSimulator_${{ needs.refs.outputs.version }}.zip
- name: Upload build assets
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}_${{ needs.refs.outputs.version }}
path: output/${{ needs.refs.outputs.version }}/obkSimulator_${{ needs.refs.outputs.version }}.zip
build:
name: Build
needs: refs
Expand Down
2 changes: 2 additions & 0 deletions .releaserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ generateNotes:
| LN882H | OTA Update | [OpenLN882H_{{version}}_OTA.bin]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenLN882H_{{version}}_OTA.bin) |
| LN882H | UART Flash | [OpenLN882H_{{version}}.bin]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenLN882H_{{version}}.bin) |
| BK7231M | UART Flash | [OpenBK7231M_QIO_{{version}}.bin]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/OpenBK7231M_QIO_{{version}}.bin) |
| Win32 | - | [obkSimulator_{{version}}.zip]({{host}}/{{owner}}/{{repository}}/releases/download/{{version}}/obkSimulator_{{version}}.zip) |
CCtr Flash = Tuya cloud Cutter flash
SPI Flash can be flashed through SPI, even if you broke BK bootloader
Expand Down Expand Up @@ -177,6 +178,7 @@ publish:
- path: "output/**/OpenW600*"
- path: "output/**/OpenW800*"
- path: "output/**/OpenLN882H*"
- path: "output/**/obkSimulator*"

success:
- "@semantic-release/github"
Expand Down
Binary file added Release Win32/openBeken_win32.exp
Binary file not shown.
1,223 changes: 435 additions & 788 deletions openBeken_win32_mvsc2017.vcxproj

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions openBeken_win32_mvsc2017.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@
<ClCompile Include="src\driver\drv_spiLED.c" />
<ClCompile Include="src\driver\drv_sm15155e.c" />
<ClCompile Include="src\selftest\selftest_demo_signAndValue.c" />
<ClCompile Include="src\driver\drv_charts.c" />
<ClCompile Include="src\driver\drv_test_charts.c" />
<ClCompile Include="src\sim\Controller_Switch.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\base64\base64.h" />
Expand Down Expand Up @@ -491,6 +494,7 @@
<ClInclude Include="src\obk_config.h" />
<ClInclude Include="src\sim\Controller_WS2812.h" />
<ClInclude Include="src\driver\drv_spiLED.h" />
<ClInclude Include="src\sim\Controller_Switch.h" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\platforms\bk7231t\bk7231t_os\beken378\func\include\net_param_pub.h" />
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions run_1600x900_port9000.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
openBeken_win32.exe -runUnitTests 0 -w 1600 -h 900
1 change: 1 addition & 0 deletions run_800x600_port80.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
openBeken_win32.exe -runUnitTests 0 -w 800 -h 600 -port 80
1 change: 1 addition & 0 deletions run_800x600_port9000.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
openBeken_win32.exe -runUnitTests 0 -w 800 -h 600 -port 9000
1 change: 0 additions & 1 deletion run_without_selfTests.bat

This file was deleted.

8 changes: 7 additions & 1 deletion src/cmnds/cmd_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,14 @@ const char *CMD_ExpandConstantString(const char *s, const char *stop, char *out,
ret = strCompareBound(s, "$autoexec.bat", stop, false);
if (ret) {
byte* data = LFS_ReadFile("autoexec.bat");
if (data == 0)
if (data == 0) {
#if 1
strcpy_safe(out, "No autoexec.bat for this sample", outLen);
return ret;
#else
return false;
#endif
}
strcpy_safe(out, (char*)data, outLen);
free(data);
return ret;
Expand Down
9 changes: 9 additions & 0 deletions src/driver/drv_tuyaMCU.c
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,15 @@ void TuyaMCU_ProcessIncoming(const byte* data, int len) {
// added for https://www.elektroda.com/rtvforum/viewtopic.php?p=21095905#21095905
TuyaMCU_SendCommandWithData(0x04, 0, 0);
break;
case 0x22:
{
byte data23[1] = { 1 };
addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU, "ProcessIncoming: 0x22 replying");
// For example, the module returns 55 aa 00 23 00 01 01 24
TuyaMCU_SendCommandWithData(0x23, data23, 1);
}
break;


case TUYA_CMD_STATE:
TuyaMCU_ParseStateMessage(data + 6, len - 6);
Expand Down
51 changes: 19 additions & 32 deletions src/hal/ln882h/hal_pins_ln882h.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,19 @@ uint32_t get_adv_timer_base(uint8_t ch)
{
switch(ch)
{
case 0:
case 1: return ADV_TIMER_0_BASE;
case 2:
case 3: return ADV_TIMER_1_BASE;
case 4:
case 5: return ADV_TIMER_2_BASE;
case 6:
case 7: return ADV_TIMER_3_BASE;
case 8:
case 9: return ADV_TIMER_4_BASE;
case 10:
case 11: return ADV_TIMER_5_BASE;
case 0: return ADV_TIMER_0_BASE;
case 1: return ADV_TIMER_1_BASE;
case 2: return ADV_TIMER_2_BASE;
case 3: return ADV_TIMER_3_BASE;
case 4: return ADV_TIMER_4_BASE;
case 5: return ADV_TIMER_5_BASE;
}
}

void pwm_init(uint32_t freq, float duty, uint8_t pwm_channel_num, uint32_t gpio_reg_base, gpio_pin_t gpio_pin)
void pwm_init(uint32_t freq, uint8_t pwm_channel_num, uint32_t gpio_reg_base, gpio_pin_t gpio_pin)
{
uint32_t reg_base = get_adv_timer_base(pwm_channel_num);

hal_gpio_pin_afio_select(gpio_reg_base, gpio_pin, (afio_function_t)(ADV_TIMER_PWM0 + pwm_channel_num));
hal_gpio_pin_afio_en(gpio_reg_base, gpio_pin, HAL_ENABLE);

adv_tim_init_t_def adv_tim_init;
memset(&adv_tim_init, 0, sizeof(adv_tim_init));

Expand All @@ -167,42 +158,38 @@ void pwm_init(uint32_t freq, float duty, uint8_t pwm_channel_num, uint32_t gpio_
adv_tim_init.adv_tim_load_value = 1000000 / freq - 2;
}

if((pwm_channel_num & 0x01) == 0)
adv_tim_init.adv_tim_cmp_a_value = (adv_tim_init.adv_tim_load_value + 2) * duty / 100.0f;
else
adv_tim_init.adv_tim_cmp_b_value = (adv_tim_init.adv_tim_load_value + 2) * duty / 100.0f;

adv_tim_init.adv_tim_cmp_a_value = 0;
adv_tim_init.adv_tim_dead_gap_value = 0;
adv_tim_init.adv_tim_dead_en = ADV_TIMER_DEAD_DIS;
adv_tim_init.adv_tim_cnt_mode = ADV_TIMER_CNT_MODE_INC;
adv_tim_init.adv_tim_cha_inv_en = ADV_TIMER_CHA_INV_EN;
adv_tim_init.adv_tim_chb_inv_en = ADV_TIMER_CHB_INV_EN;

hal_adv_tim_init(reg_base, &adv_tim_init);

hal_gpio_pin_afio_select(gpio_reg_base, gpio_pin, (afio_function_t)(ADV_TIMER_PWM0 + pwm_channel_num * 2));
hal_gpio_pin_afio_en(gpio_reg_base, gpio_pin, HAL_ENABLE);

}

void pwm_start(uint8_t pwm_channel_num)
{
uint32_t reg_base = get_adv_timer_base(pwm_channel_num);
if((pwm_channel_num & 0x01) == 0)
hal_adv_tim_a_en(reg_base, HAL_ENABLE);
else
hal_adv_tim_b_en(reg_base, HAL_ENABLE);
hal_adv_tim_a_en(reg_base, HAL_ENABLE);
}

void pwm_set_duty(float duty, uint8_t pwm_channel_num)
{
uint32_t reg_base = get_adv_timer_base(pwm_channel_num);
if((pwm_channel_num & 0x01) == 0)
hal_adv_tim_set_comp_a(reg_base, (hal_adv_tim_get_load_value(reg_base) + 2) * duty / 100.0f);
else
hal_adv_tim_set_comp_b(reg_base, (hal_adv_tim_get_load_value(reg_base) + 2) * duty / 100.0f);
hal_adv_tim_set_comp_a(reg_base, (hal_adv_tim_get_load_value(reg_base) + 2) * duty / 100.0f);
}

void HAL_PIN_PWM_Stop(int index) {
if(index >= g_numPins)
return;
lnPinMapping_t* pin = g_pins + index;
if(pin->pwm_cha < 0) return;
uint32_t reg_base = get_adv_timer_base(pin->pwm_cha);
hal_adv_tim_a_en(reg_base, HAL_DISABLE);
hal_gpio_pin_afio_en(pin->base, pin->pin, HAL_DISABLE);
g_active_pwm &= ~(1 << pin->pwm_cha);
uint8_t chan = pin->pwm_cha;
Expand All @@ -215,12 +202,12 @@ void HAL_PIN_PWM_Start(int index)
if(index >= g_numPins)
return;
uint8_t freecha;
for(freecha = 0; freecha < 11; freecha++) if((g_active_pwm >> freecha & 1) == 0) break;
for(freecha = 0; freecha < 5; freecha++) if((g_active_pwm >> freecha & 1) == 0) break;
lnPinMapping_t* pin = g_pins + index;
g_active_pwm |= 1 << freecha;
pin->pwm_cha = freecha;
ADDLOG_DEBUG(LOG_FEATURE_CMD, "PWM_Start: ch_pwm: %u", freecha);
pwm_init(10000, 0, freecha, pin->base, pin->pin);
pwm_init(10000, freecha, pin->base, pin->pin);
pwm_start(freecha);
}

Expand Down
2 changes: 1 addition & 1 deletion src/hal/win32/hal_pins_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void SIM_SetVoltageOnADCPin(int index, float v) {
v = 0;
float f = v / 3.3f;
int iVal = f * 1024;
SIM_SetIntegerValueADCPin(index, v);
SIM_SetIntegerValueADCPin(index, iVal);
}
int SIM_GetPWMValue(int index) {
return g_simulatedPWMs[index];
Expand Down
7 changes: 6 additions & 1 deletion src/httpserver/http_tcp_server_nonblocking.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ int HTTPServer_Start() {
}
}
#define DEFAULT_BUFLEN 10000
int g_prevHTTPResult;

void HTTPServer_RunQuickTick() {
int iResult;
int err;
Expand All @@ -93,7 +95,10 @@ void HTTPServer_RunQuickTick() {
if (ClientSocket == INVALID_SOCKET) {
iResult = WSAGetLastError();
if(iResult != WSAEWOULDBLOCK) {
printf("accept failed with error: %d\n", iResult);
if (iResult != g_prevHTTPResult) {
printf("accept failed with error: %d\n", iResult);
g_prevHTTPResult = iResult;
}
}
return;
}
Expand Down
19 changes: 18 additions & 1 deletion src/littlefs/our_lfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,24 @@

// we need that even if LFS is disabled

#if PLATFORM_BK7231T
#if WINDOWS

// start 0x1000 after OTA addr
#define LFS_BLOCKS_START 0x133000
#define LFS_BLOCKS_START_MIN 0x133000

// end of OTA flash
#define LFS_BLOCKS_END 0x1B3000
// 512k MAX - i.e. no more that 0x80000
// 0x8000 = 32k
#define LFS_BLOCKS_MIN_LEN 0x4000
#define LFS_BLOCKS_MAX_LEN 0x80000
#define LFS_BLOCKS_DEFAULT_LEN 0x8000

#define LFS_BLOCK_SIZE 0x1000

#elif PLATFORM_BK7231T

// start 0x1000 after OTA addr
#define LFS_BLOCKS_START 0x133000
#define LFS_BLOCKS_START_MIN 0x133000
Expand Down
2 changes: 2 additions & 0 deletions src/new_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "new_common.h"
#include "hal/hal_wifi.h"

#define test12321321 321321321

typedef enum ioRole_e {
//iodetail:{"name":"None",
//iodetail:"title":"TODO",
Expand Down
3 changes: 3 additions & 0 deletions src/selftest/selftest_cmd_channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ void Test_Commands_Channels() {
CMD_ExecuteCommand("setChannel 1 $rand", 0);
printf("Rand - channel 1 is %i\n", CHANNEL_Get(1));
}

// cause error
//SELFTEST_ASSERT_CHANNEL(3, 666);
}


Expand Down
33 changes: 16 additions & 17 deletions src/selftest/selftest_expandConstant.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,63 @@ void Test_ExpandConstant() {
// reset whole device
SIM_ClearOBK(0);

CMD_ExpandConstantsWithinString("Hello", buffer, sizeof(buffer), 0);
CMD_ExpandConstantsWithinString("Hello", buffer, sizeof(buffer));
SELFTEST_ASSERT_STRING(buffer, "Hello");


CHANNEL_Set(1, 123, 0);
CMD_ExpandConstantsWithinString("$CH1", buffer,sizeof(buffer), 0);
CMD_ExpandConstantsWithinString("$CH1", buffer,sizeof(buffer));
SELFTEST_ASSERT_STRING(buffer, "123");

CHANNEL_Set(1, 456, 0);
CMD_ExpandConstantsWithinString("$CH1", buffer, sizeof(buffer), 0);;
CMD_ExpandConstantsWithinString("$CH1", buffer, sizeof(buffer));;
SELFTEST_ASSERT_STRING(buffer, "456");

CHANNEL_Set(11, 2022, 0);
// must be able to tell whether it's $CH11 or a $CH1
CMD_ExpandConstantsWithinString("$CH11", buffer, sizeof(buffer), 0);
CMD_ExpandConstantsWithinString("$CH11", buffer, sizeof(buffer));
SELFTEST_ASSERT_STRING(buffer, "2022");

CMD_ExpandConstantsWithinString("$CH1", buffer, sizeof(buffer), 0);
CMD_ExpandConstantsWithinString("$CH1", buffer, sizeof(buffer));
SELFTEST_ASSERT_STRING(buffer, "456");

// must be able to tell whether it's $CH11 or a $CH1 - with a suffix
CMD_ExpandConstantsWithinString("$CH11ba", buffer, sizeof(buffer), 0);
CMD_ExpandConstantsWithinString("$CH11ba", buffer, sizeof(buffer));
SELFTEST_ASSERT_STRING(buffer, "2022ba");

CMD_ExpandConstantsWithinString("$CH1ba", buffer, sizeof(buffer), 0);
CMD_ExpandConstantsWithinString("$CH1ba", buffer, sizeof(buffer));
SELFTEST_ASSERT_STRING(buffer, "456ba");

// must be able to tell whether it's $CH11 or a $CH1 - with a prefix
CMD_ExpandConstantsWithinString("ba$CH11", buffer, sizeof(buffer), 0);
CMD_ExpandConstantsWithinString("ba$CH11", buffer, sizeof(buffer));
SELFTEST_ASSERT_STRING(buffer, "ba2022");

CMD_ExpandConstantsWithinString("ba$CH1", buffer, sizeof(buffer), 0);
CMD_ExpandConstantsWithinString("ba$CH1", buffer, sizeof(buffer));
SELFTEST_ASSERT_STRING(buffer, "ba456");

// must be able to tell whether it's $CH11 or a $CH1 - with a prefix and a suffix
CMD_ExpandConstantsWithinString("ba$CH11ha", buffer, sizeof(buffer), 0);
CMD_ExpandConstantsWithinString("ba$CH11ha", buffer, sizeof(buffer));
SELFTEST_ASSERT_STRING(buffer, "ba2022ha");

CMD_ExpandConstantsWithinString("ba$CH1ha", buffer, sizeof(buffer), 0);
CMD_ExpandConstantsWithinString("ba$CH1ha", buffer, sizeof(buffer));
SELFTEST_ASSERT_STRING(buffer, "ba456ha");

CMD_ExpandConstantsWithinString("ba$CH1$CH1ha", buffer, sizeof(buffer), 0);
CMD_ExpandConstantsWithinString("ba$CH1$CH1ha", buffer, sizeof(buffer));
SELFTEST_ASSERT_STRING(buffer, "ba456456ha");

CMD_ExpandConstantsWithinString("$CH1$CH1ha", buffer, sizeof(buffer), 0);
CMD_ExpandConstantsWithinString("$CH1$CH1ha", buffer, sizeof(buffer));
SELFTEST_ASSERT_STRING(buffer, "456456ha");

CMD_ExpandConstantsWithinString("$CH1$CH1", buffer, sizeof(buffer), 0);
CMD_ExpandConstantsWithinString("$CH1$CH1", buffer, sizeof(buffer));
SELFTEST_ASSERT_STRING(buffer, "456456");

// check buffer len truncating
CMD_ExpandConstantsWithinString("Hello long one!", smallBuffer, sizeof(smallBuffer), 0);
CMD_ExpandConstantsWithinString("Hello long one!", smallBuffer, sizeof(smallBuffer));
// Buffer was too short - text truncated!
SELFTEST_ASSERT_STRING(smallBuffer, "Hello l");


//CMD_ExpandConstantsWithinString("Hello $CH1", smallBuffer, sizeof(smallBuffer), 0);
//CMD_ExpandConstantsWithinString("Hello $CH1", smallBuffer, sizeof(smallBuffer));
// Buffer was too short - text truncated!
//SELFTEST_ASSERT_STRING(smallBuffer, "Hello 4");
// NOTE: it won't work like that because of the sprintf behaviour....
Expand Down Expand Up @@ -115,7 +115,6 @@ void Test_ExpandConstant() {
free(ptr);
//system("pause");


CFG_SetFlag(OBK_FLAG_HTTP_PINMONITOR, 0);
ptr = CMD_ExpandingStrdup("$FLAG13");
SELFTEST_ASSERT_STRING(ptr, "0");
Expand Down
Loading

0 comments on commit 5fb7f75

Please sign in to comment.