This repository was archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Stuck on testing Ethernet Class #14
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a70eb6b
Stuck on testing Ethernet Class
cecb63c
Clang formating
6c04f5d
Merge branch 'master' into master
e26f7cf
Update .arduino-ci.yml
0a59373
ready for testing
ce7fca5
Merge branch 'master' of github.com:Kavikick/TankControllerLib
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "Ethernet_TC.h" | ||
|
||
Ethernet_TC *Ethernet_TC::_instance = nullptr; | ||
|
||
// Establishes the Ethenet connection and sets class variables | ||
Ethernet_TC::Ethernet_TC() { | ||
pinMode(4, OUTPUT); | ||
digitalWrite(4, HIGH); | ||
if (Ethernet.begin(mac) == 0) { | ||
Serial.println(F("Failed to configure Ethernet using DHCP")); | ||
IPAddress defaultIP = IPAddress(192, 168, 1, 2); | ||
Ethernet.begin(mac, defaultIP); | ||
IP = defaultIP; | ||
} | ||
} | ||
|
||
Ethernet_TC *Ethernet_TC::getInstance() { | ||
if (_instance == nullptr) { | ||
_instance = new Ethernet_TC; | ||
} | ||
return _instance; | ||
} | ||
|
||
void Ethernet_TC::renewDHCPLease() { | ||
unsigned long current_millis = millis(); | ||
|
||
if (current_millis - previous_lease >= LEASE_INTERVAL) { | ||
Ethernet.maintain(); | ||
previous_lease = current_millis; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Based off Arduino's Ethernet library | ||
Implements a wrapper for the Ethernet Class | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "Ethernet.h" | ||
|
||
class Ethernet_TC { | ||
public: | ||
static Ethernet_TC *getInstance(); | ||
IPAddress getIP() { | ||
return IP; | ||
}; | ||
void renewDHCPLease(); | ||
|
||
protected: | ||
Ethernet_TC(); | ||
|
||
private: | ||
static Ethernet_TC *_instance; | ||
byte mac[6] = {0x90, 0xA2, 0xDA, 0x00, 0x00, 0x00}; | ||
IPAddress defaultIP; | ||
IPAddress time_serverIP; | ||
IPAddress IP; | ||
unsigned long previous_lease; | ||
const unsigned long LEASE_INTERVAL = 345600000; // 4 days in milliseconds | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If the
begin()
method is successful, doesIP
get initialized?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.
The IP is either initialized through DHCP in the
begin(mac)
contructor, or (I moved the constructor so it won't be declared unless needed) it will be given a defaultIP with thebegin(mac, IP)
constructor