Morse Micro IoT SDK  2.9.7
ping.c File Reference

Detailed Description

Simple ping demonstration.

Note
It is assumed that you have followed the steps in the Getting Started guide and are therefore familiar with how to build, flash, and monitor an application using the MM-IoT-SDK framework.

This file demonstrates how to ping a target using the Morse Micro WLAN API.

See Application helper routines for Wireless LAN interface for details of WLAN and IP stack configuration. Additional configuration options for this application can be found in the config.hjson file.

Definition in file ping.c.

#include <string.h>
#include "mmhal.h"
#include "mmosal.h"
#include "mmwlan.h"
#include "mmconfig.h"
#include "mmping.h"
#include "mmipal.h"
#include "mm_app_common.h"
Include dependency graph for ping.c:

Go to the source code of this file.

Macros

#define PING_COUNT   10
 Number of ping requests to send. More...
 
#define PING_DATA_SIZE   56
 Size of the ping request data, excluding 8-byte ICMP header. More...
 
#define PING_INTERVAL_MS   1000
 Interval between successive ping requests. More...
 
#define POST_PING_DELAY_MS   10000
 Delay in ms to wait before terminating connection on completion of ping. More...
 
#define UPDATE_INTERVAL_MS   (5000)
 Interval (in milliseconds) at which to provide updates when the receive count has not changed. More...
 

Enumerations

enum  debug_state {
  DEBUG_STATE_INIT = 0x00 , DEBUG_STATE_BOOTING_CHIP = 0x01 , DEBUG_STATE_CONNECTING = 0x03 , DEBUG_STATE_CONNECTED = 0x02 ,
  DEBUG_STATE_CONNECTED_IDLE = 0x00 , DEBUG_STATE_PINGING = 0x02 , DEBUG_STATE_PING_DONE = 0x03 , DEBUG_STATE_IDLE = 0x01 ,
  DEBUG_STATE_TERMINATING = 0x00 , DEBUG_STATE_INIT = 0x00 , DEBUG_STATE_CONNECTING = 0x01 , DEBUG_STATE_CONNECTED = 0x03 ,
  DEBUG_STATE_PINGING_0 = 0x02 , DEBUG_STATE_PING_0_DONE = 0x00 , DEBUG_STATE_WNM_SLEEP = 0x01 , DEBUG_STATE_EXITING_WNM_SLEEP = 0x03 ,
  DEBUG_STATE_WNM_SLEEP_DONE = 0x02 , DEBUG_STATE_PINGING_1 = 0x00 , DEBUG_STATE_PING_1_DONE = 0x01 , DEBUG_STATE_WNM_SLEEP_POWER_DOWN = 0x03 ,
  DEBUG_STATE_EXITING_WNM_SLEEP_POWER_DOWN = 0x02 , DEBUG_STATE_WNM_SLEEP_POWER_DOWN_DONE = 0x00 , DEBUG_STATE_TERMINATING = 0x01
}
 Enumeration of debug states that will be reflected on debug pins. More...
 

Functions

static void set_debug_state (enum debug_state state)
 Perform necessary operation (i.e., setting GPIO pins) upon entering the given debug state. More...
 
void app_init (void)
 Main entry point to the application. More...
 

Macro Definition Documentation

◆ PING_COUNT

#define PING_COUNT   10

Number of ping requests to send.

Set to 0 to continue indefinitely.

Definition at line 35 of file ping.c.

◆ PING_DATA_SIZE

#define PING_DATA_SIZE   56

Size of the ping request data, excluding 8-byte ICMP header.

Definition at line 39 of file ping.c.

◆ PING_INTERVAL_MS

#define PING_INTERVAL_MS   1000

Interval between successive ping requests.

Definition at line 43 of file ping.c.

◆ POST_PING_DELAY_MS

#define POST_PING_DELAY_MS   10000

Delay in ms to wait before terminating connection on completion of ping.

Definition at line 47 of file ping.c.

◆ UPDATE_INTERVAL_MS

#define UPDATE_INTERVAL_MS   (5000)

Interval (in milliseconds) at which to provide updates when the receive count has not changed.

Definition at line 52 of file ping.c.

Enumeration Type Documentation

◆ debug_state

Enumeration of debug states that will be reflected on debug pins.

Note that due to limited availability of pins, the values are mapped to 2-bit codes and so are not unique. The code sequence has been chosen to be gray code like in that only one bit changes at a time, but it does not return to zero so a zero code can be used to identify the first state.

Enumerator
DEBUG_STATE_INIT 

Initial state at startup.

DEBUG_STATE_BOOTING_CHIP 

Indicates that we are booting the MM chip (note that this will also include the host MCU startup time.

DEBUG_STATE_CONNECTING 

Indicates we are connecting to the AP.

DEBUG_STATE_CONNECTED 

Indicates we are connected to the AP.

DEBUG_STATE_CONNECTED_IDLE 

Indicates that we have connected to the AP, but have not started the ping yet.

DEBUG_STATE_PINGING 

Indicates that the ping is in progress.

DEBUG_STATE_PING_DONE 

Indicates that the ping has completed.

DEBUG_STATE_IDLE 

Indicates that we are idling with WLAN still on.

DEBUG_STATE_TERMINATING 

Indicates that we are disconnecting from the AP.

DEBUG_STATE_INIT 

Initial state at startup.

DEBUG_STATE_CONNECTING 

Indicates we are connecting to the AP.

DEBUG_STATE_CONNECTED 

Indicates we are connected to the AP.

DEBUG_STATE_PINGING_0 

Indicates that the ping is in progress.

DEBUG_STATE_PING_0_DONE 

Indicates that the ping has completed.

DEBUG_STATE_WNM_SLEEP 

Indicates that WNM sleep is in progress.

DEBUG_STATE_EXITING_WNM_SLEEP 

Indicates that we are exiting WNM sleep.

DEBUG_STATE_WNM_SLEEP_DONE 

Indicates that WNM sleep has completed.

DEBUG_STATE_PINGING_1 

Indicates that the ping is in progress.

DEBUG_STATE_PING_1_DONE 

Indicates that the ping has completed.

DEBUG_STATE_WNM_SLEEP_POWER_DOWN 

Indicates that WNM sleep is in progress with chip powered down.

DEBUG_STATE_EXITING_WNM_SLEEP_POWER_DOWN 

Indicates that we are exiting WNM sleep with chip powered down.

DEBUG_STATE_WNM_SLEEP_POWER_DOWN_DONE 

Indicates that WNM sleep with chip powered down has completed.

DEBUG_STATE_TERMINATING 

Indicates that we are disconnecting from the AP.

Definition at line 61 of file ping.c.

Function Documentation

◆ app_init()

void app_init ( void  )

Main entry point to the application.

This will be invoked in a thread once operating system and hardware initialization has completed. It may return, but it does not have to.

Executes the ping.

Definition at line 98 of file ping.c.

◆ set_debug_state()

static void set_debug_state ( enum debug_state  state)
static

Perform necessary operation (i.e., setting GPIO pins) upon entering the given debug state.

Parameters
stateThe debug state to enter. See debug_state.

Definition at line 89 of file ping.c.