port: GetConfiguration() return reference, not copy (#161)

This commit is contained in:
Andrey G 2022-09-20 01:27:08 +03:00 committed by GitHub
parent 5fbe108258
commit 0a4a609db9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 11 deletions

View File

@ -95,12 +95,12 @@ int InitConfiguration()
return 0; return 0;
} }
Configuration GetConfiguration() static Configuration c;
Configuration& GetConfiguration()
{ {
const auto& cfg = __configflash__start__; const auto& cfg = __configflash__start__;
Configuration c;
// If config has been written before, use the stored configuration // If config has been written before, use the stored configuration
if (cfg.IsValid()) if (cfg.IsValid())
{ {

View File

@ -117,10 +117,12 @@ static struct {
uint8_t pad[128]; uint8_t pad[128];
} config; } config;
Configuration GetConfiguration() static Configuration c;
Configuration& GetConfiguration()
{ {
// TODO: implement me! // TODO: implement me!
return {}; return c;
} }
void SetConfiguration(const Configuration& newConfig) void SetConfiguration(const Configuration& newConfig)

View File

@ -81,10 +81,12 @@ static struct {
uint8_t pad[128]; uint8_t pad[128];
} config; } config;
Configuration GetConfiguration() static Configuration c;
Configuration& GetConfiguration()
{ {
// TODO: implement me! // TODO: implement me!
return {}; return c;
} }
void SetConfiguration(const Configuration& newConfig) void SetConfiguration(const Configuration& newConfig)

View File

@ -108,10 +108,12 @@ int InitConfiguration()
return 0; return 0;
} }
Configuration GetConfiguration() static Configuration c;
Configuration& GetConfiguration()
{ {
// TODO: implement me! // TODO: implement me!
return {}; return c;
} }
void SetConfiguration(const Configuration& newConfig) void SetConfiguration(const Configuration& newConfig)

View File

@ -38,7 +38,7 @@ public:
uint8_t pad[128 - 1 - 4]; uint8_t pad[128 - 1 - 4];
}; };
Configuration GetConfiguration(); Configuration& GetConfiguration();
void SetConfiguration(const Configuration& newConfig); void SetConfiguration(const Configuration& newConfig);
/* TS stuff */ /* TS stuff */

View File

@ -100,7 +100,7 @@ void CanRxThread(void*)
// Check if it's an "index set" message // Check if it's an "index set" message
else if (frame.DLC == 1 && frame.EID == WB_MSG_SET_INDEX) else if (frame.DLC == 1 && frame.EID == WB_MSG_SET_INDEX)
{ {
auto newCfg = GetConfiguration(); auto &newCfg = GetConfiguration();
newCfg.CanIndexOffset = frame.data8[0]; newCfg.CanIndexOffset = frame.data8[0];
SetConfiguration(newCfg); SetConfiguration(newCfg);
configuration = GetConfiguration(); configuration = GetConfiguration();