PAL_MOT-single
This ACT acquires several samples of acceleration data after sleep recovery and sends that data.
The ACT of the "Act" includes the following
Sending and receiving wireless packets
Configuration through Interactive settings mode - <STG_STD>
State transition control by state machine - <SM_SIMPLE>
Explanation of ACT
Wake up → start acquiring accelerometer data → wait for accelerometer FIFO interrupt → retrieve accelerometer data → wireless transmission → sleep.
The accelerometer stops adding data to the FIFO queue when the FIFO queue is full.
宣言部
インクルード
To support MOT PAL or TWELITE CUE, the include part is a macro. Define either USE_PAL_MOT
or USE_CUE
.
If USE_PAL_MOT
is defined, the board BEHAVIOR <PAL_MOT>
is included.
state-defined
Define states for sequential processing during loop()
and also state machinestep
is declared.
Sensor data storage
Data structure for storing sensor data.
setup()
Registers board, configuration, and network behavior objects.
Interactive settings mode
Initialize the Interactive settings mode.
First, adjust the configuration items. Here, we set the title name SETTINGS::appname
to be displayed in menu items, the default value of Application ID SETTINGS::appid_default
, the default value of CHANNEL SETTINGS::ch_default
, the default value of logical device ID default SETTINGS::lid_default
, and .hide_items()
for hidden items.
This sample transitions to Interactive settings mode when the SET pin is LO at startup. If digitalRead(brd.PIN_SET)
confirms that the pin is LO, specify SETTINGS::open_at_start()
. This specification causes the Interactive settings mode screen to appear immediately after exiting SETUP()
. When the screen is displayed, begin()
and loop()
are executed. In this sample, the state STATE::INTERACTIVE
is set so that no action such as sleep is performed during loop()
and nothing is done.
Next, the configuration values are read. To read the configuration values, be sure to execute .reload()
. In this sample, the option bit setting .u32opt1()
is read.
the_twelite
the_twelite
is a class object that manages the basic behavior of the system. This object performs various initializations such as Application ID and CHANNEL within setup()
.
Here some of the settings for Interactive settings mode is reflected.
If you wish to change an item reflected in the Interactive settings mode settings to another setting, continue with the setting you wish to override.
NWK_SIMPLE Object
Settings are also made for the network behavior object. The logical device ID (LID) and retransmission settings in Interactive settings mode are reflected.
Other hardware initialization, etc.
LED blink settings and other settings.
begin()
Called after setup()
is finished. Here, the first sleep is performed. However, if the screen in Interactive settings mode is displayed, it does not sleep.
wakeup()
After waking up, the state variable eState
is set to the initial state INIT. After this, loop()
is executed.
loop()
The basic structure of loop()
is <SM_STATE>
state machine state
with switch ... . case clause. The initial state is STATE::INIT
or STATE::INTERACTIVE
.
STATE::INTERACTIVE
This is the state of the Interactive settings mode screen when it is displayed. Nothing is done. Interactive settings mode is used for Serial input and output in this screen.
STATE::INIT
INIT in its initial state.
In state INIT, initialization (clearing the queue for storing results) and initialization of the data structure for storing results is performed. transition to STATE::START_CAPTURE. After setting this transition, the while loop is executed again.
STATE::CAPTURE
In the state START_CAPTURE, the FIFO acquisition of the MC3630 sensor is started. Here, the FIFO interrupt is set to occur when 4 samples are acquired at 400 Hz.
Set timeout for exception handling and transition to the next state STATE::WAIT_CAPTURE
.
STATE::WAIT_CAPTURE
In the state WAIT_CAPTURE, it waits for a FIFO interrupt. When an interrupt occurs and data is stored in the result storage queue, sns_MC3630.available()
becomes true
. Call sns_MC3630.end()
to terminate the process.
Get the number of samples and sample sequence numbers.
Reads and averages all sample data.
Here, the maximum and minimum are obtained for the acquired samples using the iterator corresponding to each axis.
The std::mimmax_element
is introduced as an example of using the algorithm of the C++ Standard Template Library, but you can also find the maximum and minimum in the for loop as shown in the comments.
Call .sns_MC3630.get_que().clear()
to clear the data in the queue. If this is not called, subsequent sample acquisitions will not be possible. After that, it transits to the STATE::REQUEST_TX
state.
. is_timeout()
checks for timeout. If timeout occurs, it transits to STATE::EXIT_FATAL
as an error.
STATE::REQUEST_TX
In state REQUEST_TX
, the locally defined function TxReq()
is called to process the obtained sensor data and generate and send a transmission packet. The transmission request may fail due to the status of the transmission queue or other factors. If the transmission request succeeds, TxReq()returns as true, but no transmission is performed yet. The
on_tx_comp()` callback is called to complete the transmission.
Also, .clear_flag()
clears the flag to indicate that transmission is complete. At the same time, a timeout is set.
E_SATE::WAIT_TX
In state STATE::WAIT_TX
, it waits for the completion of wireless packet transmission. The flag is set by the on_tx_comp()
callback function, and .is_flag_ready()
becomes true after it is set.
E_SATE::EXIT_NORMAL, FATAL
When a series of operations is completed, it transits to the state STATE::EXIT_NORMAL
and calls the locally defined function sleepNow()
to execute sleep. When an error is detected, it transits to state STATE::EXIT_FATAL
and performs a system reset.
MWX_APIRET TxReq()
The last step is to generate a packet and request that it be sent. The packet should include the continuation number, the number of samples, the average value of XYZ, the minimum sample value of XYZ, and the maximum sample value of XYZ.
sleepNow()
Sleep procedure.
Serial ports should call
Serial.flush()
to output all before sleep.The
<SM_SIMPLE>
state machine must doon_sleep()
.
最終更新