alan broad
/
carbon_v5_arm_studio
arm studio build
src/wbit_util.cpp@0:a91cd1b08360, 2018-06-18 (annotated)
- Committer:
- alan1974
- Date:
- Mon Jun 18 17:31:35 2018 +0000
- Revision:
- 0:a91cd1b08360
- Child:
- 1:0d25d9ddbe9f
first checkin
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alan1974 | 0:a91cd1b08360 | 1 | #include "wbit_util.h" |
alan1974 | 0:a91cd1b08360 | 2 | #include "dot_util.h" |
alan1974 | 0:a91cd1b08360 | 3 | #include "mbed.h" |
alan1974 | 0:a91cd1b08360 | 4 | #include "mDot.h" |
alan1974 | 0:a91cd1b08360 | 5 | |
alan1974 | 0:a91cd1b08360 | 6 | uint8_t j_attempts = 0; |
alan1974 | 0:a91cd1b08360 | 7 | //return number of attempts it took to join the network |
alan1974 | 0:a91cd1b08360 | 8 | uint8_t join_network_attempts_wbit() { |
alan1974 | 0:a91cd1b08360 | 9 | return j_attempts; |
alan1974 | 0:a91cd1b08360 | 10 | } |
alan1974 | 0:a91cd1b08360 | 11 | |
alan1974 | 0:a91cd1b08360 | 12 | bool join_network_wbit(uint8_t nmbAttempts) { |
alan1974 | 0:a91cd1b08360 | 13 | //int32_t j_attempts = 0; |
alan1974 | 0:a91cd1b08360 | 14 | j_attempts = 0; |
alan1974 | 0:a91cd1b08360 | 15 | int32_t ret = mDot::MDOT_ERROR; |
alan1974 | 0:a91cd1b08360 | 16 | |
alan1974 | 0:a91cd1b08360 | 17 | // attempt to join the network |
alan1974 | 0:a91cd1b08360 | 18 | while (ret != mDot::MDOT_OK) { |
alan1974 | 0:a91cd1b08360 | 19 | j_attempts++; |
alan1974 | 0:a91cd1b08360 | 20 | logInfo("attempt %d to join network",j_attempts); |
alan1974 | 0:a91cd1b08360 | 21 | ret = dot->joinNetwork(); |
alan1974 | 0:a91cd1b08360 | 22 | if (ret == mDot::MDOT_OK) return true; |
alan1974 | 0:a91cd1b08360 | 23 | |
alan1974 | 0:a91cd1b08360 | 24 | logError("failed to join network %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
alan1974 | 0:a91cd1b08360 | 25 | if (j_attempts >= nmbAttempts) |
alan1974 | 0:a91cd1b08360 | 26 | { |
alan1974 | 0:a91cd1b08360 | 27 | logInfo("attempts %d to join network exceeds specified attempts $d ",j_attempts,nmbAttempts); |
alan1974 | 0:a91cd1b08360 | 28 | return false; |
alan1974 | 0:a91cd1b08360 | 29 | } |
alan1974 | 0:a91cd1b08360 | 30 | // in some frequency bands we need to wait until another channel is available before transmitting again |
alan1974 | 0:a91cd1b08360 | 31 | uint32_t delay_s = (dot->getNextTxMs() / 1000) + 1; |
alan1974 | 0:a91cd1b08360 | 32 | if (delay_s < 2) { |
alan1974 | 0:a91cd1b08360 | 33 | logInfo("waiting %lu s until next free channel", delay_s); |
alan1974 | 0:a91cd1b08360 | 34 | wait(delay_s); |
alan1974 | 0:a91cd1b08360 | 35 | } else { |
alan1974 | 0:a91cd1b08360 | 36 | logInfo("sleeping %lu s until next free channel", delay_s); |
alan1974 | 0:a91cd1b08360 | 37 | dot->sleep(delay_s, mDot::RTC_ALARM, false); |
alan1974 | 0:a91cd1b08360 | 38 | } |
alan1974 | 0:a91cd1b08360 | 39 | }//while |
alan1974 | 0:a91cd1b08360 | 40 | return false; |
alan1974 | 0:a91cd1b08360 | 41 | } |