Network handling
This GOAL core module provides an interface to the application for TCP/IP connections, see Figure 15. A TCP/IP stack is required. The TCP/IP stack must be enabled by the compiler-define GOAL_CONFIG_TCPIP_STACK = 1
.
Â
Figure: topology for net channels
GOAL creates the number of GOAL_CONFIG_NET_CHAN_MAX
net channels during initialization automatically for this purpose. Each net channel can be opened as one of the following network connection types:
GOAL_NET_UDP_SERVER
GOAL_NET_UDP_CLIENT
GOAL_NET_TCP_LISTENER represents the TCP server
GOAL_NET_TCP_CLIENT
The connection between the net channels and the TCP/IP stack is addressed by the local IP address, local netmask and local gateway address. The connection between the TCP/IP Stack to a remote Ethernet device is addressed by the remote IP address, the remote netmask and remote gateway address. The rules for the determination of the local address are shown in Figure 16. The local address is determined during creation of the net channels in the state GOAL_FSA_INIT
automatically. The remote address is configured by calling the function goal_netOpen()
.
Figure: determination of the local address of net channels
Â
The connection to the application is realized by a callback function, see Chapter: Callback functions. Each net channel must be activated before data can be transmitted or received via the net channel. The activation is done by function goal_netActivate()
.
The following options are available to configure the TCP/IP stack:
GOAL_NET_OPTION_NONBLOCK: socket connection between net channel and TCP/IP stack is
0: blocking
1: non-blocking
GOAL_NET_OPTION_BROADCAST:
0: no broadcast reception
1: broadcast reception supported
GOAL_NET_OPTION_TTL:
set TTL value in IP-header
GOAL_NET_OPTION_TOS:
set TOS-value in IP-header
GOAL_NET_OPTION_MCAST_ADD:
enable the specified multicast address for the receipt of multicast packets
GOAL_NET_OPTION_MCAST_DROP:
disable the specified multicast address for the receipt of multicast packets
GOAL_NET_OPTION_REUSEADDR:
0: TCP/IP socket shall be not reusable
1: TCP/IP socket shall be reusable
The options can be can be changed by function goal_netSetOption()
. The availability and the default setting of the options depends on the TCP/IP stack.
GOAL files:
goal_net.[h,c], goal_net_dhcp.[h,c], goal_net_cli.c
example:
…\goal\appl\00410_goal\tcp_client
Configuration
Compiler-defines
The following compiler-defines are available to configure the network handling:
GOAL_CONFIG_TCPIP_STACK:
0: network handling is disabled (default)
1: network handling is enabled
GOAL_CONFIG_NET_CHAN_MAX:
number of network channels (default: 4)
GOAL_CONFIG_DHCP:
0: static assignment of IP-addresses (default)
1: dynamic assignment of IP-addresses via DHCP
GOAL_CONFIG_IP_STATS:
0: output of IP-statistics switched off (default)
1: output of IP-statistics switched on
CM-variables
The following CM-variables are available to configure the network handling:
Table: NET_CM_VAR_IP
CM-Module-ID | GOAL_ID_NET |
CM-variable-ID | 0 |
CM-variable name | NET_CM_VAR_IP |
Description | IP address of first interface |
CM data type | GOAL_CM_IPV4 |
Size | 4 bytes |
Default value | from NVS or 0 |
Â
Table: NET_CM_VAR_ NETMASK
CM-Module-ID | GOAL_ID_NET |
CM-variable-ID | 1 |
CM-variable name | NET_CM_VAR_ NETMASK |
Description | netmask of first interface |
CM data type | GOAL_CM_IPV4 |
Size | 4 bytes |
Default value | from NVS or 0 |
Â
Table: NET_CM_VAR_ GW
CM-Module-ID | GOAL_ID_NET |
CM-variable-ID | 2 |
CM-variable name | NET_CM_VAR_ GW |
Description | gateway of first interface |
CM data type | GOAL_CM_IPV4 |
Size | 4 bytes |
Default value | from NVS or 0 |
Â
Table: NET_CM_VAR_ COMMIT
CM-Module-ID | GOAL_ID_NET |
CM-variable-ID | 3 |
CM-variable name | NET_CM_VAR_ COMMIT |
Description | Write any value to this CM-variable applies the IP settings |
CM data type | GOAL_CM_UINT8 |
Size | 1 byte |
Default value | from NVS or 0 |
Â
Table: NET_CM_VAR_ VALID
CM-Module-ID | GOAL_ID_NET |
CM-variable-ID | 4 |
CM-variable name | NET_CM_VAR_ VALID |
Description | validity of IP address:
|
CM data type | GOAL_CM_UINT8 |
Size | 1 byte |
Default value | from NVS or 0 |
Â
Table: NET_CM_VAR_ DHCP_ENABLED
CM-Module-ID | GOAL_ID_NET |
CM-variable-ID | 5 |
CM-variable name | NET_CM_VAR_ DHCP_ENABLED |
Description | CM-variable to disable/enable DHCP:
|
CM data type | GOAL_CM_UINT8 |
Size | 1 byte |
Default value | from NVS or 0 |
Â
Table: NET_CM_VAR_ DHCP_STATE
CM-Module-ID | GOAL_ID_NET |
CM-variable-ID | 6 |
CM-variable name | NET_CM_VAR_ DHCP_STATE |
Description | CM-variable to indicate the current state of DHCP if DHCP is enabled:
|
CM data type | GOAL_CM_UINT8 |
Size | 1 byte |
Default value | from NVS or 0 |
Â
Table: NET_CM_VAR_ DNS0
CM-Module-ID | GOAL_ID_NET |
CM-variable-ID | 7 |
CM-variable name | NET_CM_VAR_ DNS0 |
Description | first DNS server of the first interface |
CM data type | GOAL_CM_IPV4 |
Size | 4 bytes |
Default value | from NVS or 0 |
Â
Table: NET_CM_VAR_ DNS1
CM-Module-ID | GOAL_ID_NET |
CM-variable-ID | 8 |
CM-variable name | NET_CM_VAR_ DNS1 |
Description | second DNS server of the first interface |
CM data type | GOAL_CM_IPV4 |
Size | 4 bytes |
Default value | from NVS or 0 |
Â
Table: NET_CM_VAR_ HOSTNAME
CM-Module-ID | GOAL_ID_NET |
CM-variable-ID | 9 |
CM-variable name | NET_CM_VAR_ HOSTNAME |
Description | host name of the first interface |
CM data type | GOAL_CM_STRING |
Size | 20 bytes |
Default value | from NVS or 0 |
Callback functions
The user of this module can specify the following callback function for each network channel:
Table: Callback function cbNetFunc()
Prototype | void cbNetFunc(GOAL_NET_CB_TYPE_T cbType, struct GOAL_NET_CHAN_T *pChan, struct GOAL_BUFFER_T *pBuf) | |
Description | This callback function is used for the following operations:
| |
Parameters | cbType | type of operation:
|
pChan | handle of the network channel | |
pBuf | for GOAL_NET_CB_NEW_DATA: buffer with the received data | |
Return values | none | |
Category | optional | |
Registration | during runtime via function goal_netOpen() |
IP statistics
GOAL provides the possibility to analyze communication problems by IP statistics. The supported IP statistics bases on /RFC_1213/ and depend on the platform. GOAL provides the following typical IP statistics:
Table: provided IP statistic by GOAL
GOAL number of IP statistic | Description /RFC_1213/ | |
---|---|---|
Number | Identifier (object type) | |
0 | GOAL_NET_IP_STATS_IPINHDRERRORS | The number of input datagrams discarded due to errors in their IP headers, including bad checksums, version number mismatch, other format errors, time-to-live exceeded, errors discovered in processing their IP options, etc. |
1 | GOAL_NET_IP_STATS_IPINADDRERRORS | The number of input datagrams discarded because the IP address in their IP headers destination field was not a valid address to be received at this entity. This count includes invalid addresses and addresses of unsupported classes. For entities which are not IP gateways and therefore do not forward datagrams, this counter includes datagrams discarded because the destination address was not a local address. |
2 | GOAL_NET_IP_STATS_IPINUNKNOWNPROTOS | The number of locally-addressed datagrams received successfully but discarded because of an unknown or unsupported protocol. |
3 | GOAL_NET_IP_STATS_IPINDISCARDS | The number of input IP datagrams for which no problems were encountered to prevent their continued processing, but which were discarded. Note that this counter does not include any datagrams discarded while awaiting re-assembly. |
4 | GOAL_NET_IP_STATS_IPINDELIVERS | The total number of input datagrams successfully delivered to IP user-protocols (including ICMP). |
5 | GOAL_NET_IP_STATS_IPOUTREQUESTS | The total number of IP datagrams which local IP user-protocols (including ICMP) supplied to IP in requests for transmission. Note that this counter does not include any datagrams counted in 14/GOAL_NET_IP_STATS_IPFORWDATAGRAMS. |
6 | GOAL_NET_IP_STATS_IPOUTDISCARDS | The number of output IP datagrams for which no problem was encountered to prevent their transmission to their destination, but which were discarded. Note that this counter would include datagrams counted in 14/GOAL_NET_IP_STATS_IPFORWDATAGRAMS if any such packets met this discard criterion. |
7 | GOAL_NET_IP_STATS_IPOUTNOROUTES | The number of IP datagrams discarded because no route could be found to transmit them to their destination. Note that this counter includes any packets counted in 14/GOAL_NET_IP_STATS_IPFORWDATAGRAMS which meet this "no-route" criterion. Note that this includes any datagram which a host cannot route because all of its default gateways are down. |
8 | GOAL_NET_IP_STATS_IPREASMOKS | The number of IP datagrams successfully reassembled. |
9 | GOAL_NET_IP_STATS_IPREASMFAILS | The number of failures detected by the IP reassembly algorithm. Note that this is not necessarily a count of discarded IP fragments since some algorithms can lose track of the number of fragments by combining them as they are received. |
10 | GOAL_NET_IP_STATS_IPFRAGOKS | The number of IP datagrams that have been successfully fragmented at this entity. |
11 | GOAL_NET_IP_STATS_IPFRAGFAILS | The number of IP datagrams that have been discarded because they needed to be fragmented at this entity but could not be. |
12 | GOAL_NET_IP_STATS_IPFRAGCREATES | The number of IP datagram fragments that have been generated as a result of fragmentation at this entity. |
13 | GOAL_NET_IP_STATS_IPREASMREQGDS | The number of IP fragments received which needed to be reassembled at this entity. |
14 | GOAL_NET_IP_STATS_IPFORWDATAGRAMS | The number of input datagrams for which this entity was not their final IP destination, as a result of which an attempt was made to find a route to forward them to that final destination. In entities which do not act as IP gateways, this counter will include only those packets which were source-routed via this entity, and the source-route option processing was successful. |
15 | GOAL_NET_IP_STATS_IPINRECEIVES | The total number of input datagrams received from interfaces, including those received in error. |
16 | GOAL_NET_IP_STATS_TCPACTIVEOPENS | The number of times TCP connections have made a direct transition from the CLOSED state to the SYN-SENT state. |
17 | GOAL_NET_IP_STATS_TCPPASSIVEOPENS | The number of times TCP connections have made a direct transition from the LISTEN state to the SYN-RCVD state. |
18 | GOAL_NET_IP_STATS_TCPATTEMPTFAILS | The number of times TCP connections have made a direct transition from either the SYN-SENT or SYN-RCVD state to the CLOSED state, plus the number of times TCP connections have made a direct transition from the SYN-RCVD state to the LISTEN state. |
19 | GOAL_NET_IP_STATS_TCPESTABRESETS | The number of times TCP connections have made a direct transition from either the ESTABLISHED or CLOSE-WAIT state to the CLOSE state. |
20 | GOAL_NET_IP_STATS_TCPOUTSEGS | The total number of segments sent, including those on current connections but excluding those containing only retransmitted octets. |
21 | GOAL_NET_IP_STATS_TCPRETRANSSEGS | The total number of segments retransmitted. That is the number of TCP segments transmitted containing one or more previously transmitted. |
22 | GOAL_NET_IP_STATS_TCPINSEGS | The total number of segments received, including those received in error. This count includes segments received on currently established connections. |
23 | GOAL_NET_IP_STATS_TCPINERRS | The total number of segments received in error. |
24 | GOAL_NET_IP_STATS_TCPOUTRSTS | The number of TCP segments sent containing the RST flag. |
25 | GOAL_NET_IP_STATS_UDPINDATAGRAMS | The total number of UDP datagrams delivered to UDP user. |
26 | GOAL_NET_IP_STATS_UDPNOPORTS | The total number of received UDP datagrams for which there was no application at the destination port. |
27 | GOAL_NET_IP_STATS_UDPINERRORS | The number of received UDP datagrams that could not be delivered for reasons other than the lack of an application at the destination port. |
28 | GOAL_NET_IP_STATS_UDPOUTDATAGRAMS | The total number of UDP datagrams sent from this entity. |
29 | GOAL_NET_IP_STATS_ICMPINMSGS | The total number of ICMP messages which the entity received. Note that this counter includes all those counted by 30/ GOAL_NET_IP_STATS_ICMPINERRORS. |
30 | GOAL_NET_IP_STATS_ICMPINERRORS | The number of ICMP messages which the entity received but determined as having ICMP-specific errors. |
31 | GOAL_NET_IP_STATS_ICMPINDESTUNREACHS | The number of ICMP Destination Unreachable messages received. |
32 | GOAL_NET_IP_STATS_ICMPINTIMEEXDS | The number of ICMP Time Exceeded messages received. |
33 | GOAL_NET_IP_STATS_ICMPINPARMPROBS | The number of ICMP Parameter Problem messages received. |
34 | GOAL_NET_IP_STATS_ICMPINSRCQUENCHS | The number of ICMP Source Quench messages received. |
35 | GOAL_NET_IP_STATS_ICMPINREDIRECTS | The number of ICMP Redirect messages received. |
36 | GOAL_NET_IP_STATS_ICMPINECHOS | The number of ICMP Echo (request) messages received. |
37 | GOAL_NET_IP_STATS_ICMPINECHOREPS | The number of ICMP Echo Reply messages received. |
38 | GOAL_NET_IP_STATS_ICMPINTIMESTAMPS | The number of ICMP Timestamp (request) messages received. |
39 | GOAL_NET_IP_STATS_ICMPINTIMESTAMPREPS | The number of ICMP Timestamp Reply messages received. |
40 | GOAL_NET_IP_STATS_ICMPINADDRMASKS | The number of ICMP Address Mask Request messages received. |
41 | GOAL_NET_IP_STATS_ICMPINADDRMASKREPS | The number of ICMP Address Mask Reply messages received. |
42 | GOAL_NET_IP_STATS_ICMPOUTMSGS | The total number of ICMP messages which this entity attempted to send. Note that this counter includes all those counted by 43/ GOAL_NET_IP_STATS_ICMPOUTERRORS. |
43 | GOAL_NET_IP_STATS_ICMPOUTERRORS | The number of ICMP messages which this entity did not send due to problems discovered within ICMP such as a lack of buffers. This value should not include errors discovered outside the ICMP layer such as the inability of IP zo route the resultant datagram. In some implementations there may be no types of error which contribute to this counter's value. |
44 | GOAL_NET_IP_STATS_ICMPOUTDESTUNREACHS | The number of ICMP Destination Unreachable message sent. |
45 | GOAL_NET_IP_STATS_ICMPOUTTIMEEXCDS | The number of ICMP Time Exceeded messages sent. |
46 | GOAL_NET_IP_STATS_ICMPOUTECHOS | The number of ICMP Echo (request) messages sent. |
47 | GOAL_NET_IP_STATS_ICMPOUTECHOREPS | The number of TCMP Echo Reply messages sent. |
48 | GOAL_NET_IP_STATS_IFINOCTETS | The total number of octets received on the interface, including framing characters. |
49 | GOAL_NET_IP_STATS_IFINUCASTPKTS | The number of subnetwork-unicast packets delivered to a higher-layer protocol. |
50 | GOAL_NET_IP_STATS_IFINNUCASTPKTS | The number of non-unicast packets delivered to a higher-layer protocol. |
51 | GOAL_NET_IP_STATS_IFINDISCARDS | The number of inbound packet which were chosen to be discarded even though no errors had been detected to prevent their being deliverable to a higher-layer protocol. |
52 | GOAL_NET_IP_STATS_IFINERRORS | The number of inbound packets that contained errors preventing them from being deliverable to a higher-layer protocol. |
53 | GOAL_NET_IP_STATS_IFINUNKNOWNPROTOS | The number of packets received via the interface which were discarded because of an unknown or unsupported protocol. |
54 | GOAL_NET_IP_STATS_IFOUTOCTETS | The total number of octets transmitted out of the interface, including framing characters. |
55 | GOAL_NET_IP_STATS_IFOUTUCASTPKTS | The total number of packets that higher-level protocols requested be transmitted to a subnetwork-unicast address, including those that were discarded or not sent. |
56 | GOAL_NET_IP_STATS_IFOUTNUCASTPKTS | The total number of packets that higher-level protocols requested be transmitted to a non-unicast address, including those that were discarded or not sent. |
57 | GOAL_NET_IP_STATS_IFOUTDISCARDS | The number of outbound packets which were chosen to be discarded even though no errors had been detected to prevent their being transmitted. One possible reason for discarding such a packet could be to free up buffer space. |
58 | GOAL_NET_IP_STATS_IFOUTERRORS | The number of outbound packets that could not be transmitted because of errors. |
Each platform manages the support of the IP statistics listed in Table 5 by a bit-coded mask of the GOAL data type uint64_t
. Bit 0 of the mask represents the IP statistic with the GOAL number 0.
The access to the statistic values are realized about the Ethernet commands:
GOAL_NET_CMD_IP_STATS_MASK_GET:
read the supported IP statistics from the platform as bit-coded mask for all port
GOAL_NET_CMD_IP_STATS_GET:
read the values of all supported IP statistics
GOAL_NET_CMD_IP_STATS_RST:
reset IP statistics;
it is platform-specific which statistics of one or all ports are reset
The IP commands are executed by function goal_targetNetCmd()
.
Platform API
GOAL requires the following indication function for the handling of net channels:
Table: goal_targetNetGetHandleSize()
Prototype | uint32_t goal_targetNetGetHandleSize(void) |
Description | This indication function returns the memory size, which is needed for a net channel handle. |
Parameters | None |
Return values | size of a net channel handle in bytes |
Category | Mandatory |
Table: goal_targetNetRecv()
Prototype | GOAL_STATUS_T goal_targetNetRecv(GOAL_BUFFER_T **ppBuf) | |
Description | This indication function is called everytime a TCP/IP packet is received. | |
Parameters | ppBuf | GOAL Ethernet buffer containing the received packet |
Return values | GOAL return status, see Chapter: GOAL status | |
Category | Mandatory |
Table: goal_targetNetIpSet()
Prototype | GOAL_STATUS_T goal_targetNetIpSet(uint32_t addrIp, uint32_t addrMask, uint32_t addrGw, GOAL_BOOL_T flgTemp) | |
Description | This indication function allows to set the IP configuration for the TCP/IP stack. This function is called in state GOAL_FSA_INIT normally. | |
Parameters | addrIp | local IP address |
addrMask | local subnet mask | |
addrGw | local gateway address | |
flgTemp | kind of the IP configuration
| |
Return values | GOAL return status, see Chapter: GOAL status | |
Category | Mandatory |
Table: goal_targetNetIpGet()
Prototype | GOAL_STATUS_T goal_targetNetIpGet(uint32_t *pAddrIp, uint32_t *pAddrMask, uint32_t *pAddrGw, GOAL_BOOL_T *pFlgTemp) | |
Description | This indication function returns the current IP configuration used by the TCP/IP stack. | |
Parameters | pAddrIp | current local IP address |
pAddrMask | current local subnet mask | |
pAddrGw | current local gateway address | |
pFlgTemp | current kind of the IP configuration
| |
Return values | GOAL return status, see Chapter: GOAL status | |
Category | Mandatory |
Table: goal_targetNetOpen()
Prototype | GOAL_STATUS_T goal_targetNetOpen(void **ppTargetHandle, GOAL_NET_TYPE_T type, GOAL_NET_ADDR_T *pAddr) | |
Description | This indication function allows to open a net channel. | |
Parameters | ppTargetHandle | handle for the net channel |
type | connection type:
| |
pAddr | local and maybe remote address of the net channel | |
Return values | GOAL return status, see Chapter: GOAL status | |
Category | Mandatory |
Table: goal_targetNetReopen()
Prototype | GOAL_STATUS_T goal_targetNetReopen(char *pTgtHandle, GOAL_NET_TYPE_T type, GOAL_NET_ADDR_T *pAddr) | |
Description | This indication function allows to reopen the net channel specified by the handle. | |
Parameters | pTgtHandle | handle for the net channel |
type | connection type:
| |
pAddr | local and maybe remote address of the net channel | |
Return values | GOAL return status, see Chapter: GOAL status | |
Category | Mandatory |
Table: goal_targetNetClose()
Prototype | GOAL_STATUS_T goal_targetNetClose(void *pTargetHandle, GOAL_NET_TYPE_T type) | |
Description | This indication function allows to close the net channel specified by the handle. | |
Parameters | pTargetHandle | handle for the net channel |
type | connection type:
| |
Return values | GOAL return status, see Chapter: GOAL status | |
Category | Mandatory |
Table: goal_targetNetActivate()
Prototype | GOAL_STATUS_T goal_targetNetActivate(void *pTargetHandle) | |
Description | This indication function allows to activate the net channel specified by the handle. | |
Parameters | pTargetHandle | handle for the net channel |
Return values | GOAL return status, see Chapter: GOAL status | |
Category | Mandatory |
Table: goal_targetNetDeactivate()
Prototype | GOAL_STATUS_T goal_targetNetDeactivate(void *pTargetHandle) | |
Description | This indication function allows to deactivate the net channel specified by the handle. | |
Parameters | pTargetHandle | handle for the net channel |
Return values | GOAL return status, see Chapter: GOAL status | |
Category | Mandatory |
Table: goal_targetNetSend()
Prototype | GOAL_STATUS_T goal_targetNetSend(void *pTargetHandle, GOAL_NET_TYPE_T type, GOAL_NET_ADDR_T *pAddr, GOAL_BUFFER_T *pBuf) | |
Description | This indication function transmit data via the net channel to the TCP/IP stack. | |
Parameters | pTargetHandle | handle for the net channel |
type | connection type:
| |
pAddr | local and maybe remote address of the net channel | |
pBuf | buffer with the packet to transmit | |
Return values | GOAL return status, see Chapter: GOAL status | |
Category | Mandatory |
Table: goal_targetNetOptSet()
Prototype | GOAL_STATUS_T goal_targetNetOptSet(void *pTargetHandle, GOAL_NET_TYPE_T type, GOAL_NET_OPTION_T option, void *pValue) | |
Description | This indication function allows to change one property of the net channel. | |
Parameters | pTargetHandle | handle for the net channel |
type | connection type:
| |
option | property of the net channel:
| |
pValue | value of the selected option | |
Return values | GOAL return status, see Chapter: GOAL status | |
Category | Mandatory |
Table: goal_targetNetPoll()
Prototype | void goal_targetNetPoll(void) |
Description | This indication function is called in the state GOAL_FSA_OPERATION execute loop-controlled actions. |
Parameters | None |
Return values | None |
Category | Mandatory |
Table: goal_targetNetAvail()
Prototype | GOAL_BOOL_T goal_targetNetAvail(void) |
Description | This indication function checks if new data was received. |
Parameters | None |
Return values | state of received data:
|
Category | Mandatory |
Â
Table: goal_targetNetAvail()
Prototype | GOAL_STATUS_T goal_targetNetCmd(GOAL_NET_CMD_T id, GOAL_BOOL_T wrFlag, void *pArg) | |
Description | This indication function allows to execute a net command. | |
Parameters | id | command identifier |
wrFlag | access direction
| |
pArg | argument to the net command | |
Return values | GOAL return status, see Chapter: GOAL status | |
Category | mandatory |
Â
Command line interface
Â
Table: net ip set
Command | net ip set <ip> <netmask> <gateway> | |
Description | Sets the remote IP-address, the netmask and the default gateway of the underlying TCP/IP stack. | |
Parameter | <ip> | The new IP address in the format xxx.xxx.xxx.xxx |
<netmask> | The new netmask in the format xxx.xxx.xxx.xxx | |
<gateway> | The new default gateway in the format xxx.xxx.xxx.xxx |
Table: net ip show
Command | net ip show |
Description | Prints the remote address consisting of the IP-address, netmask and gateway address of the underlying TCP/IP stack to the command line interface. |
Parameter | none |
Â
Implementation guidelines
Configure, open and activate a net channel
All net channels are created automatically in the state
GOAL_FSA_INIT_GOAL
and the local addresses are determined.Set the local IP address in state
GOAL_FSA_INIT
:uint32_t ipAddr; uint32_t netmask; uint32_t gatewayAddr; ipAddr= GOAL_NET_IPV4(192, 168, 0, 100); netmask = GOAL_NET_IPV4(255, 255, 255, 0); gatewayAddr = GOAL_NET_IPV4(0, 0, 0, 0); goal_netIpSet(ipAddr, netmask, gatewayAddr);
Â
Create a callback function to handle actions on the net channel application-specific:
void applNetCallback(GOAL_NET_CB_TYPE_T cbType, struct GOAL_NET_CHAN_T *pChan, struct GOAL_BUFFER_T *pBuf) { … }
Â
Create a handle for the net channel:
GOAL_NET_CHAN_T *pNetChanHdl;
Â
Create the address information of the net channel:
Â
Open a net channel by function
goal_netOpen()
and specify the remote address and a callback function:Â
Maybe change a property of the net channel by function
goal_netSetOption()
, e.g. configure the net channel as non-blocking:Â
Activate the net channel by function
goal_netActivate()
:
Send data
Use a buffer managed about a GOAL queue to transmit data.
Create a handle for the queue:
Â
Create a queue with max. 10 buffers and allocate the memory for all buffers. The size of each buffer is 20 bytes. The queue has to be created by function goal_queueInit() in the state GOAL_FSA_INIT.
Â
Create a handle for a buffer:
Â
Take an uninitialized buffer from the queue:
Â
Initialize the buffer and mark the buffer as used:
Â
Write a value of 4 bytes to the buffer:
Â
Send data by function goal_netSend() and receive data via the specified callback function:
Â
Close and deactivate the net channel by function goal_netClose():