int main(){ int conn1; char recbuf[PKTSIZE]; int size,j,i; sequence_init(); tcp_init(); conn1=tcp_add_connection("134.130.62.98" ,2500, "134.130.62.94",2500, CONN_SERVER); tcp_add_ip(conn1,"134.130.62.98" ,2501, "134.130.62.94",2501); tcp_add_ip(conn1,"134.130.62.98" ,2502, "134.130.62.94",2502); tcp_add_ip(conn1,"134.130.62.98" ,2503, "134.130.62.94",2503); if (tcp_establish_connection(conn1) < 0) { printf("kann Verbindung nicht aufbauen!\n"); exit(-1); } i = 0; while(1) { printf("testing for data...\n"); while (!tcp_select(conn1, 0)) { printf("."); fflush(stdout); sleep(1); } printf("\n"); printf("message available!\n"); size = tcp_receive_message(recbuf, PKTSIZE, conn1); if (size != i) { fprintf(stderr, "expected %d Bytes, got %d Bytes\n", i, size); fflush(stderr); } fprintf(stderr, "got %d Bytes, first Byte: %d\n", size, (int)((char*)recbuf)[1]); fflush(stderr); if (*((char*)recbuf) == FERTIG) { printf("Dienstschluss!\n"); break; } for ( j = 1; j < size; j++) if (((char*)recbuf)[j] != sequence()) { fprintf(stderr,"error in data: size= %d, pos = %d!\n",size,j);fflush(stderr); exit(-1); } i += 128; } tcp_close_connections(conn1); return 1; }
int main (void){ cli(); // debug DDRB |= (1<<DEBUG_LED_PIN); debug_init(); // push button DDRD |= (1<<BUTTON_PWR_PIN); PORTD |= (1<<BUTTON_PWR_PIN); DDRD &= ~(1<<BUTTON_PIN); PORTD |= (1<<BUTTON_PIN); uint8_t button_press_counter; // init sequence_init(); generator_init(); sequence_update(0); sequence_runmode = SEQ_RUNMODE_SEQUENTIAL; generator_update(); uint16_t frame_counter; uint8_t seed=0; _delay_ms(10); // Global interrupt enable. sei(); while(1) { srand(seed++); // the refresh rate depends on the driver rate if(pwm_packet_counter>20){ pwm_packet_counter = 0; generator_run(); DEBUG_LED_PIN_TOGGLE(); if((frame_counter++ > 0x3FF)&&(sequence_runmode==SEQ_RUNMODE_TOGGLE)){ sequence_skip(); generator_update(); frame_counter = 0; } } // serial cmd received if(debug_char != 0xFF){ sequence_update(debug_char); generator_update(); debug_char = 0xFF; } // push button if((PIND&(1<<BUTTON_PIN)) == 0){ button_press_counter = 0; // measure the button press duration while((PIND&(1<<BUTTON_PIN)) == 0){ _delay_ms(100); button_press_counter++; } // short press => next sequence if (button_press_counter < 10){ frame_counter = 0; sequence_skip(); generator_update(); // debug_putc('d'); // skip sequence } // long press => switch between normal and sequential mode else{ frame_counter = 0; sequence_runmode ^= SEQ_RUNMODE_TOGGLE; // debug_putc('c'); // switch normal(current sequence)<->sequential } } } }