Skip to content

Commit c225965

Browse files
committed
Add command to set nina-fw system time
1 parent b846a55 commit c225965

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

src/WiFi.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ unsigned long WiFiClass::getTime()
360360
return WiFiDrv::getTime();
361361
}
362362

363+
int WiFiClass::setTime(unsigned long unixTime)
364+
{
365+
return WiFiDrv::setTime(unixTime);
366+
}
367+
363368
void WiFiClass::lowPowerMode()
364369
{
365370
WiFiDrv::setPowerMode(1);

src/WiFi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ class WiFiClass
277277
int hostByName(const char* aHostname, IPAddress& aResult);
278278

279279
unsigned long getTime();
280+
int setTime(unsigned long unixTime);
280281

281282
void lowPowerMode();
282283
void noLowPowerMode();

src/utility/wifi_drv.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,36 @@ uint32_t WiFiDrv::getTime()
862862
return _data;
863863
}
864864

865+
int WiFiDrv::setTime(uint32_t epochTime)
866+
{
867+
WAIT_FOR_SLAVE_SELECT();
868+
// Send Command
869+
SpiDrv::sendCmd(SET_TIME_CMD, PARAM_NUMS_1);
870+
SpiDrv::sendParam((uint8_t*)&epochTime, sizeof(epochTime), LAST_PARAM);
871+
872+
// pad to multiple of 4
873+
int commandSize = 5 + sizeof(epochTime);
874+
while (commandSize % 4) {
875+
SpiDrv::readChar();
876+
commandSize++;
877+
}
878+
879+
SpiDrv::spiSlaveDeselect();
880+
//Wait the reply elaboration
881+
SpiDrv::waitForSlaveReady();
882+
SpiDrv::spiSlaveSelect();
883+
884+
// Wait for reply
885+
uint8_t _data = 0;
886+
uint8_t _dataLen = 0;
887+
if (!SpiDrv::waitResponseCmd(SET_TIME_CMD, PARAM_NUMS_1, &_data, &_dataLen))
888+
{
889+
WARN("error waitResponse");
890+
}
891+
SpiDrv::spiSlaveDeselect();
892+
return _data;
893+
}
894+
865895
void WiFiDrv::setPowerMode(uint8_t mode)
866896
{
867897
WAIT_FOR_SLAVE_SELECT();

src/utility/wifi_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ class WiFiDrv
280280
static const char* getFwVersion();
281281

282282
static uint32_t getTime();
283+
static int setTime(uint32_t epochTime);
283284

284285
static void setPowerMode(uint8_t mode);
285286

src/utility/wifi_spi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ enum {
117117
PREFERENCES_GET = 0x5C,
118118
PREFERENCES_GETTYPE = 0x5D,
119119

120+
// regular format commands
121+
SET_TIME_CMD = 0x5F,
122+
120123
// regular format commands
121124
WRITE_FILE = 0x60,
122125
READ_FILE = 0x61,

0 commit comments

Comments
 (0)