Exemplo n.º 1
0
int get_key_len(const char **user){
    char section[50]; //nazwa sekcji
    char mobile[50]; //nazwa telefonu dla uzytkownika

	int key_len; // dlogosc klucza z konfigu
    int  s; //iterator sekcji
    int  b; // enabled, true/false

//  Szukaj uzytkownikow
	for (s = 0; ini_getsection(s, section, sizearray(section), inifile_users) > 0; s++) {
		printf("get_key_len() [%s] user: %s\n", section, *user);
		if (!strcmp(*user, section)){
			printf("user cfg exists\n");
			b = ini_getbool(section, "enabled", 0, inifile_users);
			if(b == 1){
			//pobierz nazwe telfonu przypisanego do uzytkownika
				ini_gets(section, "mobile", "0", mobile, sizearray(mobile), inifile_users);
			//  pobierz dlugosc klucza i klucz
				key_len = ini_getl(mobile, "key_len", 1, inifile_mobiles);
				printf("get_key_len(): key length: %d\n", key_len);
				return key_len;
			}
		}
	} /* for */
	return -1;
}
Exemplo n.º 2
0
void load_config(void)
{
/*
	config._.RollStabilizaionAilerons = ROLL_STABILIZATION_AILERONS;
	config._.RollStabilizationRudder = ROLL_STABILIZATION_RUDDER;
	config._.PitchStabilization = PITCH_STABILIZATION;
	config._.YawStabilizationRudder = YAW_STABILIZATION_RUDDER;
	config._.YawStabilizationAileron = YAW_STABILIZATION_AILERON;

	config._.AileronNavigation = AILERON_NAVIGATION;
	config._.RudderNavigation = RUDDER_NAVIGATION;

	config._.AltitudeholdStabilized = ALTITUDEHOLD_STABILIZED;
	config._.AltitudeholdWaypoint = ALTITUDEHOLD_WAYPOINT;
	config._.RacingMode = RACING_MODE;
 */
	config._.RollStabilizaionAilerons = ini_getbool(strStabilise, "roll_ail", ROLL_STABILIZATION_AILERONS, strConfigFile);
	config._.RollStabilizationRudder = ini_getbool(strStabilise, "roll_rud", ROLL_STABILIZATION_RUDDER, strConfigFile);
	config._.PitchStabilization = ini_getbool(strStabilise, "pitch", PITCH_STABILIZATION, strConfigFile);
	config._.YawStabilizationRudder = ini_getbool(strStabilise, "yaw_rud", YAW_STABILIZATION_RUDDER, strConfigFile);
	config._.YawStabilizationAileron = ini_getbool(strStabilise, "yaw_ail", YAW_STABILIZATION_AILERON, strConfigFile);

	config._.AileronNavigation = ini_getbool(strNavigation, "ail", AILERON_NAVIGATION, strConfigFile);
	config._.RudderNavigation = ini_getbool(strNavigation, "rud", RUDDER_NAVIGATION, strConfigFile);
	// = ini_getbool(strNavigation, "wind", WIND_GAIN_ADJUSTMENT, strConfigFile);

	config._.AltitudeholdStabilized = ini_getl(strAltitude, "stabilised", ALTITUDEHOLD_STABILIZED, strConfigFile);
	config._.AltitudeholdWaypoint = ini_getl(strAltitude, "waypoint", ALTITUDEHOLD_WAYPOINT, strConfigFile);
//	config._.RacingMode = ini_getbool(strMode, "racing", RACING_MODE, strConfigFile);
}
Exemplo n.º 3
0
int
ini_getbool_port (int *value, char *port, char *param)
{
    char key[MAX_KEY_SIZE];

    KEY_PORT (key, sizeof(key), port, param);
    if (ini_getbool (value, key))
        return 1;
    return ini_getbool_id (value, param);
}
Exemplo n.º 4
0
int
ini_getbool_id (int *value, char *param)
{
    char key[MAX_KEY_SIZE];

    KEY_ID (key, sizeof(key), param);
    if (ini_getbool (value, key))
        return 1;
    return ini_getbool_default (value, param);
}
Exemplo n.º 5
0
int
ini_getbool_default (int *value, char *param)
{
  char key[MAX_KEY_SIZE];

  KEY_DEF (key, param);
  if (ini_getbool (value, key))
    return 1;
  return 0;
}
Exemplo n.º 6
0
// Wejscie:
//      user - login
// Wyjscia
//      btaddr
//      port
//      mobile_id 
//      rssi
int get_user_data(const char **user, char* btaddr, int *port, char *mobile_id,
        float *rssi){
    char section[50]; //nazwa sekcji
    char mobile[50]; //nazwa telefonu dla uzytkownika
    char addr[18];

    int  s; //iterator sekcji
    int  b; // enabled, true/false
    int  p; // port
    float min_rssi; // rssi
    //char user_login[] = *user;

      for (s = 0; ini_getsection(s, section, sizearray(section), inifile_users) > 0; s++) {
        //printf("    [%s] user: %s\n", section, *user);

        if (!strcmp(*user, section)){
            printf("user cfg exists\n");

            b = ini_getbool(section, "enabled", 0, inifile_users);
            if(b == 1){
//pobierz nazwe telfonu przypisanego do uzytkownika
                ini_gets(section, "mobile", "0", mobile, sizearray(mobile), inifile_users);
//pobierrz btaddr i port telefonu o ww nazwie
                ini_gets(mobile, "btaddr", "999", addr, sizearray(addr),
                 inifile_mobiles);
                p = ini_getl(mobile, "port", 999, inifile_mobiles);
//  pobierz wartosc progu RSSI
                min_rssi = ini_getf(mobile, "min_rssi", "-5.0", inifile_users);
                
                printf("user %s enabled with mobile: %s\n", *user, mobile);
                printf("mobile btaddr: %s, port: %d\n", addr, p);
                printf("rssi threshold: %f\n", min_rssi);
                //printf("check_user(): key length: %d, key: %s\n", key_len, k);

//zapisz btaddr, port i klucz do adresow z argumetu
                strcpy(btaddr,addr);
                strcpy(mobile_id, mobile);
                *port = p;
                *rssi = min_rssi;
                return 0;
            }

            //for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) {
            //  printf("\t%s\n", str);
            //} /* for */
        }
      } /* for */
return E_INI_FILE;
}
Exemplo n.º 7
0
void ev3rt_load_configuration() {
	/**
	 * Create '/ev3rt/etc/'
	 */
	f_mkdir("/ev3rt");
	f_mkdir("/ev3rt/etc");

	static char localname[100];
	ini_gets("Bluetooth", "LocalName", "Mindstorms EV3", localname, 100, CFG_INI_FILE);
	ini_puts("Bluetooth", "LocalName", localname, CFG_INI_FILE);
	ev3rt_bluetooth_local_name = localname;

	static char pincode[17];
	ini_gets("Bluetooth", "PinCode", "0000", pincode, 17, CFG_INI_FILE);
	ini_puts("Bluetooth", "PinCode", pincode, CFG_INI_FILE);
	ev3rt_bluetooth_pin_code = pincode;

	static bool_t disable_port_1;
	disable_port_1 = ini_getbool("Sensors", "DisablePort1", false, CFG_INI_FILE);
	ini_putl("Sensors", "DisablePort1", disable_port_1, CFG_INI_FILE);
	ev3rt_sensor_port_1_disabled = &disable_port_1;
}
Exemplo n.º 8
0
void ev3rt_load_configuration() {
	/**
	 * Create '/ev3rt/etc/'
	 */
	f_mkdir("/ev3rt");
	f_mkdir("/ev3rt/etc");

    char sio_default_port[5];
	ini_gets("Debug", "DefaultPort", NULL, sio_default_port, 5, CFG_INI_FILE);
    if (!strcasecmp("UART", sio_default_port)) {
        SIO_PORT_DEFAULT = SIO_PORT_UART;
    } else if (!strcasecmp("BT", sio_default_port)) {
        SIO_PORT_DEFAULT = SIO_PORT_BT;
    } else { // Use LCD by default
        SIO_PORT_DEFAULT = SIO_PORT_LCD;
	    ini_puts("Debug", "DefaultPort", "LCD", CFG_INI_FILE);
    }

	static bool_t low_battery_warning;
	low_battery_warning = ini_getbool("Debug", "LowBatteryWarning", true, CFG_INI_FILE);
	ini_putl("Debug", "LowBatteryWarning", low_battery_warning, CFG_INI_FILE);
	ev3rt_low_battery_warning = &low_battery_warning;

	static bool_t disable_bluetooth;
	disable_bluetooth = ini_getbool("Bluetooth", "TurnOff", false, CFG_INI_FILE);
	ini_putl("Bluetooth", "TurnOff", disable_bluetooth, CFG_INI_FILE);
    ev3rt_bluetooth_disabled = &disable_bluetooth;

	static char localname[100];
	ini_gets("Bluetooth", "LocalName", "Mindstorms EV3", localname, 100, CFG_INI_FILE);
	ini_puts("Bluetooth", "LocalName", localname, CFG_INI_FILE);
	ev3rt_bluetooth_local_name = localname;

	static char pincode[17];
	ini_gets("Bluetooth", "PinCode", "0000", pincode, 17, CFG_INI_FILE);
	ini_puts("Bluetooth", "PinCode", pincode, CFG_INI_FILE);
	ev3rt_bluetooth_pin_code = pincode;

	static int disable_pan;
#if !defined(BUILD_LOADER) // TODO: Bluetooth PAN is only supported by loader currently
    disable_pan = 1;
#else
	disable_pan = ini_getbool("Bluetooth", "DisablePAN", false, CFG_INI_FILE);
	ini_putl("Bluetooth", "DisablePAN", disable_pan, CFG_INI_FILE);
#endif
	ev3rt_bluetooth_pan_disabled = &disable_pan;

    // TODO: check valid IP address
	static char ip_address[16];
	ini_gets("Bluetooth", "IPAddress", "10.0.10.1", ip_address, 17, CFG_INI_FILE);
	ini_puts("Bluetooth", "IPAddress", ip_address, CFG_INI_FILE);
	ev3rt_bluetooth_ip_address = ip_address;

	static bool_t disable_port_1;
	disable_port_1 = ini_getbool("Sensors", "DisablePort1", false, CFG_INI_FILE);
	ini_putl("Sensors", "DisablePort1", disable_port_1, CFG_INI_FILE);
    if (SIO_PORT_DEFAULT == SIO_PORT_UART) disable_port_1 = true;
    DEBUG_UART = disable_port_1 ? 0 : 4;
	ev3rt_sensor_port_1_disabled = &disable_port_1;

	static bool_t auto_term_app;
	auto_term_app = ini_getbool("USB", "AutoTerminateApp", true, CFG_INI_FILE);
	ini_putl("USB", "AutoTerminateApp", auto_term_app, CFG_INI_FILE);
	ev3rt_usb_auto_terminate_app = &auto_term_app;
}
Exemplo n.º 9
0
static void load_network(void)
{
	int port = 0;
	int result;

	result = ini_gets(strNetwork, "address", "10.10.10.10", address, sizeof(address), strConfigFile);
	result = ini_gets(strNetwork, "gateway", "10.1.1.1", gateway, sizeof(gateway), strConfigFile);
	result = ini_gets(strNetwork, "subnet", "255.0.0.0", subnet, sizeof(subnet), strConfigFile);
	port = ini_getl(strNetwork, "port", 21, strConfigFile);
	dhcp = ini_getbool(strNetwork, "dhcp", 1, strConfigFile);

	printf("IP address: %s\r\n", address);
	printf("IP gateway: %s\r\n", gateway);
	printf("IP subnet: %s\r\n", subnet);
	printf("IP port: %u\r\n", port);
	printf("DHCP: %u\r\n", dhcp);

	nw_mod._.uart1           = ini_getbool(strNetwork, "uart1", NETWORK_USE_UART1, strConfigFile);
	nw_mod._.uart2           = ini_getbool(strNetwork, "uart2", NETWORK_USE_UART2, strConfigFile);
	nw_mod._.flybywire       = ini_getbool(strNetwork, "flybywire", NETWORK_USE_FLYBYWIRE, strConfigFile);
	nw_mod._.mavlink         = ini_getbool(strNetwork, "mavlink", NETWORK_USE_MAVLINK, strConfigFile);
	nw_mod._.debug           = ini_getbool(strNetwork, "debug", NETWORK_USE_DEBUG, strConfigFile);
	nw_mod._.adsb            = ini_getbool(strNetwork, "adsb", NETWORK_USE_ADSB, strConfigFile);
	nw_mod._.logo            = ini_getbool(strNetwork, "logo", NETWORK_USE_LOGO, strConfigFile);
	nw_mod._.cam_tracking    = ini_getbool(strNetwork, "cam_tracking", NETWORK_USE_CAM_TRACKING, strConfigFile);
	nw_mod._.gpstest         = ini_getbool(strNetwork, "gpstest", NETWORK_USE_GPSTEST, strConfigFile);
	nw_mod._.pwmreport       = ini_getbool(strNetwork, "pwmreport", NETWORK_USE_PWMREPORT, strConfigFile);
	nw_mod._.xplane          = ini_getbool(strNetwork, "xplane", NETWORK_USE_XPLANE, strConfigFile);
	nw_mod._.telemetry_extra = ini_getbool(strNetwork, "telemetry_extra", NETWORK_USE_TELEMETRY_EXTRA, strConfigFile);
	nw_mod._.ground_station  = ini_getbool(strNetwork, "ground_station", NETWORK_USE_GROUND_STATION, strConfigFile);
}
Exemplo n.º 10
0
int main(int argc, char **argv)
{
	char spin[] = "-\\|/", SequenceCount = 'a';
	char Message[65], Data[100], upload_exclude[200], Command[200], Telemetry[100], *Bracket, *Start;
	int Bytes, Sentence_Count, sc = 0;
	double Latitude, Longitude;
	unsigned int Altitude;
	uint8_t opmode, flags1, flags2, old_opmode = 0, old_flags1 = 0, old_flags2 = 0;
	const char *inifile = "gateway.ini"; // FIXME
	float node_lat, node_lon;
	time_t next_beacon;
	bool bmp085, xap;

	/* load configuration */
	ini_gets("node", "id", "", node_id, sizeof(node_id), inifile);
	node_lat = ini_getf("node", "lat", 999, inifile);
	node_lon = ini_getf("node", "lon", 999, inifile);
	bmp085 = ini_getbool("sensors", "bmp085", false, inifile);
	xap = ini_getbool("xap", "enabled", false, inifile);
	ini_gets("upload", "exclude", "", upload_exclude, sizeof(upload_exclude), inifile);
	
	if (strlen(node_id) == 0) {
		puts("Node ID has not been specified");
		exit(1);
	}

	printf("Upload exclude list is \"%s\"\n", upload_exclude);

	if (xap) {
		xapInit();
	}

	if (node_lat < 900 && node_lon < 900) {
		/* put the gateway on the map */
		sprintf(Message,"0aL%f,%f:%s[%s]", node_lat, node_lon, GIT_VER, node_id);
	} else {
		sprintf(Message,"0a:%s[%s]", GIT_VER, node_id);
	}

	UploadPacket(Message,0);
	if (xap) {
		xapSendPacket(Message, 0);
	}

	if (bmp085) {
		next_beacon = time(NULL) + 10;
		printf("Initialising BMP085\n");
		bmp085_Calibration();
	}

	printf("Initialising RFM69\n");

	setupRFM69();
	
	printf("Starting main loop ...\n");

	Sentence_Count = 0;

	while (1)
	{
		if (rfm69_available())
		{
			Bytes = rfmM69_recv(Message, sizeof(Message));
			printf ("%s Data available - %d bytes\n", Now(), Bytes);
			printf ("rx: %s|%d\n", Message,RFM69_lastRssi());

			if (Bytes > 0)
			{
				if (!excluded(Message, upload_exclude)) {
					// UKHASNet upload
					UploadPacket(Message, RFM69_lastRssi());
				}

				if (xap) {
					// xAP broadcast
					xapSendPacket(Message, RFM69_lastRssi());
				}
#if 0
				// Habitat upload
				// 3dL51.95023,-2.54445,155[DA1]
				if (strstr(Message, "DA1"))
				{
					if (Start = strchr(Message, 'L'))
					{
						// DA1,2,19:35:37,51.95023,-2.54445,160*05%0A

						if (sscanf(Start+1, "%lf,%lf,%u[", &Latitude, &Longitude, &Altitude))
						{
							printf("Altitude = %u\n", Altitude);
							sprintf(Telemetry, "%s,%d,%s,%lf,%lf,%u", "DA1", ++Sentence_Count, Now(), Latitude, Longitude, Altitude);
							sprintf(Command, "wget -O habitat.txt \"http://habitat.habhub.org/transition/payload_telemetry\" --post-data \"callsign=DA0&string=\\$\\$%s*%s%s&string_type=ascii&metadata={}\"",	Telemetry, Checksum(Telemetry), "\%0A");
							printf("%s\n", Command);
							system(Command);
						}
					}
				}
#endif
			}
		}
		else
		{