成员函数中的/Arduino/libraries/SI4735/SI4735.cpp::char* if 4735::getRdsTime():/Users/rcaratti/Documents/Arduino/libraries/SI4735/SI4735.cpp:1534:5:警告:在此函数中未初始化'blkb.si47x_rds_blockb::refined.si47x_rds_blockb::::groupType‘,如果(getRdsGroupType() == 4 )
/*
* Block B data type
* See also Si47XX PROGRAMMING GUIDE; AN332; pages 78 and 79
* See also https://en.wikipedia.org/wiki/Radio_Data_System
*/
typedef union {
struct
{
uint8_t address : 2; // Depends on Group Type and Version codes. If 0A or 0B it is the Text Segment Address.
uint8_t DI : 1; // Decoder Controll bit
uint8_t MS : 1; // Music/Speech
uint8_t TA : 1; // Traffic Announcement
uint8_t programType : 5; // PTY (Program Type) code
uint8_t trafficProgramCode : 1; // (TP) => 0 = No Traffic Alerts; 1 = Station gives Traffic Alerts
uint8_t versionCode : 1; // (B0) => 0=A; 1=B
uint8_t groupType : 4; // Group Type code.
} group0;
struct
{
uint8_t address : 4; // Depends on Group Type and Version codes. If 2A or 2B it is the Text Segment Address.
uint8_t textABFlag : 1; // Do something if it chanhes from binary "0" to binary "1" or vice-versa
uint8_t programType : 5; // PTY (Program Type) code
uint8_t trafficProgramCode : 1; // (TP) => 0 = No Traffic Alerts; 1 = Station gives Traffic Alerts
uint8_t versionCode : 1; // (B0) => 0=A; 1=B
uint8_t groupType : 4; // Group Type code.
} group2;
struct
{
uint8_t content : 4; // Depends on Group Type and Version codes.
uint8_t textABFlag : 1; // Do something if it chanhes from binary "0" to binary "1" or vice-versa
uint8_t programType : 5; // PTY (Program Type) code
uint8_t trafficProgramCode : 1; // (TP) => 0 = No Traffic Alerts; 1 = Station gives Traffic Alerts
uint8_t versionCode : 1; // (B0) => 0=A; 1=B
uint8_t groupType : 4; // Group Type code.
} refined;
struct
{
uint8_t lowValue;
uint8_t highValue; // Most Significant byte first
} raw;
} si47x_rds_blockb;/*
* Returns the Group Type (extracted from the Block B)
*/
uint8_t SI4735::getRdsGroupType(void)
{
si47x_rds_blockb blkb;
blkb.raw.lowValue = currentRdsStatus.resp.BLOCKBL;
blkb.raw.highValue = currentRdsStatus.resp.BLOCKBH;
return blkb.refined.groupType;
}/*
* Gets the RDS time and date when the Group type is 4
*/
char *SI4735::getRdsTime()
{
// Under Test and construction
// Need to check the Group Type before.
si47x_rds_date_time dt;
if (getRdsGroupType() == 4)
{
char offset_sign;
int offset_h;
int offset_m;
// uint16_t y, m, d;
dt.raw[4] = currentRdsStatus.resp.BLOCKBL;
dt.raw[5] = currentRdsStatus.resp.BLOCKBH;
dt.raw[2] = currentRdsStatus.resp.BLOCKCL;
dt.raw[3] = currentRdsStatus.resp.BLOCKCH;
dt.raw[0] = currentRdsStatus.resp.BLOCKDL;
dt.raw[1] = currentRdsStatus.resp.BLOCKDH;
/*
y = (unsigned)(dt.refined.mjd - 15078.2) / 365.25;
m = ((unsigned)(dt.refined.mjd - 14956.1) - (unsigned)(y * 365.25)) / 30.6001;
d = (unsigned)(dt.refined.mjd - 14956) - (unsigned)(y * 365.25) - (m * 30.6001);
if (m > 13) {
m = 1;
y++;
}
y = y % 100;
*/
// sprintf(rds_time, "%02/%02/%04 %02d:%02d", d,m,y,dt.refined.hour, dt.refined.minute);
offset_sign = (dt.refined.offset_sense == 1) ? '+' : '-';
offset_h = (dt.refined.offset * 30) / 60;
offset_m = (dt.refined.offset * 30) - (offset_h * 60);
sprintf(rds_time, "%02d:%02d %c%02d:%02d", dt.refined.hour, dt.refined.minute, offset_sign, offset_h, offset_m);
return rds_time;
}
return NULL;
}发布于 2020-03-30 07:27:09
C++标准说:
位域跨分配单元在一些机器上,而不是在另一些机器上.
所以很明显,如果我们看看
struct
{
uint8_t content : 4; // Depends on Group Type and Version codes.
uint8_t textABFlag : 1; // Do something if it chanhes from binary "0" to binary "1" or vice-versa
uint8_t programType : 5; // PTY (Program Type) code
uint8_t trafficProgramCode : 1; // (TP) => 0 = No Traffic Alerts; 1 = Station gives Traffic Alerts
uint8_t versionCode : 1; // (B0) => 0=A; 1=B
uint8_t groupType : 4; // Group Type code.
} refined;在位字段不跨越分配单元的机器上,content和textABFlag被打包到第一个八进制,programType (不完全适合于第一个)与trafficProgramCode和versionCode一起打包到第二个,groupType被打包成第三个八进制。考虑到这个,
uint8_t SI4735::getRdsGroupType(void)
{
si47x_rds_blockb blkb;
blkb.raw.lowValue = currentRdsStatus.resp.BLOCKBL;
blkb.raw.highValue = currentRdsStatus.resp.BLOCKBH;
return blkb.refined.groupType;
}在局部变量blkb中,该函数只设置前两个八进制(lowValue和highValue),但从未初始化的第三个八进制返回groupType。
为了可靠地将所有这些位字段放入两个八进制,我们必须使用uint16_t而不是uint8_t,但请记住:
位字段在一些机器上从右到左分配,在另一些机器上从左到右分配.
发布于 2020-03-31 14:16:56
谢谢。我修复了Arduino DUE、STM32和ESP32平台以及其他使用GCC编译器的平台上的问题。GCC编译器不允许“越界”。例如,由一组位组成的字段不能由字节的一部分及其后续字节形成。
我的解决方案是:ty胡枝子联合{ struct { uint16_t内容: 4;//取决于Group和版本代码。uint16_t textABFlag : 1;//如果从二进制"0“到二进制"1”或反之亦然- uint16_t programType : 5;// PTY (程序类型)代码uint16_t trafficProgramCode : 1;// (TP) => 0=无交通告警;1=给出交通警报uint16_t versionCode : 1;// (B0) => 0=A;1=B uint16_t groupType : 4;//组类型代码。} refinedValues;struct { uint16_t lowValue;uint16_t highValue;//最重要的字节优先};uint16_t值;} si47x_rds_blockb;
https://stackoverflow.com/questions/60922341
复制相似问题