void init_tcpip_lwip_stack(void) { extern void lwip_system_init(void); extern rt_err_t eth_system_device_init(void); /* register ethernetif device */ eth_system_device_init(); RT_APPS_INIT_DEBUG(("eth_system_device_init() succ!\n")); rt_hw_stm32_eth_init(); RT_APPS_INIT_DEBUG(("func:%s, line:%u, eie:0x%x!\n", __FUNCTION__, __LINE__, enc28j60_read(EIE))); /* to assure Ethernet Phy work well */ //lihao //Ethernet_Security(); RT_APPS_INIT_DEBUG(("func:%s, line:%u!\n", __FUNCTION__, __LINE__)); /* re-init device driver */ rt_device_init_all(); RT_APPS_INIT_DEBUG(("func:%s, line:%u, eie:0x%x!\n", __FUNCTION__, __LINE__, enc28j60_read(EIE))); /* init lwip system */ lwip_system_init(); RT_APPS_INIT_LOG(("TCP/IP initialized, eie:0x%x!\n", enc28j60_read(EIE))); /* init net apps */ #if RT_USING_HTTPSERVER_RAW httpd_init(); #endif #if RT_USING_TELNETD telnetd_init(); #endif }
/***************************************************************************** 函 数 名 : uip_app_init 功能描述 : the uip appliacation function 输入参数 : void 输出参数 : 无 返 回 值 : 调用函数 : 被调函数 : 修改历史 : 1.日 期 : 2017年4月17日 作 者 : QSWWD 修改内容 : 新生成函数 *****************************************************************************/ void uip_app_init(void) { uip_ipaddr_t ipaddr; uip_ipaddr(ipaddr, 8,8,8,8); /* hello_world_init();*/ /* resolv_init(); uip_ipaddr(ipaddr, 195,54,122,204); resolv_conf(ipaddr); resolv_query("www.sics.se");*/ example1_init(); example2_init(); telnetd_init(); smtp_init(); uip_ipaddr(ipaddr, 127,0,0,1); smtp_configure("localhost", ipaddr); SMTP_SEND("*****@*****.**", NULL, "*****@*****.**", "Testing SMTP from uIP", "Test message sent by uIP\r\n"); hello_world_init(); httpd_init(); #if UIP_UDP my_udp8899_init(); dhcpc_init(&uip_ethaddr,6); resolv_init(); resolv_conf(ipaddr); resolv_query("www.baidu.com"); #endif }
/** * \brief Inicializa os servicos disponiveis pela camada mult. */ void services_init(void){ CHAT_PORT = 5555; //inicializa o chat com uma porta default. que será alterada de acordo com a def do chat. global_chat_flag = 0; //chat começa desabilitado, só é habilitado pela cli. telnetd_init(); //telnet faz comunicação através da porta 23 httpd_init(); //http faz comunicação através da porta 80. chat_init(); //porta inicial, ela será alterada de acordo com o chat. //ftp_init(); //inicializa serviço de ftp sftd_init(); }
/** * Initialize demo application */ static void _app_init(void) { printf("P: telnetd application init\n\r"); telnetd_init(); #ifdef __DHCPC_H__ printf("P: DHCPC Init\n\r"); dhcpc_init(MacAddress.addr, 6); #endif }
//---------------------------------------------------------------------------- //Initialisierung der console void console_init (void) { // Initialisiere Pufferverwaltung console_tx_counter = 0; // initiliaze device modules #if USE_TELNET if ( console_mode & CONSOLE_TELNET ); telnetd_init(); #endif #if USE_USART if ( console_mode & CONSOLE_USART ); // usart_init(BAUDRATE); usart_init(); #endif console_isinit = 1; }
void IpStack_Thread_init( void ) { DRV_Uart_Error eUart_Error; DRV_Uart_Cfg tUart0Settings; DRV_SoftTimer_Error eSofTimerError; DRV_SoftTimer_Cfg sParam; uip_ipaddr_t addr; struct uip_udp_conn *c; IpStack_Thread_Data.iEtape = kETAPE_Init; //Uart open tUart0Settings.RXCallBack=NULL; tUart0Settings.eBaudRate = BR115200; tUart0Settings.cEndOfBuff='\r'; tUart0Settings.eParity = PARNone; tUart0Settings.eSLIPModeEnable=1; tUart0Settings.eStopBit = SB_1; tUart0Settings.iRXNbChar = 0; eUart_Error = DRV_Uart_Open("/dev/ttyUSB0",&IpStack_Thread_Data.hUart,&tUart0Settings); //Soft Timer open sParam.tType=TimeOut; sParam.uiValue = 10; eSofTimerError = DRV_SoftTimer_Open("timer1PStack",&IpStack_Thread_Data.hTimer,&sParam); DRV_SoftTimer_Start(IpStack_Thread_Data.hTimer); //uiP Stack init uip_init(); uip_ipaddr(IpStack_Thread_Data.ipaddr, 192,168,2,3); uip_sethostaddr(IpStack_Thread_Data.ipaddr); //telnetd_init(); httpd_init(); hello_world_init(); telnetd_init(); uip_ipaddr(&addr, 192,168,2,1); c = uip_udp_new(&addr, HTONS(12345)); LIB_Trace_Printf(1,"IpStack init Done\n"); }
int main(void) { network_init(); #if MY_DEBUG uartInit(); uartSetBaudRate(9600); rprintfInit(uartSendByte); #endif int i; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; clock_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); uip_init(); struct uip_eth_addr mac = {UIP_ETHADDR0, UIP_ETHADDR1, UIP_ETHADDR2, UIP_ETHADDR3, UIP_ETHADDR4, UIP_ETHADDR5}; uip_setethaddr(mac); telnetd_init(); #ifdef __DHCPC_H__ dhcpc_init(&mac, 6); #else uip_ipaddr(ipaddr, 192,168,0,1); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,0,1); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); #endif /*__DHCPC_H__*/ while(1){ uip_len = network_read(); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)){ uip_arp_ipin(); uip_input(); if(uip_len > 0) { uip_arp_out(); network_send(); } }else if(BUF->type == htons(UIP_ETHTYPE_ARP)){ uip_arp_arpin(); if(uip_len > 0){ network_send(); } } }else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); if(uip_len > 0) { uip_arp_out(); network_send(); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); if(uip_len > 0) { uip_arp_out(); network_send(); } } #endif /* UIP_UDP */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } return 0; }
void Network::Spin() { // Basically we can't do anything if we can't interact with LWIP if (!LockLWIP()) { platform->ClassReport(longWait); return; } if (state == NetworkActive) { // See if we can read any packets if (readingData) { readingData = false; do { // read all queued packets from the RX buffer } while (ethernet_read()); ethernet_set_rx_callback(&emac_read_packet); } // See if we can send anything NetworkTransaction *r = writingTransactions; if (r != NULL && r->Send()) { // We're done, free up this transaction ConnectionState *cs = r->cs; NetworkTransaction *rn = r->nextWrite; writingTransactions = r->next; AppendTransaction(&freeTransactions, r); // If there is more data to write on this connection, do it next time if (cs != NULL) { cs->sendingTransaction = rn; } if (rn != NULL) { PrependTransaction(&writingTransactions, rn); } } } else if (state == NetworkInitializing && establish_ethernet_link()) { start_ethernet(platform->IPAddress(), platform->NetMask(), platform->GateWay()); ethernet_set_rx_callback(&emac_read_packet); httpd_init(); ftpd_init(); telnetd_init(); netbios_init(); state = NetworkActive; } UnlockLWIP(); platform->ClassReport(longWait); }
void init_apps( void ){ telnetd_init(); return; }
/*---------------------------------------------------------------------------*/ int main(void) { EEPROM_main(); int i; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; memcpy (&uip_ethaddr.addr[0], &eeprom.MAC[0], 6); AVR_init(); egpio_init(); clock_init(); mbuf_init(); adlc_init(); GICR = (1 << INT0); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); nic_init(); uip_ipaddr(ipaddr, eeprom.IPAddr[0],eeprom.IPAddr[1],eeprom.IPAddr[2],eeprom.IPAddr[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, eeprom.Gateway[0],eeprom.Gateway[1],eeprom.Gateway[2],eeprom.Gateway[3]); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, eeprom.Subnet[0],eeprom.Subnet[1],eeprom.Subnet[2],eeprom.Subnet[3]); uip_setnetmask(ipaddr); telnetd_init(); aun_init(); internet_init(); egpio_write (EGPIO_STATUS_GREEN); while(1) { // check the econet for complete packets adlc_poller(); aun_poller (); uip_len = nic_poll(); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ maybe_send(); } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { nic_send(NULL); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); maybe_send(); } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); maybe_send(); } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } }
static portTASK_FUNCTION( tunggu, pvParameters ) { struct t_env *envx; envx = (char *) ALMT_ENV; portBASE_TYPE xARPTimer; uip_ipaddr_t xIPAddr; int loop; int mul; unsigned int timer_menit=0; unsigned int loop_menit=0; static volatile portTickType xStartTime, xCurrentTime; vTaskDelay(200); /* baca environtment (dapat IP dll dulu) */ baca_env(0); printf("UIP : uip_init\r\n"); uip_init (); //uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 ); uip_ipaddr( xIPAddr, envx->IP0, envx->IP1, envx->IP2, envx->IP3 ); uip_sethostaddr( xIPAddr ); printf("ARP : arp_init\r\n"); uip_arp_init (); printf("Init ENC28J .. "); if (enc28j60Init() == 1) { printf(" .. ENC OK\r\n"); } else printf("ENC tidak respons !\r\n"); #ifdef PAKE_HTTP printf("SIMPLE HTTP : init\r\n"); httpd_init (); #endif #ifdef PAKE_TELNETD printf("SIMPLE TELNET : init\r\n"); telnetd_init (); #endif #ifdef BOARD_KOMON printf("MONITA : monita init\r\n"); // monita_init(); #endif #if (PAKAI_KONTROL == 1) printf("MONITA : monita kontrol init\r\n"); kontrol_init(); #endif //#ifdef BOARD_TAMPILAN //#ifdef CARI_SUMBERNYA #ifdef SAMPURASUN_SERVER printf("MONITA : sambungan_aktif init\r\n"); sambungan_init(); mul = 0; #endif #ifdef SAMPURASUN_CLIENT //printf("MONITA : monita init\r\n"); printf("Monita : sampurasun client init !\r\n"); monita_init(); #endif #ifdef PAKAI_WEBCLIENT int ngitung=0; webclient_init(); printf("webclient inited !\r\n"); unsigned char datakeserver[512]; int wclient=0, jmlData=0, nos=0, flag_nos=0, flag_sumber=0, jmlsumbernya=0; //int noPMaktif[JML_SUMBER]; char il[256], dl[256]; char ipdest[15], angkaangka[5]; extern int kirimURL; extern char terkirimURL; extern int noawal; int tiapKirim=950; int maxkirim=12; #endif #ifdef PAKAI_KIRIM_BALIK int anginkecil=0; int giliran; extern int sumber_datanya; extern int target_kirim; target_kirim = 4-1; sumber_datanya=3-1; //giliran=1-1; printf("Kirim Balik inited, Target data: sumber %d, target kirim: %d !\r\n", sumber_datanya+1, target_kirim+1); #endif /* Initialise the local timers */ xStartTime = xTaskGetTickCount (); xARPTimer = 0; /* supaya cukup waktu buat siap2 */ loop = -1000; #ifdef BOARD_KOMON_420_SABANG vTaskDelay(200); #endif #ifdef PAKAI_WEBCLIENT vTaskDelay(2000); vTaskDelay(2000); #endif //printf("mau loop for\r\n"); for (;;) { vTaskDelay(1); //portYIELD(); #if 1 #ifdef PAKAI_WEBCLIENT if (envx->statusWebClient==1) { wclient++; if (envx->burst==1) { jmlData=kirimModul(1, 0, 0, il, dl); //jmlsumbernya=1; tiapKirim = 500; } else { // kirim 1-1 /* #ifdef BANYAK_SUMBER struct t_sumber *pmx; pmx = (char *) ALMT_SUMBER; jmlsumbernya=0; for(selang=0; selang<JML_SUMBER; selang++) { if (pmx[selang].status==1) { printf("selang: %d, status: %d\r\n", selang, pmx[selang].status); noPMaktif[jmlsumbernya]=selang; jmlsumbernya++; } } if (jmlsumbernya==0) { jmlsumbernya=1; } //jmlData=kirimModul(0, noPMaktif[sumbernya], 0, il, dl); printf("jml Data: %d, sumbernya: %d\r\n", jmlData, sumbernya); // kenapa ini ??? harusnya tiap detik, knapa jadi tiap 4 detik ???? //tiapKirim = (int) (100/jmlsumbernya); tiapKirim = (int) (195/jmlsumbernya); //printf("wclient: %d\r\n", wclient); #endif //*/ } if (wclient == tiapKirim) { ngitung++; struct t_sumber *sumber; sumber = (char *) ALMT_SUMBER; if (!flag_nos) { nos++; while(sumber[nos-1].status!=1) { // cari modul sumber aktif if (nos>JML_SUMBER) { nos=0; jmlsumbernya=0; } nos++; } } jmlsumbernya++; //printf("kirim: %5d, nos: %d, wclient: %d, sumber.status: %d, jmlsumbernya: %d\r\n", ngitung, nos-1, wclient, sumber[nos-1].status, jmlsumbernya); // cek datanya PM ?? // <--- ternyata gak cuma PM, modul lain juga bisa if (sumber[nos-1].tipe==0 || sumber[nos-1].tipe==1 || sumber[nos-1].tipe==100) { // PM710 || PM810 jmlData=kirimModul(0, nos-1, noawal, il, dl); if (jmlData==12) { flag_nos=1; } else { // sudah habis, reset ke 0 flag_nos=0; noawal=0; } //printf("nilai noawal: %d, flagnos: %d\r\n", noawal, flag_nos); } else { jmlData=kirimModul(0, nos-1, 0, il, dl); noawal=0; } // hitung jml loop kirim ke server if (flag_sumber<jmlsumbernya) { flag_sumber=jmlsumbernya; tiapKirim=950/jmlsumbernya; } wclient = 0; if (jmlData>0) { sprintf(ipdest, "%d.%d.%d.%d", envx->GW0, envx->GW1, envx->GW2, envx->GW3); //portENTER_CRITICAL(); //sprintf(datakeserver, "%s?i=%s&p=diesel&j=%d&%s&%s", envx->berkas, envx->SN, jmlData, il, dl); strcpy(datakeserver, envx->berkas); strcat(datakeserver, "?i="); strcat(datakeserver, envx->SN); strcat(datakeserver, "&p=diesel&j="); sprintf(angkaangka, "%d", jmlData); strcat(datakeserver, angkaangka); strcat(datakeserver, "&"); strcat(datakeserver, il); strcat(datakeserver, "&"); strcat(datakeserver, dl); //portEXIT_CRITICAL(); //printf("datakeserver: %s\r\n",datakeserver); webclient_get(ipdest, 80, datakeserver); } } } #endif //#if defined(BOARD_TAMPILAN) || defined (TAMPILAN_MALINGPING) #ifdef SAMPURASUN_SERVER //#ifdef CARI_SUMBERNYA loop++; if (loop > 200) // 50, 40, 80 { loop = 0; sambungan_connect(mul); mul++; if (mul > JML_SUMBER) mul = 0; } #endif #ifdef PAKAI_KIRIM_BALIK anginkecil++; if (anginkecil > 2000) { /* tiap 2 detik */ kirim_balik_connect(target_kirim); anginkecil=0; //giliran++; //if (giliran > JML_SUMBER) mul = 0; } #endif //if (enc28j60WaitForData (uipMAX_BLOCK_TIME) == pdTRUE) if (cek_paket()) { //printf("masuk cekpaket \r\n"); #if 1 paket_per_menit++; /* Let the network device driver read an entire IP packet into the uip_buf. If it returns > 0, there is a packet in the uip_buf buffer. */ if ((uip_len = enc28j60Receive ()) > 0) { if (pucUIP_Buffer->type == htons (UIP_ETHTYPE_IP)) { uip_arp_ipin (); uip_input (); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out (); enc28j60Send (); paket_kita++; } } else if (pucUIP_Buffer->type == htons (UIP_ETHTYPE_ARP)) { uip_arp_arpin (); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) enc28j60Send (); } } #endif } else { /* The poll function returned 0, so no packet was received. Instead we check if it is time that we do the periodic processing. */ xCurrentTime = xTaskGetTickCount (); if ((xCurrentTime - xStartTime) >= RT_CLOCK_SECOND) { portBASE_TYPE i; /* Reset the timer. */ xStartTime = xCurrentTime; /* Periodic check of all connections. */ for (i = 0; i < UIP_CONNS; i++) { uip_periodic (i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { //printf("S:%d", i); uip_arp_out (); enc28j60Send (); } } #if UIP_UDP_KU for (i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic (i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out (); enc28j60Send (); } } #endif /* UIP_UDP */ /* Periodically call the ARP timer function. */ if (++xARPTimer == uipARP_FREQUENCY) { uip_arp_timer (); xARPTimer = 0; } } if ((xCurrentTime - timer_menit) >= RT_MENIT) { extern unsigned int error_ENC; timer_menit = xCurrentTime; loop_menit++; /* printf("%d menit, paket = %d, kita=%d, idle=%d\n", loop_menit, paket_per_menit, paket_kita, loop_idle); if (error_ENC != 0) { printf("ERR ENC = %X\n", error_ENC); }*/ paket_per_menit = 0; paket_kita = 0; } } // tanpa paket /* // proses ADC dipindah ke shell 1 Okt 2010// #ifdef PAKAI_ADC #ifdef BOARD_KOMON_A_RTD proses_data_adc(); #endif #ifdef BOARD_KOMON_B_THERMO proses_data_adc(); #endif #ifdef BOARD_KOMON_420_SAJA proses_data_adc(); #endif #endif //*/ #endif } }
int main(void) { //Konfiguration der Ausgänge bzw. Eingänge //definition erfolgt in der config.h DDRA = OUTA; #if USE_SER_LCD DDRC = OUTC; #else DDRC = OUTC; #if PORTD_SCHALT DDRD = OUTD; #endif #endif // RoBue: // Pullups einschalten PORTA = (1 << PORTA0) | (1 << PORTA1) | (1 << PORTA2) | (1 << PORTA3) | (1 << PORTA4) | (1 << PORTA5) | (1 << PORTA6); unsigned long a; #if USE_SERVO servo_init (); #endif //USE_SERVO usart_init(BAUDRATE); // setup the UART #if USE_ADC ADC_Init(); #endif usart_write("\n\rSystem Ready\n\r"); usart_write("Compiliert am "__DATE__" um "__TIME__"\r\n"); usart_write("Compiliert mit GCC Version "__VERSION__"\r\n"); for(a=0;a<1000000;a++){asm("nop");}; //Applikationen starten stack_init(); httpd_init(); telnetd_init(); //Spielerrei mit einem LCD #if USE_SER_LCD udp_lcd_init(); lcd_init(); // RoBue: // LCD-Ausgaben: lcd_clear(); lcd_print(0,0,"*AVR-NET-IO "Version"*"); lcd_print(2,0,"Counter: "); lcd_print(3,0,"Zeit:"); #endif //Ethernetcard Interrupt enable ETH_INT_ENABLE; #if USE_SER_LCD // RoBue: // IP auf LCD lcd_print(1,0,"%1i.%1i.%1i.%1i",myip[0],myip[1],myip[2],myip[3]); #endif //Globale Interrupts einschalten sei(); #if USE_CAM #if USE_SER_LCD lcd_print(1,0,"CAMERA INIT"); #endif //USE_SER_LCD for(a=0;a<2000000;a++){asm("nop");}; cam_init(); max_bytes = cam_picture_store(CAM_RESELUTION); #if USE_SER_LCD back_light = 0; lcd_print(1,0,"CAMERA READY"); #endif //USE_SER_LCD #endif // -> USE_CAM #if USE_NTP ntp_init(); ntp_request(); #endif //USE_NTP #if USE_WOL wol_init(); #endif //USE_WOL #if USE_MAIL mail_client_init(); #endif //USE_MAIL // Startwerte für ow_array setzen #if USE_OW uint8_t i = 0; for (i=0;i<MAXSENSORS;i++){ ow_array[i]=OW_START; } for (i=MAXSENSORS;i<MAXSENSORS*3;i++){ ow_array[i]=OW_MINMAX; } DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ); for(a=0;a<1000000;a++){asm("nop");}; auslesen = 0; minmax = 1; #endif //Hauptschlfeife // ************* while(1) { #if USE_ADC ANALOG_ON; #endif eth_get_data(); //Terminalcommandos auswerten if (usart_status.usart_ready){ usart_write("\r\n"); if(extract_cmd(&usart_rx_buffer[0])) { usart_write("Ready\r\n\r\n"); } else { usart_write("ERROR\r\n\r\n"); } usart_status.usart_ready =0; } // RoBue: // Counter ausgeben #if USE_SER_LCD lcd_print(2,9,"%4i",var_array[MAX_VAR_ARRAY-1]); #endif // RoBue: // Uhrzeit bestimmen und auf LCD ausgeben hh = (time/3600)%24; mm = (time/60)%60; ss = time%60; #if USE_SER_LCD lcd_print(3,7,"%2i:%2i:%2i",hh,mm,ss); #endif #if USE_HIH4000 var_array[VA_OUT_HIH4000] = ((var_array[VA_IN_HIH4000]-160)/6); #endif #if USE_OW // RoBue: // Zurücksetzen der Min/Max-Werte um 00:00 Uhr einschalten if (( hh == 00 )&&( mm == 00 )) { minmax = 1; } #endif // ****************************************************************** // RoBue: // 1-Wire-Temperatursensoren (DS18B20) abfragen // ****************************************************************** #if USE_OW uint8_t i = 0; uint8_t subzero, cel, cel_frac_bits; uint8_t tempID[OW_ROMCODE_SIZE]; // Messen bei ss=5,15,25,35,45,55 if ( ss%10 == 5 ) { // Messen? if ( messen == 1 ) { // RoBue Anmerkung: // Hiermit werden ALLE Sensoren zum Messen aufgefordert. // Aufforderung nur bestimmter Sensoren: // "NULL" durch "tempID" ersetzen // RoBue Testausgabe UART: // usart_write("Starte Messvorgang ...\r\n"); DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ); // Kein Messen mehr bis ss=5,15,25,35,45,55 messen = 0; // Jetzt kann ausgelesen werden auslesen = 1; } // -> if messen } // -> if ss // Auslesen bei ss=8,18,28,38,48,58 if ( ss%10 == 8 ) { // Auslesen? if ( auslesen == 1 ) { // (erste) ID ins RAM holen memcpy_P(tempID,DS18B20IDs[0],OW_ROMCODE_SIZE); while ( tempID[0] != 0 ) { //while ( tempID[0] == 0x10 ) { // RoBue Anmerkung: // Hiermit wird jeweils ein einzelner Sensor ausgelesen // und die Temperatur in ow_array abgelegt. // Achtung: // Pro Sekunde können max. ca. 10 Sensoren ausgelesen werden! if ( DS18X20_read_meas( tempID, &subzero,&cel, &cel_frac_bits) == DS18X20_OK ) { ow_array[i] = DS18X20_temp_to_decicel(subzero, cel, cel_frac_bits); // Minuswerte: if ( subzero ) ow_array[i] *= (-1); // min/max: if ( minmax == 1 ) { // Zurücksetzen der Min/Max_Werte 1x/Tag // auf die gerade aktuellen Temperaturen ow_array[i+MAXSENSORS] = ow_array[i]; ow_array[i+MAXSENSORS*2] = ow_array[i]; } else { // Abgleich der Temp. mit den gespeicherten Min/Max-Werten if (ow_array[i] < ow_array[i+MAXSENSORS]) ow_array[i+MAXSENSORS] = ow_array[i]; if (ow_array[i] > ow_array[i+MAXSENSORS*2]) ow_array[i+MAXSENSORS*2] = ow_array[i]; } //TWert = DS18X20_temp_to_decicel(subzero, cel, cel_frac_bits); //ow_array[i] = TWert; // RoBue: // Testausgabe UART: // usart_write("%2i:%2i:%2i: Temperatur: %3i Grad\r\n",hh,mm,ss,ow_array[i]/10); } // -> if else { usart_write("\r\nCRC Error (lost connection?) "); DS18X20_show_id_uart( tempID, OW_ROMCODE_SIZE ); } // -> else // nächste ID ins RAM holen memcpy_P(tempID,DS18B20IDs[++i],OW_ROMCODE_SIZE); } // -> while // RoBue: // Temperatur auf LCD ausgeben (IP von Startausgabe (s.o.) wird Überschrieben) #if USE_SER_LCD lcd_print(1,0,"Tmp: "); lcd_print(1,5,"%i C",ow_array[0]/10); lcd_print(1,11,"%i C",ow_array[1]/10); #endif } // -> if auslesen auslesen = 0; // Auslesen vorläufig abschalten messen = 1; // Messen wieder ermöglichen minmax = 0; // Min/Max-Werte vergleichen } // -> if ss #endif // ********************************************************** // RoBue: // Schalten der Ports (PORTC) durch bestimmte Bedingungen // - Temperatur (1-Wire -> PORTA7) mit/ohne Lüftungsautomatik // - digital, analog (-> PORTA0-6) // - Zeit // ********************************************************** // Automatik eingeschaltet? if ( var_array[9] == 1 ) { if ( ss%10 == 1 ) { schalten = 1; } // Abfrage bei ss =0,10,20,30,40,50 if ( ss%10 == 0 ) { if ( schalten == 1 ) { // RoBue Testausgabe UART: // usart_write("%2i:%2i: Schaltfunktionen testen ...\r\n",hh,mm); // PORTC0: // Über Temperatur: var_array[10] - Sensor0 if (( ow_array[0]/10 < var_array[10] ) || ( ow_array[0] < 0 )) { PORTC |= (1 << PC0); // ein // // Über Temperatur: var_array[10] - Sensor0 - PORTA0 // if ((PINA&0b00000001) == 0 ) { // PORTA0: Fenster geschlossen? // if (( ow_array[0]/10 < var_array[10] ) || ( ow_array[0] < 0 )) { // PORTC |= (1 << PC0); // ein // } // else { // PORTC &= ~(1 << PC0); // aus // } } else { PORTC &= ~(1 << PC0); // aus } // PORTC1: // Über Temperatur: var_array[11] - Sensor1 // if (( ow_array[1]/10 < var_array[11] ) || ( ow_array[1] < 0 )) { // PORTC |= (1 << PC1); // ein // // Über Temperatur: var_array[11] - Sensor1 - PORTA1 if ((PINA&0b00000010) == 0 ) { // PORTA1: Fenster geschlossen? if (( ow_array[1]/10 < var_array[11] ) || ( ow_array[1] < 0 )) { PORTC |= (1 << PC1); // ein } else { PORTC &= ~(1 << PC1); // aus } } else { PORTC &= ~(1 << PC1); // aus } // PORTC2: // Über Temperatur: var_array[12] - Sensor2 // if (( ow_array[2]/10 < var_array[12] ) || ( ow_array[2] < 0 )) { // PORTC |= (1 << PC2); // ein // Über Temperatur: var_array[12] - Sensor2 - PORTA2 // if ((PINA&0b00000100) == 0 ) { // PORTA2: Fenster geschlossen? // if (( ow_array[2]/10 < var_array[12] ) || ( ow_array[2] < 0 )) { // PORTC |= (1 << PC2); // ein // } // else { // PORTC &= ~(1 << PC2); // aus // } //} //else { // PORTC &= ~(1 << PC2); // aus //} // PORTC4: // Über 2 Temperaturen (Differenz) // var_array[13] - Sensor3 Vorlauf, Sensor4 Ruecklauf // // z.B. Zirkulationspumpe für Warmwasser // Achtung: Temp. von Sensor3 MUSS höher/gleich sein als Temp. von Sensor4 // Ansonsten laeuft die Pumpe immer // if ( (ow_array[3]/10 - ow_array[4]/10) >= var_array[14] ) { PORTC |= (1 << PC4); // ein } else { PORTC &= ~(1 << PC4); // aus } // PORTC6: // Über Analogwert: if ( var_array[6] > var_array[18] ) { PORTC |= (1 << PC6); // ein } else { PORTC &= ~(1 << PC6); // aus } // PORTC7: // Über Zeit: ein/aus if ( hh == var_array[20] ) { if ( mm == var_array[21] ) { PORTC |= (1 << PC7); // ein } } if ( hh == var_array[22] ) { if ( mm == var_array[23] ) { PORTC &= ~(1 << PC7); // aus } } schalten = 0; // Vorerst nicht mehr schalten } // -> schalten == 1 } // -> if ss == ... } // -> if var_array == 1 //Wetterdaten empfangen (Testphase) #if GET_WEATHER http_request (); #endif //Empfang von Zeitinformationen #if USE_NTP if(!ntp_timer){ ntp_timer = NTP_REFRESH; ntp_request(); } #endif //USE_NTP //Versand von E-Mails #if USE_MAIL if (mail_enable == 1) { mail_enable = 0; mail_send(); } #endif //USE_MAIL //Rechner im Netzwerk aufwecken #if USE_WOL if (wol_enable == 1) { wol_enable = 0; wol_request(); } #endif //USE_WOL //USART Daten für Telnetanwendung? telnetd_send_data(); } return(0); }
void vuIP_TASK( void *pvParameters ) { int i; struct uip_eth_addr MacAddr = *(struct uip_eth_addr *)pvParameters; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; clock_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); /* Initialise the Enc28j60*/ enc28j60Init(MacAddr.addr); /* Initialize the uIP TCP/IP stack. */ uip_init(); uip_arp_init(); /*init mac addr to uip*/ uip_setethaddr(MacAddr); uip_ipaddr(ipaddr, 192,168,1,101); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,1,1); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); /* Initialize the HTTP server. */ telnetd_init(); while(1) { uip_len = enc28j60PacketReceive(); if(uip_len > 0) { if(pucUIP_Buffer->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); enc28j60PacketSend(); } } else if(pucUIP_Buffer->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { enc28j60PacketSend(); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); enc28j60PacketSend(); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); enc28j60PacketSend(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } }