User Tools

Site Tools


lokos

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lokos [2019/05/29 06:36]
2480
lokos [2019/10/23 21:11] (current)
Line 53: Line 53:
    
 int main() { int main() {
-    printf("​Hello World!"​);​+    printf("​Hello World!\n");
 } }
  </​code>​  </​code>​
Line 146: Line 146:
  
  
-ε) Για το ε δηλώσαμε το onboard πλήκτρο σαν InterrruptIn ​ και χρησιμοποιήσαμε την ​κλάση fall η οποία κάθε φορά που το πλήκτρο πιέζεται ανάβει ή σβήνει το λαμπάκι. ​+ε) Για το ε δηλώσαμε το onboard πλήκτρο σαν InterrruptIn ​ και χρησιμοποιήσαμε την ​συνάρτηση fall η οποία κάθε φορά που το πλήκτρο πιέζεται ανάβει ή σβήνει το λαμπάκι. ​
  
 <​code>​ <​code>​
Line 265: Line 265:
  
 DigitalOut myled(LED1);​ DigitalOut myled(LED1);​
-InterruptIn button(SW2);​ 
- 
 Timer timer; Timer timer;
 Serial pc(USBTX, USBRX); ​ //serial channel over HDK USB interface Serial pc(USBTX, USBRX); ​ //serial channel over HDK USB interface
 +InterruptIn btn(SW2);
  
-double benchtime, dps; + 
-unsigned long loops;+ 
 +void pressed(){ 
 +    ​double benchtime, dps; 
 +    unsigned long loops;
     ​     ​
-  
-void button_pressed() { 
     double DMIPS;     double DMIPS;
-    double ​sum_DMIPS ​= 0; +    double ​totalDMIPSScores ​= 0; 
-    double ​max_DMIPS ​= -1000;+    double ​max = -1000;
     double avg;     double avg;
-    int number_of_runs=0; +    int totalRepetitions=0
-    printf("​Dhrystone Benchmark Program \n");+     
 +     
 +    pc.baud(9600)
 +    printf("​Dhrystone Benchmark Program ​C/1 12/01/84\r\n");
     timer.start();​     timer.start();​
     while(1) {     while(1) {
Line 290: Line 293:
             loops += LOOPS;             loops += LOOPS;
             benchtime = timer.read();​             benchtime = timer.read();​
-        } while (benchtime <= 10.000);+        } while (benchtime <= 60.000);
         myled = 0;         myled = 0;
-        ​ 
-        number_of_runs++;​ 
         dps = (double)loops / benchtime;         dps = (double)loops / benchtime;
-        DMIPS = dps/1757; 
-        if(max_DMIPS < DMIPS){ 
-            max_DMIPS = DMIPS; ​   
-        } 
         ​         ​
-        ​sum_DMIPS += DMIPS+        DMIPS = dps/1757  //1757 was the score from first MCU 
-        avg sum_DMIPS/number_of_runs+        ​totalRepetitions++
-        ​printf("​Dhrystone time for %ld passes = %.3f sek\r\n",​ loops, benchtime)+        ​totalDMIPSScores += DMIPS; 
-        ​printf("​This machine benchmarks at %.0f DMPIS\r\n", ​DMIPS)+        avg = totalDMIPSScores/​totalRepetitions ​;
-        ​printf("​The best DMIPS is : %.0f\r\n",​ max_DMIPS);​ +
-        printf("​The average DMIPS is : %.0f\r\n", ​avg);+
         ​         ​
 +        if(max < DMIPS){
 +            max = DMIPS; ​  
 +        }
 +
 +         ​printf("​Dhrystone time for %ld passes = %.3f sek\r\n",​ loops, benchtime);
 +         ​printf("​benchmarks Result =  %.0f DMPIS\r\n",​ DMIPS);
 +         ​printf("​Best DMIPS Score = : %.0f\r\n",​ max);
 +         ​printf("​Average DMIPS Score =  : %.0f\r\n",​ avg);
         wait(1.0);         wait(1.0);
     }     }
 +  ​
 } }
-  + 
-int main(int, char**) { + 
-    ​button.fall(&button_pressed); + 
-    ​while(1){}+int main() { 
 +    ​ 
 +    btn.fall(&pressed); 
 +    ​
 } }
 +
 </​code>​ </​code>​
 +
 +
 +===== Αποτελέσματα =====
 +
 +{{2a.jpg}}
 +
 +
  
  
Line 322: Line 337:
  
  
-γ) Για το γ ερώτημα ​χρειαζόματε τα εξής βήματα: +γ) Για το γ ερώτημα ​κάναμε ​κάποιες τροποποιήσεις. ​Δημιουργήσαμε μια συνάρτηση pressed η οποία ​είναι συνδεδεμένη με ενα από ​τα onboard button και είναι καταχωρημένο ως interruptIn. Στη main καλούμε τη συνάρτηση dhrystoneBenchmark() 
-  - Δημιουργία ξεχωριστών ​συναρτήσεων  +η οποία ​εκτελεί το benchmark και ​στη διάρκεια αυτής της ​εκτέλεσης πατούσαμε αρκετές φορές το interrupt button βλέποντας ταυτόχρονα την φωτεινή ένδειξη να ανάβει και να σβήνει κάθε φορά που καλούταν η pressed 
-  - Δημιουργία νημάτων για την ταυτόχρονη εκτέλεση +
-  - Εισαγωγή της ​βιβλιοθήκης rtos η οποία υποστηρίζει την εκτέλεση νημάτων.+
  
  
Line 331: Line 344:
 #include "​mbed.h"​ #include "​mbed.h"​
 #include "​dhry.h"​ #include "​dhry.h"​
-#include "​rtos.h"​ 
- 
-Thread benchThread;​ 
-Thread potThread; 
  
 DigitalOut myled(LED1);​ DigitalOut myled(LED1);​
-InterruptIn button(SW2);​ 
- 
 Timer timer; Timer timer;
 Serial pc(USBTX, USBRX); ​ //serial channel over HDK USB interface Serial pc(USBTX, USBRX); ​ //serial channel over HDK USB interface
 +InterruptIn btn(SW2);
  
-double benchtime, dps; 
-unsigned long loops; 
  
 +AnalogIn potentiometer(A3);​
 +DigitalOut led(LED2);
  
-void dhrystoneBenchmark() {+void pressed(){ 
 +     
 +    if (led)  
 +        led = 0; 
 +    else 
 +        led = 1; 
 +
 + 
 + 
 +void dhrystoneBenchmark(){ 
 +     
 +    double benchtime, dps; 
 +    unsigned long loops; 
 +    ​
     double DMIPS;     double DMIPS;
-    double ​sum_DMIPS ​= 0; +    double ​totalDMIPSScores ​= 0; 
-    double ​max_DMIPS ​= -1000;+    double ​max = -1000;
     double avg;     double avg;
-    int number_of_runs=0; +    int totalRepetitions=0
-    printf("​Dhrystone Benchmark Program \n");+     
 +     
 +    pc.baud(9600)
 +    printf("​Dhrystone Benchmark Program ​C/1 12/01/84\r\n");
     timer.start();​     timer.start();​
-    ​for(int i=0; i<10; i++){+    ​ 
 +    while(1) {
         loops = 0l;         loops = 0l;
         myled = 1;         myled = 1;
Line 362: Line 387:
             loops += LOOPS;             loops += LOOPS;
             benchtime = timer.read();​             benchtime = timer.read();​
-        } while (benchtime <= 10.000);+        } while (benchtime <= 60.000);
         myled = 0;         myled = 0;
-        ​ 
-        number_of_runs++;​ 
         dps = (double)loops / benchtime;         dps = (double)loops / benchtime;
-        DMIPS = dps/1757; 
-        if(max_DMIPS < DMIPS){ 
-            max_DMIPS = DMIPS; ​   
-        } 
         ​         ​
-        ​sum_DMIPS += DMIPS+        DMIPS = dps/1757  //1757 was the score from first MCU 
-        avg sum_DMIPS/number_of_runs+        ​totalRepetitions++
-        ​printf("​Dhrystone time for %ld passes = %.3f sek\r\n",​ loops, benchtime)+        ​totalDMIPSScores += DMIPS; 
-        ​printf("​This machine benchmarks at %.0f DMPIS\r\n", ​DMIPS)+        avg = totalDMIPSScores/​totalRepetitions ​;
-        ​printf("​The best DMIPS is : %.0f\r\n",​ max_DMIPS);​ +
-        printf("​The average DMIPS is : %.0f\r\n", ​avg);+
         ​         ​
 +        if(max < DMIPS){
 +            max = DMIPS; ​  
 +        }
 +
 +         ​printf("​Dhrystone time for %ld passes = %.3f sek\r\n",​ loops, benchtime);
 +         ​printf("​benchmarks Result =  %.0f DMPIS\r\n",​ DMIPS);
 +         ​printf("​Best DMIPS Score = : %.0f\r\n",​ max);
 +         ​printf("​Average DMIPS Score =  : %.0f\r\n",​ avg);     
         wait(1.0);         wait(1.0);
     }     }
 +    ​
 } }
  
 +int main() {
 +   
 +    dhrystoneBenchmark();​
 +    btn.fall(&​pressed);​
 +    ​
 +}
  
-AnalogIn potentiometer(A3);​ 
-DigitalOut red(D7); 
  
-void runPotentiometer(){ +</​code>​
-    float potValue ; +
-     +
-    while(1) { +
-        potValue = potentiometer.read();​ +
-   +
-        red = 1;    +
-        wait(potValue*1000);​ +
-        red = 0;   +
  
 +
 +===== Αποτελέσματα =====
 +
 +
 +
 +Τα αποτελέσματα που πήραμε ήταν παράδοξα καθώς τα νούμερα ήταν μεγαλύτερα απο το ερώτημα 2α. 
 +{{23.jpg}}
 +
 +
 +
 +====== Project Μέρος 3 ======
 +
 +
 +Αρχικός στόχος μας ήταν η δημιουργία μιας εφαρμογής στην οποία θα μπορούσαμε να εξοικειωθούμε με την χρήση της θύρας ethernet καθώς με διάφορα περιφερειακά με τα οποία θα μπορούσαμε να είχαμε αλληλεπίδραση με το χρήστη.
 +
 +Η εφαρμογή η οποία δημιουργήσαμε αποστέλει ενα HTTP request στην ιστοσελίδα openweathermap.org με την δυνατότητα ο χρήστης να επιλέξει την πόλη την οποία επιθυμεί. Στη συνέχεια διαχωρίζουμε τα δεδομένα τα οποία δεχτήκαμε και εκτυπώνουμε αυτά τα οποία έχουμε προεπιλέξει.
 +
 +Για την εφαρμογή χρησιμοποιήσαμε την βιβλιοθήκη **mbed-http**
 + 
 +
 +
 +
 +
 +
 +
 +
 +<​code>#​if DEMO == DEMO_HTTP
 +
 +#include "​mbed.h"​
 +#include "​http_request.h" ​
 +#include "​mbed_mem_trace.h"​
 +#include <​iostream>​
 +
 +using namespace std;
 +
 +void dump_response(HttpResponse* res) {
 +    char buffer[3000];​
 +    string result;
 +    printf("​Status:​ %d - %s\n", res->​get_status_code(),​ res->​get_status_message().c_str());​
 +
 +    printf("​Headers:​\n"​);​
 +    for (size_t ix = 0; ix < res->​get_headers_length();​ ix++) {
 +        printf("​\t%s:​ %s\n", res->​get_headers_fields()[ix]->​c_str(),​ res->​get_headers_values()[ix]->​c_str());​
 +        ​
     }     }
 +    printf("​\nBody (%d bytes):​\n\n%s\n",​ res->​get_body_length(),​ res->​get_body_as_string().c_str());​
 +    ​
 } }
  
  
 +NetworkInterface *connect_to_default_network_interface() {
 +    printf("​[Connecting to network...\n"​);​
  
-int main(int, char**) { +    NetworkInterfacenetwork = NetworkInterface::​get_default_instance(); 
-    benchThread.start(dhrystoneBenchmark); + 
-    ​potThread.start(runPotentiometer); +    ​if (!network{ 
-    while(1+        ​printf(" No network interface found, select an interface in '​network-helper.h'​\n"​); 
-    {+        ​return NULL;
     }     }
 +
 +    nsapi_error_t connect_status = network->​connect();​
 +
 +    if (connect_status != NSAPI_ERROR_OK) {
 +        printf("​ Failed to connect to network (%d)\n",​ connect_status);​
 +        return NULL;
 +    }
 +
 +    printf("​Connected to the network\n"​);​
 +    printf("​IP address: %s\n", network->​get_ip_address());​
 +    return network;
 } }
  
  
-</​code>​ 
  
 +int main() {
 +    printf("​Program Starting..\n"​);​
 +    ​
 +    // Connect to the network with the default networking interface
 +    NetworkInterface* network = connect_to_default_network_interface();​
  
  
 +    // Do a GET request ​
 +    {
 +        // By default the body is automatically parsed and stored in a buffer, this is memory heavy.
 +        // To receive chunked response, pass in a callback as last parameter to the constructor.
 +        ​
 +        HttpRequest* get_req = new HttpRequest(network,​ HTTP_GET, "​http://​api.openweathermap.org/​data/​2.5/​weather?​q=Ioannina&​units=metric&​APPID=3ff29328f7c661abef83a312168bc559"​);​
 +        ​
 +        HttpResponse* get_res = get_req->​send();​
 +        if (!get_res) {
 +            printf("​HttpRequest failed (error code %d)\n",​ get_req->​get_error());​
 +            return 1;
 +        }
  
 +        printf("​\n----- HTTP GET response -----\n"​);​
 +        dump_response(get_res);​
 +
 +        delete get_req;
 +    }
 +
 +    wait(osWaitForever);​
 +}
  
 +#endif
 +  </​code>​
  
 +===== Αποτελέσματα ===== 
  
 +{{output.jpg}}
  
  
lokos.1559100978.txt.gz · Last modified: 2019/10/23 21:11 (external edit)