Skip to content

Commit

Permalink
support multiple RAW_TAC2121C_VCP channels for devices with 3 phases,…
Browse files Browse the repository at this point in the history
… etc
  • Loading branch information
openshwprojects committed Dec 8, 2024
1 parent 2cf3c37 commit 6e176a3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/driver/drv_tuyaMCU.c
Original file line number Diff line number Diff line change
Expand Up @@ -1601,15 +1601,23 @@ void TuyaMCU_ParseStateMessage(const byte* data, int len) {
case DP_TYPE_RAW_TAC2121C_VCP:
{
if (sectorLen == 8 || sectorLen == 10) {
int iV, iC, iP;
// voltage
iVal = data[ofs + 0 + 4] << 8 | data[ofs + 1 + 4];
CHANNEL_SetFirstChannelByType(ChType_Voltage_div10, iVal);
iV = data[ofs + 0 + 4] << 8 | data[ofs + 1 + 4];
// current
iVal = data[ofs + 3 + 4] << 8 | data[ofs + 4 + 4];
CHANNEL_SetFirstChannelByType(ChType_Current_div1000, iVal);
iC = data[ofs + 3 + 4] << 8 | data[ofs + 4 + 4];
// power
iVal = data[ofs + 6 + 4] << 8 | data[ofs + 7 + 4];
CHANNEL_SetFirstChannelByType(ChType_Power, iVal);
iP = data[ofs + 6 + 4] << 8 | data[ofs + 7 + 4];
if (mapping->channel < 0) {
CHANNEL_SetFirstChannelByType(ChType_Voltage_div10, iV);
CHANNEL_SetFirstChannelByType(ChType_Current_div1000, iC);
CHANNEL_SetFirstChannelByType(ChType_Power, iP);
}
else {
CHANNEL_Set(mapping->channel, iV, 0);
CHANNEL_Set(mapping->channel+1, iC, 0);
CHANNEL_Set(mapping->channel+2, iP, 0);
}
}
else {

Expand Down
23 changes: 23 additions & 0 deletions src/selftest/selftest_tuyaMCU.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,30 @@ void Test_TuyaMCU_Basic() {
// nothing is sent by OBK at that point
SELFTEST_ASSERT_HAS_UART_EMPTY();



SIM_ClearUART();


// this will write to channel 40, 41, and 42
// 232.6V 153mA 3.5W
// 0.0153*232.6 = 3.55878W
CMD_ExecuteCommand("linkTuyaMCUOutputToChannel 6 RAW_TAC2121C_VCP 40", 0);
CMD_ExecuteCommand("uartFakeHex 55AA03070014060000080916000099000023010200040000000310", 0);
// above command will just put into buffer - need at least a frame to parse it
Sim_RunFrames(100, false);
SELFTEST_ASSERT_CHANNEL(40, 2326);
SELFTEST_ASSERT_CHANNEL(41, 153);
SELFTEST_ASSERT_CHANNEL(42, 35);

CMD_ExecuteCommand("linkTuyaMCUOutputToChannel 8 RAW_TAC2121C_VCP 45", 0);
CMD_ExecuteCommand("uartFakeHex 55 AA 03 07 00 0C 08 00 00 08 09 01 00 01 2E 00 00 43 A1 ", 0);
// above command will just put into buffer - need at least a frame to parse it
Sim_RunFrames(100, false);
SELFTEST_ASSERT_CHANNEL(45, 2305);
SELFTEST_ASSERT_CHANNEL(46, 302);
SELFTEST_ASSERT_CHANNEL(47, 67);

}

#endif

0 comments on commit 6e176a3

Please sign in to comment.