Created
January 31, 2018 22:51
-
-
Save shakna-israel/6e6f7d6dcec871505f2d9b0f033ea584 to your computer and use it in GitHub Desktop.
Ardl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <EEPROM.h> | |
#include "base64.hpp" | |
void help() { | |
Serial.println(F("Ardl Helpfile\n" | |
"\n" | |
"System Limitations:\n" | |
"Maximum Input Length: 255 characters\n" | |
"CPU Speed: 8Mhz\n" | |
"\n" | |
"System Commands:\n" | |
"echo ...var\tEchoes an input back to the console.\n" | |
"clear\tClears the console by printing 1000 newlines.\n" | |
"b64 ..msg\tEncode a string to base64.\n" | |
"-b64 ..msg\tDecode a base64 string.\n" | |
"?\tShows this message.\n")); | |
} | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("Welcome to Ardl!"); | |
help(); | |
} | |
char command[255]; | |
int com_pos = 0; | |
void b64() { | |
unsigned char b64[strlen(String(command).substring(4).c_str()) - 1]; | |
for (int i = 0; i < strlen(String(command).substring(4).c_str() - 1); i++) { | |
b64[i] = 0; | |
} | |
encode_base64(String(command).substring(4).c_str(), strlen(String(command).substring(4).c_str()), b64); | |
Serial.println((char*)b64); | |
} | |
void ub64() { | |
char str[251]; | |
for (int i = 0; i < 251; i++) { | |
str[i] = 0; | |
} | |
decode_base64(String(command).substring(5).c_str(), str); | |
Serial.println(str); | |
} | |
void eval() { | |
if (command[0] == '?') { | |
help(); | |
} else if (strncmp(command, "echo", 4) == 0) { | |
Serial.println(String(command).substring(5).c_str()); | |
} else if (strncmp(command, "clear", 5) == 0) { | |
for (int i = 0; i < 1000; i++) { | |
Serial.write('\n'); | |
} | |
} else if (strncmp(command, "b64", 3) == 0) { | |
b64(); | |
} else if (strncmp(command, "-b64", 4) == 0) { | |
ub64(); | |
} else { | |
Serial.print("Error, command not understood: "); | |
Serial.println(command); | |
} | |
} | |
void loop() { | |
if (Serial.available() > 0) { | |
int data = Serial.read(); | |
if (data != 10) { | |
command[com_pos] = data; | |
if (com_pos < 254) { | |
com_pos += 1; | |
} | |
} else { | |
eval(); | |
for (int i = 0; i < 255; i++) { | |
command[i] = 0; | |
} | |
com_pos = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment