精简2401中从未使用的设置参数

This commit is contained in:
Stone 2015-12-14 17:30:37 +00:00
parent eda3889b71
commit 4b197b5a9b
2 changed files with 15 additions and 35 deletions

View File

@ -216,15 +216,11 @@ NRF24L01::NRF24L01()
Channel = 0; // 默认通道0 Channel = 0; // 默认通道0
AddrBits = 0x01; // 默认使能地址0 AddrBits = 0x01; // 默认使能地址0
Timeout = 50;
PayloadWidth= 32; PayloadWidth= 32;
AutoAnswer = true; AutoAnswer = true;
Retry = 15;
RetryPeriod = 500; // 500us
Speed = 250; Speed = 250;
RadioPower = 0xFF; RadioPower = 0xFF;
MaxError = 10;
Error = 0; Error = 0;
_tidOpen = 0; _tidOpen = 0;
@ -419,8 +415,9 @@ bool NRF24L01::Config()
} }
} }
static const short powers[] = {-12, -6, -4, 0, 1, 3, 4, 7}; static const short powers[] = {-12, -6, -4, 0, 1, 3, 4, 7};
if(RadioPower >= ArrayLength(powers)) RadioPower = ArrayLength(powers) - 1; auto rp = RadioPower;
debug_printf(" 射频通道: %d %dMHz %ddBm\r\n", Channel, 2400 + Channel, powers[RadioPower]); if(rp >= ArrayLength(powers)) rp = ArrayLength(powers) - 1;
debug_printf(" 射频通道: %d %dMHz %ddBm\r\n", Channel, 2400 + Channel, powers[rp]);
// 检查WiFi通道 // 检查WiFi通道
static const byte wifis[] = {2, 32, 70, 5, 35, 68, 8, 39, 65, 11, 41, 62}; static const byte wifis[] = {2, 32, 70, 5, 35, 68, 8, 39, 65, 11, 41, 62};
for(int i=0; i<ArrayLength(wifis); i++) for(int i=0; i<ArrayLength(wifis); i++)
@ -439,15 +436,7 @@ bool NRF24L01::Config()
debug_printf(" 负载大小: %d字节\r\n", PayloadWidth); debug_printf(" 负载大小: %d字节\r\n", PayloadWidth);
debug_printf(" 自动应答: %s\r\n", AutoAnswer ? "true" : "false"); debug_printf(" 自动应答: %s\r\n", AutoAnswer ? "true" : "false");
if(AutoAnswer) if(AutoAnswer)
{ debug_printf(" 重试周期: %dus + 86us\r\n", 500);
debug_printf(" 应答重试: %d次\r\n", Retry);
int period = RetryPeriod / 250 - 1;
if(period < 0) period = 0;
RetryPeriod = (period + 1) * 250;
debug_printf(" 重试周期: %dus + 86us\r\n", RetryPeriod);
}
debug_printf(" 发送超时: %dms\r\n", Timeout);
debug_printf(" 出错重启: %d次\r\n", MaxError);
#endif #endif
// 必须拉低CE后修改配置然后再拉高 // 必须拉低CE后修改配置然后再拉高
@ -455,17 +444,14 @@ bool NRF24L01::Config()
SetPowerMode(false); SetPowerMode(false);
SetAddress(true); SetAddress();
if(AutoAnswer) if(AutoAnswer)
{ {
//设置自动重发间隔时间:500us + 86us;最大自动重发次数:10次 // 设置自动重发间隔时间:500us + 86us;最大自动重发次数:10次
int period = RetryPeriod / 250 - 1;
if(period < 0) period = 0;
RF_SETUP_RETR retr; RF_SETUP_RETR retr;
retr.ARC = Retry; retr.ARC = 15;
retr.ARD = period; retr.ARD = 500 / 250 - 1;
WriteReg(SETUP_RETR, retr.ToByte()); WriteReg(SETUP_RETR, retr.ToByte());
} }
else else
@ -663,8 +649,8 @@ bool NRF24L01::SetMode(bool isReceive)
return true; return true;
} }
// 设置地址。参数指定是否设置0通道地址以外的完整地址 // 设置地址
void NRF24L01::SetAddress(bool full) void NRF24L01::SetAddress()
{ {
TS("R24::SetAddress"); TS("R24::SetAddress");
@ -674,8 +660,6 @@ void NRF24L01::SetAddress(bool full)
WriteBuf(RX_ADDR_P0, Address, addrLen); // 写接收端0地址 WriteBuf(RX_ADDR_P0, Address, addrLen); // 写接收端0地址
WriteReg(SETUP_AW, addrLen - 2); // 设置地址宽度 WriteReg(SETUP_AW, addrLen - 2); // 设置地址宽度
if(!full) return;
byte bits = AddrBits >> 1; byte bits = AddrBits >> 1;
if(bits & 0x01) if(bits & 0x01)
{ {
@ -914,7 +898,7 @@ bool NRF24L01::OnWrite(const Array& bs)
//_CE = false; //_CE = false;
bool rs = false; bool rs = false;
uint ms = RetryPeriod * Retry; uint ms = 250 * 15 / 1000;
if(ms > 4 && AutoAnswer) ms = 4; if(ms > 4 && AutoAnswer) ms = 4;
// https://devzone.nordicsemi.com/question/17074/nrf24l01-data-loss/ // https://devzone.nordicsemi.com/question/17074/nrf24l01-data-loss/
// It is important never to keep the nRF24L01+ in TX mode for more than 4ms at a time. // It is important never to keep the nRF24L01+ in TX mode for more than 4ms at a time.
@ -995,9 +979,9 @@ bool NRF24L01::OnWriteEx(const Array& bs, void* opt)
void NRF24L01::AddError() void NRF24L01::AddError()
{ {
Error++; Error++;
if(MaxError > 0 && Error >= MaxError) if(Error >= 10)
{ {
debug_printf("RF24::Error 出错%d次超过最大次数%d准备重启模块\r\n", Error, MaxError); debug_printf("RF24::Error 出错%d次超过最大次数%d准备重启模块\r\n", Error, 10);
Close(); Close();
Open(); Open();

View File

@ -41,14 +41,10 @@ public:
byte PayloadWidth; // 负载数据宽度默认32字节。0表示使用动态负载 byte PayloadWidth; // 负载数据宽度默认32字节。0表示使用动态负载
bool AutoAnswer; // 自动应答,默认启用 bool AutoAnswer; // 自动应答,默认启用
byte Retry; // 重试次数最大15次
ushort RetryPeriod; // 重试间隔250us的倍数最小250us
ushort Speed; // 射频数据率单位kbps默认250kbps可选1000kbps/2000kbps速度越低传输越远 ushort Speed; // 射频数据率单位kbps默认250kbps可选1000kbps/2000kbps速度越低传输越远
byte RadioPower; // 发射功率。共8档最高0x07代表7dBm最大功率 byte RadioPower; // 发射功率。共8档最高0x07代表7dBm最大功率
uint Timeout; // 超时时间ms ushort Error; // 错误次数,超过最大错误次数则自动重置
ushort MaxError; // 最大错误次数超过该次数则自动重置0表示不重置默认10
ushort Error; // 错误次数,超过最大错误次数则自动重置
byte AddrLength; // 地址长度。默认0主站建议设为5 byte AddrLength; // 地址长度。默认0主站建议设为5
NRF24L01(); NRF24L01();
@ -61,7 +57,7 @@ public:
bool SetPowerMode(bool on); // 设置当前电源状态。返回是否成功 bool SetPowerMode(bool on); // 设置当前电源状态。返回是否成功
bool GetMode(); // 获取当前模式是否接收模式 bool GetMode(); // 获取当前模式是否接收模式
bool SetMode(bool isReceive); // 切换收发模式,不包含参数设定 bool SetMode(bool isReceive); // 切换收发模式,不包含参数设定
void SetAddress(bool full); // 设置地址。参数指定是否设置0通道地址以外的完整地址 void SetAddress(); // 设置地址
// 电源等级变更(如进入低功耗模式)时调用 // 电源等级变更(如进入低功耗模式)时调用
virtual void ChangePower(int level); virtual void ChangePower(int level);