1.9.1.4 Cycles

The cycles application file (app_cycles.c) manages the cycles of the joined devices. Once the devices are joined to the network, after 2 minutes since the last join, it starts cycling all the joined devices with ICMPv6 requests (pings), one by one. For each device, three ICMPv6 packet lengths are used (64, 300 and 1000 bytes). After 10 seconds without response, it is considered as error (timeout). When all ICMPv6 Echo Requests have been sent to all devices, it starts again with the first device. The results are displayed through a serial port.

The state machine is implemented in the APP_CYCLES_Tasks() function. The different states are:
  • APP_CYCLES_STATE_WAIT_TCPIP_READY: TCP/IP stack status is checked and when it is ready, ICMPv6 callback is registered using TCPIP_ICMPV6_CallbackRegister() and the state is changed to APP_CYCLES_STATE_WAIT_FIRST_JOIN.
  • APP_CYCLES_STATE_WAIT_FIRST_JOIN: The number of joined devices is checked and when it is more than zero, a timer of 2 minutes (defined in APP_CYCLES_TIME_WAIT_CYCLE_MS) is started.
  • APP_CYCLES_STATE_WAIT_FIRST_CYCLE: If timer has expired, the first ICMPv6 Echo Request (64 bytes) is sent to the first device. Otherwise, the number of joined devices is checked again and if it has changed, the timer of 2 minutes is restarted.
  • APP_CYCLES_STATE_CYCLING: It checks if timeout (10 seconds, defined in APP_CYCLES_TIMEOUT_MS) expired in order to send the next ICMPv6 Echo Request. When all packet lengths have been sent (64, 300 and 1000 bytes), it starts with the next device (with the delay defined in APP_CYCLES_TIME_BTW_DEVICE_CYCLES_MS). When all ICMPv6 Echo Requests have been sent to all devices, it starts again with the first device.
  • APP_CYCLES_STATE_WAIT_NEXT_DEVICE_CYCLE: If timer has expired, ICMPv6 Echo Requests is sent to the next device.
  • APP_CYCLES_STATE_ERROR: There was an error during TCP/IP stack initialization.
One TCP/IP stack callback is registered:
  • _APP_CYCLES_IcmpCallback(): It indicates that an ICMPv6 packet has been received. It is checked that it is an Echo Reply and that the remote address is the expected one. When ICMPv6 Echo Reply is received, it sends the next ICMPv6 Echo Request. When all packet lengths have been sent (64, 300 and 1000 bytes), it starts with the next device. When all ICMPv6 Echo Requests have been sent to all devices, it starts again with the first device.
There is another function that is called from G3 management application:
  • APP_CYCLES_AdpBufferIndication(): It indicates that there was a change in ADP buffers availability. If one type of buffer (small, medium or large) is unavailable, cycles are stopped until all types of buffers are available. This implementation is very simple, but the user could use this indication in another way, taking into account the length of the buffer (100, 400 or 1280 bytes) that is unavailable.