Exemplo n.º 1
0
void startUp(int argc, const char *argv[])
    {
#if __BORLANDC__ >= 1106
    set_new_handler(0);
#endif

    strcpy(fullExePath, argv[0]);

#ifndef WINCIT
    fseek(stdin, 0, SEEK_CUR);  // Borland says to fseek() before setbuf()
    setbuf(stdin, NULL);
#endif

#ifndef WINCIT
#ifdef MULTI
    if (!initTaskInfo(&ti))
#else
    cfg.maxrooms = 0 ;
    if (!initFakeTaskInfo())
#endif
        {
        printf("Could not create initial task information structure.\n");
        exit(200);
        }
#endif

    tzset();

    critical(TRUE);

#ifndef WINCIT
    if (checkDataVer() != NumericVer)
        {
        printf("CTDL.DAT is version %d; version %d needed.\n", checkDataVer(), NumericVer);
        critical(FALSE);
        exit(200);
        }

    if (!read_messages())
        {
        printf("Could not read messages from CTDL.DAT\n");
        critical(FALSE);
        exit(200);
        }

    InitializeTimer();
#else
    if (checkDataVer() != NumericVer)
        {
		char bbb[100];
		sprintf(bbb, "CTDL.DAT is version %d; version %d needed.", checkDataVer(), NumericVer);

        MessageBox(NULL, bbb, NULL, MB_ICONSTOP | MB_OK);
        exit(200);
        }

    if (!read_messages())
        {
        MessageBox(NULL, "Could not read messages from CTDL.DAT.", NULL, MB_ICONSTOP | MB_OK);
        exit(200);
        }

    WNDCLASS wndclass;

    // define and register the main window class
    wndclass.style = 0; // CS_HREDRAW | CS_VREDRAW
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = hInstance;
    wndclass.hIcon = LoadIcon(hInstance, "CITADEL");
    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);

    // define and register the logo window class
    wndclass.lpszMenuName = NULL;
    wndclass.lpfnWndProc = logoWndProc;
    wndclass.lpszClassName = "Citadel Logo";
    if (!RegisterClass(&wndclass))
        {
        MessageBox(NULL, "Could not register logo window", NULL, MB_ICONSTOP | MB_OK);
        exit(200);
        }

#ifdef NAHERROR
    // define and register the error window class
    wndclass.style = CS_VREDRAW;
    wndclass.lpfnWndProc = errorWndProc;
    wndclass.lpszClassName = "Citadel Error";
    if (!RegisterClass(&wndclass))
        {
        MessageBox(NULL, "Could not register error window", NULL, MB_ICONSTOP | MB_OK);
        exit(200);
        }

    // define and register the msg window class
    wndclass.lpfnWndProc = msgWndProc;
    wndclass.lpszClassName = "Citadel Message";
    if (!RegisterClass(&wndclass))
        {
        MessageBox(NULL, "Could not register msg window", NULL, MB_ICONSTOP | MB_OK);
        exit(200);
        }
#endif
#endif

    // initialize all drivers to internal functions

#ifdef WINCIT
    // com
//  initrs          = (void (cdecl *)(int,int,int,int,int,int)) nullFunc;
//  deinitrs        = nullFunc;
//  ringstatrs      = (int (cdecl *)(void)) nullFunc;
//  carrstatrs      = (int (cdecl *)(void)) nullFunc;
//  statrs          = (int (cdecl *)(void)) nullFunc;
//  flushrs         = nullFunc;
//  getrs           = (int (cdecl *)(void)) nullFunc;
//  putrs           = (void (cdecl *)(char)) nullFunc;
//  dtrrs           = (void (cdecl *)(int)) nullFunc;
//  flushoutrs      = nullFunc;
#else
    // Start using BIOS
    charattr = bioschar;
    stringattr = biosstring;

    // com
    initrs          = InitRS;
    deinitrs        = DeInitRS;
    ringstatrs      = RingStatRS;
    carrstatrs      = CarrStatRS;
    statrs          = StatRS;
    flushrs         = FlushRS;
    getrs           = GetRS;
    putrs           = PutRS;
    dtrrs           = DtrRS;
    flushoutrs      = nullFunc;

    // ups
    initups         = nullFunc;
    deinitups       = nullFunc;
    statups         = NULL;

    // kbd
    initkbd         = nullFunc;
    deinitkbd       = nullFunc;
    statcon         = StatCON;
    getcon          = GetCON;
    sp_press        = special_pressed;

    // snd
    init_sound      = (int (cdecl *)(void)) nullFunc;
    close_sound     = (int (cdecl *)(void)) nullFunc;
    get_version     = (int (cdecl *)(void)) nullFunc;
    query_drivers   = (int (cdecl *)(void)) nullFunc;
    query_status    = (int (cdecl *)(void)) nullFunc;
    start_snd_src   = (int (cdecl *)(int, const void *)) nullFunc;
    play_sound      = (int (cdecl *)(int)) nullFunc;
    stop_sound      = (int (cdecl *)(int)) nullFunc;
    pause_sound     = (int (cdecl *)(int)) nullFunc;
    resume_sound    = (int (cdecl *)(int)) nullFunc;
    read_snd_stat   = (int (cdecl *)(int)) nullFunc;
    set_midi_map    = (int (cdecl *)(int)) nullFunc;
    get_src_vol     = (int (cdecl *)(int)) nullFunc;
    set_src_vol     = (int (cdecl *)(int, int)) nullFunc;
    set_fade_pan    = (int (cdecl *)(void *)) nullFunc;
    strt_fade_pan   = (int (cdecl *)(void)) nullFunc;
    stop_fade_pan   = (int (cdecl *)(int)) nullFunc;
    pse_fade_pan    = (int (cdecl *)(void)) nullFunc;
    res_fade_pan    = (int (cdecl *)(void)) nullFunc;
    read_fade_pan   = (int (cdecl *)(int)) nullFunc;
    get_pan_pos     = (int (cdecl *)(int)) nullFunc;
    set_pan_pos     = (int (cdecl *)(int, int)) nullFunc;
    say_ascii       = (int (cdecl *)(const char *, int)) nullFunc;
#endif

    parseArgs(argc, argv);

#ifndef WINCIT
    if (!cfg.bios)
        {
        charattr = directchar;
        stringattr = directstring;
        }
#endif

#ifndef WINCIT
    if (!cmdLine[1])
        {
        uchar *ptr = (uchar *) MK_FP(_psp, 128);

        if (ptr[0])
            {
            memcpy(cmdLine, ptr + 1, max(128, ptr[0]));

            cmdLine[ptr[0]] = 0;
            }
        }

    OC.whichIO = CONSOLE;
#endif


    if (!initCitadel())
        {
#ifndef WINCIT
        DeinitializeTimer();
#endif
        critical(FALSE);
        exit(200);
        }


#ifndef WINCIT
    ScreenSaver.Update();
#endif

    if (BoardNameHash && hash(cfg.nodeTitle) != BoardNameHash)
        {
        crashout(getmsg(681));
        }

#ifndef WINCIT
    // Set system to a known state
    OC.Echo = BOTH;
    OC.SetOutFlag(IMPERVIOUS);
    modStat = FALSE;
    OC.whichIO = CONSOLE;

    OC.setio();

    if (!(login_pw || login_user || (slv_door && cfg.forcelogin)))
        {
        CommPort->FlushInput();
        greeting();
        }

    Cron.ResetTimer();

    if (slv_net)
        {
        doccr();

        if(read_tr_messages())
            {
            cPrintf(gettrmsg(49), slv_node);
            dump_tr_messages();
            }

        if (net_callout(slv_node))
            {
            did_net(slv_node);
            }

        ExitToMsdos = TRUE;
        }

    if (slv_door) // set according to carrier
        {
        // set baud rate even if carrier not present
        if (slv_baud != PS_ERROR)
            {
            CommPort->SetSpeed(slv_baud);
            }
        else
            {
            CommPort->SetSpeed(cfg.initbaud);
            }

        for (ModemSpeedE i = MS_300; i < MS_NUM; i = (ModemSpeedE) (i +1))
            {
            if (connectbauds[i] == bauds[CommPort->GetSpeed()])
                {
                CommPort->SetModemSpeed(i);
                break;
                }
            }

        if (CommPort->HaveConnection())
            {
            CarrierJustFound();

            OC.whichIO = MODEM;
            OC.setio();
            }
        else
            {
            OC.whichIO = CONSOLE;
            OC.setio();
            }
        }

    setdefaultTerm(TT_ANSI);

    StatusLine.Toggle();        // Turns it on (starts life off).

    ScreenSaver.SetMayTurnOn(TRUE);

    time(&LastActiveTime);
    TimeoutChecking = TRUE;

    if (*cmd_script)
        {
#ifdef WINCIT
        runScript(cmd_script, NULL);
#else
        runScript(cmd_script);
#endif
        }

    doEvent(EVT_STARTUP);
#endif
    }
Exemplo n.º 2
0
static void do_command (int sock, char* func, char*args[], int num_args)
{
	int result;
	char response[100];
	struct cpg_name group_name;
	ssize_t rc;
	size_t send_len;

	qb_log (LOG_TRACE, "RPC:%s() called.", func);

	if (strcmp ("cpg_mcast_joined",func) == 0) {
		struct iovec iov[5];
		int a;

		for (a = 0; a < num_args; a++) {
			iov[a].iov_base = args[a];
			iov[a].iov_len = strlen(args[a])+1;
		}
		cpg_mcast_joined (cpg_handle, CPG_TYPE_AGREED, iov, num_args);

	} else if (strcmp ("cpg_join",func) == 0) {
		if (strlen(args[0]) >= CPG_MAX_NAME_LENGTH) {
			qb_log (LOG_ERR, "Invalid group name");
			exit (1);
		}
		strcpy (group_name.value, args[0]);
		group_name.length = strlen(args[0]);
		result = cpg_join (cpg_handle, &group_name);
		if (result != CS_OK) {
			qb_log (LOG_ERR,
				"Could not join process group, error %d", result);
			exit (1);
		}
		qb_log (LOG_INFO, "called cpg_join(%s)!", group_name.value);

	} else if (strcmp ("cpg_leave",func) == 0) {

		strcpy (group_name.value, args[0]);
		group_name.length = strlen(args[0]);

		result = cpg_leave (cpg_handle, &group_name);
		if (result != CS_OK) {
			qb_log (LOG_ERR,
				"Could not leave process group, error %d", result);
			exit (1);
		}
		qb_log (LOG_INFO, "called cpg_leave(%s)!", group_name.value);

	} else if (strcmp ("cpg_initialize",func) == 0) {
		int retry_count = 0;

		result = cpg_initialize (&cpg_handle, &callbacks);
		while (result != CS_OK) {
			qb_log (LOG_ERR,
				"cpg_initialize error %d (attempt %d)",
				result, retry_count);
			if (retry_count >= 3) {
				exit (1);
			}
			sleep(1);
			retry_count++;
			result = cpg_initialize (&cpg_handle, &callbacks);
		}

		cpg_fd_get (cpg_handle, &cpg_fd);
		qb_loop_poll_add (ta_poll_handle_get(),
			QB_LOOP_MED,
			cpg_fd,
			POLLIN|POLLNVAL,
			NULL,
			cpg_dispatch_wrapper_fn);

	} else if (strcmp ("cpg_local_get", func) == 0) {
		unsigned int local_nodeid;

		cpg_local_get (cpg_handle, &local_nodeid);
		snprintf (response, 100, "%u",local_nodeid);
		send_len = strlen (response);
		rc = send (sock, response, send_len, 0);
		assert(rc == send_len);
	} else if (strcmp ("cpg_finalize", func) == 0) {

		if (cpg_handle > 0) {
			cpg_finalize (cpg_handle);
			cpg_handle = 0;
		}

	} else if (strcmp ("record_config_events", func) == 0) {
		record_config_events (sock);
	} else if (strcmp ("record_messages", func) == 0) {
		record_messages ();
	} else if (strcmp ("read_config_event", func) == 0) {
		read_config_event (sock);
	} else if (strcmp ("read_messages", func) == 0) {
		read_messages (sock, args[0]);
	} else if (strcmp ("msg_blaster_zcb", func) == 0) {
		msg_blaster_zcb (sock, args[0]);
	} else if (strcmp ("pcmk_test", func) == 0) {
		pcmk_test = 1;
	} else if (strcmp ("msg_blaster", func) == 0) {
		msg_blaster (sock, args[0]);
	} else if (strcmp ("context_test", func) == 0) {
		context_test (sock);
	} else if (strcmp ("are_you_ok_dude", func) == 0) {
		snprintf (response, 100, "%s", OK_STR);
		send_len = strlen (response);
		rc = send (sock, response, strlen (response), 0);
		assert(rc == send_len);
	} else if (strcmp ("cfg_shutdown", func) == 0) {

		qb_log (LOG_INFO, "calling %s() called!", func);
		result = corosync_cfg_try_shutdown (cfg_handle, COROSYNC_CFG_SHUTDOWN_FLAG_REQUEST);
		qb_log (LOG_INFO,"%s() returned %d!", func, result);

	} else if (strcmp ("cfg_initialize",func) == 0) {
		int retry_count = 0;

		qb_log (LOG_INFO,"%s() called!", func);
		result = corosync_cfg_initialize (&cfg_handle, &cfg_callbacks);
		while (result != CS_OK) {
			qb_log (LOG_ERR,
				"cfg_initialize error %d (attempt %d)",
				result, retry_count);
			if (retry_count >= 3) {
				exit (1);
			}
			sleep(1);
			retry_count++;
			result = corosync_cfg_initialize (&cfg_handle, &cfg_callbacks);
		}
		qb_log (LOG_INFO,"corosync_cfg_initialize() == %d", result);

		result = corosync_cfg_fd_get (cfg_handle, &cfg_fd);
		qb_log (LOG_INFO,"corosync_cfg_fd_get() == %d", result);

		qb_loop_poll_add (ta_poll_handle_get(),
			QB_LOOP_MED,
			cfg_fd,
			POLLIN|POLLNVAL,
			NULL,
			cfg_dispatch_wrapper_fn);
	} else {
		qb_log(LOG_ERR, "RPC:%s not supported!", func);
	}
}
Exemplo n.º 3
0
Arquivo: run.c Projeto: Yunaik/asp
int main(int argc, char argv[]) {
//Serial Configs

    initialize_defaults();
    open_serial();

//Reading messages
    //FREQUENCY OF READ MSG
    int f_linux = 10;

    int i ;
    int wert;
    int check=0;
    int unique_counter =0;

    int counter = 0;
    int unique_list[100];
    int liste[100];
    int time_start;
    int time_stop;
    int error_counter = 0;
    float t_sample_linux = 1.0/(float)f_linux;
    int sleep_time = t_sample_linux*1e6;
    /*int fails = 0;*/
//..........
    time_start = get_time_usec();

    // Read out all the messages in a for loop that has 1000 iterations (about 0.25s) and storing them into a list (unsorted and not filtered)
    while((get_time_usec()-time_start)/1000000.0 < 1)
    {
        int success = read_messages(&all_counter, &wert);
        float t = messages.global_position_int.time_boot_ms;
        /*printf("Time since start %0.3f", t/1000.0 - t_px_start);*/
        /*printf("\n ---------------- \nLinux Time: %0.3f \n", (get_time_usec()-time_start)/1e6);*/
        liste[counter] = wert;
        if(success == 1) {
            counter++;
        }
        else {
            error_counter++;
        }
        /*printf("i %i \n", i);*/
        /*if(get_time_usec()-time_start > 5000000){break;}*/
        time_stop = get_time_usec();

        usleep(sleep_time);
    }

    float t_diff = (time_stop - time_start)/1000000.0;
    int int_t_diff = t_diff*1e6;
//..........
    float scale  = 1/t_diff;
    float frequency = scale*all_counter;
    float t_sample = 1/frequency;
    printf("Received %i messages in %f secs (Real time)\n", all_counter, t_diff);
    printf("Pixhawk time difference: %f \n -----------------\n", t_px_stop - t_px_start);
    printf("Sample Rate of Linux: %0.4f , Frequency of Linux: %i \n", t_sample_linux, f_linux);
    printf("Sample time: %f and Frequency: %f \n -------------\n", t_sample, frequency);
    int times_called = error_counter + all_counter;
    printf("Error counter: %i, Times called: %i \n", error_counter, times_called);
    printf("Time for a while loop: %i us \n", (int_t_diff - times_called*sleep_time)/times_called);
    printf("int_t_diff %i, times_called %i, sleep_time %i \n", int_t_diff, times_called, sleep_time);

    printf("---------------------\n");

    printf("Packets dropped: %i \n", packets_dropped);


// Generating a list with unique values
    for(i=0; i<all_counter; i++) {
        wert = liste[i];
        check = 0;
        int a;
        for(a=0; a<unique_counter; a++) {
            if(wert ==unique_list[a]) {
                check =1;
            }
        }

        if (check == 0) {
            unique_list[unique_counter] = wert;
            unique_counter++;
        }
    }

    qsort(unique_list, unique_counter, sizeof(int), cmpfcn);

    int unique_count_list[100] = {0}; //variable size cannot be initialized
    /*for (i=0; i < unique_counter; i++){*/
    /*printf("value of ucl %i \n", unique_count_list[i]);*/
    /*}*/

    for(i=0; i < unique_counter; i++) {
        int unique_value = unique_list[i];
        /*printf("\n ----------\n unique_value %i \n", unique_value);*/
        int a;
        for(a=0; a < all_counter; a++) {
            /*printf("liste[a] %i \n", liste[a]);*/
            if(unique_value == liste[a]) {
                unique_count_list[i] += 1;
                /*printf("unique_coutn_value %i \n",unique_count_list[i]);*/
            }
        }
    }

//Printing the results
    printf("Got %i unique values: \n", unique_counter);


    for (i = 0; i < unique_counter; i++) {
        printf("%i: %i times\n", unique_list[i], unique_count_list[i]);
    }
    printf("..............................\n");



//Serial Port stuff
    close_serial();
    sleep(1);
    return 0;
}
Exemplo n.º 4
0
static void do_command (int sock, char* func, char*args[], int num_args)
{
	int result;
	char response[100];
	struct cpg_name group_name;

	if (parse_debug)
		syslog (LOG_DEBUG,"RPC:%s() called.", func);

	if (strcmp ("cpg_mcast_joined",func) == 0) {
		struct iovec iov[5];
		int a;

		for (a = 0; a < num_args; a++) {
			iov[a].iov_base = args[a];
			iov[a].iov_len = strlen(args[a])+1;
		}
		cpg_mcast_joined (cpg_handle, CPG_TYPE_AGREED, iov, num_args);

	} else if (strcmp ("cpg_join",func) == 0) {

		strcpy (group_name.value, args[0]);
		group_name.length = strlen(args[0]);

		result = cpg_join (cpg_handle, &group_name);
		if (result != CS_OK) {
			syslog (LOG_ERR,
				"Could not join process group, error %d\n", result);
			exit (1);
		}
		syslog (LOG_INFO, "called cpg_join()!");

	} else if (strcmp ("cpg_leave",func) == 0) {

		strcpy (group_name.value, args[0]);
		group_name.length = strlen(args[0]);

		result = cpg_leave (cpg_handle, &group_name);
		if (result != CS_OK) {
			syslog (LOG_ERR,
				"Could not leave process group, error %d\n", result);
			exit (1);
		}
		syslog (LOG_INFO, "called cpg_leave()!");

	} else if (strcmp ("cpg_initialize",func) == 0) {
		int retry_count = 0;

		result = cpg_initialize (&cpg_handle, &callbacks);
		while (result != CS_OK) {
			syslog (LOG_ERR,
				"cpg_initialize error %d (attempt %d)\n",
				result, retry_count);
			if (retry_count >= 3) {
				exit (1);
			}
			sleep(1);
			retry_count++;
			result = cpg_initialize (&cpg_handle, &callbacks);
		}

		cpg_fd_get (cpg_handle, &cpg_fd);
		poll_dispatch_add (ta_poll_handle_get(), cpg_fd, POLLIN|POLLNVAL, NULL, cpg_dispatch_wrapper_fn);

	} else if (strcmp ("cpg_local_get", func) == 0) {
		unsigned int local_nodeid;

		cpg_local_get (cpg_handle, &local_nodeid);
		snprintf (response, 100, "%u",local_nodeid);
		send (sock, response, strlen (response), 0);
	} else if (strcmp ("cpg_finalize", func) == 0) {

		cpg_finalize (cpg_handle);
		poll_dispatch_delete (ta_poll_handle_get(), cpg_fd);
		cpg_fd = -1;

	} else if (strcmp ("record_config_events", func) == 0) {
		record_config_events (sock);
	} else if (strcmp ("record_messages", func) == 0) {
		record_messages ();
	} else if (strcmp ("read_config_event", func) == 0) {
		read_config_event (sock);
	} else if (strcmp ("read_messages", func) == 0) {
		read_messages (sock, args[0]);
	} else if (strcmp ("msg_blaster_zcb", func) == 0) {
		msg_blaster_zcb (sock, args[0]);
	} else if (strcmp ("pcmk_test", func) == 0) {
		pcmk_test = 1;
	} else if (strcmp ("msg_blaster", func) == 0) {
		msg_blaster (sock, args[0]);
	} else if (strcmp ("context_test", func) == 0) {
		context_test (sock);
	} else if (strcmp ("are_you_ok_dude", func) == 0) {
		snprintf (response, 100, "%s", OK_STR);
		send (sock, response, strlen (response), 0);

	} else if (strcmp ("cfg_shutdown", func) == 0) {

		corosync_cfg_try_shutdown (cfg_handle, COROSYNC_CFG_SHUTDOWN_FLAG_REQUEST);

	} else if (strcmp ("cfg_initialize",func) == 0) {
		int retry_count = 0;

		syslog (LOG_INFO,"%s %s() called!", __func__, func);
		result = corosync_cfg_initialize (&cfg_handle, &cfg_callbacks);
		while (result != CS_OK) {
			syslog (LOG_ERR,
				"cfg_initialize error %d (attempt %d)\n",
				result, retry_count);
			if (retry_count >= 3) {
				exit (1);
			}
			sleep(1);
			retry_count++;
			result = corosync_cfg_initialize (&cfg_handle, &cfg_callbacks);
		}

		corosync_cfg_fd_get (cfg_handle, &cfg_fd);

		corosync_cfg_state_track (cfg_handle, 0, &notification_buffer);

		poll_dispatch_add (ta_poll_handle_get(), cfg_fd, POLLIN|POLLNVAL, NULL, cfg_dispatch_wrapper_fn);
	} else {
		syslog (LOG_ERR,"%s RPC:%s not supported!", __func__, func);
	}
}