voidloop() {auto&& brd =the_twelite.board.use<PAL_MOT>();if (!b_transmit) {if (!brd.sns_MC3630.available()) { Serial <<"..sensor is not available."<< mwx::crlf << mwx::flush;sleepNow(); } // send a packet Serial <<"..finish sensor capture."<< mwx::crlf<<" seq="<<int(brd.sns_MC3630.get_que().back().t) <<"/ct="<<int(brd.sns_MC3630.get_que().size()); // calc average in the queue. {int32_t x =0, y =0, z =0;for (auto&& v:brd.sns_MC3630.get_que()) { x +=v.x; y +=v.y; z +=v.z; } x /=brd.sns_MC3630.get_que().size(); y /=brd.sns_MC3630.get_que().size(); z /=brd.sns_MC3630.get_que().size(); Serial <<format("/ave=%d,%d,%d", x, y, z) << mwx::crlf; }for (int ip =0; ip <2; ip++) {if(auto&& pkt =the_twelite.network.use<NWK_SIMPLE>().prepare_tx_packet()) // set tx packet behavior pkt <<tx_addr(0x00)<<tx_retry(0x1)<<tx_packet_delay(0,0,2); // prepare packet (first)uint8_t siz = (brd.sns_MC3630.get_que().size() >= MAX_SAMP_IN_PKT)? MAX_SAMP_IN_PKT :brd.sns_MC3630.get_que().size();uint16_t seq =brd.sns_MC3630.get_que().front().t;pack_bytes(pkt.get_payload(),make_pair(FOURCHARS,4), seq , siz ); // store sensor data (36bits into 5byts, alas 4bits are not used...)for (int i =0; i < siz; i++) {auto&& v =brd.sns_MC3630.get_que().front();uint32_t v1; v1 = ((uint16_t(v.x/2) &4095) <<20) // X:12bits| ((uint16_t(v.y/2) &4095) <<8) // Y:12bits| ((uint16_t(v.z/2) &4095) >>4); // Z:8bits from MSBuint8_t v2 = (uint16_t(v.z/2) &255); // Z:4bits from LSBpack_bytes(pkt.get_payload(), v1, v2); // add into pacekt entry.brd.sns_MC3630.get_que().pop(); // pop an entry from queue. } // perform transmit MWX_APIRET ret =pkt.transmit();if (ret) { Serial <<"..txreq("<<int(ret.get_value()) <<')';txid[ip] =ret.get_value() &0xFF; } else {sleepNow(); } } } // finished tx request b_transmit =true; } else {if( the_twelite.tx_status.is_complete(txid[0])&&the_twelite.tx_status.is_complete(txid[1]) ) {sleepNow(); } }}
if (!brd.sns_MC3630.available()) { Serial <<"..sensor is not available."<< mwx::crlf << mwx::flush;sleepNow();}
無線送信パケットでは使用しないのですが、取り出した加速度の情報を確認してみます。
Serial <<"..finish sensor capture."<< mwx::crlf<<" seq="<<int(brd.sns_MC3630.get_que().front().t) <<"/ct="<<int(brd.sns_MC3630.get_que().size());// calc average in the queue.{int32_t x =0, y =0, z =0;for (auto&& v:brd.sns_MC3630.get_que()) { x +=v.x; y +=v.y; z +=v.z; } x /=brd.sns_MC3630.get_que().size(); y /=brd.sns_MC3630.get_que().size(); z /=brd.sns_MC3630.get_que().size(); Serial <<format("/ave=%d,%d,%d", x, y, z) << mwx::crlf;}