/*
Struct Opções utilizando: enum
Autor: Eng. Fabrício Ribeiro
19/05/2025
Byte MHDR
| Mtype | RFU | Versão |
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
*/
//Mtype
typedef enum _Mtype{
Join_Request,
Join_Accept,
Unconfirmed_Data_Up,
Unconfirmed_Data_Down,
Confirmed_Data_Up,
Confirmed_Data_Down,
Rejoin_Request,
Proprietary,
};
//RFU
typedef enum _RFU{
Teste0,
Teste1,
Teste2,
Teste3,
Teste4,
Teste5,
Teste6,
Teste7,
};
//Versão
typedef enum _Version{
Version_0,
Version_1,
Version_2,
Version_3,
};
//Struct de 1 byte
struct _MHDR{
byte Mtype:3; //3bit
byte RFU:3; //3bit
byte Version:2; //2bit
};
void setup(){
Serial.begin(115200);
_MHDR MHDR;
_Mtype Mtype = Join_Accept;
_RFU RFU = Teste1;
_Version Version = Version_1;
MHDR.Mtype = Mtype;
MHDR.RFU = RFU;
MHDR.Version = Version;
Serial.print("MHDR = ");
for(int i=2; i>=0; i--){
Serial.print(bitRead(MHDR.Mtype,i));
}
for(int i=2; i>=0; i--){
Serial.print(bitRead(MHDR.RFU,i));
}
for(int i=1; i>=0; i--){
Serial.print(bitRead(MHDR.Version,i));
}
Serial.println(" ");
}
void loop(){
}