Skip to content

Commit

Permalink
Astyle formatting ncurses example
Browse files Browse the repository at this point in the history
  • Loading branch information
TMRh20 committed Dec 10, 2021
1 parent 0e739e0 commit 49fd7da
Showing 1 changed file with 121 additions and 113 deletions.
234 changes: 121 additions & 113 deletions examples_RPi/ncurses/RF24Mesh_Ncurses_Master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,145 +40,153 @@ uint16_t failID = 0;
int main()
{

printf("Establishing mesh...\n");
mesh.setNodeID(0);
if (!mesh.begin()) {
printf("Radio hardware not responding or could not connect to network.\n");
return 0;
}
radio.printDetails();

initscr(); /* Start curses mode */
start_color();
curs_set(0);
//keypad(stdscr, TRUE); //Enable user interaction
init_pair(1, COLOR_GREEN, COLOR_BLACK);
init_pair(2, COLOR_BLUE, COLOR_GREEN);
attron(COLOR_PAIR(1));
printw("RF24Mesh Master Node Monitoring Interface by TMRh20 - 2014-2021\n");
attroff(COLOR_PAIR(1));
refresh(); /* Print it on to the real screen */

uint32_t kbTimer = 0,kbCount = 0, pingTimer=millis();
unsigned long totalPayloads = 0;
uint8_t boldID = 0;
while(1)
{
printf("Establishing mesh...\n");
mesh.setNodeID(0);
if (!mesh.begin()) {
printf("Radio hardware not responding or could not connect to network.\n");
return 0;
}
radio.printDetails();

initscr(); /* Start curses mode */
start_color();
curs_set(0);
//keypad(stdscr, TRUE); //Enable user interaction
init_pair(1, COLOR_GREEN, COLOR_BLACK);
init_pair(2, COLOR_BLUE, COLOR_GREEN);
attron(COLOR_PAIR(1));
printw("RF24Mesh Master Node Monitoring Interface by TMRh20 - 2014-2021\n");
attroff(COLOR_PAIR(1));
refresh(); /* Print it on to the real screen */

uint32_t kbTimer = 0, kbCount = 0, pingTimer = millis();
unsigned long totalPayloads = 0;
uint8_t boldID = 0;

while (1)
{

// Call mesh.update to keep the network updated
mesh.update();
// In addition, keep the 'DHCP service' running on the master node so addresses will
// be assigned to the sensor nodes
mesh.DHCP();
mesh.DHCP();

attron(A_BOLD | COLOR_PAIR(1));
mvprintw(2,0,"[Last Payload Info]\n");
mvprintw(2, 0, "[Last Payload Info]\n");
attroff(A_BOLD | COLOR_PAIR(1));

// Check for incoming data from the sensors
while(network.available()){
RF24NetworkHeader header;
network.peek(header);

// Print the total number of received payloads
mvprintw(9,0," Total: %lu\n",totalPayloads++);
// Check for incoming data from the sensors
while (network.available()) {
RF24NetworkHeader header;
network.peek(header);

// Print the total number of received payloads
mvprintw(9, 0, " Total: %lu\n", totalPayloads++);

kbCount++;
kbCount++;

// Read the network payload
network.read(header,0,0);
// Read the network payload
network.read(header, 0, 0);

// Display the header info
mvprintw(3,0," HeaderID: %u \n Type: %d \n From: 0%o \n ",header.id,header.type,header.from_node);
// Display the header info
mvprintw(3, 0, " HeaderID: %u \n Type: %d \n From: 0%o \n ", header.id, header.type, header.from_node);

for(uint8_t i=0; i<mesh.addrListTop; i++){
if(header.from_node == mesh.addrList[i].address){
boldID = mesh.addrList[i].nodeID;
}
}
for (uint8_t i = 0; i < mesh.addrListTop; i++) {
if (header.from_node == mesh.addrList[i].address) {
boldID = mesh.addrList[i].nodeID;
}
}
}
printNodes(boldID);

if(millis()-kbTimer > 1000){
kbTimer = millis();
attron(A_BOLD | COLOR_PAIR(1));
mvprintw(7,0,"[Data Rate (In)]");
attroff(A_BOLD | COLOR_PAIR(1));
mvprintw(8,0," Kbps: %.2f",(kbCount * 32 * 8)/1000.00);
kbCount = 0;
if (millis() - kbTimer > 1000) {
kbTimer = millis();
attron(A_BOLD | COLOR_PAIR(1));
mvprintw(7, 0, "[Data Rate (In)]");
attroff(A_BOLD | COLOR_PAIR(1));
mvprintw(8, 0, " Kbps: %.2f", (kbCount * 32 * 8) / 1000.00);
kbCount = 0;

}
}

// Ping each connected node, one per second
if(millis()-pingTimer>1003 && mesh.addrListTop > 0){
pingTimer=millis();
if( nodeCounter == mesh.addrListTop){
nodeCounter = 0;
}
pingNode(nodeCounter);
nodeCounter++;
}
// Ping each connected node, one per second
if (millis() - pingTimer > 1003 && mesh.addrListTop > 0) {
pingTimer = millis();
if ( nodeCounter == mesh.addrListTop) {
nodeCounter = 0;
}
pingNode(nodeCounter);
nodeCounter++;
}

/*uint32_t nOK,nFails;
network.failures(&nFails,&nOK);
attron(A_BOLD | COLOR_PAIR(1));
mvprintw(2,24,"[Transmit Results] ");
attroff(A_BOLD | COLOR_PAIR(1));
mvprintw(3,25," #OK: %u ",nOK);
mvprintw(4,25," #Fail: %u ",nFails);*/
/*uint32_t nOK,nFails;
network.failures(&nFails,&nOK);
attron(A_BOLD | COLOR_PAIR(1));
mvprintw(2,24,"[Transmit Results] ");
attroff(A_BOLD | COLOR_PAIR(1));
mvprintw(3,25," #OK: %u ",nOK);
mvprintw(4,25," #Fail: %u ",nFails);*/


refresh();
delay(2);
}//while 1
refresh();
delay(2);
}//while 1

endwin(); /* End curses mode */
return 0;
endwin(); /* End curses mode */
return 0;
}


void printNodes(uint8_t boldID){

uint8_t xCoord = 2;
attron(A_BOLD | COLOR_PAIR(1));
mvprintw(xCoord++,27,"[Address Assignments]\n");
attroff(A_BOLD | COLOR_PAIR(1));
for( uint8_t i=0; i<mesh.addrListTop; i++){
if( failID == mesh.addrList[i].nodeID){
attron(COLOR_PAIR(2));
}else
if( boldID == mesh.addrList[i].nodeID ){
attron(A_BOLD | COLOR_PAIR(1));
}
mvprintw(xCoord++,28,"ID: %d Network: 0%o ",mesh.addrList[i].nodeID,mesh.addrList[i].address);
attroff(A_BOLD | COLOR_PAIR(1));
attroff(COLOR_PAIR(2));
void printNodes(uint8_t boldID) {

uint8_t xCoord = 2;
attron(A_BOLD | COLOR_PAIR(1));
mvprintw(xCoord++, 27, "[Address Assignments]\n");
attroff(A_BOLD | COLOR_PAIR(1));
for ( uint8_t i = 0; i < mesh.addrListTop; i++) {
if ( failID == mesh.addrList[i].nodeID) {
attron(COLOR_PAIR(2));
} else if ( boldID == mesh.addrList[i].nodeID ) {
attron(A_BOLD | COLOR_PAIR(1));
}
mvprintw(xCoord++, 28, "ID: %d Network: 0%o ", mesh.addrList[i].nodeID, mesh.addrList[i].address);
attroff(A_BOLD | COLOR_PAIR(1));
attroff(COLOR_PAIR(2));
}
mvprintw(xCoord++,28," ");
mvprintw(xCoord++,28," ");
mvprintw(xCoord++,28," ");
mvprintw(xCoord++, 28, " ");
mvprintw(xCoord++, 28, " ");
mvprintw(xCoord++, 28, " ");
}

void pingNode(uint8_t listNo){

attron(A_BOLD | COLOR_PAIR(1));
mvprintw(11,0,"[Ping Test]\n");
attroff(A_BOLD | COLOR_PAIR(1));

RF24NetworkHeader headers(mesh.addrList[listNo].address,NETWORK_PING);
uint32_t pingtime=millis();
bool ok = false;
if(headers.to_node){
ok = network.write(headers,0,0);
if(ok && failID == mesh.addrList[listNo].nodeID){ failID = 0; }
if(!ok){ failID = mesh.addrList[listNo].nodeID; }
}
pingtime = millis()-pingtime;
mvprintw(12,0," ID:%d ",mesh.addrList[listNo].nodeID);
mvprintw(13,0," Net:0%o ",mesh.addrList[listNo].address);
mvprintw(14,0," Time:%ums ",pingtime);

if(ok || !headers.to_node){ mvprintw(15,0," OK ");
} else{ attron(A_BOLD); mvprintw(15,0," FAIL"); attron(A_BOLD); }
void pingNode(uint8_t listNo) {

attron(A_BOLD | COLOR_PAIR(1));
mvprintw(11, 0, "[Ping Test]\n");
attroff(A_BOLD | COLOR_PAIR(1));

RF24NetworkHeader headers(mesh.addrList[listNo].address, NETWORK_PING);
uint32_t pingtime = millis();
bool ok = false;
if (headers.to_node) {
ok = network.write(headers, 0, 0);
if (ok && failID == mesh.addrList[listNo].nodeID) {
failID = 0;
}
if (!ok) {
failID = mesh.addrList[listNo].nodeID;
}
}
pingtime = millis() - pingtime;
mvprintw(12, 0, " ID:%d ", mesh.addrList[listNo].nodeID);
mvprintw(13, 0, " Net:0%o ", mesh.addrList[listNo].address);
mvprintw(14, 0, " Time:%ums ", pingtime);

if (ok || !headers.to_node) {
mvprintw(15, 0, " OK ");
} else {
attron(A_BOLD);
mvprintw(15, 0, " FAIL");
attron(A_BOLD);
}
}

0 comments on commit 49fd7da

Please sign in to comment.