PCDU P60 HK Set Update #204

Merged
meierj merged 8 commits from mueller/pcdu-hk-core-sets into develop 2022-04-08 17:48:51 +02:00
13 changed files with 205 additions and 194 deletions
Showing only changes of commit 4e3fa54ae2 - Show all commits

View File

@ -3,7 +3,6 @@
#include "OBSWConfig.h" #include "OBSWConfig.h"
#include "fsfw/datapool/PoolReadGuard.h" #include "fsfw/datapool/PoolReadGuard.h"
#include "fsfw/timemanager/Clock.h" #include "fsfw/timemanager/Clock.h"
#include "mission/utility/compileTime.h" #include "mission/utility/compileTime.h"
#if FSFW_DEV_HYPERION_GPS_CREATE_NMEA_CSV == 1 #if FSFW_DEV_HYPERION_GPS_CREATE_NMEA_CSV == 1

View File

@ -4,7 +4,7 @@
ACUHandler::ACUHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie) ACUHandler::ACUHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie)
: GomspaceDeviceHandler(objectId, comIF, comCookie, ACU::MAX_CONFIGTABLE_ADDRESS, : GomspaceDeviceHandler(objectId, comIF, comCookie, ACU::MAX_CONFIGTABLE_ADDRESS,
ACU::MAX_HKTABLE_ADDRESS, ACU::HK_TABLE_REPLY_SIZE, &acuHkTableDataset), ACU::MAX_HKTABLE_ADDRESS, ACU::HK_TABLE_REPLY_SIZE),
acuHkTableDataset(this) {} acuHkTableDataset(this) {}
ACUHandler::~ACUHandler() {} ACUHandler::~ACUHandler() {}
@ -39,6 +39,13 @@ void ACUHandler::letChildHandleHkReply(DeviceCommandId_t id, const uint8_t *pack
#endif #endif
} }
LocalPoolDataSetBase *ACUHandler::getDataSetHandle(sid_t sid) {
if (sid == acuHkTableDataset.getSid()) {
return &acuHkTableDataset;
}
return nullptr;
}
void ACUHandler::parseHkTableReply(const uint8_t *packet) { void ACUHandler::parseHkTableReply(const uint8_t *packet) {
uint16_t dataOffset = 0; uint16_t dataOffset = 0;
acuHkTableDataset.read(); acuHkTableDataset.read();

View File

@ -31,6 +31,8 @@ class ACUHandler : public GomspaceDeviceHandler {
virtual ReturnValue_t childCommandHook(DeviceCommandId_t cmd, const uint8_t* commandData, virtual ReturnValue_t childCommandHook(DeviceCommandId_t cmd, const uint8_t* commandData,
size_t commandDataLen) override; size_t commandDataLen) override;
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
private: private:
static const DeviceCommandId_t PRINT_CHANNEL_STATS = 51; static const DeviceCommandId_t PRINT_CHANNEL_STATS = 51;

View File

@ -7,20 +7,14 @@
GomspaceDeviceHandler::GomspaceDeviceHandler(object_id_t objectId, object_id_t comIF, GomspaceDeviceHandler::GomspaceDeviceHandler(object_id_t objectId, object_id_t comIF,
CookieIF* comCookie, uint16_t maxConfigTableAddress, CookieIF* comCookie, uint16_t maxConfigTableAddress,
uint16_t maxHkTableAddress, uint16_t hkTableReplySize, uint16_t maxHkTableAddress, uint16_t hkTableReplySize)
LocalPoolDataSetBase* hkTableDataset)
: DeviceHandlerBase(objectId, comIF, comCookie), : DeviceHandlerBase(objectId, comIF, comCookie),
maxConfigTableAddress(maxConfigTableAddress), maxConfigTableAddress(maxConfigTableAddress),
maxHkTableAddress(maxHkTableAddress), maxHkTableAddress(maxHkTableAddress),
hkTableReplySize(hkTableReplySize), hkTableReplySize(hkTableReplySize) {
hkTableDataset(hkTableDataset) {
if (comCookie == nullptr) { if (comCookie == nullptr) {
sif::error << "GomspaceDeviceHandler::GomspaceDeviceHandler: Invalid com cookie" << std::endl; sif::error << "GomspaceDeviceHandler::GomspaceDeviceHandler: Invalid com cookie" << std::endl;
} }
if (hkTableDataset == nullptr) {
sif::error << "GomspaceDeviceHandler::GomspaceDeviceHandler: Invalid hk table data set"
<< std::endl;
}
} }
GomspaceDeviceHandler::~GomspaceDeviceHandler() {} GomspaceDeviceHandler::~GomspaceDeviceHandler() {}
@ -405,14 +399,6 @@ ReturnValue_t GomspaceDeviceHandler::generateRequestFullHkTableCmd(uint16_t hkTa
uint32_t GomspaceDeviceHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 0; } uint32_t GomspaceDeviceHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 0; }
LocalPoolDataSetBase* GomspaceDeviceHandler::getDataSetHandle(sid_t sid) {
if (sid == hkTableDataset->getSid()) {
return hkTableDataset;
} else {
return nullptr;
}
}
void GomspaceDeviceHandler::setModeNormal() { mode = MODE_NORMAL; } void GomspaceDeviceHandler::setModeNormal() { mode = MODE_NORMAL; }
ReturnValue_t GomspaceDeviceHandler::printStatus(DeviceCommandId_t cmd) { ReturnValue_t GomspaceDeviceHandler::printStatus(DeviceCommandId_t cmd) {

View File

@ -39,7 +39,7 @@ class GomspaceDeviceHandler : public DeviceHandlerBase {
*/ */
GomspaceDeviceHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie, GomspaceDeviceHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie,
uint16_t maxConfigTableAddress, uint16_t maxHkTableAddress, uint16_t maxConfigTableAddress, uint16_t maxHkTableAddress,
uint16_t hkTableReplySize, LocalPoolDataSetBase *hkTableDataset); uint16_t hkTableReplySize);
virtual ~GomspaceDeviceHandler(); virtual ~GomspaceDeviceHandler();
/** /**
@ -100,7 +100,7 @@ class GomspaceDeviceHandler : public DeviceHandlerBase {
*/ */
virtual void letChildHandleHkReply(DeviceCommandId_t id, const uint8_t *packet) = 0; virtual void letChildHandleHkReply(DeviceCommandId_t id, const uint8_t *packet) = 0;
virtual LocalPoolDataSetBase *getDataSetHandle(sid_t sid) override; virtual LocalPoolDataSetBase *getDataSetHandle(sid_t sid) = 0;
/** /**
* @brief Can be overriden by child classes to implement device specific commands. * @brief Can be overriden by child classes to implement device specific commands.

View File

@ -6,9 +6,9 @@
P60DockHandler::P60DockHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie) P60DockHandler::P60DockHandler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie)
: GomspaceDeviceHandler(objectId, comIF, comCookie, P60Dock::MAX_CONFIGTABLE_ADDRESS, : GomspaceDeviceHandler(objectId, comIF, comCookie, P60Dock::MAX_CONFIGTABLE_ADDRESS,
P60Dock::MAX_HKTABLE_ADDRESS, P60Dock::HK_TABLE_REPLY_SIZE, P60Dock::MAX_HKTABLE_ADDRESS, P60Dock::HK_TABLE_REPLY_SIZE),
&p60dockHkTableDataset), coreHk(this),
p60dockHkTableDataset(this) {} auxHk(this) {}
P60DockHandler::~P60DockHandler() {} P60DockHandler::~P60DockHandler() {}
@ -23,7 +23,7 @@ void P60DockHandler::letChildHandleHkReply(DeviceCommandId_t id, const uint8_t *
* Hk table will be sent to the commander if hk table request was not triggered by the * Hk table will be sent to the commander if hk table request was not triggered by the
* P60DockHandler itself. * P60DockHandler itself.
*/ */
handleDeviceTM(&p60dockHkTableDataset, id, true); handleDeviceTM(&coreHk, id, true);
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_P60DOCK == 1 #if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_P60DOCK == 1
p60dockHkTableDataset.read(); p60dockHkTableDataset.read();
@ -73,8 +73,12 @@ void P60DockHandler::letChildHandleHkReply(DeviceCommandId_t id, const uint8_t *
void P60DockHandler::parseHkTableReply(const uint8_t *packet) { void P60DockHandler::parseHkTableReply(const uint8_t *packet) {
using namespace P60Dock; using namespace P60Dock;
uint16_t dataOffset = 0; uint16_t dataOffset = 0;
PoolReadGuard pg(&p60dockHkTableDataset); PoolReadGuard pg0(&coreHk);
if (pg.getReadResult() != HasReturnvaluesIF::RETURN_OK) { PoolReadGuard pg1(&auxHk);
if (pg0.getReadResult() != HasReturnvaluesIF::RETURN_OK or
pg1.getReadResult() != HasReturnvaluesIF::RETURN_OK) {
coreHk.setValidity(false, true);
auxHk.setValidity(false, true);
return; return;
} }
/** /**
@ -83,129 +87,116 @@ void P60DockHandler::parseHkTableReply(const uint8_t *packet) {
*/ */
dataOffset += 12; dataOffset += 12;
for (uint8_t idx = 0; idx < hk::CHNLS_LEN; idx++) { for (uint8_t idx = 0; idx < hk::CHNLS_LEN; idx++) {
p60dockHkTableDataset.currents[idx] = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1); coreHk.currents[idx] = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
} }
for (uint8_t idx = 0; idx < hk::CHNLS_LEN; idx++) { for (uint8_t idx = 0; idx < hk::CHNLS_LEN; idx++) {
p60dockHkTableDataset.voltages[idx] = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1); coreHk.voltages[idx] = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
} }
for (uint8_t idx = 0; idx < hk::CHNLS_LEN; idx++) { for (uint8_t idx = 0; idx < hk::CHNLS_LEN; idx++) {
p60dockHkTableDataset.outputEnables[idx] = *(packet + dataOffset); coreHk.outputEnables[idx] = *(packet + dataOffset);
dataOffset += 3; dataOffset += 3;
} }
p60dockHkTableDataset.temperature1 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1); coreHk.temperature1 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
p60dockHkTableDataset.temperature2 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1); coreHk.temperature2 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
p60dockHkTableDataset.bootcause = *(packet + dataOffset) << 24 | auxHk.bootcause = *(packet + dataOffset) << 24 |
*(packet + dataOffset + 1) << 16 | *(packet + dataOffset + 1) << 16 | *(packet + dataOffset + 2) << 8 |
*(packet + dataOffset + 3);
dataOffset += 6;
coreHk.bootCount = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6; dataOffset += 6;
p60dockHkTableDataset.bootCount = *(packet + dataOffset) << 24 | auxHk.uptime = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6; dataOffset += 6;
p60dockHkTableDataset.uptime = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | auxHk.resetcause = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
*(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6;
p60dockHkTableDataset.resetcause = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
p60dockHkTableDataset.battMode = *(packet + dataOffset); coreHk.battMode = *(packet + dataOffset);
dataOffset += 3; dataOffset += 3;
p60dockHkTableDataset.heaterOn = *(packet + dataOffset); auxHk.heaterOn = *(packet + dataOffset);
/* + 13 because here begins a new gomspace csp data field */ /* + 13 because here begins a new gomspace csp data field */
dataOffset += 13; dataOffset += 13;
p60dockHkTableDataset.converter5VStatus = *(packet + dataOffset); auxHk.converter5VStatus = *(packet + dataOffset);
dataOffset += 3; dataOffset += 3;
for (uint8_t idx = 0; idx < hk::CHNLS_LEN; idx++) { for (uint8_t idx = 0; idx < hk::CHNLS_LEN; idx++) {
p60dockHkTableDataset.latchups[idx] = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1); auxHk.latchups[idx] = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
} }
p60dockHkTableDataset.dockVbatVoltageValue = auxHk.dockVbatVoltageValue = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
*(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
p60dockHkTableDataset.dockVccCurrent = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1); auxHk.dockVccCurrent = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
p60dockHkTableDataset.batteryCurrent = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1); coreHk.batteryCurrent = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
p60dockHkTableDataset.batteryVoltage = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1); coreHk.batteryVoltage = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
p60dockHkTableDataset.batteryTemperature1 = auxHk.batteryTemperature1 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
*(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
p60dockHkTableDataset.batteryTemperature2 = auxHk.batteryTemperature2 = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
*(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
for (uint8_t idx = 0; idx < NUM_DEVS; idx++) { for (uint8_t idx = 0; idx < NUM_DEVS; idx++) {
p60dockHkTableDataset.devicesType[idx] = *(packet + dataOffset); auxHk.devicesType[idx] = *(packet + dataOffset);
dataOffset += 3; dataOffset += 3;
} }
for (uint8_t idx = 0; idx < NUM_DEVS; idx++) { for (uint8_t idx = 0; idx < NUM_DEVS; idx++) {
p60dockHkTableDataset.devicesStatus[idx] = *(packet + dataOffset); auxHk.devicesStatus[idx] = *(packet + dataOffset);
dataOffset += 3; dataOffset += 3;
} }
p60dockHkTableDataset.dearmStatus = *(packet + dataOffset); auxHk.dearmStatus = *(packet + dataOffset);
dataOffset += 3; dataOffset += 3;
p60dockHkTableDataset.wdtCntGnd = *(packet + dataOffset) << 24 | auxHk.wdtCntGnd = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6; dataOffset += 6;
p60dockHkTableDataset.wdtCntI2c = *(packet + dataOffset) << 24 | auxHk.wdtCntI2c = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6; dataOffset += 6;
p60dockHkTableDataset.wdtCntCan = *(packet + dataOffset) << 24 | auxHk.wdtCntCan = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6; dataOffset += 6;
p60dockHkTableDataset.wdtCntCsp1 = *(packet + dataOffset) << 24 | auxHk.wdtCntCsp1 = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6; dataOffset += 6;
p60dockHkTableDataset.wdtCntCsp2 = *(packet + dataOffset) << 24 | auxHk.wdtCntCsp2 = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6; dataOffset += 6;
p60dockHkTableDataset.wdtGndLeft = *(packet + dataOffset) << 24 | auxHk.wdtGndLeft = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6; dataOffset += 6;
p60dockHkTableDataset.wdtI2cLeft = *(packet + dataOffset) << 24 | auxHk.wdtI2cLeft = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
dataOffset += 6; dataOffset += 6;
p60dockHkTableDataset.wdtCanLeft = *(packet + dataOffset) << 24 | auxHk.wdtCanLeft = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 1) << 16 |
*(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3);
/* +16 because here begins a new gomspace csp packet */ /* +16 because here begins a new gomspace csp packet */
dataOffset += 16; dataOffset += 16;
p60dockHkTableDataset.wdtCspLeft1 = *(packet + dataOffset); auxHk.wdtCspLeft1 = *(packet + dataOffset);
dataOffset += 3; dataOffset += 3;
p60dockHkTableDataset.wdtCspLeft2 = *(packet + dataOffset); auxHk.wdtCspLeft2 = *(packet + dataOffset);
dataOffset += 3; dataOffset += 3;
p60dockHkTableDataset.batteryChargeCurrent = auxHk.batteryChargeCurrent = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
*(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
p60dockHkTableDataset.batteryDischargeCurrent = auxHk.batteryDischargeCurrent = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
*(packet + dataOffset) << 8 | *(packet + dataOffset + 1);
dataOffset += 4; dataOffset += 4;
p60dockHkTableDataset.ant6Depl = *(packet + dataOffset); auxHk.ant6Depl = *(packet + dataOffset);
dataOffset += 3; dataOffset += 3;
p60dockHkTableDataset.ar6Depl = *(packet + dataOffset); auxHk.ar6Depl = *(packet + dataOffset);
p60dockHkTableDataset.setValidity(true, true); coreHk.setValidity(true, true);
auxHk.setValidity(true, true);
} }
ReturnValue_t P60DockHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, ReturnValue_t P60DockHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
@ -260,7 +251,8 @@ ReturnValue_t P60DockHandler::initializeLocalDataPool(localpool::DataPool &local
localDataPoolMap.emplace(pool::P60DOCK_ANT6_DEPL, new PoolEntry<int8_t>({0})); localDataPoolMap.emplace(pool::P60DOCK_ANT6_DEPL, new PoolEntry<int8_t>({0}));
localDataPoolMap.emplace(pool::P60DOCK_AR6_DEPL, new PoolEntry<int8_t>({0})); localDataPoolMap.emplace(pool::P60DOCK_AR6_DEPL, new PoolEntry<int8_t>({0}));
poolManager.subscribeForPeriodicPacket(p60dockHkTableDataset.getSid(), false, 10.0, false); poolManager.subscribeForPeriodicPacket(coreHk.getSid(), false, 10.0, false);
poolManager.subscribeForPeriodicPacket(auxHk.getSid(), false, 30.0, false);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -268,16 +260,17 @@ ReturnValue_t P60DockHandler::printStatus(DeviceCommandId_t cmd) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
switch (cmd) { switch (cmd) {
case (GOMSPACE::PRINT_SWITCH_V_I): { case (GOMSPACE::PRINT_SWITCH_V_I): {
PoolReadGuard pg(&p60dockHkTableDataset); PoolReadGuard pg0(&coreHk);
result = pg.getReadResult(); PoolReadGuard pg1(&auxHk);
if (result != HasReturnvaluesIF::RETURN_OK) { if (pg0.getReadResult() != HasReturnvaluesIF::RETURN_OK or
pg1.getReadResult() != HasReturnvaluesIF::RETURN_OK) {
break; break;
} }
printHkTableSwitchIV(); printHkTableSwitchIV();
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
case (GOMSPACE::PRINT_LATCHUPS): { case (GOMSPACE::PRINT_LATCHUPS): {
PoolReadGuard pg(&p60dockHkTableDataset); PoolReadGuard pg(&auxHk);
result = pg.getReadResult(); result = pg.getReadResult();
printHkTableLatchups(); printHkTableLatchups();
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
@ -296,25 +289,22 @@ ReturnValue_t P60DockHandler::printStatus(DeviceCommandId_t cmd) {
void P60DockHandler::printHkTableSwitchIV() { void P60DockHandler::printHkTableSwitchIV() {
using namespace P60Dock; using namespace P60Dock;
sif::info << "P60 Dock Info:" << std::endl; sif::info << "P60 Dock Info:" << std::endl;
sif::info << "Boot Cause: " << p60dockHkTableDataset.bootcause sif::info << "Boot Cause: " << auxHk.bootcause << " | Boot Count: " << std::setw(4) << std::right
<< " | Boot Count: " << std::setw(4) << std::right << p60dockHkTableDataset.bootCount << coreHk.bootCount << std::endl;
<< std::endl; sif::info << "Reset Cause: " << auxHk.resetcause
sif::info << "Reset Cause: " << p60dockHkTableDataset.resetcause << " | Battery Mode: " << static_cast<int>(coreHk.battMode.value) << std::endl;
<< " | Battery Mode: " << static_cast<int>(p60dockHkTableDataset.battMode.value)
<< std::endl;
sif::info << "SwitchState, Currents [mA], Voltages [mV]:" << std::endl; sif::info << "SwitchState, Currents [mA], Voltages [mV]:" << std::endl;
sif::info << std::setw(MAX_CHANNEL_STR_WIDTH) << std::left << "Dock VBAT VCC" << std::dec sif::info << std::setw(MAX_CHANNEL_STR_WIDTH) << std::left << "Dock VBAT VCC" << std::dec
<< "| -, " << std::setw(4) << std::right << p60dockHkTableDataset.dockVccCurrent << ", " << "| -, " << std::setw(4) << std::right << auxHk.dockVccCurrent << ", " << std::setw(5)
<< std::setw(5) << p60dockHkTableDataset.dockVbatVoltageValue << std::endl; << auxHk.dockVbatVoltageValue << std::endl;
sif::info << std::setw(MAX_CHANNEL_STR_WIDTH) << std::left << "BATT" << std::dec << "| -, " sif::info << std::setw(MAX_CHANNEL_STR_WIDTH) << std::left << "BATT" << std::dec << "| -, "
<< std::setw(4) << std::right << p60dockHkTableDataset.batteryCurrent.value << ", " << std::setw(4) << std::right << coreHk.batteryCurrent.value << ", " << std::setw(5)
<< std::setw(5) << p60dockHkTableDataset.batteryVoltage.value << std::endl; << coreHk.batteryVoltage.value << std::endl;
auto genericPrintoutHandler = [&](std::string name, uint8_t idx) { auto genericPrintoutHandler = [&](std::string name, uint8_t idx) {
sif::info << std::setw(MAX_CHANNEL_STR_WIDTH) << std::left << name << std::dec << "| " sif::info << std::setw(MAX_CHANNEL_STR_WIDTH) << std::left << name << std::dec << "| "
<< unsigned(p60dockHkTableDataset.outputEnables[idx]) << ", " << std::setw(4) << unsigned(coreHk.outputEnables[idx]) << ", " << std::setw(4) << std::right
<< std::right << p60dockHkTableDataset.currents[idx] << ", " << std::setw(5) << coreHk.currents[idx] << ", " << std::setw(5) << coreHk.voltages[idx] << std::endl;
<< p60dockHkTableDataset.voltages[idx] << std::endl;
}; };
genericPrintoutHandler("ACU VCC", hk::ACU_VCC); genericPrintoutHandler("ACU VCC", hk::ACU_VCC);
@ -328,12 +318,21 @@ void P60DockHandler::printHkTableSwitchIV() {
genericPrintoutHandler("Stack 5V", hk::STACK_5V); genericPrintoutHandler("Stack 5V", hk::STACK_5V);
} }
LocalPoolDataSetBase *P60DockHandler::getDataSetHandle(sid_t sid) {
if (sid == coreHk.getSid()) {
return &coreHk;
} else if (sid == auxHk.getSid()) {
return &auxHk;
}
return nullptr;
}
void P60DockHandler::printHkTableLatchups() { void P60DockHandler::printHkTableLatchups() {
using namespace P60Dock; using namespace P60Dock;
sif::info << "P60 Latchup Information" << std::endl; sif::info << "P60 Latchup Information" << std::endl;
auto genericPrintoutHandler = [&](std::string name, uint8_t idx) { auto genericPrintoutHandler = [&](std::string name, uint8_t idx) {
sif::info << std::setw(MAX_CHANNEL_STR_WIDTH) << std::left << name << std::dec << "| " sif::info << std::setw(MAX_CHANNEL_STR_WIDTH) << std::left << name << std::dec << "| "
<< std::setw(4) << std::right << p60dockHkTableDataset.latchups[idx] << std::endl; << std::setw(4) << std::right << auxHk.latchups[idx] << std::endl;
}; };
genericPrintoutHandler("ACU VCC", hk::ACU_VCC); genericPrintoutHandler("ACU VCC", hk::ACU_VCC);
genericPrintoutHandler("ACU VBAT", hk::ACU_VBAT); genericPrintoutHandler("ACU VBAT", hk::ACU_VBAT);

View File

@ -31,12 +31,14 @@ class P60DockHandler : public GomspaceDeviceHandler {
* @return * @return
*/ */
ReturnValue_t printStatus(DeviceCommandId_t cmd) override; ReturnValue_t printStatus(DeviceCommandId_t cmd) override;
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
void printHkTableSwitchIV(); void printHkTableSwitchIV();
void printHkTableLatchups(); void printHkTableLatchups();
private: private:
P60Dock::HkTableDataset p60dockHkTableDataset; P60Dock::CoreHkSet coreHk;
P60Dock::HkTableDataset auxHk;
static constexpr uint8_t MAX_CHANNEL_STR_WIDTH = 16; static constexpr uint8_t MAX_CHANNEL_STR_WIDTH = 16;
PoolEntry<int16_t> hkCurrents = PoolEntry<int16_t>(P60Dock::hk::CHNLS_LEN); PoolEntry<int16_t> hkCurrents = PoolEntry<int16_t>(P60Dock::hk::CHNLS_LEN);

View File

@ -7,8 +7,7 @@
PDU1Handler::PDU1Handler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie) PDU1Handler::PDU1Handler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie)
: GomspaceDeviceHandler(objectId, comIF, comCookie, PDU::MAX_CONFIGTABLE_ADDRESS, : GomspaceDeviceHandler(objectId, comIF, comCookie, PDU::MAX_CONFIGTABLE_ADDRESS,
PDU::MAX_HKTABLE_ADDRESS, PDU::HK_TABLE_REPLY_SIZE, PDU::MAX_HKTABLE_ADDRESS, PDU::HK_TABLE_REPLY_SIZE),
&pdu1HkTableDataset),
pdu1HkTableDataset(this) {} pdu1HkTableDataset(this) {}
PDU1Handler::~PDU1Handler() {} PDU1Handler::~PDU1Handler() {}
@ -430,6 +429,13 @@ ReturnValue_t PDU1Handler::initializeLocalDataPool(localpool::DataPool &localDat
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
LocalPoolDataSetBase *PDU1Handler::getDataSetHandle(sid_t sid) {
if (sid == pdu1HkTableDataset.getSid()) {
return &pdu1HkTableDataset;
}
return nullptr;
}
ReturnValue_t PDU1Handler::printStatus(DeviceCommandId_t cmd) { ReturnValue_t PDU1Handler::printStatus(DeviceCommandId_t cmd) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
switch (cmd) { switch (cmd) {

View File

@ -36,7 +36,7 @@ class PDU1Handler : public GomspaceDeviceHandler {
virtual ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override; virtual ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override;
virtual void letChildHandleHkReply(DeviceCommandId_t id, const uint8_t* packet) override; virtual void letChildHandleHkReply(DeviceCommandId_t id, const uint8_t* packet) override;
ReturnValue_t printStatus(DeviceCommandId_t cmd) override; ReturnValue_t printStatus(DeviceCommandId_t cmd) override;
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
ReturnValue_t setParamCallback(SetParamMessageUnpacker& unpacker, bool afterExectuion) override; ReturnValue_t setParamCallback(SetParamMessageUnpacker& unpacker, bool afterExectuion) override;
private: private:

View File

@ -7,8 +7,7 @@
PDU2Handler::PDU2Handler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie) PDU2Handler::PDU2Handler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie)
: GomspaceDeviceHandler(objectId, comIF, comCookie, PDU::MAX_CONFIGTABLE_ADDRESS, : GomspaceDeviceHandler(objectId, comIF, comCookie, PDU::MAX_CONFIGTABLE_ADDRESS,
PDU::MAX_HKTABLE_ADDRESS, PDU::HK_TABLE_REPLY_SIZE, PDU::MAX_HKTABLE_ADDRESS, PDU::HK_TABLE_REPLY_SIZE),
&pdu2HkTableDataset),
pdu2HkTableDataset(this) {} pdu2HkTableDataset(this) {}
PDU2Handler::~PDU2Handler() {} PDU2Handler::~PDU2Handler() {}
@ -54,6 +53,13 @@ void PDU2Handler::assignChannelHookFunction(GOMSPACE::ChannelSwitchHook hook, vo
this->hookArgs = args; this->hookArgs = args;
} }
LocalPoolDataSetBase *PDU2Handler::getDataSetHandle(sid_t sid) {
if (sid == pdu2HkTableDataset.getSid()) {
return &pdu2HkTableDataset;
}
return nullptr;
}
void PDU2Handler::parseHkTableReply(const uint8_t *packet) { void PDU2Handler::parseHkTableReply(const uint8_t *packet) {
uint16_t dataOffset = 0; uint16_t dataOffset = 0;
pdu2HkTableDataset.read(); pdu2HkTableDataset.read();

View File

@ -36,6 +36,7 @@ class PDU2Handler : public GomspaceDeviceHandler {
virtual void letChildHandleHkReply(DeviceCommandId_t id, const uint8_t* packet) override; virtual void letChildHandleHkReply(DeviceCommandId_t id, const uint8_t* packet) override;
ReturnValue_t printStatus(DeviceCommandId_t cmd) override; ReturnValue_t printStatus(DeviceCommandId_t cmd) override;
ReturnValue_t setParamCallback(SetParamMessageUnpacker& unpacker, bool afterExecution) override; ReturnValue_t setParamCallback(SetParamMessageUnpacker& unpacker, bool afterExecution) override;
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
private: private:
static constexpr uint8_t MAX_CHANNEL_STR_WIDTH = 24; static constexpr uint8_t MAX_CHANNEL_STR_WIDTH = 24;

View File

@ -351,7 +351,9 @@ static const uint16_t MAX_CONFIGTABLE_ADDRESS = 408;
static const uint16_t MAX_HKTABLE_ADDRESS = 187; static const uint16_t MAX_HKTABLE_ADDRESS = 187;
static const uint16_t HK_TABLE_SIZE = 188; static const uint16_t HK_TABLE_SIZE = 188;
static const uint8_t HK_TABLE_DATA_SET_ID = 0x3; static constexpr uint32_t CORE_TABLE_SET_ID = 0x3;
static constexpr uint32_t AUX_TABLE_DATA_SET_ID = 0x4;
static const uint8_t HK_TABLE_ENTRIES = 100; static const uint8_t HK_TABLE_ENTRIES = 100;
/** /**
@ -360,18 +362,11 @@ static const uint8_t HK_TABLE_ENTRIES = 100;
*/ */
static const uint16_t HK_TABLE_REPLY_SIZE = 407; static const uint16_t HK_TABLE_REPLY_SIZE = 407;
/** class CoreHkSet : public StaticLocalDataSet<16> {
* @brief This class defines a dataset for the hk table of the P60 Dock.
* @details
* The GS port and X3 are not required for EIVE. X3 is another slot on the P60 dock and
* GS is required for a module from Gomspace which is not used.
*/
class HkTableDataset : public StaticLocalDataSet<HK_TABLE_ENTRIES> {
public: public:
HkTableDataset(HasLocalDataPoolIF* owner) : StaticLocalDataSet(owner, HK_TABLE_DATA_SET_ID) {} CoreHkSet(HasLocalDataPoolIF* owner) : StaticLocalDataSet(owner, CORE_TABLE_SET_ID) {}
HkTableDataset(object_id_t objectId) CoreHkSet(object_id_t objectId) : StaticLocalDataSet(sid_t(objectId, CORE_TABLE_SET_ID)) {}
: StaticLocalDataSet(sid_t(objectId, HK_TABLE_DATA_SET_ID)) {}
/** Measured output currents */ /** Measured output currents */
lp_vec_t<int16_t, P60Dock::hk::Index::CHNLS_LEN> currents = lp_vec_t<int16_t, P60Dock::hk::Index::CHNLS_LEN> currents =
@ -387,22 +382,42 @@ class HkTableDataset : public StaticLocalDataSet<HK_TABLE_ENTRIES> {
lp_vec_t<uint8_t, P60Dock::hk::Index::CHNLS_LEN> outputEnables = lp_vec_t<uint8_t, P60Dock::hk::Index::CHNLS_LEN> outputEnables =
lp_vec_t<uint8_t, P60Dock::hk::Index::CHNLS_LEN>(sid.objectId, P60System::pool::OUTPUT_ENABLE, lp_vec_t<uint8_t, P60Dock::hk::Index::CHNLS_LEN>(sid.objectId, P60System::pool::OUTPUT_ENABLE,
this); this);
lp_var_t<uint32_t> bootCount =
lp_var_t<uint32_t>(sid.objectId, P60System::pool::P60DOCK_BOOT_CNT, this);
lp_var_t<uint8_t> battMode =
lp_var_t<uint8_t>(sid.objectId, P60System::pool::P60DOCK_BATT_MODE, this);
// Difference between charge and discharge current
lp_var_t<int16_t> batteryCurrent =
lp_var_t<int16_t>(sid.objectId, P60System::pool::P60DOCK_BATTERY_CURRENT, this);
lp_var_t<uint16_t> batteryVoltage =
lp_var_t<uint16_t>(sid.objectId, P60System::pool::P60DOCK_BATTERY_VOLTAGE, this);
lp_var_t<int16_t> temperature1 = lp_var_t<int16_t> temperature1 =
lp_var_t<int16_t>(sid.objectId, P60System::pool::P60DOCK_TEMPERATURE_1, this); lp_var_t<int16_t>(sid.objectId, P60System::pool::P60DOCK_TEMPERATURE_1, this);
lp_var_t<int16_t> temperature2 = lp_var_t<int16_t> temperature2 =
lp_var_t<int16_t>(sid.objectId, P60System::pool::P60DOCK_TEMPERATURE_2, this); lp_var_t<int16_t>(sid.objectId, P60System::pool::P60DOCK_TEMPERATURE_2, this);
};
/**
* @brief This class defines a dataset for the hk table of the P60 Dock.
* @details
* The GS port and X3 are not required for EIVE. X3 is another slot on the P60 dock and
* GS is required for a module from Gomspace which is not used.
*/
class HkTableDataset : public StaticLocalDataSet<32> {
public:
HkTableDataset(HasLocalDataPoolIF* owner) : StaticLocalDataSet(owner, AUX_TABLE_DATA_SET_ID) {}
HkTableDataset(object_id_t objectId)
: StaticLocalDataSet(sid_t(objectId, AUX_TABLE_DATA_SET_ID)) {}
lp_var_t<uint32_t> bootcause = lp_var_t<uint32_t> bootcause =
lp_var_t<uint32_t>(sid.objectId, P60System::pool::P60DOCK_BOOT_CAUSE, this); lp_var_t<uint32_t>(sid.objectId, P60System::pool::P60DOCK_BOOT_CAUSE, this);
lp_var_t<uint32_t> bootCount =
lp_var_t<uint32_t>(sid.objectId, P60System::pool::P60DOCK_BOOT_CNT, this);
lp_var_t<uint32_t> uptime = lp_var_t<uint32_t> uptime =
lp_var_t<uint32_t>(sid.objectId, P60System::pool::P60DOCK_UPTIME, this); lp_var_t<uint32_t>(sid.objectId, P60System::pool::P60DOCK_UPTIME, this);
lp_var_t<uint16_t> resetcause = lp_var_t<uint16_t> resetcause =
lp_var_t<uint16_t>(sid.objectId, P60System::pool::P60DOCK_RESETCAUSE, this); lp_var_t<uint16_t>(sid.objectId, P60System::pool::P60DOCK_RESETCAUSE, this);
lp_var_t<uint8_t> battMode =
lp_var_t<uint8_t>(sid.objectId, P60System::pool::P60DOCK_BATT_MODE, this);
/** Battery heater control only possible on BP4 packs */ /** Battery heater control only possible on BP4 packs */
lp_var_t<uint8_t> heaterOn = lp_var_t<uint8_t> heaterOn =
lp_var_t<uint8_t>(sid.objectId, P60System::pool::P60DOCK_HEATER_ON, this); lp_var_t<uint8_t>(sid.objectId, P60System::pool::P60DOCK_HEATER_ON, this);
@ -418,11 +433,6 @@ class HkTableDataset : public StaticLocalDataSet<HK_TABLE_ENTRIES> {
lp_var_t<uint16_t>(sid.objectId, P60System::pool::P60DOCK_DOCK_VBAT, this); lp_var_t<uint16_t>(sid.objectId, P60System::pool::P60DOCK_DOCK_VBAT, this);
lp_var_t<int16_t> dockVccCurrent = lp_var_t<int16_t> dockVccCurrent =
lp_var_t<int16_t>(sid.objectId, P60System::pool::P60DOCK_DOCK_VCC_CURRENT, this); lp_var_t<int16_t>(sid.objectId, P60System::pool::P60DOCK_DOCK_VCC_CURRENT, this);
// Difference between charge and discharge current
lp_var_t<int16_t> batteryCurrent =
lp_var_t<int16_t>(sid.objectId, P60System::pool::P60DOCK_BATTERY_CURRENT, this);
lp_var_t<uint16_t> batteryVoltage =
lp_var_t<uint16_t>(sid.objectId, P60System::pool::P60DOCK_BATTERY_VOLTAGE, this);
lp_var_t<int16_t> batteryTemperature1 = lp_var_t<int16_t> batteryTemperature1 =
lp_var_t<int16_t>(sid.objectId, P60System::pool::P60DOCK_BATTERY_TEMPERATURE_1, this); lp_var_t<int16_t>(sid.objectId, P60System::pool::P60DOCK_BATTERY_TEMPERATURE_1, this);

View File

@ -5,14 +5,17 @@
* Authors: * Authors:
* *
* Assembled from the code released on Stackoverflow by: * Assembled from the code released on Stackoverflow by:
* Dennis (instructable.com/member/nqtronix) | https://stackoverflow.com/questions/23032002/c-c-how-to-get-integer-unix-timestamp-of-build-time-not-string * Dennis (instructable.com/member/nqtronix) |
* https://stackoverflow.com/questions/23032002/c-c-how-to-get-integer-unix-timestamp-of-build-time-not-string
* and * and
* Alexis Wilke | https://stackoverflow.com/questions/10538444/do-you-know-of-a-c-macro-to-compute-unix-time-and-date * Alexis Wilke |
* https://stackoverflow.com/questions/10538444/do-you-know-of-a-c-macro-to-compute-unix-time-and-date
* *
* Assembled by Jean Rabault * Assembled by Jean Rabault
* *
* UNIX_TIMESTAMP gives the UNIX timestamp (unsigned long integer of seconds since 1st Jan 1970) of compilation from macros using the compiler defined __TIME__ macro. * UNIX_TIMESTAMP gives the UNIX timestamp (unsigned long integer of seconds since 1st Jan 1970) of
* This should include Gregorian calendar leap days, in particular the 29ths of February, 100 and 400 years modulo leaps. * compilation from macros using the compiler defined __TIME__ macro. This should include Gregorian
* calendar leap days, in particular the 29ths of February, 100 and 400 years modulo leaps.
* *
* Careful: __TIME__ is the local time of the computer, NOT the UTC time in general! * Careful: __TIME__ is the local time of the computer, NOT the UTC time in general!
* *
@ -25,27 +28,29 @@
#define SEC_PER_MIN 60UL #define SEC_PER_MIN 60UL
#define SEC_PER_HOUR 3600UL #define SEC_PER_HOUR 3600UL
#define SEC_PER_DAY 86400UL #define SEC_PER_DAY 86400UL
#define SEC_PER_YEAR (SEC_PER_DAY*365) #define SEC_PER_YEAR (SEC_PER_DAY * 365)
// extracts 1..4 characters from a string and interprets it as a decimal value // extracts 1..4 characters from a string and interprets it as a decimal value
#define CONV_STR2DEC_1(str, i) (str[i]>'0'?str[i]-'0':0) #define CONV_STR2DEC_1(str, i) (str[i] > '0' ? str[i] - '0' : 0)
#define CONV_STR2DEC_2(str, i) (CONV_STR2DEC_1(str, i)*10 + str[i+1]-'0') #define CONV_STR2DEC_2(str, i) (CONV_STR2DEC_1(str, i) * 10 + str[i + 1] - '0')
#define CONV_STR2DEC_3(str, i) (CONV_STR2DEC_2(str, i)*10 + str[i+2]-'0') #define CONV_STR2DEC_3(str, i) (CONV_STR2DEC_2(str, i) * 10 + str[i + 2] - '0')
#define CONV_STR2DEC_4(str, i) (CONV_STR2DEC_3(str, i)*10 + str[i+3]-'0') #define CONV_STR2DEC_4(str, i) (CONV_STR2DEC_3(str, i) * 10 + str[i + 3] - '0')
// Custom "glue logic" to convert the month name to a usable number // Custom "glue logic" to convert the month name to a usable number
#define GET_MONTH(str, i) (str[i]=='J' && str[i+1]=='a' && str[i+2]=='n' ? 1 : \ #define GET_MONTH(str, i) \
str[i]=='F' && str[i+1]=='e' && str[i+2]=='b' ? 2 : \ (str[i] == 'J' && str[i + 1] == 'a' && str[i + 2] == 'n' ? 1 \
str[i]=='M' && str[i+1]=='a' && str[i+2]=='r' ? 3 : \ : str[i] == 'F' && str[i + 1] == 'e' && str[i + 2] == 'b' ? 2 \
str[i]=='A' && str[i+1]=='p' && str[i+2]=='r' ? 4 : \ : str[i] == 'M' && str[i + 1] == 'a' && str[i + 2] == 'r' ? 3 \
str[i]=='M' && str[i+1]=='a' && str[i+2]=='y' ? 5 : \ : str[i] == 'A' && str[i + 1] == 'p' && str[i + 2] == 'r' ? 4 \
str[i]=='J' && str[i+1]=='u' && str[i+2]=='n' ? 6 : \ : str[i] == 'M' && str[i + 1] == 'a' && str[i + 2] == 'y' ? 5 \
str[i]=='J' && str[i+1]=='u' && str[i+2]=='l' ? 7 : \ : str[i] == 'J' && str[i + 1] == 'u' && str[i + 2] == 'n' ? 6 \
str[i]=='A' && str[i+1]=='u' && str[i+2]=='g' ? 8 : \ : str[i] == 'J' && str[i + 1] == 'u' && str[i + 2] == 'l' ? 7 \
str[i]=='S' && str[i+1]=='e' && str[i+2]=='p' ? 9 : \ : str[i] == 'A' && str[i + 1] == 'u' && str[i + 2] == 'g' ? 8 \
str[i]=='O' && str[i+1]=='c' && str[i+2]=='t' ? 10 : \ : str[i] == 'S' && str[i + 1] == 'e' && str[i + 2] == 'p' ? 9 \
str[i]=='N' && str[i+1]=='o' && str[i+2]=='v' ? 11 : \ : str[i] == 'O' && str[i + 1] == 'c' && str[i + 2] == 't' ? 10 \
str[i]=='D' && str[i+1]=='e' && str[i+2]=='c' ? 12 : 0) : str[i] == 'N' && str[i + 1] == 'o' && str[i + 2] == 'v' ? 11 \
: str[i] == 'D' && str[i + 1] == 'e' && str[i + 2] == 'c' ? 12 \
: 0)
// extract the information from the time string given by __TIME__ and __DATE__ // extract the information from the time string given by __TIME__ and __DATE__
#define __TIME_SECONDS__ CONV_STR2DEC_2(__TIME__, 6) #define __TIME_SECONDS__ CONV_STR2DEC_2(__TIME__, 6)
@ -57,41 +62,29 @@
// Days in February // Days in February
#define _UNIX_TIMESTAMP_FDAY(year) \ #define _UNIX_TIMESTAMP_FDAY(year) \
(((year) % 400) == 0UL ? 29UL : \ (((year) % 400) == 0UL ? 29UL \
(((year) % 100) == 0UL ? 28UL : \ : (((year) % 100) == 0UL ? 28UL : (((year) % 4) == 0UL ? 29UL : 28UL)))
(((year) % 4) == 0UL ? 29UL : \
28UL)))
// Days in the year // Days in the year
#define _UNIX_TIMESTAMP_YDAY(year, month, day) \ #define _UNIX_TIMESTAMP_YDAY(year, month, day) \
( \ (/* January */ day /* February */ + (month >= 2 ? 31UL : 0UL) /* March */ + \
/* January */ day \ (month >= 3 ? _UNIX_TIMESTAMP_FDAY(year) : 0UL) /* April */ + \
/* February */ + (month >= 2 ? 31UL : 0UL) \ (month >= 4 ? 31UL : 0UL) /* May */ + (month >= 5 ? 30UL : 0UL) /* June */ + \
/* March */ + (month >= 3 ? _UNIX_TIMESTAMP_FDAY(year) : 0UL) \ (month >= 6 ? 31UL : 0UL) /* July */ + (month >= 7 ? 30UL : 0UL) /* August */ + \
/* April */ + (month >= 4 ? 31UL : 0UL) \ (month >= 8 ? 31UL : 0UL) /* September */ + (month >= 9 ? 31UL : 0UL) /* October */ + \
/* May */ + (month >= 5 ? 30UL : 0UL) \ (month >= 10 ? 30UL : 0UL) /* November */ + (month >= 11 ? 31UL : 0UL) /* December */ + \
/* June */ + (month >= 6 ? 31UL : 0UL) \ (month >= 12 ? 30UL : 0UL))
/* July */ + (month >= 7 ? 30UL : 0UL) \
/* August */ + (month >= 8 ? 31UL : 0UL) \
/* September */+ (month >= 9 ? 31UL : 0UL) \
/* October */ + (month >= 10 ? 30UL : 0UL) \
/* November */ + (month >= 11 ? 31UL : 0UL) \
/* December */ + (month >= 12 ? 30UL : 0UL) \
)
// get the UNIX timestamp from a digits representation // get the UNIX timestamp from a digits representation
#define _UNIX_TIMESTAMP(year, month, day, hour, minute, second) \ #define _UNIX_TIMESTAMP(year, month, day, hour, minute, second) \
( /* time */ second \ (/* time */ second + minute * SEC_PER_MIN + hour * SEC_PER_HOUR + \
+ minute * SEC_PER_MIN \ /* year day (month + day) */ (_UNIX_TIMESTAMP_YDAY(year, month, day) - 1) * SEC_PER_DAY + \
+ hour * SEC_PER_HOUR \ /* year */ (year - 1970UL) * SEC_PER_YEAR + ((year - 1969UL) / 4UL) * SEC_PER_DAY - \
+ /* year day (month + day) */ (_UNIX_TIMESTAMP_YDAY(year, month, day) - 1) * SEC_PER_DAY \ ((year - 1901UL) / 100UL) * SEC_PER_DAY + ((year - 1601UL) / 400UL) * SEC_PER_DAY)
+ /* year */ (year - 1970UL) * SEC_PER_YEAR \
+ ((year - 1969UL) / 4UL) * SEC_PER_DAY \
- ((year - 1901UL) / 100UL) * SEC_PER_DAY \
+ ((year - 1601UL) / 400UL) * SEC_PER_DAY \
)
// the UNIX timestamp // the UNIX timestamp
#define UNIX_TIMESTAMP (_UNIX_TIMESTAMP(__TIME_YEARS__, __TIME_MONTH__, __TIME_DAYS__, __TIME_HOURS__, __TIME_MINUTES__, __TIME_SECONDS__)) #define UNIX_TIMESTAMP \
(_UNIX_TIMESTAMP(__TIME_YEARS__, __TIME_MONTH__, __TIME_DAYS__, __TIME_HOURS__, \
__TIME_MINUTES__, __TIME_SECONDS__))
#endif #endif