Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opaygo step by step librairies and functions integration #100

Merged
merged 30 commits into from
Aug 21, 2023

Conversation

Peguy-WANDA
Copy link
Contributor

Add in main.cpp the function GetDataFromToken(...) from opaygo_decoder.h

@frimic-solarly frimic-solarly marked this pull request as draft July 18, 2023 11:55
@Peguy-WANDA
Copy link
Contributor Author

Hi @dmohns, i would like to know how to organize the functions and libraries of Opaygo that we are going to use? Two possibilities are available to us:
1-Create in the src folder, new files containing the functions and libraries necessary for opaygo;
2-Add the opaygo functions and libraries in the existing openSmartMeter files in the src folder.

Personally I suggest that we opt for the first possibility to have a more structured and more organized code. But for now I'm waiting for your answer to organize the rest of the code. THANKS

@Peguy-WANDA Peguy-WANDA requested a review from dmohns July 18, 2023 12:32
@dmohns
Copy link
Member

dmohns commented Jul 26, 2023

Hi @dmohns, i would like to know how to organize the functions and libraries of Opaygo that we are going to use? Two possibilities are available to us: 1-Create in the src folder, new files containing the functions and libraries necessary for opaygo; 2-Add the opaygo functions and libraries in the existing openSmartMeter files in the src folder.

Personally I suggest that we opt for the first possibility to have a more structured and more organized code. But for now I'm waiting for your answer to organize the rest of the code. THANKS

Hey @Peguy-WANDA sorry for the late reply 🙈

Unfortunately, I'm not sure I understand the question. Let me clarify:

The opaygo-decoder should be treated as a library. What I mean by this is: We should not modify any files from the library, but use it the way it is right now. That's why it's currently sitting in the lib/ folder of the project.

Moving forward, the code will entirely disappear from the OpenSmartMeter repository and will be pulled in via dependencies of platform.ini. However, this is only possible after: EnAccess/OpenPAYGO-HW#14 has been solved.

In case you are talking about "wrapper" functions that are needed in OpenSmartMeter firmware to utilize PAYGO functions: These function can basically go wherever you see them fit best. I, personally, would probably put it to a similar place where the current token functions sit, i.e. token_management.hpp. But not a strong opinion here.

@dmohns
Copy link
Member

dmohns commented Jul 26, 2023

Another comment. It looks like your branched out from a very old version of the main branch.

image

(Blue in the screenshot)

Could you rebase or update your branch to the latest version of main?

@Peguy-WANDA Peguy-WANDA marked this pull request as ready for review July 26, 2023 15:03
Copy link
Member

@dmohns dmohns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments

@@ -29,7 +29,6 @@ uint64_t ConvertHashToTokenExtended(uint64_t this_hash) {
}

uint64_t GenerateOPAYGOTokenExtended(uint64_t LastToken, char SECRET_KEY[16]) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert that change, so the files is untouched?

@@ -9,6 +9,7 @@
#include "opaygo_decoder_extended.h"



Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert that change, so the files is untouched?

@@ -45,3 +45,4 @@ lib_deps =
thingsboard/ThingsBoard@0.6.0
vshymanskyy/TinyGSM@0.11.5
https://github.com/cyberp/AT24Cx.git
Wire
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this needed for?

@@ -10,3 +10,4 @@ DerivePointerAlignment: false
# Always break after if to get accurate coverage
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert that change so the file is untouched?

Comment on lines 1 to 3
#pragma once

//#pragma once
#ifndef credit_hpp
#define credit_hpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two syntaxe are doing the same things but there is a difference between them.
The #ifndef/#define/#endif trick works on any C compiler, and on some of them it speeds up the compilation process. The #pragma trick is non-standards, and only works on few C compilers, and may result in different semantics in those that do not support it.
When I use #pragma trick, I have many warning, but with #ifndef/#define/#endif trick the warnings disappear

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but for this PR I'm just going to put back #pragma once as you wanted

Copy link
Member

@dmohns dmohns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, few comments on the PR, would be great if you could address them

  1. Could you revert all whitespace changes to files that are unrelated to this PR? If you think any of those changes would be better for code readability please feel free to send a separate PR.
  2. I see you are changing all include guards from #pragma once to #ifndef any specific reason why you need this? As above, please leave these untouched in this PR, but open another one, if you think this will make the code better.

Other than that, looks good to me!! Thanks for all the work

Comment on lines 93 to 96
delay(20);
lcd.clear();
buss();
lcd.clear();
lcd.setCursor(0, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what the buss() function does. Could you explain why it is needed for lcd.clear() to be called after buss() instead of before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I will add comments in the code to explain it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The position of lcd.clear() in relation to buss() has no impact on the code, before or after it doesn't change anything and besides I hadn't even noticed that I had indeed changed it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buss() function is there just to emit a sound to signal to the user that he can already enter the token in sts mode

@Peguy-WANDA
Copy link
Contributor Author

Daniel I think as of now everything is good for this pull request, thank you for your comments, feel free to leave more if needed.
Have a nice weekend

Comment on lines +15 to +17
#define ACTIVE_UNTIL_NVRAM_ADDRESS \
0 // 56 bytes address from 0 to 55 in the NVRAM
#define TIME_INITIALIZATION_NVRAM_ADDRESS 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are these used? If they aren't, can we remove them?

Comment on lines +34 to +41
// Device parameters location in Flash/EEPROM
unsigned int TokenCount_eeprom_location = 6;
unsigned int UsedTokens_eeprom_location = 8;
unsigned int PAYGEnabled_eeprom_location = 10;
unsigned int ActiveUntil_eeprom_location = 11;
unsigned int TokenEntryLockedUntil_eeprom_location = 15;
unsigned int LAST_TIME_STAMP_ADDRESS = 27;
unsigned int NB_DISCONNECTIONS_ADDRESS = 32;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about making some like a "global" EEPROM map? We don't have to do this now in this PR, but as an idea?

For example, in global_defined we could include all the EEPROM locations as macros?

Comment on lines +121 to +132
uint32_t GetTimeInSeconds() {
/*
*Returns the unixtime in seconds of Now
*/
DateTime now = rtc.now();
uint32_t nowInSeconds =
(now.unixtime() -
timeInitializationRtc); // we substract the init time so that it's
// easier to read when debugging, and works the
// same as Arduino Time mgt
return (nowInSeconds);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't PAYGO related, but time related, should it go in time_management.hpp instead?

Comment on lines +181 to +202
void AddTime(int ActivationValue) {
uint32_t Now = GetTimeInSeconds();
int NumberOfSecondsToActivate = (ActivationValue * 3600 * 24) / TIME_DIVIDER;

if (ActiveUntil < Now) {
ActiveUntil = Now;
}

ActiveUntil +=
NumberOfSecondsToActivate; // We add the number of days (converted in
// seconds for to compare to our RTC time)
}

void SetTime(int ActivationValue) {
uint32_t Now = GetTimeInSeconds();
int NumberOfSecondsToActivate = (ActivationValue * 3600 * 24) / TIME_DIVIDER;

ActiveUntil =
Now +
NumberOfSecondsToActivate; // We set the number of days (converted in
// seconds for to compare to our RTC time)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't PAYGO related, but time related, should it go in time_management.hpp instead?

Comment on lines +285 to +313
void initializeTime() {
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1)
;
}

if (!rtc.isrunning()) {
Serial.println("RTC is NOT running!");
}

// We check that it is not a disconnection power - Arduino
uint32_t nvramCheck = readUint32FromNvram(TIME_INITIALIZATION_NVRAM_ADDRESS);
if (nvramCheck == 0) { // it is the first setup of the Arduino
rtc.adjust(
DateTime(F(__DATE__), F(__TIME__))); // sets the RTC to the date & time
// this sketch was compiled
DateTime now = rtc.now();
timeInitializationRtc = now.unixtime();
storeUint32InNvram(timeInitializationRtc,
TIME_INITIALIZATION_NVRAM_ADDRESS);
} else { // a disconnection happened
timeInitializationRtc = nvramCheck;
incrementNbDisconnectionsEeprom();
storeTimeStampEEPROM(
GetTimeInSeconds()); // to avoid counting twice the disconnection if
// the previous TimeStamp was too long ago
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't PAYGO related, but time related, should it go in time_management.hpp instead?

#define NON_ACCEPTED_KEY -3

#define TIME_DIVIDER 1
// #define RESTRICTED_DIGIT_SET_MODE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this comment be removed?

@dmohns dmohns merged commit 9c69263 into main Aug 21, 2023
@dmohns dmohns deleted the Opaygo-step-by-step-librairies-and-functions-integration branch August 21, 2023 10:18
dmohns added a commit that referenced this pull request Aug 30, 2023
* git changes

* Changes in loop

* change on token_management

* main.cpp

* include opaygo_decoder

* token_management

* add function GetDataFromToken from opaygo_decoder

* this commit is only to update the branch

* update branch

* add opaygo_functions

* add LoadActivationVariables() function

* complete main.cpp with functions of opaygo

* add UpdateDeviceStatusFromTokenValue()

* add functions in opaygo_functions

* update code

* add functions in opaygo_functions

* solving problem of time

* editorConfig problem solving

* editorConfig problem solving

* editorConfig problem solving

* clang-format problem solving

* EditConfig problem solving

* EditConfig problem solving

* commit before changing branch

* solving conflict for PR

* format document

* format document

---------

Co-authored-by: Peguy WANDA <peguy@debian-BULLSEYE-live-builder-AMD64>
Co-authored-by: Daniel Mohns <daniel.mohns@posteo.de>
dmohns added a commit that referenced this pull request Aug 30, 2023
* git changes

* Changes in loop

* change on token_management

* main.cpp

* include opaygo_decoder

* token_management

* add function GetDataFromToken from opaygo_decoder

* this commit is only to update the branch

* update branch

* add opaygo_functions

* add LoadActivationVariables() function

* complete main.cpp with functions of opaygo

* add UpdateDeviceStatusFromTokenValue()

* add functions in opaygo_functions

* update code

* add functions in opaygo_functions

* solving problem of time

* editorConfig problem solving

* editorConfig problem solving

* editorConfig problem solving

* clang-format problem solving

* EditConfig problem solving

* EditConfig problem solving

* commit before changing branch

* solving conflict for PR

* format document

* format document

---------

Co-authored-by: Peguy WANDA <peguy@debian-BULLSEYE-live-builder-AMD64>
Co-authored-by: Daniel Mohns <daniel.mohns@posteo.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants