Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface mbed-rtos mbed
main.cpp
00001 #include <stdio.h> 00002 00003 #include "mbed.h" 00004 #include "rtos.h" 00005 #include "cmsis_os.h" 00006 #include "EthernetIf.h" 00007 00008 #include "Settings.h" 00009 #include "Capture.h" 00010 #include "Http_post.h" 00011 #include "CommTCP.h" 00012 #include "SignalProcessor.h" 00013 #include "EventDetector.h" 00014 00015 #include "TelnetServer.h" 00016 00017 00018 EthernetInterface eth; 00019 00020 void thread1(void const *args) 00021 { 00022 DigitalOut led1(LED1); 00023 int n = 0; 00024 //int tatual, tnovo; 00025 float rms[NUMBER_OF_CHANNELS]; 00026 00027 Capture::Initialize(); 00028 /* 00029 Timer t; 00030 t.start(); 00031 tatual = 0; 00032 */ 00033 while(1) 00034 { 00035 Capture::Wait(); 00036 00037 SignalProcessor::CalculateRMSBulk(rms); 00038 00039 //rms[0] = 2050; 00040 //rms[1]=rms[2]=rms[3]=rms[4]=rms[5]=2000; 00041 00042 for(int i=0;i<6;i++){ 00043 //printf("Main %d\n", i); 00044 EventDetector::get_Detector(i).ProcessEvent(rms[i], i); 00045 //wait_ms(2); 00046 } 00047 //Thread::yield(); 00048 00049 00050 /* 00051 for(int i =0; i < 6; i++) 00052 printf("%5.2f\t", rms[i]); 00053 printf("\n"); 00054 00055 wait(5); 00056 */ 00057 n++; 00058 if(n==60) 00059 { 00060 printf("%f %f %f %f %f %f\n",rms[0],rms[1],rms[2],rms[3],rms[4],rms[5]); 00061 led1 = !led1; 00062 n=0; 00063 //t.stop(); 00064 00065 /* 00066 for(int i =0; i < 6; i++) 00067 printf("%5.2f\t", rms[i]); 00068 printf("\n"); 00069 // 00070 */ 00071 /* 00072 tnovo = t.read_us(); 00073 printf("MAIN: The time XXX taken loop %d\n", tnovo - tatual); 00074 tatual = tnovo; 00075 t.reset(); 00076 */ 00077 //Thread::wait(1000); //1000 00078 wait(1); 00079 } 00080 } 00081 } 00082 00083 /* 00084 void InitializeEthernetLink() 00085 { 00086 if(Settings::get_Dhcp()) 00087 eth.init(); //Use DHCP 00088 else 00089 eth.init(Settings::get_IpAddress(),Settings::get_Netmask(),Settings::get_Gateway()); 00090 00091 eth.connect(); 00092 printf("IP Address is %s\n", eth.getIPAddress()); 00093 } 00094 */ 00095 void InitializeEthernetLink() 00096 { 00097 if(Settings::get_Dhcp()) 00098 EthernetIf::Initialize(); //Use DHCP 00099 else 00100 EthernetIf::Initialize(Settings::get_IpAddress(),Settings::get_Netmask(),Settings::get_Gateway()); 00101 00102 EthernetIf::Connect(); 00103 printf("IP Address is %s\n", EthernetIf::get_IpAddress()); 00104 } 00105 00106 int main() { 00107 FILE *f; 00108 //Set Highest Priority 00109 //osThreadSetPriority(osThreadGetId(),osPriorityHigh); 00110 00111 Settings::ReadFile(); 00112 //printf("Passou Settings, carregou arquivo\n"); 00113 //Settings::ShowValues(); 00114 00115 InitializeEthernetLink(); 00116 //printf("Inicializou link Ethernet\n"); 00117 00118 //Start HTTP POST service 00119 Thread http_post(HttpPost::HttpPost_Thread); 00120 00121 //Start TCP daemon service 00122 //Thread TcpService(CommTCP::CommTCP_Thread); 00123 00124 00125 //Start Telnet Service 00126 //Thread telnetserver(TelnetServer::TelnetServer_Thread); 00127 //Start TFTP Service 00128 00129 /* 00130 unsigned short vet[256] = {2105,2105,2113,2127,2127,2125,2112,2113,2130,2130,2123,2112,2112,2128,2128,2123,2112,2113,2136,2136,2374,2551,2671,2869,2887,3036,2964,2964,2964,3145,3145,3206,3209,3298,3298,3264,3261,3208,3239,3239,3197,3197,3113,3032,3065,3065,3000,2901,2943,2943,2900,2852,2844,2863,2863,2838,2764,2791,2724,2724,2668,2710,2636,2658,2658,2606,2527,2443,2434,2434,2258,2066,2061,2080,2080,2063,2055,2055,2070,2070,2064,2051,2054,2069,2069,2062,2054,2058,2066,2309,2062,2052,2054,2067,2067,2063,2051,2049,2068,2068,2060,2053,2050,2067,2066,2069,2051,2053,2070,2070,2064,2050,2053,2070,2070,2062,2052,2055,2068,2068,2065,2052,2057,2072,2072,2064,2054,2054,2072,2072,2064,2053,2052,2069,2069,2064,2052,2053,2064,2064,2062,2049,2051,2067,2067,2059,2051,2050,2068,2068,2058,2046,2050,2068,2068,2061,2052,2058,2068,2068,2059,2052,2053,2067,2067,1744,1526,1471,1289,1289,1137,1142,1055,1120,1120,997,967,894,941,941,928,887,1001,949,949,1028,1105,1079,1191,1191,1223,1211,1223,1267,1267,1325,1267,1356,1327,1327,1369,1439,1381,1498,1498,1503,1503,1527,1545,1545,1635,1650,1778,1792,1792,1971,2108,2109,2126,2126,2124,2117,2118,2131,2131,2126,2118,2118,2138,2138,2134,2124,2114,2135,2135,2129,2121,2120,2136,2136,2128,2122,2122,2143,2120,2130,2120,2121,2139,2139,2130,2119,2121,2136,2136,2129}; 00131 float sen[12],cos[12],vm; 00132 SignalProcessor::CalculateFFT(vet,sen,cos,&vm,1); 00133 00134 printf("VM = %f\n",vm); 00135 for(int i=0;i<12;i++) 00136 { 00137 printf("SEN%d = %f, COS%d = %f\n",i,sen[i],i,cos[i]); 00138 } 00139 */ 00140 00141 //Jump to the capture routine(will run on this thread) 00142 thread1(NULL); 00143 00144 while(1){//never reaches here 00145 printf("Reset\n"); 00146 f = fopen(FILENAMERESET, "a"); 00147 if (f == NULL) 00148 f = fopen(FILENAMERESET, "w"); 00149 fprintf(f, "Laco Errado\n"); 00150 fclose(f); 00151 Thread::yield(); 00152 } 00153 }
Generated on Fri Jul 15 2022 22:11:24 by
1.7.2