001 - Setting IP Configuration of Server
The following Page describes, how to configure the used IP configuration. Basically, there two options.
Configuring while Compiling
Use the following defines to set the desired IP configuration. Please note, that the application has to be compiled again each time the define is changed.
#define GOAL_CONFIG_NET_ADDR_IP_DEFAULT GOAL_NET_IPV4(192, 168, 1, 100);
#define GOAL_CONFIG_NET_ADDR_MASK_DEFAULT GOAL_NET_IPV4(255, 255, 255, 0);
#define GOAL_CONFIG_NET_ADDR_GATEWAY_DEFAULT GOAL_NET_IPV4(192, 168, 1, 0);
Configuring while Runtime
The IP Configuration at startup has to be set in the function appl_setup()
like shown below.
static uint32_t ip; /* module global IP address */
static uint32_t nm; /* module global netmask */
static uint32_t gw; /* module global gateway */
GOAL_STATUS_T appl_setup(
void
)
{
GOAL_STATUS_T res; /* GOAL result */
/* set IP address */
ip = GOAL_NET_IPV4(192, 168, 1, 100);
nm = GOAL_NET_IPV4(255, 255, 255, 0);
gw = GOAL_NET_IPV4(192, 168, 1, 0);
res = goal_netIpSet(ip, nm, gw, GOAL_FALSE);
if (GOAL_RES_ERR(res)) {
goal_logErr("Setting IP failed");
return res;
}
It is also possible, to link a specified holding register to the IP configuration. In the following Example, the holding register with the index 3000 is used to set the IP configuration.
GOAL_STATUS_T appl_mbCallback(
...
)
{
switch (id) {
case GOAL_MB_CB_ID_DATA_WRITE:
if ((GOAL_MB_DATA_HOLD_REG == pCb->data[0].dataType) &&
(3000 == pCb->data[1].index)) {
/* parse and set received IP configuration */
ip = (uint32_t) (pCb->data[2].value);
goal_netIpSet(ip, nm, gw, GOAL_FALSE);
}
}
}
Â