Skip to content

Commit

Permalink
Remote_global_and _local_mqtt_display
Browse files Browse the repository at this point in the history
  • Loading branch information
G4lile0 committed Mar 7, 2020
1 parent 6e4d676 commit 283a615
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 14 deletions.
86 changes: 79 additions & 7 deletions FossaGroundStation/src/Display/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ void displayInit(){
display = new SSD1306(board.OLED__address, board.OLED__SDA, board.OLED__SCL);

ui = new OLEDDisplayUi(display);

ui->setTargetFPS(60);
ui->setActiveSymbol(activeSymbol);
ui->setInactiveSymbol(inactiveSymbol);
Expand Down Expand Up @@ -127,9 +126,44 @@ void drawFrame2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int1


void drawFrame3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(ArialMT_Plain_10);
display->drawString(x, y, "pantalla global");
// display->setTextAlignment(TEXT_ALIGN_LEFT);
// display->setFont(ArialMT_Plain_10);
// display->drawString(x, y, "pantalla global");

if (status.global_frame_text_leght==0 ) ui->nextFrame();

for (uint8_t n=0; n<status.global_frame_text_leght;n++){

switch (status.global_frame_text[n].text_font) {
case 2:
display->setFont(ArialMT_Plain_16);
break;

default:
display->setFont(ArialMT_Plain_10);
break;
}

// 0 Left 1 Right 2 Center 3 Center Both
switch (status.global_frame_text[n].text_alignment) {
case 1:
display->setTextAlignment(TEXT_ALIGN_RIGHT);
break;
case 2:
display->setTextAlignment(TEXT_ALIGN_CENTER);
break;
case 3:
display->setTextAlignment(TEXT_ALIGN_CENTER_BOTH);
break;

default:
display->setTextAlignment(TEXT_ALIGN_LEFT);
break;
}
display->drawString(x+status.global_frame_text[n].text_pos_x, y+ status.global_frame_text[n].text_pos_y, String(status.global_frame_text[n].text));

}

}

void drawFrame4(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
Expand Down Expand Up @@ -220,9 +254,47 @@ void drawFrame7(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int1


void drawFrame8(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(ArialMT_Plain_10);
display->drawString(x, y, "pantalla rec local");
// display->setTextAlignment(TEXT_ALIGN_LEFT);
// display->setFont(ArialMT_Plain_10);
// display->drawString(x, y, "pantalla rec local");


if (status.local_frame_text_leght==0 ) ui->nextFrame();

for (uint8_t n=0; n<status.local_frame_text_leght;n++){
switch (status.local_frame_text[n].text_font) {
case 2:
display->setFont(ArialMT_Plain_16);
break;

default:
display->setFont(ArialMT_Plain_10);
break;
}

// 0 Left 1 Right 2 Center 3 Center Both
switch (status.local_frame_text[n].text_alignment) {
case 1:
display->setTextAlignment(TEXT_ALIGN_RIGHT);
break;
case 2:
display->setTextAlignment(TEXT_ALIGN_CENTER);
break;
case 3:
display->setTextAlignment(TEXT_ALIGN_CENTER_BOTH);
break;

default:
display->setTextAlignment(TEXT_ALIGN_LEFT);
break;
}

display->drawString(x+status.local_frame_text[n].text_pos_x, y+ status.local_frame_text[n].text_pos_y, status.local_frame_text[n].text);
}




}


Expand Down
27 changes: 26 additions & 1 deletion FossaGroundStation/src/Mqtt/MQTT_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ String MQTT_Client::buildTopic(const char* topic){
}

void MQTT_Client::subscribeToAll() {
String sat_pos_oled = String(topicStart) + "/global/sat_pos_oled";
String sat_pos_oled = String(topicStart) + "/global/#";
subscribe(buildTopic(topicData).c_str());
subscribe(sat_pos_oled.c_str());
}
Expand Down Expand Up @@ -245,6 +245,18 @@ void MQTT_Client::manageMQTTData(char *topic, uint8_t *payload, unsigned int len
manageSatPosOled((char*)payload, length);
}

// Remote_Frame_Local_A -m "[]" -t fossa/global/global_frame
//
// [number of strings,
// [font,TextAlignment,x,y,"string text"],
// ...
// ]
//
// if (!strcmp(topic, "fossa/global/global_frame")) { // no tengo permisos por ahora pruebas en el usuario local
if (!strcmp(topic, "fossa/g4lile0/test_G4lile0_new/data/remote/global_frame")) {
radio.remote_global_frame((char*)payload, length);
}

// Remote_Reset -m "[1]" -t fossa/g4lile0/test_G4lile0_new/remote/reset
if (!strcmp(topic, buildTopic((String(topicRemote) + String(topicRemoteReset)).c_str()).c_str())) {
ESP.restart();
Expand Down Expand Up @@ -314,8 +326,21 @@ if (!strcmp(topic, buildTopic((String(topicRemote) + String(topicRemoteFook)).c_
radio.remote_fook((char*)payload, length);
}


// Remote_Satellite_Name -m "[\"FossaSat-3\"]" -t fossa/g4lile0/test_G4lile0_new/data/remote/sat
if (!strcmp(topic, buildTopic((String(topicRemote) + String(topicRemoteSat)).c_str()).c_str())) {
radio.remote_sat((char*)payload, length);
}

// Remote_Frame_Local_ -m "[\"FossaSat-3\"]" -t fossa/g4lile0/test_G4lile0_new/data/remote/sat
if (!strcmp(topic, buildTopic((String(topicRemote) + String(topicRemoteLocalFrame)).c_str()).c_str())) {
radio.remote_local_frame((char*)payload, length);
}


}


void MQTT_Client::manageSatPosOled(char* payload, size_t payload_len) {
DynamicJsonDocument doc(60);
char payloadStr[payload_len+1];
Expand Down
5 changes: 3 additions & 2 deletions FossaGroundStation/src/Mqtt/MQTT_Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ class MQTT_Client : public PubSubClient {
const char* topicRemoteFbw PROGMEM= "fbw";
const char* topicRemoteFsw PROGMEM= "fsw";
const char* topicRemoteFook PROGMEM= "fok";


const char* topicRemoteLocalFrame PROGMEM= "frame_l";
const char* topicRemoteSat PROGMEM= "sat";



};
Expand Down
79 changes: 77 additions & 2 deletions FossaGroundStation/src/Radio/Radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,6 @@ void Radio::remote_fsw(char* payload, size_t payload_len) {
readState(state);
}



void Radio::remote_fook(char* payload, size_t payload_len) {
DynamicJsonDocument doc(60);
char payloadStr[payload_len+1];
Expand All @@ -799,8 +797,85 @@ void Radio::remote_fook(char* payload, size_t payload_len) {
else
// state = ((SX1268*)lora)->setDataShapingOOK(ook_shape);
readState(state);
}

void Radio::remote_sat(char* payload, size_t payload_len) {
DynamicJsonDocument doc(256);
char payloadStr[payload_len+1];
memcpy(payloadStr, payload, payload_len);
payloadStr[payload_len] = '\0';
deserializeJson(doc, payload);

const char* satelite = doc[0];
String str(satelite);
status.modeminfo.satelite = str;
Serial.println("");
Serial.print(F("Listening Satellite: ")); Serial.print(str);

}


void Radio::remote_global_frame(char* payload, size_t payload_len) {
DynamicJsonDocument doc(256);
char payloadStr[payload_len+1];
memcpy(payloadStr, payload, payload_len);
payloadStr[payload_len] = '\0';
deserializeJson(doc, payload);
status.global_frame_text_leght = doc[0];
Serial.println("");
Serial.println(status.global_frame_text_leght);
Serial.print(F("received frame: ")); Serial.print(status.global_frame_text_leght);
const char* texto = "12345678901234567890";

for (uint8_t n=0; n<status.global_frame_text_leght;n++){
status.global_frame_text[n].text_font = doc[n+1][0];
status.global_frame_text[n].text_alignment = doc[n+1][1];
status.global_frame_text[n].text_pos_x = doc[n+1][2];
status.global_frame_text[n].text_pos_y = doc[n+1][3];
texto = doc[n+1][4];
String str(texto);
status.global_frame_text[n].text= str; Serial.println("");
Serial.print(F("Text "));Serial.print(n);
Serial.print(F(" Font "));Serial.print(status.global_frame_text[n].text_font);
Serial.print(F(" Alig "));Serial.print(status.global_frame_text[n].text_alignment);
Serial.print(F(" Pos x "));Serial.print(status.global_frame_text[n].text_pos_x);
Serial.print(F(" Pos y "));Serial.print(status.global_frame_text[n].text_pos_y);
Serial.print(F(" -> "));Serial.print(status.global_frame_text[n].text);
}
}


void Radio::remote_local_frame(char* payload, size_t payload_len) {
DynamicJsonDocument doc(256);
char payloadStr[payload_len+1];
memcpy(payloadStr, payload, payload_len);
payloadStr[payload_len] = '\0';
deserializeJson(doc, payload);
status.local_frame_text_leght = doc[0];
Serial.println("");
Serial.println(status.local_frame_text_leght);
Serial.print(F("received frame: ")); Serial.print(status.local_frame_text_leght);
const char* texto = "12345678901234567890";

for (uint8_t n=0; n<status.local_frame_text_leght;n++){
status.local_frame_text[n].text_font = doc[n+1][0];
status.local_frame_text[n].text_alignment = doc[n+1][1];
status.local_frame_text[n].text_pos_x = doc[n+1][2];
status.local_frame_text[n].text_pos_y = doc[n+1][3];
texto = doc[n+1][4];
String str(texto);
status.local_frame_text[n].text= str; Serial.println("");
Serial.print(F("Text "));Serial.print(n);
Serial.print(F(" Font "));Serial.print(status.local_frame_text[n].text_font);
Serial.print(F(" Alig "));Serial.print(status.local_frame_text[n].text_alignment);
Serial.print(F(" Pos x "));Serial.print(status.local_frame_text[n].text_pos_x);
Serial.print(F(" Pos y "));Serial.print(status.local_frame_text[n].text_pos_y);
Serial.print(F(" -> "));Serial.print(status.local_frame_text[n].text);
}
}






4 changes: 4 additions & 0 deletions FossaGroundStation/src/Radio/Radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class Radio {
void remote_fbw(char* payload, size_t payload_len);
void remote_fsw(char* payload, size_t payload_len);
void remote_fook(char* payload, size_t payload_len);
void remote_global_frame(char* payload, size_t payload_len);
void remote_local_frame(char* payload, size_t payload_len);
void remote_sat(char* payload, size_t payload_len);


private:
Radio();
Expand Down
30 changes: 28 additions & 2 deletions FossaGroundStation/src/Status.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct SysInfo {
};

struct PacketInfo {
String time = " Waiting ";
String time = "Waiting ";
float rssi = 0;
float snr = 0;
float frequencyerror = 0;
Expand All @@ -59,13 +59,39 @@ struct ModemInfo {
};


struct Global_Frame_Text {
uint8_t n;
uint8_t text_font;
uint8_t text_alignment;
int16_t text_pos_x;
int16_t text_pos_y;
String text = "12345678901234567890";
};

struct Local_Frame_Text {
uint8_t n;
uint8_t text_font;
uint8_t text_alignment;
int16_t text_pos_x;
int16_t text_pos_y;
String text = "12345678901234567890";
};




struct Status {
const uint32_t version = 2003021; // version year month day release
const uint32_t version = 2003061; // version year month day release
bool mqtt_connected = false;
SysInfo sysInfo;
PacketInfo lastPacketInfo;
ModemInfo modeminfo;
float satPos[2] = {0, 0};
uint8_t global_frame_text_leght = 0;
uint8_t local_frame_text_leght = 0;
Global_Frame_Text global_frame_text[10];
Local_Frame_Text local_frame_text[10];

};


Expand Down

0 comments on commit 283a615

Please sign in to comment.