Other Parts Discussed in Thread: CC3120,
I've been porting the CC3120 SDK into my microcontroller project, and I've been examining the "network_terminal" application as an example of how to construct a working application, in terms of handling events, etc. I'm making a point to write robust events handlers, so that at a minimum, I will catch and report each possible event ID for each event type, even if I do nothing with it.
I finished the section for WLAN events, and next up are the NetApp events. I was a bit confused about the nomenclature of the event IDs used in the network terminal example:
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
{
if (!pNetAppEvent)
return;
switch (pNetAppEvent->Id)
{
case SL_DEVICE_EVENT_DROPPED_NETAPP_IPACQUIRED:
[...]
case SL_DEVICE_EVENT_DROPPED_NETAPP_IPACQUIRED_V6:
[...]
case SL_DEVICE_EVENT_DROPPED_NETAPP_IP_LEASED:
[...]
case SL_DEVICE_EVENT_DROPPED_NETAPP_IP_RELEASED:
{
UART_PRINT("\n\r[NETAPP EVENT] IP is released.\n\r");
}
break;
}
}
"Event Dropped", what's that about? I did a search and found all of the relevant macros in device.h:
/****************** NETAPP CLASS status ****************/ #define SL_DEVICE_EVENT_DROPPED_NETAPP_IPACQUIRED (0x00000001L) #define SL_DEVICE_EVENT_DROPPED_NETAPP_IPACQUIRED_V6 (0x00000002L) #define SL_DEVICE_EVENT_DROPPED_NETAPP_IP_LEASED (0x00000004L) #define SL_DEVICE_EVENT_DROPPED_NETAPP_IP_RELEASED (0x00000008L) #define SL_DEVICE_EVENT_DROPPED_NETAPP_IPV4_LOST (0x00000010L) #define SL_DEVICE_EVENT_DROPPED_NETAPP_DHCP_ACQUIRE_TIMEOUT (0x00000020L) #define SL_DEVICE_EVENT_DROPPED_NETAPP_IP_COLLISION (0x00000040L) #define SL_DEVICE_EVENT_DROPPED_NETAPP_IPV6_LOST (0x00000080L)
Hmm, OK, that certainly looks like a list of events. But from doing the WLAN events, I knew that those event IDs were in wlan.h. So I thought, wait, why are NetApp event IDs in device.h? So I looked in netapp.h and here's what I found:
/* NetApp user events */
typedef enum
{
SL_NETAPP_EVENT_IPV4_ACQUIRED = 1,
SL_NETAPP_EVENT_IPV6_ACQUIRED,
SL_NETAPP_EVENT_IP_COLLISION,
SL_NETAPP_EVENT_DHCPV4_LEASED,
SL_NETAPP_EVENT_DHCPV4_RELEASED,
SL_NETAPP_EVENT_HTTP_TOKEN_GET,
SL_NETAPP_EVENT_HTTP_TOKEN_POST,
SL_NETAPP_EVENT_IPV4_LOST,
SL_NETAPP_EVENT_DHCP_IPV4_ACQUIRE_TIMEOUT,
SL_NETAPP_EVENT_IPV6_LOST,
SL_NETAPP_EVENT_MAX
} SlNetAppEventId_e;
Now I'm thinking, wait, these look like the macros/enumerations I should be using, not the "SL_DEVICE_EVENT_DROPPED" macros. But wait, how did the network terminal app ever work if it was using the wrong macros?
The answer: sheer bloody coincidence.
| Device macro | NetApp enum | Integer value |
SL_DEVICE_EVENT_DROPPED_NETAPP_IPACQUIRED |
SL_NETAPP_EVENT_IPV4_ACQUIRED |
1 (0x00000001L) |
SL_DEVICE_EVENT_DROPPED_NETAPP_IPACQUIRED_V6 |
SL_NETAPP_EVENT_IPV6_ACQUIRED |
2 (0x00000002L) |
SL_DEVICE_EVENT_DROPPED_NETAPP_IP_LEASED |
SL_NETAPP_EVENT_DHCPV4_LEASED |
4 (0x00000004L) |
SL_DEVICE_EVENT_DROPPED_NETAPP_IP_RELEASED |
SL_NETAPP_EVENT_IPV4_LOST |
8 (0x00000008L) |
By pure luck, the Device.h macros, which are intended to be bitmasks, happened to equal the value of the relevant NetApp event IDs. In the case of "IP released", the network terminal app was actually reporting the "IPv4 Lost" event, which likely coincides with the DHCPv4 lease released event.
I searched through the rest of the SDK directory, and the "network_terminal" app is the only one that appears to misuse the "SL_DEVICE_EVENT_DROPPED" macros; all the other example applications use the "SL_NETAPP_EVENT" enumerations as intended.
However, the problem is that "network_terminal" is kinda your featured example application for users of the CC3120 SDK. And I've found at least two examples in the forums, linked here and here, where users have duplicated the misuse of these macros, so they're obviously getting that behavior from the example.
The "network_terminal" example needs to have its SimpleLinkNetAppEventHandler() function corrected, so that users know to use the "SL_NETAPP_EVENT" enumerations as intended.
(Currently using simplelink_msp432_sdk_wifi_plugin_1_40_00_02)

