据我所知,我具有以下功能,nesC
其中基本相同!C
event void AdaptiveSampling.dataAvailable(error_t result, float val, bool isRealData)
{
if(result == SUCCESS)
{
//converting raw ADC to centigrade
centiGrade = -39.60 + 0.01 * val;
//printing the value to serial port
if(isRealData)
{
printf("REAL: Temperature is: %d CentiGrade\r\n", centiGrade); //line 91
printf("%d,R,%d,%d\r\n", _counter, val, centiGrade); //line 92
}
else
{
printf("PEDICTED: Temperature is: %d CentiGrade\r\n", centiGrade); //line 96
printf("%d,P,%d,%d\r\n", _counter, val, centiGrade); //line 97
}
_counter++;
}
else
{
printf("Error reading sensor!");
}
}
而且,在我的代码顶部,我定义了这些变量:
uint32_t _counter;
uint16_t centiGrade;
这是我在构建过程中收到的警告:
AdaptiveSamplingC.nc:92:11: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘uint32_t’ [-Wformat]
AdaptiveSamplingC.nc:92:11: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘float’ [-Wformat]
AdaptiveSamplingC.nc:97:11: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘uint32_t’ [-Wformat]
AdaptiveSamplingC.nc:97:11: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘float’ [-Wformat]
这是屏幕上的输出示例:
PEDICTED: Temperature is: 26 CentiGrade
291,P,0,-3402
REAL: Temperature is: 26 CentiGrade
292,R,0,4096
PEDICTED: Temperature is: 26 CentiGrade
293,P,0,-1495
问题:
在第 91 行,我希望看到温度值是浮动的……我的意思是26.25
……但由于某种原因,它打印为整数。我试图更改%d
为,%f
但它没有帮助,因为您看到第 92 行和第 97 行的输出由于我无法弄清楚的原因而几乎损坏!
我也无法解释为什么第 92 和 97 行表现得那么奇怪,以及为什么它们在构建期间会出现警告。
您能告诉我如何改进吗?