
hi
Fork of Riggen_internettoffentlig by
Revision 2:78362145c4f7, committed 2018-04-13
- Comitter:
- tehmur
- Date:
- Fri Apr 13 13:53:03 2018 +0000
- Parent:
- 1:55755f9baff9
- Commit message:
- hi
Changed in this revision
--- a/C12832.lib Fri Apr 13 09:51:50 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://mbed.org/users/chris/code/C12832/#7de323fa46fe
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE.md Fri Apr 13 13:53:03 2018 +0000 @@ -0,0 +1,165 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright +owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities +that control, are controlled by, or are under common control with that entity. +For the purposes of this definition, "control" means (i) the power, direct or +indirect, to cause the direction or management of such entity, whether by +contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including +but not limited to software source code, documentation source, and configuration +files. + +"Object" form shall mean any form resulting from mechanical transformation or +translation of a Source form, including but not limited to compiled object code, +generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made +available under the License, as indicated by a copyright notice that is included +in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that +is based on (or derived from) the Work and for which the editorial revisions, +annotations, elaborations, or other modifications represent, as a whole, an +original work of authorship. For the purposes of this License, Derivative Works +shall not include works that remain separable from, or merely link (or bind by +name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version +of the Work and any modifications or additions to that Work or Derivative Works +thereof, that is intentionally submitted to Licensor for inclusion in the Work +by the copyright owner or by an individual or Legal Entity authorized to submit +on behalf of the copyright owner. For the purposes of this definition, +"submitted" means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, and +issue tracking systems that are managed by, or on behalf of, the Licensor for +the purpose of discussing and improving the Work, but excluding communication +that is conspicuously marked or otherwise designated in writing by the copyright +owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf +of whom a Contribution has been received by Licensor and subsequently +incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable (except as stated in this section) patent license to make, have +made, use, offer to sell, sell, import, and otherwise transfer the Work, where +such license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by combination +of their Contribution(s) with the Work to which such Contribution(s) was +submitted. If You institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work or a +Contribution incorporated within the Work constitutes direct or contributory +patent infringement, then any patent licenses granted to You under this License +for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof +in any medium, with or without modifications, and in Source or Object form, +provided that You meet the following conditions: + +You must give any other recipients of the Work or Derivative Works a copy of +this License; and +You must cause any modified files to carry prominent notices stating that You +changed the files; and +You must retain, in the Source form of any Derivative Works that You distribute, +all copyright, patent, trademark, and attribution notices from the Source form +of the Work, excluding those notices that do not pertain to any part of the +Derivative Works; and +If the Work includes a "NOTICE" text file as part of its distribution, then any +Derivative Works that You distribute must include a readable copy of the +attribution notices contained within such NOTICE file, excluding those notices +that do not pertain to any part of the Derivative Works, in at least one of the +following places: within a NOTICE text file distributed as part of the +Derivative Works; within the Source form or documentation, if provided along +with the Derivative Works; or, within a display generated by the Derivative +Works, if and wherever such third-party notices normally appear. The contents of +the NOTICE file are for informational purposes only and do not modify the +License. You may add Your own attribution notices within Derivative Works that +You distribute, alongside or as an addendum to the NOTICE text from the Work, +provided that such additional attribution notices cannot be construed as +modifying the License. +You may add Your own copyright statement to Your modifications and may provide +additional or different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works as a whole, +provided Your use, reproduction, and distribution of the Work otherwise complies +with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted +for inclusion in the Work by You to the Licensor shall be under the terms and +conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the terms of +any separate license agreement you may have executed with Licensor regarding +such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, +service marks, or product names of the Licensor, except as required for +reasonable and customary use in describing the origin of the Work and +reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the +Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, +including, without limitation, any warranties or conditions of TITLE, +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are +solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your exercise of +permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), +contract, or otherwise, unless required by applicable law (such as deliberate +and grossly negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, incidental, +or consequential damages of any character arising as a result of this License or +out of the use or inability to use the Work (including but not limited to +damages for loss of goodwill, work stoppage, computer failure or malfunction, or +any and all other commercial damages or losses), even if such Contributor has +been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to +offer, and charge a fee for, acceptance of support, warranty, indemnity, or +other liability obligations and/or rights consistent with this License. However, +in accepting such obligations, You may act only on Your own behalf and on Your +sole responsibility, not on behalf of any other Contributor, and only if You +agree to indemnify, defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason of your +accepting any such warranty or additional liability.
--- a/main.cpp Fri Apr 13 09:51:50 2018 +0000 +++ b/main.cpp Fri Apr 13 13:53:03 2018 +0000 @@ -1,8 +1,20 @@ - //-----------Bibilioteker------------// +//-----------Bibilioteker------------// #include "mbed.h" +#define BUTTON1 p18 +#include <stdio.h> +#include <errno.h> #include "EthernetInterface.h" -#include "C12832.h" // Biblioteket til skjermen på applikasjonsbrettet +#include "FATFileSystem.h" +#include "SDBlockDevice.h" +// Physical block device, can be any device that supports the BlockDevice API +SDBlockDevice bd( + MBED_CONF_SD_SPI_MOSI, + MBED_CONF_SD_SPI_MISO, + MBED_CONF_SD_SPI_CLK, + MBED_CONF_SD_SPI_CS); +// File system declaration +FATFileSystem fs("fs"); Serial pc(USBTX, USBRX); // Serial kommunikasjon med PC SPI bus(p11, p12, p13); // p11-mosi brukes ikke, p12-miso kobles til pinne 3 på sensoren, p13-sck kobles til pinne 4 på sensoren @@ -11,17 +23,17 @@ DigitalOut slave_3(p17); // p18-SS, koble til pinne 5 på sensor 3 EthernetInterface net; //Ethernet interface TCPSocket socket; //TCP socket -Timer tid; // Timer -Ticker t, t1; // Tikker for å kjøre avlesningen to ganger i sekundet. -C12832 lcd(p5, p7, p6, p8, p11);// Skjermen +Timer tid; // Timer +Ticker t; // Tikker for å kjøre avlesningen to ganger i sekundet. - //--------------Funksjoner-------------// + +//--------------Funksjoner-------------// void data(float s1, float av1,float s2, float av2,float s3, float av3); // Oppretting av et array for webaddressen void send(char *arr, int lengde); // Sender data til mottat webaddresse void sensor(); // Avlesning av Sensor verdiene void omregning(int a, float speed); // Omregning av avlesningen - //----------Globale variable-----------// +//----------Globale variable-----------// int i=0, ant=0; // Variabelen i er til for å forenkle valget av de tre sensorene, ant er der for antallet avlesninger int avlest[3]; // Array for lagring av avlest verdi float trykk[3]; // Array for lagring av omregnet trykkverdi @@ -30,7 +42,7 @@ float avvik[3]; // Array for lagring av standardavviket på vannhastigheten float gjennomsnitt[3]; // Array for lagring av gjennomsnittelig vannhastighet - //--------Definisjoner----------------// +//--------Definisjoner----------------// #define ut_min 0x0666 // Minste avleste verdi defineres #define ut_max 0x399A // Maksimum avlest verdi defineres #define trykk_min -6000 // Minimale trykkverdi i Pascal på sensoren defineres @@ -38,41 +50,35 @@ int main() { + fs.mount(&bd); // Try to mount the filesystem pc.printf("\nSetter opp nettverksforbindelse"); net.connect(); // Setter opp nettforbindelse pc.printf("\nTilkoblet nettet"); - + const char *ip = net.get_ip_address();// Innhenter IP addresse printf("\nIP address is: %s\n\n", ip ? ip : "No IP"); - + bus.format(16,0); // Oppsett av SPI dataformat, (16 bit data, mode 0) - // mode 0 = (klokke verdi ved tomgang = 0, data avleses ved opp-flanke av klokkepuls) + // mode 0 = (klokke verdi ved tomgang = 0, data avleses ved opp-flanke av klokkepuls) bus.frequency(800000); // Velger frekvensen på kommuniaksjonsklokken til 800KHz slave_1 = slave_2 = slave_3 = 1;// Ingen slave valgt pc.printf("\n\tSensor 1\t\t\tSensor 2\t\t\tSensor 3\t\n"); pc.printf("Inn\tP\t\t[m/s]\tInn\tP\t\t[m/s]\tInn\tP\t\t[m/s]\n"); t.attach(&sensor,0.5); // Setter igang Tikker med sensor() fuknsjonen som kalles 2 ganger i sekundet tid.start(); // Starter timer - lcd.cls(); // Sletter alt som er på lokale skjermmen - lcd.locate(0,3); // Lokkaliserer hvor på skjermen skriften skal komme - lcd.printf(" S1 S2 S3"); - - //-----------Evig løkke-------------// - while(1) - { + + + //-----------Evig løkke-------------// + while(1) { static bool sist = false; // Dette er en liten kode for å sende kun en gang. - while (16 < tid.read()) // Tiden må ha passert 16 sekunder for dette blir sant - { - if(ant==144) // Tester på om det er blitt utført 144 målinger - { + while (16 < tid.read()) { // Tiden må ha passert 16 sekunder for dette blir sant + if(ant==144) { // Tester på om det er blitt utført 144 målinger ant=0; // Antallet målinger nullstilles for en ny runde - if(!sist) // Tester om ikke sist - { + if(!sist) { // Tester om ikke sist sist = true; // Setter sist til sann, slik at sendingenn kun utføres en gang etter 16 sekunder t.detach(); // Detacher fuknsjonen sensor fra Tikker for å kunne sende uavbrutt. data(gjennomsnitt[0], avvik[0], gjennomsnitt[1], avvik[1], gjennomsnitt[2], avvik[2]);// Sender data - for(int c=0; c<3; c++)// En For løkke for å nullstille de Globale variablene - { + for(int c=0; c<3; c++) { // En For løkke for å nullstille de Globale variablene avlest[c]=0; gjennomsnitt[c]=0.0; avvik[c]=0.0; @@ -81,76 +87,71 @@ sum_fart[c]=0.0; } t.attach(&sensor,0.5);// Tilegner funksjonen sensor til Tikker igjen for avlesning av sensor verdier + tid.stop(); // Stopper Timer og resetter for ny runde tid.reset(); } - } - else // En del av sending en gang - { + } else { // En del av sending en gang sist=false; } } + + tid.start(); // Starter timer igjen for nye 16 sekunder - tid.start(); // Starter timer igjen for nye 16 sekunder } } - //----------Sensor funskjonen------------// -void sensor() +//----------Sensor funskjonen------------// +void sensor() { - for(i=0; i<3; i++) // En for løkke for å lese av alle tre sensorene - { - if(i==0) - { + for(i=0; i<3; i++) { // En for løkke for å lese av alle tre sensorene + if(i==0) { slave_1 = 0; // Velger sensor 1 som slave avlest[i] = bus.write(0x0001);// Sender dummy command for å få respons slave_1 = 1; // Slipper slaven } - - if(i==1) - { - slave_2 = 0; // Velger sensor 2 som slave + + if(i==1) { + slave_2 = 0; // Velger sensor 2 som slave avlest[i] = bus.write(0x0001);// Be om trykk verdi avlesning slave_2 = 1; // Slipper slaven } - - if(i==2) - { - slave_3 = 0; // Velger sensor 3 som slave + + if(i==2) { + slave_3 = 0; // Velger sensor 3 som slave avlest[i] = bus.write(0x0001);// Be om trykk verdi avlesning slave_3 = 1; // Slipper slaven } - + trykk[i]=1.0*(avlest[i]-ut_min)*(trykk_max-trykk_min)/(ut_max - ut_min)+trykk_min; // Omregningsformel gitt fra produsenten fart[i]= sqrt(abs(2*trykk[i])/1000); // Omregner trykket til hastighet - pc.printf("%X\t%.2f\t\t%.2f\t", avlest[i], trykk[i], fart[i]); // Hviser innlest og omregnet verdier + pc.printf("%X\t%.2f\t%.2f\t", avlest[i], trykk[i], fart[i]); // Hviser innlest og omregnet verdier omregning(i, fart[i]); + } - pc.printf("\n"); // New line for at visningen på Teraterm blir forståelig - lcd.locate(0,15); // Lokaloserer hvor på skjermen verdiene skal skrives - lcd.printf(" %.2f %.2f %.2f", fart[0], fart[1], fart[2]);// Viser verdiene på lokal skjerm - + FILE *fp = fopen("/fs/verdier.csv","a");// Åpner fila verdier for skriving + fprintf(fp,"%X;%f;%f; ;%X;%f;%f; ;%X;%f;%f; ;", avlest[0], trykk[0], fart[0], avlest[1], trykk[1], fart[1], avlest[2], trykk[2], fart[2]); // Loggfører verdien + fprintf(fp,"\n"); //ny linje i csv filen + fclose(fp); } - //----------Omregningsfunskjonen------------// - void omregning(int a, float speed) - { +//----------Omregningsfunskjonen------------// +void omregning(int a, float speed) +{ ant++; // Inkrementerer den globale variabelen ant med en sum_fart[a] = sum_fart[a] + speed;// summerer alle hastigheter for gjennomsnitt utregning - if(ant==144) - { - for(int b=0;b<3;b++) // Regner ut gjennomsnittet for alle tre hastigheten - { + if(ant==144) { + for(int b=0; b<3; b++) { // Regner ut gjennomsnittet for alle tre hastigheten gjennomsnitt[b]=sum_fart[b]/48; avvik[b]=sqrt(((pow(sum_fart[b]-gjennomsnitt[b], 2)))/(48-1)); pc.printf("\n Gjennonsnitt: %.2f\t Standardavvik: %.2f\n",gjennomsnitt[b],avvik[b]); } pc.printf("antallet: %d\n",ant); } - } +} - //----------Sende funksjon------------// +//----------Sende funksjon------------// void send(char *arr, int lengde) { socket.open(&net); @@ -164,11 +165,11 @@ socket.close(); } - //----------Dataene som skal sendes------------// +//----------Dataene som skal sendes------------// void data(float s1, float av1,float s2, float av2,float s3, float av3) { char a[200]; // Oppretter buffer ////Fyller buffer med update link med riktig felt og verdi - sprintf (a, "GET https://api.thingspeak.com/update?api_key=TT0INEEL44E31AHP&field1=%.2f&field2=%.2f&field3=%.2f&field4=%.2f&field5=%.2f&field6=%.2f\r\n",s1,av1,s2,av2,s3,av3); + sprintf (a, "GET https://api.thingspeak.com/update?api_key=TT0INEEL44E31AHP&field1=%.2f&field2=%.2f&field3=%.2f&field4=%.2f&field5=%.2f&field6=%.2f\r\n",s1,av1,s2,av2,s3,av3); send(a,200); //Kaller opp funksjonen send for å sende til thingspeak pc.printf("\n\tSensor 1\t\t\tSensor 2\t\t\tSensor 3\t\n"); pc.printf("Inn\tP\t\t[m/s]\tInn\tP\t\t[m/s]\tInn\tP\t\t[m/s]\n");
--- a/mbed-os.lib Fri Apr 13 09:51:50 2018 +0000 +++ b/mbed-os.lib Fri Apr 13 13:53:03 2018 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#f9ee4e849f8cbd64f1ec5fdd4ad256585a208360 +https://github.com/ARMmbed/mbed-os/#addec7ba10054be03849eff58a1d17f157391e7d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed_app.json Fri Apr 13 13:53:03 2018 +0000 @@ -0,0 +1,7 @@ +{ + "target_overrides": { + "*": { + "platform.stdio-convert-newlines": true + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sd-driver.lib Fri Apr 13 13:53:03 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/sd-driver/#c16fa2bf36b87e862f81e0b30dbddca1460e1084