ulwip - lwip integration in user space (under development)#
Adapted Air780E Air780EP
Note
This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!
Example
--[[
Note: This library is under development and the interface may change at any time.
LWIP integration in user space, which is used to support network integration of lwip's netif to directly control the sending and receiving of MAC packets/IP packets in lua code.
The overall data path is as follows
lua Code-> ulwip.input -> lwip(netif->input) -> lwip processing logic-> luatos socket framework
lua code <- ulwip callback function <- lwip(netif->low_level_output) <- lwip processing logic <- luatos socket framework
Application example:
1. Air601 The wifi module of is used as the controlled terminal to send and receive MAC packets through UART/SPI to realize the function of Air780E/Air780EP integrated wifi module
2. Use Ethernet modules such as W5500/CH395/ENC28J60 to control the mac packet sending and receiving in the user's lua code and integrate it into the luatos socket framework
3. Through the Bluetooth module, integrated lowpan6
-- In development, please pay attention https://github.com/wendal/xt804-spinet
]]
ulwip.setup(adapter_index, mac, output_lua_ref, opts)#
Initialization lwip netif
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
adapter_index Adapter Number |
string |
mac network card mac address |
function |
output_lua_ref callback function with parameters(adapter_index, data) |
table |
Additional parameters, such {mtu=1500, flags=(ulwip.FLAG_BROADCAST | ulwip.FLAG_ETHARP)} |
Return Value
return value type |
explanation |
---|---|
boolean |
Success or not |
Examples
-- Initialize an adapter and set the callback function
ulwip.setup(socket.LWIP_STA, string.fromHex("18fe34a27b69"), function(adapter_index, data)
log.info("ulwip", "output_lua_ref", adapter_index, data:toHex())
end)
-- Note that after setup, the state of netif is down, and only after ulwip.updown(adapter_index, true) is called can data be sent and received normally.
-- Additional Parameters Configuring table Optional Values
-- mtu, Default 1460
-- flags, Default ulwip.FLAG_BROADCAST | ulwip.FLAG_ETHARP | ulwip.FLAG_ETHERNET | ulwip.FLAG_IGMP | ulwip.FLAG_MLD6
-- zbuff_out The callback function accepts zbuff as an argument, and the default false
-- reverse Local lwip device, flip call logic, default false, this parameter is designed to intercept the hardware networking data of the current device
ulwip.updown(adapter_index, up)#
Set the state of netif
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
adapter_index Adapter Number |
boolean |
up true is up, false is down |
Return Value
return value type |
explanation |
---|---|
boolean |
Success or not |
Examples
-- Reference ulwip.setup
ulwip.link(adapter_index, up)#
Set physical link status for netif
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
adapter_index Adapter Number |
boolean |
up true is up, false is down |
Return Value
return value type |
explanation |
---|---|
boolean |
Current Status |
Examples
-- Reference ulwip.setup
ulwip.input(adapter_index, data, len, offset)#
Enter data to netif
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
adapter_index Adapter Number |
string/userdata |
data Data entered |
int |
If data is zbuff, len is used of zbuff by default, which is invalid for string. |
int |
If data is zbuff, offset is the starting position of data, the default value is 0, which is invalid for string. |
Return Value
return value type |
explanation |
---|---|
boolean |
Success or not |
Examples
-- Reference ulwip.setup
ulwip.dhcp(adapter_index, up)#
Startup or Shutdown dhcp
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
adapter_index Adapter Number |
boolean |
up true to start, false to close |
Return Value
return value type |
explanation |
---|---|
boolean |
Current Status |
Examples
-- Reference ulwip.setup
ulwip.ip(adapter_index, ip, netmask, gw)#
set or obtain ip information
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
adapter_index Adapter Number |
string |
ip IP Address, which can be left blank when obtaining only |
string |
netmask Subnet mask, which can be left blank when only obtaining |
string |
gw Gateway address, which can be left blank when obtaining only |
Return Value
return value type |
explanation |
---|---|
string |
ip address, subnet mask, gateway address |
Examples
-- Get Existing Value
local ip, netmask, gw = ulwip.ip(socket.LWIP_STA)
-- Set New Value
ulwip.ip(socket.LWIP_STA, "192.168.0.1", "255.255.255.0", "192.168.0.1")
ulwip.reg(adapter_index)#
register netif to luatos socket
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
adapter_index Adapter Number |
Return Value
return value type |
explanation |
---|---|
boolean |
Success or not |
Examples
-- Reference ulwip.setup
ulwip.xt804_xfer(spi_id, cs_pin, addr, zbuff, len, offset, auto_seek, auto_len)#
Operation XT804 for SPI fast transceiver
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
spi_id SPI The ID number |
int |
cs_pin CS GPIO number of the foot |
int |
addr register address |
zbuff |
zbuff Object |
int |
len Length |
int |
offset offset, default buff:used() |
boolean |
auto_seek Whether to move offset automatically, default false |
int |
auto_len Automatic slice length, automatically selected by register by default |
Return Value
return value type |
explanation |
---|---|
nil |
No return value |
Examples
-- This function is an auxiliary function