-
Notifications
You must be signed in to change notification settings - Fork 12
Stuck on testing Ethernet Class #14
Changes from 2 commits
a70eb6b
cecb63c
6c04f5d
e26f7cf
0a59373
ce7fca5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "Ethernet_TC.h" | ||
using namespace std; | ||
|
||
TC_ethernet *TC_ethernet::_instance = nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you change the name of the class to match the filename? Please use |
||
|
||
TC_ethernet::TC_ethernet() { | ||
pinMode(4, OUTPUT); | ||
digitalWrite(4, HIGH); | ||
if (Ethernet.begin(mac) == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The IP is either initialized through DHCP in the |
||
Serial.println(F("Failed to configure Ethernet using DHCP")); | ||
Ethernet.begin(mac, defaultIP); | ||
IP = defaultIP; | ||
} | ||
|
||
defaultIP = IPAddress(192, 168, 1, 2); | ||
time_serverIP = IPAddress(132, 163, 97, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does anyone use this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find any references in the original implementation for the Time_server. But I'll remove it for now (since I'm not using it), and add it back in later if it's needed. As for |
||
} | ||
|
||
TC_ethernet *TC_ethernet::getInstance() { | ||
if (_instance == nullptr) { | ||
_instance = new TC_ethernet; | ||
} | ||
return _instance; | ||
} | ||
|
||
void TC_ethernet::renewDHCPLease() { | ||
// unsigned long current_millis = millis(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either take out the commented-out code or (even better), keep track of the previous lease time and the LEASE_INTERVAL as a private instance variable and constant so that this method can be called frequently and it will decide when it is time to renew (rather than that knowledge being in the caller). |
||
|
||
// if (current_millis - previous_lease >= LEASE_INTERVAL) { | ||
Ethernet.maintain(); | ||
// } | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add newline. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Based off Arduino's Ethernet library | ||
Implements a wrapper for the Ethernet Class | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "Ethernet.h" | ||
|
||
class TC_ethernet { | ||
public: | ||
static TC_ethernet *getInstance(); | ||
IPAddress getIP() { | ||
return IP; | ||
}; | ||
void renewDHCPLease(); | ||
|
||
protected: | ||
TC_ethernet(); | ||
|
||
private: | ||
static TC_ethernet *_instance; | ||
byte mac[6] = {0x90, 0xA2, 0xDA, 0x00, 0x00, 0x00}; | ||
IPAddress defaultIP; | ||
IPAddress time_serverIP; | ||
IPAddress IP; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <Arduino.h> | ||
#include <ArduinoUnitTests.h> | ||
|
||
#include "Ethernet_TC.h" | ||
|
||
unittest(test) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that we should be able to do some testing! Get a reference to the singleton, query for the IP, renew the lease, etc. |
||
assertTrue(true); | ||
} | ||
|
||
unittest_main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you actually using anything from
namespace std
or is this just a habit? If you have anything fromstd
then let's reference it directly asstd::
.