Skip to content

Commit

Permalink
Fix datas calculation error
Browse files Browse the repository at this point in the history
  • Loading branch information
fairecasoimeme committed Aug 7, 2024
1 parent 9c321c9 commit 4ab59c1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extern "C" {
#include "zcl_options.h"
#include "Basic.h"
#include "Identify.h"
#include "Time.h"
#include "Groups.h"

#ifdef CLD_OTA
Expand All @@ -50,6 +51,7 @@ extern "C" {
#include "SimpleMetering.h"
#include "ElectricalMeasurement.h"
#include "LixeeCluster.h"
#include "TuyaSpecific.h"
#include "meter_identification.h"
/****************************************************************************/
/*** Macro Definitions ***/
Expand All @@ -71,6 +73,10 @@ typedef struct
tsZCL_ClusterInstance sIdentifyServer;
#endif

#if (defined CLD_TIME) && (defined TIME_CLIENT)
tsZCL_ClusterInstance sTimeClient;
#endif

#if (defined CLD_ALARMS) && (defined ALARMS_SERVER)
tsZCL_ClusterInstance sAlarmsServer;
#endif
Expand All @@ -87,6 +93,10 @@ typedef struct
tsZCL_ClusterInstance sMeterIdentificationServer;
#endif

#if (defined CLD_TUYASPECIFIC)
tsZCL_ClusterInstance sTuyaSpecificServer;
#endif

/* Recommended Optional client clusters */
#if (defined CLD_GROUPS) && (defined GROUPS_CLIENT)
tsZCL_ClusterInstance sGroupsClient;
Expand Down Expand Up @@ -124,6 +134,10 @@ typedef struct
tsCLD_IdentifyCustomDataStructure sIdentifyServerCustomDataStructure;
#endif

#if (defined CLD_TIME) && (defined TIME_CLIENT)
tsCLD_Time sTimeClientCluster;
#endif

#if (defined CLD_ALARMS) && (defined ALARMS_SERVER)
/* Alarms Cluster - Server */
tsCLD_Alarms sAlarmsServerCluster;
Expand All @@ -144,6 +158,11 @@ typedef struct
tsCLD_MeterIdentification sMeterIdentification;
#endif

#if (defined CLD_TUYASPECIFIC)
/* TuyaSpecific Cluster - Server */
tsCLD_TuyaSpecific sTuyaSpecificServerCluster;
#endif

/* Optional server clusters */
#if (defined CLD_POLL_CONTROL) && (defined POLL_CONTROL_SERVER)
tsCLD_PollControl sPollControlServerCluster;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ PUBLIC teZCL_Status eZLO_RegisterSimpleMeteringEndPoint(uint8 u8EndPointIdentifi
}
#endif

#if (defined CLD_TIME && defined TIME_CLIENT)
if (eCLD_TimeCreateTime(
&psDeviceInfo->sClusterInstance.sTimeClient,
FALSE,
&sCLD_Time,
&psDeviceInfo->sTimeClientCluster,
&au8TimeClusterAttributeControlBits[0]) != E_ZCL_SUCCESS)
{
return E_ZCL_FAIL;
}
#endif

#if (defined CLD_ALARMS) && (defined ALARMS_SERVER)
/* Create an instance of an Alarms cluster as a server */
if(eCLD_AlarmsCreateAlarms(&psDeviceInfo->sClusterInstance.sAlarmsServer,
Expand Down Expand Up @@ -237,6 +249,20 @@ PUBLIC teZCL_Status eZLO_RegisterSimpleMeteringEndPoint(uint8 u8EndPointIdentifi
}
#endif


#if (defined CLD_TUYASPECIFIC)
/* Create an instance of a Basic cluster as a server */
if(eCLD_TuyaSpecificCreateLinky(&psDeviceInfo->sClusterInstance.sTuyaSpecificServer,
TRUE,
&sCLD_TuyaSpecific,
&psDeviceInfo->sTuyaSpecificServerCluster,
NULL) != E_ZCL_SUCCESS)
{
// Need to convert from cluster specific to ZCL return type so we lose the extra information of the return code
return E_ZCL_FAIL;
}
#endif

return eZCL_Register(&psDeviceInfo->sEndPoint);
}

Expand Down
23 changes: 17 additions & 6 deletions ZLinky/Source/TuyaSpecific.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,19 @@ PUBLIC void SendTuyaReportCommand(uint8_t DP)
{

teZCL_Status e_status;
e_status = eCLD_TuyaCommandTotalPowerSend(sBaseDevice.sElectricalMeasurement.u16ApparentPower);
uint16 totalApparentPower =0;
totalApparentPower = sBaseDevice.sElectricalMeasurement.u16ApparentPower +
sBaseDevice.sElectricalMeasurement.u16ApparentPowerPhB +
sBaseDevice.sElectricalMeasurement.u16ApparentPowerPhC;
e_status = eCLD_TuyaCommandTotalPowerSend(totalApparentPower);
}
break;
case 0x01:
{
uint32_t totalConsumption;
if ((sBaseDevice.sLinkyServerCluster.au8LinkyMode == 0) || (sBaseDevice.sLinkyServerCluster.au8LinkyMode == 2) )
{
totalConsumption = ((uint32_t)sBaseDevice.sSimpleMeteringServerCluster.u48CurrentSummationDelivered / 10) +
((uint32_t)sBaseDevice.sSimpleMeteringServerCluster.u48CurrentTier1SummationDelivered / 10) +
totalConsumption = ((uint32_t)sBaseDevice.sSimpleMeteringServerCluster.u48CurrentTier1SummationDelivered / 10) +
((uint32_t)sBaseDevice.sSimpleMeteringServerCluster.u48CurrentTier2SummationDelivered / 10) +
((uint32_t)sBaseDevice.sSimpleMeteringServerCluster.u48CurrentTier3SummationDelivered / 10) +
((uint32_t)sBaseDevice.sSimpleMeteringServerCluster.u48CurrentTier4SummationDelivered / 10) +
Expand Down Expand Up @@ -145,11 +148,14 @@ PUBLIC void SendTuyaReportCommand(uint8_t DP)
{
voltage=0;
Current = sBaseDevice.sElectricalMeasurement.u16RMSCurrent * 1000;
Power = sBaseDevice.sElectricalMeasurement.u16ApparentPower;
Power = 0;
}else{
voltage = sBaseDevice.sElectricalMeasurement.u16RMSVoltage*10;
Current = sBaseDevice.sElectricalMeasurement.u16RMSCurrent * 1000;
Power = sBaseDevice.sElectricalMeasurement.u16ApparentPower;
//calcul de l'intensité'
if (voltage>0)
Current = (Power*1000) / sBaseDevice.sElectricalMeasurement.u16RMSVoltage ;
}
eCLD_TuyaCommandPhaseSend(0x06,voltage,Current,Power);
DBG_vPrintf(1,"\r\n----------------------TUYA eCLD_TuyaCommandPhase1Send Voltage : %d - Current : %d - Power : %d",voltage,Current,Power);
Expand All @@ -165,11 +171,14 @@ PUBLIC void SendTuyaReportCommand(uint8_t DP)
{
voltage=0;
Current = sBaseDevice.sElectricalMeasurement.u16RMSCurrentPhB * 1000;
Power = sBaseDevice.sElectricalMeasurement.u16ApparentPowerPhB;
Power = 0;
}else{
voltage = sBaseDevice.sElectricalMeasurement.u16RMSVoltagePhB*10;
Current = sBaseDevice.sElectricalMeasurement.u16RMSCurrentPhB * 1000;
Power = sBaseDevice.sElectricalMeasurement.u16ApparentPowerPhB;
//calcul de l'intensité'
if (voltage>0)
Current = (Power*1000) / sBaseDevice.sElectricalMeasurement.u16RMSVoltage ;
}
eCLD_TuyaCommandPhaseSend(0x07,voltage,Current,Power);

Expand All @@ -184,11 +193,13 @@ PUBLIC void SendTuyaReportCommand(uint8_t DP)
{
voltage=0;
Current = sBaseDevice.sElectricalMeasurement.u16RMSCurrentPhC * 1000;
Power = sBaseDevice.sElectricalMeasurement.u16ApparentPowerPhC;
Power = 0;
}else{
voltage = sBaseDevice.sElectricalMeasurement.u16RMSVoltagePhC*10;
Current = sBaseDevice.sElectricalMeasurement.u16RMSCurrentPhC * 1000;
Power = sBaseDevice.sElectricalMeasurement.u16ApparentPowerPhC;
if (voltage>0)
Current = (Power*1000) / sBaseDevice.sElectricalMeasurement.u16RMSVoltage ;
}
eCLD_TuyaCommandPhaseSend(0x08,voltage,Current,Power);

Expand Down

0 comments on commit 4ab59c1

Please sign in to comment.