Skip to content

Instantly share code, notes, and snippets.

@xseignard
Created June 9, 2015 12:51
Show Gist options
  • Save xseignard/bd8170132a57b7dbc695 to your computer and use it in GitHub Desktop.
Save xseignard/bd8170132a57b7dbc695 to your computer and use it in GitHub Desktop.
teleinfo
#include <SoftwareSerial.h>
SoftwareSerial cptSerial(2, 3);
#define startFrame 0x02
#define endFrame 0x03
#define startLine 0x0A
#define endLine 0x0D
void setup() {
Serial.begin(9600);
cptSerial.begin(1200);
}
String GetTeleInfo() {
String TeleInfo = "";
char charIn = 0;
while (charIn != startLine) {
charIn = cptSerial.read() & 0x7F;
}
while (charIn != endLine) {
if (cptSerial.available() > 0) {
charIn = cptSerial.read() & 0x7F;
TeleInfo += charIn;
}
}
return TeleInfo;
}
String ShowTeleInfo(String keyword, String unit, int length) {
int essai = 0;
// Nombre d'étiquettes maximum, cf documentation ERDF
int max_essais = 33;
String data = "";
String msg = "";
while(data.substring(0,keyword.length()) != keyword && essai != max_essais) {
data = GetTeleInfo();
essai++;
}
msg = "\t<";
msg += keyword;
msg += " unit=\"";
msg += unit;
msg += "\">";
if (essai != max_essais)
{
msg += data.substring((keyword.length() + 1),(length + (keyword.length() + 1)));
}
else
{
msg += "NA";
}
msg += "</";
msg += keyword;
msg += ">";
return msg;
}
void loop() {
Serial.println(ShowTeleInfo("IINST1","A",3));
Serial.println(ShowTeleInfo("IINST2","A",3));
Serial.println(ShowTeleInfo("IINST3","A",3));
delay(200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment