i2c smbus过滤器函数损坏变量 [英] i2c smbus filter function corrupting variables

查看:141
本文介绍了i2c smbus过滤器函数损坏变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的函数

#define AMB_FILTER 0.7f

int32_t fValue; (this is declared in the class header)

int32_t Ambient::filter(uint32_t raw)
{
    // If we have no preliminary fValue we don't need to calculate a filter
    if(fValue == -1)
    {
        fValue = raw;
        return fValue;
    }

    float y, yy;

    y = (1.0f - AMB_FILTER) * (float) raw;
    yy = AMB_FILTER * (float) fValue;

    fValue =  (int32_t) (y + yy);

    printf("filter raw %d y %f yy %f fValue %d\n",raw, y, yy, fValue);

    return fValue; 
}

它接收从smbus ,并返回使用接收到的最后一个值过滤的值。这是它从printf语句的输出

It takes in a value that was read from smbus and returns a value that was filtered with the last value it received. Here is its output from the printf statement

filter raw 454 y 136.200012 yy 317.799988 fValue 454
filter raw 454 y 136.200012 yy 317.799988 fValue 454
filter raw 454 y 136.200012 yy 317.799988 fValue 454
filter raw 455 y 136.500000 yy 317.799988 fValue 454
filter raw 455 y 136.500000 yy 317.799988 fValue 454
filter raw 455 y 136.500000 yy 317.799988 fValue 454
filter raw 455 y 136.500000 yy 317.799988 fValue 454
filter raw 455 y 136.500000 yy 317.799988 fValue 454
filter raw 454 y 136.200012 yy 317.799988 fValue 454
filter raw 455 y 136.500000 yy -731751040.000000 fValue -731750912
filter raw 455 y 136.500000 yy -512225632.000000 fValue -512225504
filter raw 455 y 136.500000 yy -358557856.000000 fValue -358557728
filter raw 455 y 136.500000 yy -250990400.000000 fValue -250990256
filter raw 454 y 136.200012 yy -175693184.000000 fValue -175693040

发生什么事?它是如何仍然收到相同的输入,但突然变得疯狂?我不设置fValue在任何地方,但这个功能。

So what is happening? How is it that it still received the same input but all of a sudden went crazy? I don't set the fValue anywhere but this function.

我使这些变量(y和yy)非常内在的函数,因为我担心他们不知何故被修改或与其他东西碰撞。但现在,他们是完全地方我不知道发生了什么。我使用C ++类,所以这应该都在自己的空间无论如何。

I made these variables (y and yy) very internalized to the function because I was worried they were somehow being modified or collided with something else. But now that they are completely local I have no idea what is happening. I am using C++ classes so this should all be in its own space anyhow.

编辑:事实上,如果我让它运行一个更长的变量,我保持为不同i2c芯片地址也被损坏为-1075766188。到底是什么?

In fact if I let it run a little longer the variables I keep for the different i2c Chip addresses also become corrupted to -1075766188. What the hell?

推荐答案



[t1] filter raw 454 y 136.200012 yy 317.799988 fValue 454
[t2] filter raw 455 y 136.500000 yy -731751040.000000 fValue -731750912



t1 t2 之间的 fValue 已损坏。 yy 的损坏是 fValue 损坏的结果。在你的程序中的别处查找罪魁祸首。

Sometime between t1 and t2 the value of fValue was corrupted. The corruption of yy is a consequence of fValue's corruption. Look elsewhere in your program for the culprit.


  • 如果您不能使用 valgrind fvalue

  • 在您的例程中打印

  • Ambient 中打印其他成员变量的值。看看他们是否不寻常。

  • 尝试注释大量的代码。从你的程序的1/2开始。如果bug仍然存在,注释掉剩余的1/2。

  • If you can't use valgrind, then sprinkle sanity checks on the valueof fvalue throughout your program.
  • Print the value of this in your routine. See if it becomes unusual.
  • Print the value of other member variables from Ambient. See if they become unusual.
  • Try commenting out huge tracts of code. Start with 1/2 of your program. If the bug is still there, comment out 1/2 of the remainder. Continue until you find a single line that controls the corruption.

至于它是如何损坏的,有很多种可能性。也许你在某个地方引用一个野生指针。也许你写超出数组的末尾。也许你正在使用以前销毁的环境

As to how it was corrupted, there are many possibilities. Perhaps you dereference a wild pointer somewhere. Perhaps you write beyond the end of an array. Perhaps you are operating on a previously destroyed Ambient.

这篇关于i2c smbus过滤器函数损坏变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆