## 3 Application Protocol for Wireless Intelligent Sensor Networks
### Protocol Description
#### 3.2.5 Protocol Procedures  
Protocol procedures are the actions taken when a primitive is executed at any of its steps. These procedures make decisions based on the fact that they are being executed on an isolated sensor. Thus, all of the procedures tend to minimize communications and processing to optimize battery usage. The most important procedures used are detailed below:  
1. Priority management: All messages have a 2 bit field that stores the four priority levels, from 0 (lowest) to 3 (highest). When a message is received by a sensor, the priority is checked and the processed only if the battery level is enough for that priority level; otherwise, the message is discarded. For priority level 0, if the battery is below 75% the message is discarded; level 1 allows responses for a battery level down to 50%, level 2 allows responses down to 25%, and level 3 messages are always processed.
2. Awake time estimation: In the current implementation, this is the estimate of the best time to get a result from the FRBS running in the sensor. This will be upgraded to a more complex system based in FRBS in the future.
3. Base station detection: This is one important task that the protocol does itself. This procedure allows the sensor to be in movement or be aware of hardware failures in the base station. When a sensor does not have any base station set in its working parameters, it goes into the isolated  
\begin{table}
\begin{tabular}{l c c l} \hline
**Mnemonic** & **HEX code** & **Binary code** & **Description** \\ \hline SNR\_AWAKE & 40 h & 0100 00 XXb & The sensor has woken up from sleep mode \\  & & & and is ready to accept queries from the base station \\ \hline SNR\_ISOLATED & 44 h & 0100 01 XXb & The sensor has no a base station associated \\  & & & to it and requests a new one \\ \hline SNR\_OK & 48 h & 0100 10 XXb & The sensor accepts the last message sent to \\  & & & it and informs that it has been executed \\  & & & properly \\ \hline SNR\_VALUE & 4C h & 0100 11 XXb & The sensor returns the values requested by \\  & & & a GET\_VALUE message \\ \hline BST\_LINK & 04 h & 0000 01 XXb & The base station informs the sensor that it \\  & & & has been linked to that base station \\ \hline BST\_SLEEP & 08 h & 0000 10 XXb & The base station commands the sensor to \\  & & & enter in deep sleep mode \\ \hline BST\_KB & 10 h & 0001 00 XXb & This command loads a new KB into a \\  & & & sensor \\ \hline BST\_REJECT & 0C h & 0000 11 XXb & The base station informs the sensor that it \\  & & & is not allowed to link to that base station \\ \hline GET\_VALUE & C4 h & 1100 01 XXb & The sensor is requested to send back some \\  & & & values from it (probes, agent parameters, _etc._) \\ \hline SET\_VALUE & C8 h & 1100 10 XXb & This command establishes a new value of \\  & & & agent parameters, probes or actuators \\ \hline \end{tabular}
\end{table}
Table 1: Protocol messages.  
state and must broadcast a SNR_LINK command to require a new one. If a sensor does not receive an incoming message after a certain number of times (_MFTThreshold_), it assumes that it is isolated. This process uses the primitive Link. The parameters _maxhops_ and _MFTThreshold_ have been extracted from the experiments shown in Section 4.
4. Request control: All of the responses that should be transmitted must have the same sequence number as the request which originated them.
5. Power and quality information: Every message sent by a sensor must contain information about the current charge of its battery and the power level used to transmit it. Moreover, the base station must send to a sensor the quality level measured for incoming messages broadcasted by sensors.  
Acknowledgment messages are not present in the protocol, with the exception of the sensor_ok message that can be seen as an acknowledgment in some scenarios. Every request has a response, but the sending side does not know if the message reaches the other side.