Mistři v programování na #hovnokod

Ve zdrojáku zůstalo více než 7 let.

	if (pRlPDt->noclst == 0xcdcdcdcd) { //toto zatim pro osetreni havarie vno 19.10.!!!+-9/6*-
		return;
	}

Anonymous,

Ani medián, ani průměr. Tak něco mezi (všimněte si přičtení 0,5 k počtu prvků)

/// vypocet stredni hodnoty
int EvalRlPar::EvalMedVal(int * intf, const int noit)
{
	double auxd = 0;
	if (noit > 0) {
		for (int i = 0; i < noit; i++) {
			auxd += ((double)intf[i]);
		}
		return (int)(floor(auxd / noit + 0.5));
	}
	return -1;
}

Anonymous,

There's never enough of clever code...

		case GYRO_ANG:
		case GYRO_RATE:
			help = *(data)&0xFFFF;
			if(help & 0x8000)
			{
				help = ((help&0x7FFF) - 0x7FFF);
			}
			return help;
		case NXT_TEMP_F:
			help = (*data>>4) & 0x0FFF;
			if(help & 0x800)
			{
				help = ((help&0x7FF) ^ 0x7FF) + 1;
				return (-1)*(((help>>4) & 0xFF)*10 + ((help & 0xF) * 10 / 15)) * 9/5 + 320;
			}
			return (((help>>4) & 0xFF)*10 + ((help & 0xF) * 10 / 15)) * 9/5 + 320;

Jakub Vaněk,

Ten blb čeká že po odpojení klienta se znovu spustí naslouchání -_-

/*
    C socket server example
*/
 
#include<stdio.h>
#include<string.h>    //strlen
#include<sys/socket.h>
#include<arpa/inet.h> //inet_addr
#include<unistd.h>    //write
#include<fcntl.h>
#include<sys/ioctl.h>
#include<netinet/in.h>

#include <wiringPi.h>
#include <wiringSerial.h>

 
int main(int argc , char *argv[])
{
    int socket_desc , client_sock , c , read_size;
    struct sockaddr_in server , client;
    char client_message[200];

    //Create socket
    socket_desc = socket(AF_INET , SOCK_STREAM, 0);
    if (socket_desc == -1)
    {
        printf("Could not create socket");
    }
    puts("Socket created");
     
    //Prepare the sockaddr_in structure
    server.sin_family = AF_INET;
    server.sin_addr.s_addr = INADDR_ANY;
    server.sin_port = htons( 8888 );
   
    //Bind
    if( bind(socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0)
    {
        //print the error message
        perror("bind failed. Error");
        return 1;
    }
    puts("bind done");
     
    //Listen
    listen(socket_desc , 3);
     
    //Accept and incoming connection
    puts("Waiting for incoming connections...");
    c = sizeof(struct sockaddr_in);
  
    //accept connection from an incoming client
    client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c);
    if (client_sock < 0)
    {
        perror("accept failed");
        return 1;
    }
    puts("Connection accepted"); 
 
    //Receive a message from client
    while( (read_size = recv(client_sock , client_message , sizeof(client_message) , 0)) > 0 )
    {
	//Non-blocking Socket	
	ioctl(socket_desc, FIONBIO, (char *)&c); 

	//Terminal print control
        puts(client_message);

        //Send the message back to client
        write(client_sock , client_message , strlen(client_message));

	//SERIAL Connect
	int serial = serialOpen ("/dev/ttyS0", 9600);

	//SERIAL Send
	serialPrintf (serial, client_message) ;

	//Clear Buffer - client_message
        memset(client_message, 0, sizeof client_message);
    }
     
    if(read_size == 0)
    {
        puts("Client disconnected");
        fflush(stdout);
    }
    else if(read_size == -1)
    {
        perror("recv failed");
    }
     
    return 0;
}

Anonymous,

IFDEF pro každý bug

void wifi_start()
{
    #if WOP_A4_WIFI_API_SERVICE
#ifdef JIRA_WIFI0215_288
    uint32_t actual_flags = 0;
#endif //JIRA_WIFI0215_288
    OS_ERROR_CODE_T error;
#ifdef JIRA_WIFI0215_225
#if 0	//Disable the DCT
    /* Init DCT_1 */
    init_dct( );
    wiced_rtos_delay_milliseconds(1000);
#endif
#endif //JIRA_WIFI0215_225
    
#ifdef JIRA_WIFI0215_509	
     wwd_wifi_set_ioctl_value( WLC_SET_INTERFERENCE_MODE, 3, WWD_STA_INTERFACE );
#endif
#ifdef JIRA_WIFI0215_219	
    /* Register callbacks */
    wiced_network_register_link_callback( wifi_link_up, wifi_link_down, WICED_STA_INTERFACE );
#endif //JIRA_WIFI0215_219        

#ifdef JIRA_WIFI0215_288
    wiced_rtos_delay_milliseconds(1000);

    /* init flags for wifi async events */    
    wiced_rtos_init_event_flags( &g_wifiAsynEvent );
#endif     
    
#ifdef JIRA_WIFI0215_387
    wiced_rtos_init_timer  ( &update_radio_level, RADIO_LEVEL_UPDATE_PERIOD_MS, check_radio_level_event, NULL );

    // wiced_rtos_start_timer ( &update_radio_level );
#endif

#ifdef JIRA_WIFI0215_443
    host_rtos_init_semaphore( &scan_connect_semaphore );
    host_rtos_set_semaphore ( &scan_connect_semaphore, WICED_FALSE );
    
    wiced_rtos_init_timer ( &try_to_reconnect, RECONNECT_INTERVAL, reconnect_to_ap, NULL );
#endif //JIRA_WIFI0215_443

    wiced_set_ap_info_callback(wiced_vat_to_ap_info);
    /* finish wifi initialize */        
    g_isWifiInit = 1;

#ifdef JIRA_WIFI0215_288    
    while(1)
    {
        /* waiting for attach/detach event and send unsolict msg */
#ifdef JIRA_WIFI0215_443
        error = OS_EventWait(&g_wifiAsynEvent, &actual_flags, WIFI_ASYNC_EVENT_ATTACH | WIFI_ASYNC_EVENT_DETACH | WIFI_ASYNC_EVENT_RECONNECT, OS_FLAG_EVENT_ANY | OS_FLAG_CLEAR, TX_WAIT_FOREVER);
        assert(error == OS_ERR_OK);
#else      
        tx_event_flags_get( &g_wifiAsynEvent, (WIFI_ASYNC_EVENT_ATTACH | WIFI_ASYNC_EVENT_DETACH), TX_OR_CLEAR, &actual_flags, TX_WAIT_FOREVER );
#endif //JIRA_WIFI0215_443
#ifdef JIRA_WIFI0215_650
	if(g_flagSolicitedResponse == 0)
#endif
        send_Solicited_msg_to_wm( actual_flags );
#ifdef JIRA_WIFI0215_458
	send_keep_alive_data_package(actual_flags);
#endif

        actual_flags = 0;
    }
#endif //JIRA_WIFI0215_288
    #endif
}

Anonymous,