-
Notifications
You must be signed in to change notification settings - Fork 0
/
taskDHCP.cpp
51 lines (41 loc) · 1.39 KB
/
taskDHCP.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <Arduino_FreeRTOS.h>
#include "src/Ethernet/Ethernet.h"
#include "src/Ethernet/Dhcp.h"
#include "taskDHCP.h"
#include "taskSettings.h"
#include "taskStatus.h"
#include "taskManager.h"
uint8_t mac[6] = {0x00, 0x08, 0xDC, 0x1D, 0x62, 0x7F};
uint32_t notificationDHCP;
int dhcpStatus;
void TaskDHCP(void *pvParameters) { // DHCP Client
(void) pvParameters;
TickType_t xLastWakeTime;
xLastWakeTime = xTaskGetTickCount();
notificationDHCP = 0;
while ((notificationDHCP & NOTIFY_SETTINGS_READY) != NOTIFY_SETTINGS_READY) {
notificationDHCP = ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
}
DEBUG_PRINT("Hostname: ");
DEBUG_PRINTLN(settings.hostname);
mac[5] = settings.id;
while (Ethernet.begin(mac, settings.hostname) == 0) {
vTaskDelayUntil( &xLastWakeTime, ( 1000 / portTICK_PERIOD_MS ) ); // 1 second
}
notifyTasks(NOTIFY_IP_READY);
DEBUG_PRINT("My IP address: ");
for (uint8_t i = 0; i < 4; i++) {
DEBUG_PRINTDEC(Ethernet.localIP()[i]);
DEBUG_PRINT('.');
}
DEBUG_PRINTLN();
while(1) {
dhcpStatus = Ethernet.maintain();
if (dhcpStatus == DHCP_CHECK_RENEW_OK || dhcpStatus == DHCP_CHECK_REBIND_OK) {
notifyTasks(NOTIFY_IP_READY);
} else if (dhcpStatus == DHCP_CHECK_RENEW_FAIL || dhcpStatus == DHCP_CHECK_REBIND_FAIL) {
notifyTasks(STATUS_INIT);
}
vTaskDelayUntil( &xLastWakeTime, ( 1000 / portTICK_PERIOD_MS ) ); // 1 second
}
}