mirror of
https://gitee.com/dlmu-cone/tronone-h7-scaffold
synced 2026-07-23 19:25:09 +08:00
狗好了,但是PowerMeterDecode还是g的,*rxbuff是好的,但是解析出来都是0.idxOK 头疼
This commit is contained in:
@@ -13,15 +13,12 @@ static XidiPowerMeterInstance *power_meter_instance = NULL;
|
||||
* @brief 功率计数据解码函数
|
||||
* @param _instance FDCAN实例指针
|
||||
*
|
||||
* @note 新版数据格式 (大端模式):
|
||||
* DATA[0]: 电压高8位
|
||||
* DATA[1]: 电压低8位
|
||||
* DATA[2]: 电流高8位
|
||||
* DATA[3]: 电流低8位
|
||||
* DATA[4]: 功率高8位
|
||||
* DATA[5]: 功率低8位
|
||||
* DATA[6]: 标识符
|
||||
* DATA[7]: 校验和
|
||||
* @note 依据实际硬件与官方示例代码 (小端模式):
|
||||
* DATA[0]: 电压低8位
|
||||
* DATA[1]: 电压高8位
|
||||
* DATA[2]: 电流低8位
|
||||
* DATA[3]: 电流高8位
|
||||
* 功率使用 P = U * I 直接计算
|
||||
*/
|
||||
void XidiPowerMeterDecode(FDCANInstance *_instance)
|
||||
{
|
||||
@@ -40,18 +37,17 @@ void XidiPowerMeterDecode(FDCANInstance *_instance)
|
||||
// 计算时间间隔
|
||||
measure->dt = DWT_GetDeltaT(&power_meter_instance->feed_cnt);
|
||||
|
||||
// 1. 解析电压 (高8位在前,低8位在后)
|
||||
uint16_t voltage_raw = (rxbuff[0] << 8) | rxbuff[1];
|
||||
// 1. 按照图片解析电压 (小端模式:[1]为高位,[0]为低位)
|
||||
// 使用 int16_t 强转是为了兼容可能出现的负数波动
|
||||
int16_t voltage_raw = (int16_t) ((rxbuff[1] << 8) | rxbuff[0]);
|
||||
measure->voltage = (float) voltage_raw / 100.0f;
|
||||
|
||||
// 2. 解析电流 (高8位在前,低8位在后)
|
||||
uint16_t current_raw = (rxbuff[2] << 8) | rxbuff[3];
|
||||
// 2. 按照图片解析电流 (小端模式:[3]为高位,[2]为低位)
|
||||
int16_t current_raw = (int16_t) ((rxbuff[3] << 8) | rxbuff[2]);
|
||||
measure->current = (float) current_raw / 100.0f;
|
||||
|
||||
// 3. 解析功率 (高8位在前,低8位在后)
|
||||
// 既然协议里直接发了功率,我们就直接读硬件算好的,比自己用 U*I 算更准
|
||||
uint16_t power_raw = (rxbuff[4] << 8) | rxbuff[5];
|
||||
measure->power = (float) power_raw / 100.0f;
|
||||
// 3. 按照图片直接计算功率 (电压 * 电流)
|
||||
measure->power = measure->voltage * measure->current;
|
||||
|
||||
// 4. 计算累计能量 (功率 × 时间)
|
||||
measure->energy += measure->power * measure->dt * 0.001f; // dt单位是ms,转换为秒
|
||||
|
||||
@@ -1,52 +1,63 @@
|
||||
|
||||
Breakpoint=D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/module/periph/power_meters/xiditech/xidipwmeter.c:24, State=BP_STATE_ON
|
||||
Breakpoint=D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/module/periph/power_meters/xiditech/xidipwmeter.c:28:14, State=BP_STATE_DISABLED
|
||||
Breakpoint=D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/module/periph/power_meters/xiditech/xidipwmeter.c:32:29, State=BP_STATE_DISABLED
|
||||
Breakpoint=D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/module/periph/power_meters/xiditech/xidipwmeter.c:73:1, State=BP_STATE_DISABLED
|
||||
Breakpoint=D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/module/periph/power_meters/xiditech/xidipwmeter.c:77:1, State=BP_STATE_DISABLED
|
||||
GraphedExpression="(QEKF_INS).Roll", Color=#a00909
|
||||
OpenDocument="xidipwmeter.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/module/periph/power_meters/xiditech/xidipwmeter.c", Line=21
|
||||
OpenDocument="bsp_dwt.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/bsp/dwt/bsp_dwt.c", Line=59
|
||||
OpenDocument="stm32h7xx_hal_spi.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c", Line=1553
|
||||
OpenDocument="tasks.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/Middlewares/Third_Party/FreeRTOS/Source/tasks.c", Line=2295
|
||||
OpenDocument="delayticks.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/bsp/delayticks/delayticks.c", Line=4
|
||||
OpenDocument="dev_cmd.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/user_task/dev_tasks/dev_cmd.c", Line=23
|
||||
OpenDocument="main.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/Core/Src/main.c", Line=71
|
||||
OpenDocument="xidipwmeter.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/module/periph/power_meters/xiditech/xidipwmeter.c", Line=28
|
||||
OpenDocument="stm32h7xx_hal.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c", Line=404
|
||||
OpenDocument="stm32h7xx_it.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/Core/Src/stm32h7xx_it.c", Line=306
|
||||
OpenDocument="stm32h7xx_hal_spi.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c", Line=1505
|
||||
OpenDocument="QuaternionEKF.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/module/algorithm/ekf/QuaternionEKF.c", Line=436
|
||||
OpenDocument="buzzer.cpp", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/module/periph/buzzer/buzzer.cpp", Line=319
|
||||
OpenDocument="rc.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/module/periph/remote_control/rc.c", Line=0
|
||||
OpenDocument="delayticks.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/bsp/delayticks/delayticks.c", Line=4
|
||||
OpenDocument="bsp_fdcan.h", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/bsp/fdcan/bsp_fdcan.h", Line=51
|
||||
OpenDocument="port.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c", Line=217
|
||||
OpenDocument="bsp_dwt.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/bsp/dwt/bsp_dwt.c", Line=15
|
||||
OpenDocument="daemon.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/module/software/daemon/daemon.c", Line=23
|
||||
OpenDocument="robot.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/application/robot.c", Line=33
|
||||
OpenDocument="cmsis_os2.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c", Line=871
|
||||
OpenDocument="dev_cmd.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/user_task/dev_tasks/dev_cmd.c", Line=12
|
||||
OpenDocument="bsp_fdcan.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/bsp/fdcan/bsp_fdcan.c", Line=280
|
||||
OpenDocument="list.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/Middlewares/Third_Party/FreeRTOS/Source/list.c", Line=144
|
||||
OpenDocument="cmsis_gcc.h", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/Drivers/CMSIS/Include/cmsis_gcc.h", Line=264
|
||||
OpenDocument="freertos.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/Core/Src/freertos.c", Line=366
|
||||
OpenDocument="stm32h7xx_hal_fdcan.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_fdcan.c", Line=2945
|
||||
OpenDocument="stm32h7xx_hal_fdcan.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_fdcan.c", Line=2032
|
||||
OpenDocument="ws2812.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/module/periph/ws2812/ws2812.c", Line=0
|
||||
OpenDocument="ins_task.c", FilePath="D:/RM/Elec Control/TronOneH7_Scaffold/User_Code/module/periph/imu/ins_task.c", Line=0
|
||||
OpenToolbar="Debug", Floating=0, x=0, y=0
|
||||
OpenToolbar="Breakpoints", Floating=0, x=1, y=0
|
||||
OpenWindow="Call Stack", DockArea=RIGHT, x=0, y=0, w=681, h=258, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="Call Stack", DockArea=RIGHT, x=0, y=0, w=681, h=260, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="Registers 1", DockArea=BOTTOM, x=1, y=0, w=361, h=181, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, FilteredItems=[], RefreshRate=1
|
||||
OpenWindow="Source Files", DockArea=LEFT, x=0, y=0, w=551, h=273, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="Source Files", DockArea=LEFT, x=0, y=0, w=663, h=273, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="Disassembly", DockArea=BOTTOM, x=2, y=0, w=629, h=181, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="Break & Tracepoints", DockArea=LEFT, x=0, y=1, w=551, h=216, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, VectorCatchIndexMask=254
|
||||
OpenWindow="Break & Tracepoints", DockArea=LEFT, x=0, y=1, w=663, h=224, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, VectorCatchIndexMask=254
|
||||
OpenWindow="Memory 1", DockArea=BOTTOM, x=3, y=0, w=465, h=181, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, EditorAddress=0x2000B98C
|
||||
OpenWindow="Global Data", DockArea=RIGHT, x=0, y=3, w=681, h=301, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="Watched Data 1", DockArea=LEFT, x=0, y=2, w=551, h=344, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="Functions", DockArea=LEFT, x=0, y=3, w=551, h=239, TabPos=1, TopOfStack=0, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="Call Graph", DockArea=LEFT, x=0, y=3, w=551, h=239, TabPos=2, TopOfStack=1, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="Global Data", DockArea=RIGHT, x=0, y=3, w=681, h=297, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="Watched Data 1", DockArea=LEFT, x=0, y=2, w=663, h=334, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="Functions", DockArea=LEFT, x=0, y=3, w=663, h=241, TabPos=1, TopOfStack=0, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="Call Graph", DockArea=LEFT, x=0, y=3, w=663, h=241, TabPos=2, TopOfStack=1, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="Data Sampling", DockArea=BOTTOM, x=0, y=0, w=1102, h=181, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, VisibleTab=0, UniformSampleSpacing=0
|
||||
OpenWindow="Timeline", DockArea=RIGHT, x=0, y=2, w=681, h=295, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=1, DataPaneShown=1, PowerPaneShown=0, CodePaneShown=0, PinCursor="Cursor Movable", TimePerDiv="1 s / Div", TimeStampFormat="Time", DataGraphDrawAsPoints=0, DataGraphLegendShown=1, DataGraphUniformSampleSpacing=0, DataGraphLegendPosition="435;0", PowerGraphDrawAsPoints=0, PowerGraphLegendShown=0, PowerGraphAvgFilterTime=Off, PowerGraphAvgFilterLen=Off, PowerGraphUniformSampleSpacing=0, PowerGraphLegendPosition="459;-65", CodeGraphLegendShown=0, CodeGraphLegendPosition="475;0"
|
||||
OpenWindow="Console", DockArea=LEFT, x=0, y=3, w=551, h=239, TabPos=0, TopOfStack=0, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="FreeRTOS", DockArea=RIGHT, x=0, y=1, w=681, h=238, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, Showing="Task List"
|
||||
OpenWindow="Timeline", DockArea=RIGHT, x=0, y=2, w=681, h=292, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=1, DataPaneShown=1, PowerPaneShown=0, CodePaneShown=0, PinCursor="Cursor Movable", TimePerDiv="1 s / Div", TimeStampFormat="Time", DataGraphDrawAsPoints=0, DataGraphLegendShown=1, DataGraphUniformSampleSpacing=0, DataGraphLegendPosition="435;0", PowerGraphDrawAsPoints=0, PowerGraphLegendShown=0, PowerGraphAvgFilterTime=Off, PowerGraphAvgFilterLen=Off, PowerGraphUniformSampleSpacing=0, PowerGraphLegendPosition="459;-65", CodeGraphLegendShown=0, CodeGraphLegendPosition="475;0"
|
||||
OpenWindow="Console", DockArea=LEFT, x=0, y=3, w=663, h=241, TabPos=0, TopOfStack=0, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0
|
||||
OpenWindow="FreeRTOS", DockArea=RIGHT, x=0, y=1, w=681, h=243, FilterBarShown=0, TotalValueBarShown=0, ToolBarShown=0, Showing="Task List"
|
||||
TableHeader="Call Graph", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Stack Total";"Stack Local";"Code Total";"Code Local";"Depth";"Called From"], ColWidths=[384;100;100;100;100;100;118]
|
||||
TableHeader="Functions", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Address";"Size";"#Insts";"Source"], ColWidths=[1164;100;100;100;100]
|
||||
TableHeader="Global Data", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Location";"Size";"Type";"Scope"], ColWidths=[222;130;100;54;95;486]
|
||||
TableHeader="Vector Catches", SortCol="None", SortOrder="ASCENDING", VisibleCols=["";"Vector Catch";"Description"], ColWidths=[50;300;500]
|
||||
TableHeader="Break & Tracepoints", SortCol="None", SortOrder="ASCENDING", VisibleCols=["";"Type";"Location";"Extras"], ColWidths=[100;100;142;209]
|
||||
TableHeader="Break & Tracepoints", SortCol="None", SortOrder="ASCENDING", VisibleCols=["";"Type";"Location";"Extras"], ColWidths=[100;100;142;342]
|
||||
TableHeader="Call Stack", SortCol="Function", SortOrder="ASCENDING", VisibleCols=["Function";"Stack Frame";"Source";"PC";"Return Address";"Stack Used"], ColWidths=[110;126;190;100;190;100]
|
||||
TableHeader="Source Files", SortCol="File", SortOrder="ASCENDING", VisibleCols=["File";"Status";"Size";"#Insts";"Path"], ColWidths=[229;100;100;100;1046]
|
||||
TableHeader="Data Sampling Table", SortCol="None", SortOrder="ASCENDING", VisibleCols=["Index";"Time";" (QEKF_INS).Roll"], ColWidths=[100;100;100]
|
||||
TableHeader="Data Sampling Setup", SortCol="Expression", SortOrder="ASCENDING", VisibleCols=["Expression";"Type";"Value";"Min";"Max";"Average";"# Changes";"Min. Change";"Max. Change"], ColWidths=[320;100;110;110;100;110;102;118;118]
|
||||
TableHeader="Data Sampling Setup", SortCol="Expression", SortOrder="ASCENDING", VisibleCols=["Expression";"Type";"Value";"Min";"Max";"Average";"# Changes";"Min. Change";"Max. Change"], ColWidths=[320;100;110;102;100;110;102;118;118]
|
||||
TableHeader="Power Sampling", SortCol="Index", SortOrder="ASCENDING", VisibleCols=["Index";"Time";"Ch 0"], ColWidths=[100;100;100]
|
||||
TableHeader="Task List", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Run Count";"Priority";"Status";"Timeout";"Stack Info (Free / Size)";"ID";"Mutex Count";"Notified Value";"Notify State"], ColWidths=[110;110;110;110;110;110;110;110;110;110]
|
||||
TableHeader="Registers 1", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Description"], ColWidths=[100;105;294]
|
||||
TableHeader="Watched Data 1", SortCol="Expression", SortOrder="ASCENDING", VisibleCols=["Expression";"Value";"Location"], ColWidths=[171;101;258]
|
||||
TableHeader="Watched Data 1", SortCol="Expression", SortOrder="ASCENDING", VisibleCols=["Expression";"Value";"Type";"Location";"Refresh"], ColWidths=[171;101;162;112;117]
|
||||
TableHeader="RegisterSelectionDialog", SortCol="None", SortOrder="ASCENDING", VisibleCols=[], ColWidths=[]
|
||||
TableHeader="TargetExceptionDialog", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Address";"Description"], ColWidths=[27;27;27;38]
|
||||
WatchedExpression="QEKF_INS", RefreshRate=2, Window=Watched Data 1
|
||||
@@ -56,4 +67,7 @@ WatchedExpression="power_meter_instance", RefreshRate=2, Window=Watched Data 1
|
||||
WatchedExpression="pm_voltage", RefreshRate=2, Window=Watched Data 1
|
||||
WatchedExpression="pm_current", RefreshRate=2, Window=Watched Data 1
|
||||
WatchedExpression="measure.voltage", Window=Watched Data 1
|
||||
WatchedExpression="PowerMeterInstance", RefreshRate=2, Window=Watched Data 1
|
||||
WatchedExpression="PowerMeterInstance", RefreshRate=2, Window=Watched Data 1
|
||||
WatchedExpression="idx", RefreshRate=2, Window=Watched Data 1
|
||||
WatchedExpression="rxbuff", RefreshRate=2, Window=Watched Data 1
|
||||
WatchedExpression="voltage_raw", RefreshRate=2, Window=Watched Data 1
|
||||
Reference in New Issue
Block a user