void ui_loop(){ switch(ui_state){ case UI_READY: serve(); break; case UI_TWILOCK: // we do not process new socket inputs, as we have to wait for the twi bus to become ready: if(twi_try_lock_bus()){ // we aquired the bus // now we have to do our access as fast as possible, as others might wait for bus access: // call command handler, who waits for access to the bus: twi_access_fun(); sock_stream_flush(); // we again accept commands ui_state = UI_READY; twi_free_bus(); // handle other already existing commands in the buffer handleCMD(stream_get_sock()); } break; } }
void net_dataAvailable(struct dummy_packet * received, uint8_t src_addr){ // This function is called, everytime, a set o measurement results from // one collector board was successfully received. uint8_t i; // make a backup of currently active socket // as we have to switch socket to db socket uint8_t currSock = stream_get_sock(); // flush the active socket here? sock_stream_flush(); //puts_P(PSTR(".")); // send data to the database, if required: if(cfg.send_db){ net_sendResultToDB(received, src_addr); //puts_P(PSTR(",")); } // now send data to user intrefaces, if they requested so: for(i=0; i< MAX_SERVER_SOCK_NUM; i++){ if (data_request[i]){ if(W5100.readSnSR(i+FIRST_SERVER_SOCK) == SnSR::ESTABLISHED){ stream_set_sock(i+FIRST_SERVER_SOCK); fprintf_P(&sock_stream, PSTR("\n%u :: "), src_addr); send_result(received); sock_stream_flush(); }else{ // if no the requesting client is already disconnected, // remove him from the request list: data_request[i] = 0; } } } //puts_P(PSTR("-")); // restore socket: stream_set_sock(currSock); }