mirror of
https://github.com/supleed2/ELEC50003-P1-CW.git
synced 2024-11-10 01:35:50 +00:00
Create Energy<->Control reference doc
This commit is contained in:
parent
c7a5a930f1
commit
65f48f99c3
37
Control/ref/energy.cpp
Normal file
37
Control/ref/energy.cpp
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define RXpin 0 // Define your RX pin here
|
||||||
|
#define TXpin 0 // Define your TX pin here
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200); // Set up hardware UART0 (Connected to USB port)
|
||||||
|
Serial1.begin(9600, SERIAL_8N1, RXpin, TXpin); // Set up hardware UART1
|
||||||
|
|
||||||
|
// Other Drive setup stuff
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
bool charge;
|
||||||
|
DynamicJsonDocument rdoc(1024); // receive doc, not sure how big this needs to be
|
||||||
|
if(Serial1.available()){
|
||||||
|
deserializeJson(rdoc, Serial1); // Take JSON input from UART1
|
||||||
|
charge = rdoc["ch"]; // {"ch":0}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float stateOfCharge = 0;
|
||||||
|
float batteryVoltage = 0;
|
||||||
|
float batteryCycles = 0;
|
||||||
|
|
||||||
|
// Do Drive stuff, set the 5 values above
|
||||||
|
|
||||||
|
DynamicJsonDocument tdoc(1024); // transmit doc, not sure how big this needs to be
|
||||||
|
tdoc["soc"] = stateOfCharge;
|
||||||
|
tdoc["mV"] = batteryVoltage;
|
||||||
|
tdoc["cyc"] = batteryCycles;
|
||||||
|
serializeJson(tdoc, Serial1); // Build JSON and send on UART1
|
||||||
|
}
|
Loading…
Reference in a new issue