1.8.1.5 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 UDP requests (using an UDP client socket), one by one. After 10 seconds without response, it is considered as error (timeout). When all UDP requests have been sent to all devices, it starts again with the first device. The results are displayed through a serial port.

There are two options in terms of UDP data content, which is configured with the macro APP_CYCLES_METROLOGY_DATA_REQUEST (commented by default in app_cycles.h):
/* If APP_CYCLES_METROLOGY_DATA_REQUEST macro is defined, metrology data is
 * requested in cycles through UDP */
//#define APP_CYCLES_METROLOGY_DATA_REQUEST
  • If it is not defined (by default):
    • The UDP port used for the client is the same as for G3 Conformance certification tests, 0xF0BF. This port can be compressed using 6LowPAN (RFC4944, RFC6282).
    • Three UDP packet lengths are used (64, 300 and 1000 bytes) for each device. The first byte is 0x01 (UDP request), so the device should reply with 0x02 (UDP reply) and the same payload that was sent.
  • If it is defined:
    • The UDP port used for the client is 0xF0B0. This port can be compressed using 6LowPAN (RFC4944, RFC6282).
    • One UDP packet is sent for each device with only one byte (0x01). The device must respond with the metrology data defined in APP_CYCLES_METROLOGY_DATA structure. The device must be running the metering demo G3 device UDP application.
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, 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 UDP request 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 UDP response is received. After 10 seconds (defined in APP_CYCLES_TIMEOUT_MS) without response, it is considered as error (timeout). When UDP response is received or timeout expires, it sends the next UDP request. When all UDP request have been sent to a device, it starts with the next device (with the delay defined in APP_CYCLES_TIME_BTW_DEVICE_CYCLES_MS). When all UDP 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, UDP request is sent to the next device.
  • APP_CYCLES_STATE_CONFORMANCE: Cycles are disabled if G3 Conformance certification tests mode is enabled.
  • APP_CYCLES_STATE_ERROR: There was an error during TCP/IP stack initialization.
There are two functions that are 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.
  • APP_CYCLES_SetConformanceConfig(): Cycles are disabled because G3 Conformance certification tests mode is enabled.