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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f0e9c66
git changes
Peguy-WANDA Jul 17, 2023
065e3a1
Changes in loop
Peguy-WANDA Jul 17, 2023
dce484d
change on token_management
Peguy-WANDA Jul 17, 2023
71b78e6
main.cpp
Peguy-WANDA Jul 17, 2023
09e7d81
include opaygo_decoder
Peguy-WANDA Jul 17, 2023
cb1aa23
token_management
Peguy-WANDA Jul 17, 2023
c95a76c
add function GetDataFromToken from opaygo_decoder
Peguy-WANDA Jul 17, 2023
86caa97
this commit is only to update the branch
Peguy-WANDA Jul 26, 2023
624786e
update branch
Peguy-WANDA Jul 26, 2023
862364d
Merge branch 'main' into Opaygo-step-by-step-librairies-and-functions…
Peguy-WANDA Jul 26, 2023
d2c9e60
Merge branch 'Opaygo-step-by-step-librairies-and-functions-integratio…
Peguy-WANDA Jul 27, 2023
bcf9cad
add opaygo_functions
Peguy-WANDA Jul 28, 2023
089791b
add LoadActivationVariables() function
Peguy-WANDA Jul 28, 2023
8521cdb
complete main.cpp with functions of opaygo
Peguy-WANDA Jul 28, 2023
2ddee96
add UpdateDeviceStatusFromTokenValue()
Peguy-WANDA Jul 28, 2023
a301382
add functions in opaygo_functions
Peguy-WANDA Jul 28, 2023
2b52973
update code
Peguy-WANDA Jul 28, 2023
9cc79ea
add functions in opaygo_functions
Peguy-WANDA Jul 31, 2023
6ad2dee
solving problem of time
Aug 5, 2023
8da4d80
editorConfig problem solving
Aug 11, 2023
adfd8a5
editorConfig problem solving
Aug 11, 2023
e8ae210
editorConfig problem solving
Aug 11, 2023
ab6f92d
clang-format problem solving
Aug 11, 2023
f778ced
EditConfig problem solving
Aug 11, 2023
b2e55f7
EditConfig problem solving
Aug 11, 2023
deec8b2
commit before changing branch
Peguy-WANDA Aug 14, 2023
c04e9cf
Merge branch 'main' into Opaygo-step-by-step-librairies-and-functions…
dmohns Aug 16, 2023
6dd8e0c
solving conflict for PR
Peguy-WANDA Aug 19, 2023
9b71222
format document
Peguy-WANDA Aug 19, 2023
21ec3ea
format document
Peguy-WANDA Aug 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added firmware/.gitignore
Empty file.
1 change: 0 additions & 1 deletion firmware/src/credit.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once

// defines

// Arduino base libraries
Expand Down
45 changes: 45 additions & 0 deletions firmware/src/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,48 @@ void urgeent() {
}
}
}

uint32_t convertArrayToUint32(int arrayToConvert[9]) {
int i = 0;
uint32_t uint32 = 0;
for (i = 0; i < 9; i++) {
uint32 = 10 * uint32 + arrayToConvert[i];
}
return (uint32);
}

uint32_t convertByteArrayToUint32(uint8_t arrayToConvert[4]) {
uint32_t low1 = arrayToConvert[0];
uint32_t low2 = arrayToConvert[1];
low2 = low2 << 8;
uint32_t high1 = arrayToConvert[2];
high1 = high1 << 16;
uint32_t high2 = arrayToConvert[3];
high2 = high2 << 24;
uint32_t result = low1 + low2 + high1 + high2;
return (result);
}

void convertUint32ToUint8Array(uint32_t uint32ToConvert,
uint8_t arrayBytes[4]) {
byte low1 = uint32ToConvert;
byte low2 = uint32ToConvert >> 8;
byte high1 = uint32ToConvert >> 16;
byte high2 = uint32ToConvert >> 24;
arrayBytes[0] = low1;
arrayBytes[1] = low2;
arrayBytes[2] = high1;
arrayBytes[3] = high2;
}

void storeUint32InNvram(uint32_t toStore, int address) {
uint8_t arrayBytes[4];
convertUint32ToUint8Array(toStore, arrayBytes);
rtc.writenvram(address, arrayBytes, 4);
}

uint32_t readUint32FromNvram(int address) {
uint8_t readData[4] = {0};
rtc.readnvram(readData, 4, address);
return (convertByteArrayToUint32(readData));
}
82 changes: 66 additions & 16 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// defines

// Arduino base libraries
#include <Wire.h>
#include "Arduino.h"
// #include <Arduino.h>

// third party libraries
#include <ArduinoHttpClient.h>
// #include <ArduinoHttpClient.h>
// #include <Wire.h>

// OpenSmartMeter libraries
#include "credit.hpp"
Expand All @@ -14,6 +14,7 @@
#include "lcd_display.hpp"
#include "lcd_init.hpp"
#include "mem_init.hpp"
#include "opaygo_functions.hpp"
#include "power.hpp"
#include "relay.hpp"
#include "remote.hpp"
Expand All @@ -22,6 +23,17 @@
#include "time_management.hpp"
#include "token_management.hpp"

extern "C" {
#include "opaygo_decoder.h"
}

uint64_t InputToken;
TokenData Output;
uint32_t StartingCode = 123456789;
unsigned char SECRET_KEY[16] = {0xa2, 0x9a, 0xb8, 0x2e, 0xdc, 0x5f, 0xbb, 0xc4,
0x1e, 0xc9, 0x53, 0xf, 0x6d, 0xac, 0x86, 0xb1};
// char SECRET_KEY[16] = {...};

HardwareSerial Serial2(PA3, PA2);

byte fe1[8] = {0b00011, 0b00011, 0b00011, 0b00011,
Expand Down Expand Up @@ -110,7 +122,7 @@ void setup() {
lcd.print("RTC is NOT running!");
delay(2000);
}

initializeTime();
lcd.setCursor(0, 0);
lcd.print("CSOne : ");
lcd.setCursor(8, 0);
Expand All @@ -134,23 +146,44 @@ void setup() {
}
delay(10);
relay_on();
if (is_STSmode) {
#if defined(TIM1)
TIM_TypeDef* Instance = TIM1;
TIM_TypeDef* Instance = TIM1;
#else
TIM_TypeDef* Instance = TIM2;
TIM_TypeDef* Instance = TIM2;
#endif
HardwareTimer* MyTim = new HardwareTimer(Instance);
MyTim->setOverflow(20, HERTZ_FORMAT);
MyTim->attachInterrupt(urgeent);
MyTim->resume();
} else {
printf("OpenPAYGO code written here");
HardwareTimer* MyTim = new HardwareTimer(Instance);
MyTim->setOverflow(20, HERTZ_FORMAT);
switch (Mode_select) {
case 0:
lcd.clear();
lcd.setCursor(0, 0);
lcd.println("No Configuration! ");
while (Mode_select == 0) // wait for mode configuration
{
STS_keypad();
delay(20);
}
break;

case 1:
MyTim->attachInterrupt(urgeent);
MyTim->resume();
break;

case 2:
/*OpenPayGo Token initializing code; */
printf("Welcome to the OPAYGO Device\n");
printf(
"We're waiting for the * character to start recording the key "
"presses.\n(Press the '#' key to see the device activation "
"status)\n\n");
LoadActivationVariables(); // We load the activation variableS
break;
}
}

void loop() {
if (is_STSmode) {
if (Mode_select == 1) {
mesure();
if ((mains_input_value > 50)) {
credit_reminder();
Expand All @@ -163,7 +196,24 @@ void loop() {
if ((sts_mode == 0) && (mains_input_value > 50)) {
gsm_func();
}
} else {
printf("OpenPAYGO code written here");
}

if (Mode_select == 2) {
// We wait for a token to be entered
InputToken = WaitForTokenEntry();
// We get the activation value from the token

Output = GetDataFromToken(
InputToken, &TokenCount, &UsedTokens, StartingCode,
SECRET_KEY); // We get the activation value from the token

printf("\n(Token entered: %llu)", InputToken);
printf("\n(Activation Value from Token: %d)",
Output.Value); // Activation Value found in the token
printf("\n(Count: %d)", Output.Count); // Count found in the token
printf("\n(Max Count: %d)", TokenCount); // Count found in the token
printf("\n(Used Tokens: %d)\n", UsedTokens); // Count found in the token

UpdateDeviceStatusFromTokenValue(Output.Value, Output.Count);
}
}
Loading