enumclassE_STATE { INIT =0, // INIT STATE WORK_JOB, // do some job (e.g sensor capture) TX, // reuest transmit WAIT_TX, // wait its completion EXIT_NORMAL, // normal exiting. EXIT_FATAL // has a fatal error (will do system reset)};
setup()
voidsetup() { /*** SETUP section */ txreq_stat =MWX_APIRET(false,0); // the twelite main class the_twelite<< TWENET::appid(APP_ID) // set application ID (identify network group)<< TWENET::channel(CHANNEL) // set channel (pysical channel)<< TWENET::rx_when_idle(false); // open receive circuit (if not set, it can't listen packts from others) // Register Networkauto&& nwk =the_twelite.network.use<NWK_SIMPLE>(); nwk << NWK_SIMPLE::logical_id(DEVICE_ID); // set Logical ID. /*** BEGIN section */the_twelite.begin(); // start twelite! /*** INIT message */ Serial <<"--- Sleep an Tx Act ---"<< crlf;}
MWX_APIRETvTransmit() { Serial <<int(millis()) <<":vTransmit()"<< crlf;if (auto&& pkt =the_twelite.network.use<NWK_SIMPLE>().prepare_tx_packet()) { // set tx packet behavior pkt <<tx_addr(0x00) // 0..0xFF (LID 0:parent, FE:child w/ no id, FF:LID broad cast), 0x8XXXXXXX (long address)<<tx_retry(0x1) // set retry (0x3 send four times in total)<<tx_packet_delay(0,0,2); // send packet w/ delay (send first packet with randomized delay from 0 to 0ms, repeat every 2ms) // prepare packet payloadpack_bytes(pkt.get_payload() // set payload data objects.,make_pair(FOURCC,4) // string should be paired with length explicitly.,uint32_t(millis()) // put timestamp here. ); // do transmit //return nwksmpl.transmit(pkt);returnpkt.transmit(); }returnMWX_APIRET(false,0);}