initial commit
This commit is contained in:
47
lib/amb1_sdk/common/example/rarp/example_rarp.c
Normal file
47
lib/amb1_sdk/common/example/rarp/example_rarp.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <netif/etharp.h>
|
||||
#include "wifi_conf.h"
|
||||
|
||||
|
||||
#define RARP_THREAD_STACK_SIZE 200
|
||||
|
||||
const struct eth_addr macbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}};
|
||||
extern struct netif xnetif[NET_IF_NUM];
|
||||
|
||||
void rarp_retrieve(uint8_t *rarp_ip, uint8_t *rarp_mac) {
|
||||
printf("\n\rThe IP of device %02x:%02x:%02x:%02x:%02x:%02x is: %d.%d.%d.%d\r\n",
|
||||
rarp_mac[0], rarp_mac[1], rarp_mac[2], rarp_mac[3], rarp_mac[4], rarp_mac[5],
|
||||
rarp_ip[0], rarp_ip[1], rarp_ip[2], rarp_ip[3]);
|
||||
}
|
||||
|
||||
static void rarp_thread(void *param)
|
||||
{
|
||||
printf("\r\n\r\n\r\n>>>>>>>>>>>>>>>rarp example<<<<<<<<<<<<<<<<<\r\n\r\n\r\n");
|
||||
vTaskDelay(10000);
|
||||
uint8_t *mac, *ip, *netmask, *gw;
|
||||
err_t result;
|
||||
|
||||
while(wifi_is_ready_to_transceive(RTW_STA_INTERFACE) != RTW_SUCCESS){
|
||||
printf("\r\n\r\n\r\n>>>>>>>>>>>>>>Wifi is disconnected!!Please connect!!<<<<<<<<<<<<<<<<<\r\n\r\n\r\n");
|
||||
vTaskDelay(10000);
|
||||
}
|
||||
|
||||
rarp_retrieve_hook_callback(rarp_retrieve);
|
||||
|
||||
for(int i = 0; i < 3; i ++){
|
||||
printf("\n\r\n\retharp_raw: sending raw RARP packet.\n\r\n\r");
|
||||
etharp_raw(&xnetif[0], (struct eth_addr *)xnetif[0].hwaddr, &macbroadcast,
|
||||
(struct eth_addr *)xnetif[0].hwaddr, IP_ADDR_ANY,
|
||||
(struct eth_addr *)xnetif[0].hwaddr, IP_ADDR_ANY, RARP_REQUEST);
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void example_rarp(void){
|
||||
if(xTaskCreate(rarp_thread, ((const char*)"rarp_thread"), RARP_THREAD_STACK_SIZE, NULL, 1 , NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(rarp_thread) failed\n\r", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
8
lib/amb1_sdk/common/example/rarp/example_rarp.h
Normal file
8
lib/amb1_sdk/common/example/rarp/example_rarp.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef EXAMPLE_RARP_H
|
||||
#define EXAMPLE_RARP_H
|
||||
|
||||
void example_rarp(void);
|
||||
|
||||
|
||||
#endif /* EXAMPLE_RARP_H */
|
||||
|
||||
20
lib/amb1_sdk/common/example/rarp/readme.txt
Normal file
20
lib/amb1_sdk/common/example/rarp/readme.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
RARP EXAMPLE
|
||||
|
||||
Description:
|
||||
In this example, it will send rarp request for 3 times. And the rarp reply callback will print the received reply IP address.
|
||||
|
||||
Configuration:
|
||||
[platform_opts.h]
|
||||
#define CONFIG_EXAMPLE_RARP 1
|
||||
|
||||
Execution:
|
||||
You need to connect to WiFi manually by AT command. After connected the rarp request will be sent.
|
||||
|
||||
RARP server:
|
||||
For Ubuntu, you can try to setup the RARP server as doing this:
|
||||
<EFBFBD> apt-get install rarpd
|
||||
<EFBFBD> touch /etc/ethers
|
||||
<EFBFBD> add <20>00:e0:4c:87:xx:xx(Ameba<62>s MAC) client<6E> in /etc/ethers
|
||||
<EFBFBD> add<64>192.168.1.xx(Ameba<62>s ip) client<6E> in /etc/hosts
|
||||
|
||||
|
||||
Reference in New Issue
Block a user