コード例 #1
0
ファイル: config.c プロジェクト: kd0aij/matrixpilot_old
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);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: BestWanted/libgens-sonicglvl
int main(int argc, char** argv) {
	char temp[1024]="";
	char ini_file[]="lightfield.ini";

	ini_gets("Main", "TerrainFile", "", temp, 512, ini_file);
	string terrain_file=ToString(temp);
	ini_gets("Main", "Resources", "", temp, 512, ini_file);
	string resources=ToString(temp);
	ini_gets("Main", "Stage", "", temp, 512, ini_file);
	string stage=ToString(temp);
	ini_gets("Main", "GIA", "", temp, 512, ini_file);
	string gia=ToString(temp);

	float sample_unit_distance=ini_getf("Main", "SampleUnitDistance", 0.75f, ini_file);
	float saturation_multiplier=ini_getf("Main", "SaturationMultiplier", 1.0f, ini_file);
	float lookup_grid_size=ini_getf("Main", "LookupGridSize", 5.0f, ini_file);

	LibGens::initialize();
	LibGens::Error::setLogging(true);

	LibGens::Terrain terrain(terrain_file, resources, stage, gia);
	printf("Done loading Terrain\n");

	// Sample Unit Distance, Saturation Multiplier
	LibGens::VRMap *vrmap=terrain.generateVRMap(sample_unit_distance, saturation_multiplier);
	printf("VR Map setup...\n");

	vrmap->generateLookupGrid(lookup_grid_size, sample_unit_distance);
	printf("Done generating VR Map of %d samples covering %f units of area.\n", vrmap->getSampleList().size(), vrmap->getAABB().size());

	LibGens::LightField lightfield;

	float ambient_color_r=ini_getf("Main", "AmbientColorR", 1.0f, ini_file);
	float ambient_color_g=ini_getf("Main", "AmbientColorG", 1.0f, ini_file);
	float ambient_color_b=ini_getf("Main", "AmbientColorB", 1.0f, ini_file);
	float ambient_color_a=ini_getf("Main", "AmbientColorA", 1.0f, ini_file);
	int sample_min_count=ini_getl("Main", "SampleMinCount", 2, ini_file);
	float sample_blend_distance=ini_getf("Main", "SampleBlendDistance", 8.0f, ini_file);
	float min_octree_cube_size=ini_getf("Main", "MinOctreeCubeSize", 3.0f, ini_file);
	int cpu_threads=ini_getl("Main", "Threads", 1, ini_file);

	// Ambient Color, Sample Min Count, Sample Blend Distance, Min Octree Cube Size
	lightfield.generate(vrmap, LibGens::Color(ambient_color_r, ambient_color_g, ambient_color_b, ambient_color_a), sample_min_count, sample_blend_distance, min_octree_cube_size, cpu_threads);
	printf("Done generating lightfield.\n");
	lightfield.save("light-field.lft");
	printf("Saved lightfield. Press Enter to exit.\n");
    getchar();
    return 0;
}
コード例 #3
0
ファイル: config.c プロジェクト: chiloschista/MatrixPilot
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);
}
コード例 #4
0
ファイル: check_user.c プロジェクト: slaweksiluk/BlueAuth
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;
}
コード例 #5
0
ファイル: modem.c プロジェクト: nhanh0/hah
static speed_t getBaud() {
    long n = ini_getl("sms", "baud", 19200, inifile);
    speed_t speed;

    switch (n)
      {
      case 50: speed = B50; break;
      case 75: speed = B75; break;
      case 110: speed = B110; break;
      case 134: speed = B134; break;
      case 150: speed = B150; break;
      case 200: speed = B200; break;
      case 300: speed = B300; break;
      case 600: speed = B600; break;
      case 1200: speed = B1200; break;
      case 1800: speed = B1800; break;
      case 2400: speed = B2400; break;
      case 4800: speed = B4800; break;
      case 9600: speed = B9600; break;
      case 19200: speed = B19200; break;
      case 38400: speed = B38400; break;
      case 57600: speed = B57600; break;
      case 115200: speed = B115200; break;
      default:
	die("Invalid speed %d", n);
      }

    return speed;
}
コード例 #6
0
ファイル: init.c プロジェクト: johnlpayton/mxvsp-linux
static int GetPrivateProfileInt(
        char*   SecName,
        char*   ParmName,
        int     defval,
        char*   iniPath)
{
    return ini_getl(
        SecName,
        ParmName,
        defval,
        iniPath);
}
コード例 #7
0
ファイル: check_user.c プロジェクト: slaweksiluk/BlueAuth
// 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;
}
コード例 #8
0
ファイル: cfg.c プロジェクト: cloud-hot/netcwmp
int cwmp_conf_get_int(const char * key)
{
    char * s, *k;
    char name[INI_BUFFERSIZE] = {0};

    FUNCTION_TRACE();
    if(key == NULL)
    {
        return 0;
    }
    TRstrncpy(name, key, INI_BUFFERSIZE);
    cwmp_conf_split(name, &s, &k);

    return (int)ini_getl(s,k,0,cwmp_conf_handle->filename);
}
コード例 #9
0
ファイル: test.c プロジェクト: uplusplus/laser
int main(void)
{
  char str[100];
  long n;
  int s, k;
  char section[50];

  /* string reading */
  n = ini_gets("first", "string", "dummy", str, sizearray(str), inifile);
  assert(n==4 && strcmp(str,"noot")==0);
  n = ini_gets("second", "string", "dummy", str, sizearray(str), inifile);
  assert(n==4 && strcmp(str,"mies")==0);
  n = ini_gets("first", "undefined", "dummy", str, sizearray(str), inifile);
  assert(n==5 && strcmp(str,"dummy")==0);
  /* ----- */
  n = ini_gets("", "string", "dummy", str, sizearray(str), inifile2);
  assert(n==4 && strcmp(str,"noot")==0);
  n = ini_gets(NULL, "string", "dummy", str, sizearray(str), inifile2);
  assert(n==4 && strcmp(str,"noot")==0);
  /* ----- */
  printf("1. String reading tests passed\n");

  /* value reading */
  n = ini_getl("first", "val", -1, inifile);
  assert(n==1);
  n = ini_getl("second", "val", -1, inifile);
  assert(n==2);
  n = ini_getl("first", "undefined", -1, inifile);
  assert(n==-1);
  /* ----- */
  n = ini_getl(NULL, "val", -1, inifile2);
  assert(n==1);
  /* ----- */
  printf("2. Value reading tests passed\n");

  /* string writing */
  n = ini_puts("first", "alt", "flagged as \"correct\"", inifile);
  assert(n==1);
  n = ini_gets("first", "alt", "dummy", str, sizearray(str), inifile);
  assert(n==20 && strcmp(str,"flagged as \"correct\"")==0);
  /* ----- */
  n = ini_puts("second", "alt", "correct", inifile);
  assert(n==1);
  n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
  assert(n==7 && strcmp(str,"correct")==0);
  /* ----- */
  n = ini_puts("third", "test", "correct", inifile);
  assert(n==1);
  n = ini_gets("third", "test", "dummy", str, sizearray(str), inifile);
  assert(n==7 && strcmp(str,"correct")==0);
  /* ----- */
  n = ini_puts("second", "alt", "overwrite", inifile);
  assert(n==1);
  n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
  assert(n==9 && strcmp(str,"overwrite")==0);
  /* ----- */
  n = ini_puts(NULL, "alt", "correct", inifile2);
  assert(n==1);
  n = ini_gets(NULL, "alt", "dummy", str, sizearray(str), inifile2);
  assert(n==7 && strcmp(str,"correct")==0);
  /* ----- */
  printf("3. String writing tests passed\n");

  /* section/key enumeration */
  printf("4. Section/key enumertion, file contents follows\n");
  for (s = 0; ini_getsection(s, section, sizearray(section), inifile) > 0; s++) {
    printf("    [%s]\n", section);
    for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) {
      printf("\t%s\n", str);
    } /* for */
  } /* for */

  /* browsing through the file */
  printf("5. browse through all settings, file contents follows\n");
  ini_browse(Callback, NULL, inifile);

  /* string deletion */
  n = ini_puts("first", "alt", NULL, inifile);
  assert(n==1);
  n = ini_puts("second", "alt", NULL, inifile);
  assert(n==1);
  n = ini_puts("third", NULL, NULL, inifile);
  assert(n==1);
  /* ----- */
  n = ini_puts(NULL, "alt", NULL, inifile2);
  assert(n==1);
  printf("6. String deletion tests passed\n");

  return 0;
}
コード例 #10
0
ファイル: vbit.c プロジェクト: BackupGGCode/vbit
/* Command interpreter for VBIT,
	The leading SO and trailing carriage return are already removed
	The X command returns 2
	Other good commands return 0 and bad commands return 1.
	Also after a P command if selecting a single page fails, the page is created and 8 is the return code 
	*/
static int vbit_command(char *Line)
{
	static uint8_t firstLine=true;
	static uint16_t SRAMAddress;	// The address pointer into the FIFO serial ram
	unsigned char rwmode;
	unsigned char returncode=0;
	int pagecount;
	uint8_t directorySteps;
	int8_t sign; // 1=plus -1=minus
	char ch;
	unsigned char valid;
	long n;
	unsigned char i;
	char str[80];
	char *ptr;
	char *dest;
	str[0]='O';
	str[1]='K';
	str[2]='\0';
	// char data[80];
	
	// This stuff is to do with locating pages in the display list (Directory command)
	// (also shared with ee/ea command for uploading pages)
	NODEPTR np;
	DISPLAYNODE node;
	PAGEINDEXRECORD ixRec;
	uint16_t charcount;	
	uint8_t res;
	DWORD fileptr;		// Used to save the file pointer to the body of the ttx file	
	PAGE page;
	// ee/ea specific variable
	static DWORD StartOfPage;
	DWORD EndOfPage;	// Records the start and end of the new page
	PAGEINDEXRECORD pageindex;
	uint16_t ix;

	char packet[45];
	static uint8_t row;	// Teletext row counter for JA/JZ/JW command
	// tba
	
	// Read, Update or not
	switch (Line[2])
	{
	case 'R' : rwmode=CMD_MODE_READ; break;
	case 'U' : rwmode=CMD_MODE_WRITE;break;
	default:
		rwmode=CMD_MODE_NONE;
	}
	/* Is there actually any data */
	if (*Line==0)
		returncode=1;
	else
	switch (Line[1])
	{
	case 'b': // Dump the current page
		dumpPage();
		break;
	case 'C': // Create magazine lists
		// TODO: Kill video
		// TODO: C<pages to pre-allocate> // this would speed up the process immensely
		// It only needs to be approximate as FatFS will extend the file as needed.
		
		cli();
		pagecount=300;
		for (i=1;i<=1;i++) // TODO: Do we need more lists? Probably can find a way around it.
			SDCreateLists(i,pagecount);
		sei();
		break;
	case 'D': // Directory - D[<F|L>][<+|->][<n>]
		// Where F=first, L=Last, +=next, -=prev, n=number of pages to step (default 1)
		//xprintf(PSTR("D Command needs to be written"));
		// It would probably be a good idea to save the seek pointer
		// do the reading required
		// and then reset it. This would save memory.
		// If the ee command is active, don't allow D to mess the page variable.
		if (firstLine)
		{
			returncode=1; // ee command is busy. 
			break;
		}
		directorySteps=0;
		sign=1;
		for (i=2;Line[i];i++)
		{
			ch=Line[i];
			// xprintf(PSTR("Processing Line[%d]=%c\n\r"),i,Line[i]);
			switch (ch)
			{
			case 'F' : ; // Set the first item
				DirectoryFirst();
				break;
			case 'L' : ; // Set the last item
				DirectoryLast();
				break;
			case '+' : ; // Next item
				directorySteps=1;
				sign=1;
				// xprintf(PSTR("D+ not implemented"));
				break;
			case '-' : ; // Previous item
				directorySteps=1;
				sign=-1;
				// xprintf(PSTR("D- not implemented"));
				break;
			default: // Number of steps (TODO: Extend to a generic decimal)
				if (ch>='0' && ch <='9')
				{
					directorySteps=ch;
				}
				Line[i]=0;// Force this to be the last option
				break;	// Break because this must be the last option
			}
			// Find the page
			if (LocatePage(directorySteps*sign)==NULLPTR)
			{
				// Probably want to set an error value as we failed to iterate
				// But I don't think that we return anything different.
				// We rely on TED scheduler to remember the count returned by the P command and NOT overrun
			}
			// TODO: Work out what to do with the rest of the parameters
			np=GetNodePtr(&currentPage);
			// TODO: Handle sub pages
			GetNode(&node,np);
			// Instead treat the page like a single page
			f_lseek(&listFIL,(node.pageindex)*sizeof(PAGEINDEXRECORD));	// Seek the page index
			f_read(&listFIL,&ixRec,sizeof(PAGEINDEXRECORD),&charcount);	// and read it	
			// Now seek the actual page that we are referencing
			res=f_open(&PageF,"pages.all",FA_READ);					// Now look for the relevant page
			f_lseek(&PageF,ixRec.seekptr);	// Seek the actual page
			// Now we have the page, we need to seek through it to get
			// the data
			while (PageF.fptr<(ixRec.seekptr+ixRec.pagesize))
			{
				fileptr=PageF.fptr;		// Save the file pointer in case we found "OL"
				f_gets(str,sizeof(str),&PageF);
				if (str[0]=='O' && str[1]=='L')
				{
					f_lseek (&PageF, fileptr);	// Step back to the OL line
					break;
				}
				if (ParseLine(&page, str))
				{
					xprintf(PSTR("[insert]file error handler needed:%s\n"),str);
					// At this point we are stuffed.
					f_close(&PageF);
					returncode=1;
					break; // what else should we do if we get here?
				}
			}	
			// bb mpp qq cc tttt ssss n xxxxxxx
			// Leading zeros rely on PRINTF_LIB_FLOAT in makefile!!!
			sprintf_P(str,PSTR("%02X %03X %02d %02X %04X 0000 %1d 00000000"),
			3, // seconds (hex)
			0x100+(currentPage/2), // mpp
			page.subpage, // ss
			page.control, // S
			page.time,  // Cycle time (secs)
			(currentPage>>8)+1); // Mag
			f_close(&PageF);
		}
		// str[0]=0;	// might return the directory paramaters here
		break;
	case 'E' : // EO, ES, EN, EP, EL, EM - examine 
		switch (Line[2])
		{
		case 'M': // EM - Return Miscellaneous flags
			{
				// These are BFLSU. The code below is not correct
				n = ini_getl("service", "serialmode", 0, inifile);	
				if (n)
					xputs(PSTR("20"));
				else
					xputs(PSTR("00"));
				break;
			}
				break;
			default:
				returncode=1;
		case 'O': // EO - Output dataline actions set by QO
			// 18 characters on a line, but odd ignores last action
			n = ini_gets("service", "outputodd", "111Q2233P445566778", str, sizearray(str), inifile);	
			n = ini_gets("service", "outputeven", "111Q2233P445566778", str, sizearray(str), inifile);	
			xprintf(PSTR("%s"),str);
			break;
		}		
		break; // E commands
	case 'e' : // ea or ee : Upload page(s).
		// These pages add the lines at the end of the page file, and patch the index.
		// Warning. "page" is shared with the directory command
		// directory calls are blocked until you do ee.
		switch (Line[2])
		{
		case 'a' : // Add a page, line at a time.
			passBackspace=true;
			if (firstLine)
			{
				firstLine=false;
				ClearPage(&page); // Clear out our Page object
				res=f_open(&PageF,"pages.all",FA_READ| FA_WRITE);	// Ready to write
				// TODO: check the value of res
				//xprintf(PSTR("Size of pages.all=%ul\n\r"),PageF.fsize);
				/* Move to end of pages.all to append data */
				res=f_lseek(&PageF, PageF.fsize);				
				//xprintf(PSTR("lseek res=%d\n\r"),res);
				StartOfPage=PageF.fptr;  // We need the Start Of Page for the index
			}
			// uh fellows, Although we get \r => Ctrl-P, we need to map it to 0x8d which is the file format.
			for (ptr=&Line[4];*ptr;ptr++)
				if (*ptr==0x10)
					*ptr=0x8d;
			f_puts(&Line[4],&PageF);	// The rest of the line is the file contents
			f_putc('\n',&PageF);	// Add the LF that the interpreter strips out			
			xprintf(PSTR("Now writing:%s\n\r"),&Line[4]);
			// Don't unencode the line, pages.all should follow MRG \r => ctrl-P substitutions
			// Probably can ignore Viewdata escapes.
			// Write the rest of the line to pages.all
			// Parse the line so we have all the page details so we know where to put it in the array/node
			if (ParseLine(&page, &Line[4]))
			{
				xprintf(PSTR("Your page sucks. Unable to parse this nonsense\n\r"));
				returncode=1;	// failed
				// TODO: implement the break
				// break;
			}
			break; // a
		case 'e' : // We finished. End the update
			passBackspace=false;
			EndOfPage=PageF.fptr;
			f_close(&PageF);		// We are done with pages.all
			// We need to refresh the transmission file object so close and re-open it
			f_close(&pagefileFIL);
			res=f_open(&pagefileFIL,"pages.all",FA_READ);		// Only need to open this once!			
			// Or are we all done? We need to write the page to Pmpp.TTI so that we can rebuild the index later
			pageindex.seekptr=StartOfPage;
			pageindex.pagesize=(uint16_t)(EndOfPage-StartOfPage); // Warning! 16 bit file size limits to about 50 subpages.
		    xprintf(PSTR("seek %ld size %d \n\r"),pageindex.seekptr,pageindex.pagesize);
			// 1: Append pages.idx with the file start/end (append pageindex)
			f_close(&listFIL); // TODO: Perhaps we should check that this is actually opened first?
			res=f_open(&listFIL,"pages.idx",FA_READ| FA_WRITE);	// Ready to write // TODO: check the value of res
			ix=listFIL.fsize;		// This is the address in the file
			res=f_lseek(&listFIL, ix);	// Locate the end of the file
			// Now append the page index
			f_write(&listFIL,&(pageindex.seekptr),4,&charcount);	// 4 byte seek pointer
			f_write(&listFIL,&(pageindex.pagesize),2,&charcount);	// 2 byte file size 			
			// Now restore the file to the previous opened readonly state
			f_close(&listFIL);
		    res=f_open(&listFIL,"pages.idx",FA_READ);			
			// 2: Add the page to the page array. (Or we could rebuild just by doing a restart)
			ix=ix/sizeof(pageindex);
			xprintf(PSTR("New page mag=%d page=%02X --> added at ix=%d\n\r"),page.mag,page.page,ix);
			LinkPage(page.mag, page.page, page.subcode, ix);
			// TODO:
			// 3: Add the page to the node list.  (ditto)
			// TODO:
			firstLine=true;		// and reset ready for the next file
			break; // e
		default:
			str[0]=0;
			returncode=1;
		}
		break; // e commands
	case 'G': /* G - Packet 8/30 format 1 [p830f1]*/
		if (rwmode==CMD_MODE_NONE)
		{
			str[0]=0;
			returncode=1;
			break;
		}
		/* C, L N, T, D */
		switch (Line[3])
		{
		case 'C' : /* Code. 1=format 1 */
			//xputs(PSTR("GUC command not implemented. Why would we need it\n"));
			// It should always default to 0
			/** Where is the initial page done? The code below is wrong */
			//SetInitialPage(pkt830,str1,str2); // nb. Hard coded to 100
			break;
		case 'D' : /* up to 20 characters label*/
			if (rwmode==CMD_MODE_READ)
			{			
				n = ini_gets("p830f1", "label", "VBITFax             ", str, sizearray(str), inifile);			
				xprintf(PSTR("%s"),str);
			}
			if (rwmode==CMD_MODE_WRITE)
			{
				n = ini_puts("p830f1", "label", &Line[4], inifile);	
				SetStatusLabel(pkt830,&Line[4]);
			}			
			break;
		case 'L' : /* Link */
			xputs(PSTR("GUL command\n"));
			/* Alrighty. The MAG is already in the MRAG. All we actually need is 
			ppssss where pp=hex page number and ssss=hex subcode */
			n = ini_gets("p830f1", "initialpage", "003F7F", str, MAXSTR, inifile);
			break;
		case 'N' : /* Net IC  */
			if (rwmode==CMD_MODE_READ)
			{
				n = ini_gets("p830f1", "nic", "fa6f", str, sizearray(str), inifile);			
				xprintf(PSTR("%s"),str);
			}
			if (rwmode==CMD_MODE_WRITE)
			{
				n = ini_puts("p830f1", "nic", &Line[4], inifile);	
				SetNIC1(pkt830,&Line[4]);
			}
			break;
		case 'T' : /* Time */
			xputs(PSTR("GUT command\n"));
			i2c_init();			
			break;
		default:
			str[0]=0;
			returncode=1;	
		}
		break;
	case 'H': // H or HO. Set header
		if (Line[3]=='\0' || Line[5]=='\0') // Don't get confused by checksums
		{
			strcpy_P(str,PSTR("      "));
			strncat(str,g_Header,32);	// Just readback the header. TODO. Get the correct length
			str[40]=0;
		}
		else
		{
			strncpy(g_Header,&Line[9],32); // accept new header
			//g_Header[32]=0;					// Make sure it is capped
			n = ini_puts("service", "header", g_Header, inifile);	// Save this value back to the INI file.
		}
		break;
	case 'I': // III or I2
		// I20xnnmm
		if (Line[2]=='2') // SAA7113 I2C. value. 0xnnmm where nn=address mm=value to write 
		{
			strcpy_P(str,PSTR("Setting SAA7113 I2C register\n"));
			ptr=&Line[3];
			xatoi(&ptr,&n);
			xprintf(PSTR("Blah=%04X\n"),n);
			i2c_SetRegister((n>>8)&0xff,n&0xff);			
			xprintf(PSTR("Done\n"));
		}		
		break;
	case 'J' : // J<h>,DATA - Send a packet to SRAM address
		// Probably want a whole family of J commands.
		// JA<h> - Set the address pointer to SRAM page <h> where <h> is 0..d
		// JW<data> - Write a complete 45 byte packet to the current address and increment
		// JR<data> - Read back the next block of data and increment the pointer.
		// [JT<h> - Retransmit page <h> immediately. (can't work. You must Tx the parent page) ]
		// JT<mpp> - Transmit page <mpp> immediately. (probably need to set a flag in the magazine stream
		// to insert the page in the next transmission slot
		switch (Line[2])
		{
		case 'A': // eg. JA,0   - Set to the start of 
			//xprintf(PSTR("JA set SRAM address (page level)\n"));
			Line[2]='0';Line[3]='x';
			ptr=&Line[2];
			xatoi(&ptr,&n);
			//xprintf(PSTR("JA page=%X SRAMPAGECOUNT=%X SRAMPAGEBASE=%X\n"),n,SRAMPAGECOUNT,SRAMPAGEBASE);
			if (n>=SRAMPAGECOUNT)	// Make sure the page is in range
				returncode=1;					
			else
			{
				n=SRAMPAGEBASE+n*SRAMPAGESIZE;	// This is the actual address
				//xprintf(PSTR("JA address=%04X\n"),n);
				SRAMAddress=n;
				//row=1;
			}
			// We should now fill the packet with some instructions on how to use it!
			// Set the SRAM page address 0..e. There are 14 pages 
			// Coarse address setting
			// For the lulz, JZ gives random access down to byte level
			break;
		case 'Z': // Jay-Z, geddit?, JZ<hex addr 16 bit>
			Line[2]='0';Line[3]='x';
			ptr=&Line[2];
			xatoi(&ptr,&n);
			//xprintf(PSTR("JZ set SRAM address (byte level)\n"));
			//xprintf(PSTR("JZ page=%04X\n"),n);
			// Set the SRAM page address at byte level. Needs an actual 16 bit address
			// where only 15 bits are used.
			// For finer control than the JA command.
			// For the lulz and ability to plonk stuff using random access.
			SRAMAddress=n;
			break;
		case 'W': // JW,<row>,data - Write a packet to the SRAM page buffer
			//xprintf(PSTR("JW Write SRAM data\n"));
			ptr=&Line[3];
			while (*ptr>=' ' && !isdigit(*ptr)) ptr++;	// Seek the row value
			row=atoi(ptr);
			if (!row) // Row address must be greater than 0 					
			{
				returncode=1;	
				break;
			}
			while (isdigit(*ptr) || *ptr==',') ptr++;	// Seek the comma after row
			// If the fifo is transmitting, we must wait here
			for (i=0;FIFOBusy;i++);	// Can this break if the video source has stopped? We may want to timeout on this!
			// xprintf(PSTR("JW addr=%d\n"),row);
			// Write a single packet
			// Not sure how we are going to map control codes but probably the same as OL 
			// Write the packet that we are going to decode into @SRAMAddress
			// TODO: Check the row number to see we don't have a buffer overrun
			// Load and decode the packet

			// Replace this with a section that reads a line of data from USB
			
			// For the first attempt, I'll just copy the rest of the command line
			// I think it is null terminated? Hmm or \r
			// JW,<rest of command line>
			PORTC.OUT&=~VBIT_SEL; // Set the mux to MPU so that we are in control
			for (i=0;i<45;i++)packet[i]=0;
			WritePrefix(packet, 5, row); // This prefix gets replaced later
			packet[3]=row;	// The row gets encoded just before writing to FIFO
			//row++;
			// MRG line format is bit 8 set if it is a control code < ' '
			for (int i=5;i<45 && *ptr && *ptr!='\r';i++)
			{
				packet[i]=*ptr++ & 0x7f;	
			}
			// ** find the address of the row **
			n=SRAMAddress+(row-1)*PACKETSIZE;
			SetSerialRamAddress(SPIRAM_WRITE, n);
			//xprintf(PSTR("JW write address=%04X\n"),n);

			//SRAMAddress+=PACKETSIZE;
			WriteSerialRam(packet,45);
			DeselectSerialRam();
			break;
		case 'R':
			xprintf(PSTR("JR Read back SRAM data\n"));
			// Read back a single packet (translated back into OL format)
			break;
		case 'T':
			xprintf(PSTR("JT Transmit mpp\n"));
			// Set a flag to transmit the selected page ASAP.
			break;
		default:
			returncode=1;
		}
		break;
	case 'L': // L<nn>,<line data>
		// We don't use L in vbit. Because it would require RAM buffering or more file writing,
		// instead we use the e command which writes the file directly.
		xprintf(PSTR("L command not implemented. Use 'e'\n"));
		str[0]=0;
		returncode=1;
		break;
	case 'M': // MD - Delete all the pages selected by the last P command.
		xprintf(PSTR("Delete...\n"));
		// Iterate down all the pages
		// Traverse down subpages and release nodes
		// Go into the pages index and null out the entries in pages.idx
		break;
	case 'O':	/* O - Opt out. Example: O1c*/
		/* Two digit hex number. Only 6 bits are used so the valid range is 0..3f */
			ptr=&Line[0];
			Line[0]='0';Line[1]='x';
			xatoi(&ptr,&n);
			OptRelays=n & 0x3f;
		break;		
	case 'P': // P<mppss>. An invalid character will set null. P without parameters will return the current value
		ptr=&Line[2];
		if (!*ptr)
		{
			sprintf_P(str,PSTR("%s\n\r"),pageFilter);
			break;
		}
		dest=pageFilter;
		for (i=0;i<5;i++)
		{
			ch=*ptr++;
			if (ch=='*')
				valid=1;
			else
			{
				switch (i)
				{
				case 0 : // M
					valid=(ch>'0' && ch<'9' );break;
				case 1 :; // PP
				case 2 :
					valid=((ch>='0' && ch<='9') || (ch>='A' && ch<='F'));break;
				case 3 :; // SS
				case 4 :
					valid=(ch>='0' && ch<='9');break;
				}
			}
			if (valid)
				*dest++ = ch;
			else
			{
				dest[0]=0;
				break;
			}
		}
		*dest=0;	// terminate the string
		// TODO: Find out how many pages are in this page range
		pagecount=FindPageCount();
		if (pagecount<0)
		{
			pagecount=1;
			returncode=8;
			// TODO: At this point we must create the page, as we are about to receive the contents.
			xprintf(PSTR("Page has been created. Please send some data to fill the page\n\r"));
		}
		sprintf_P(str,PSTR("%04d"),pagecount); // Where nnn is the number of pages in this filter. 099 is a filler ack and checksum 
		// str[0]=0;
		break;
	case 'Q' : // QO, QM
		if (Line[2]=='M') // QMnn
		{
			ptr=&Line[3];
			xatoi(&ptr,&n);
			xprintf(PSTR("QM command, n=%d\n"),n);
			n = ini_putl("service", "serialmode", n, inifile);	
			// And at this point put it into the vbi configuration
			// vbi_mode_serial=0 or CTRL_C11_MAGAZINESERIAL_bm
			/** TBA. This setting needs to be in the VBI section
			if (n) 
				vbi_mode_serial=0;
			else
				vbi_mode_serial=CTRL_C11_MAGAZINESERIAL_bm;
			*/
			break;
		}
		// QO sets both odd and even lines
		// QD only sets the odd.
		if (Line[2]=='O' || Line[2]=='D') // QO[18 characters <P|Q|1..8|F>]. QD is the odd line and has 18 lines
		{
			int i;
			char ch;
			ptr=&Line[3];

			xputc('0');
			// Validate it.
			for (i=0;i<18;i++)
			{
				ch=*ptr++;
				switch (ch)
				{
				case '1':;case'2':;case'3':;case'4':;case'5':;case'6':;case'7':;case'8':;case'I':;
				case'F':;
				case'P':;
				case'Q':;
				case'Z':;
					break;
				default:
					returncode=1;
				}
				g_OutputActions[0][i]=ch;		// odd field
				if (Line[2]=='O')
					g_OutputActions[1][i]=ch;	// even field (QO only)
			}
			*ptr=0;
			if (returncode) break;
			n = ini_puts("service", "outputodd", &Line[3], inifile);	
			if (Line[2]=='O')
				n = ini_puts("service", "outputeven", &Line[3], inifile);	// QO only
			break;
		}
		returncode=1;
		break;
	// We could probably use the S command to encapsulate Newfor. We aren't going to be setting the page status much.
	case 'S' : ; // Newfor. This should be a Newfor command. Hmm, but how to escape SO and SI?
		// Work out how to escape data. The parity and reserved characters will break the CI
		break;
	case 'T': // T <hhmmss> (this syntax was superceded by GUT and GUt)
		// testIni();
		// test3();
		// test2();
		// UTC is the time of day in seconds
		Line[8]=0;
		ptr=&(Line[2]);
		UTC=0; // Maybe save this. We need to revert if it fails.
		for (i=2;i<8;i++)
		{
			// First multiply according to which digit
			switch (i)
			{
			case 3:;
			case 5:;
			case 7:
				UTC*=10;break;
			case 4:;
			case 6:
				UTC*=6;break; // (already *10!)
			}
			ch=*(ptr++)-'0';
			UTC+=ch;
		}
		
		// xprintf(PSTR("UTC=%d\n\r"),UTC); // This upsets the protocol!
		
		/**
		UTC=Line[7]-'0';				// s units
		UTC=UTC+(Line[6]-'0')*10;		// s tens
		UTC=UTC+(Line[5]-'0')*60;		// m units
		UTC=UTC+(Line[4]-'0')*60*10;	// m tens
		UTC=UTC+(Line[3]-'0')*60*60;	// h units
		UTC=UTC+(Line[2]-'0')*60*60*10;	// h tens
		*/
		// strcpy_P(str,PSTR("OK\n"));
		str[0]=0;
		break;
	case 'U': // TEST
		Init830F1();
		break;
	case 'V': // Communication settings. 2 hex chars (bit=(on/off) 7=Viewdata/Text 1=CRLF/CR 0=Echo/Silent
		// VBIT seems a bit fussy. When using TED Scheduler it is best to sat V00
		pagecount=sscanf(&(Line[2]),"%2X",&i);
		// xprintf(PSTR("sscanf returns %d. Parameter is %X0\n\r"),pagecount,i);
		if (pagecount>0)
		{
			echoMode=i;		// Yes, it was OK
			// TODO: Save the result in the INI
		}
		else
			returncode=1;	// No, it failed
		break;
	case 'W': // TEST Ad-tec opt outs
		// W14 - Send a mode 14 opt out
		// We want to be able to test various ATP950 modes.
		// read the parameter
		ptr=&Line[2];	
		xatoi(&ptr,&n);
		OptOutMode=n;
		xprintf(PSTR("W=%04X\n"),OptOutMode);
		// Which command? Set the appropriate opt out mode
		switch (OptOutMode)
		{
		case 14:
			xprintf(PSTR("Mode 14 shenanigans\n"),n);
			// Or just flag that we want an opt-out packet
			OptOutMode=14;
			OptOutType=OPTOUT_START;
			// Assemble a mode 14 packet
			break;
		default:
			OptOutMode=0;
			returncode=1;
		}
		// Assemble the packet and 
		break;
	case 'X':	/* X - Exit */
		return 2;	
	case 'Y': /* Y - Version. Y2 should return a date string */
		strcpy_P(str,PSTR("VBIT620 Version 0.04"));
		break;		
	case '?' :; // Status TODO
		xprintf(PSTR("STATUS %02X\n\r"),statusI2C);
		// Want to know if the chips check out and the file system is OK
		// Video Input:
		xprintf(PSTR("Video input: "));report(statusI2C & 0x01); // chip responds, generating field interrupts
		// Digital Encoder
		xprintf(PSTR("Digital encoder: "));report(statusI2C & 0x02); // chip responds
		// FIFO
		statusFIFO=test2();
		xprintf(PSTR("FIFO R/W verified: "));report(statusFIFO); // we can read and write to it
		// File system
		xprintf(PSTR("File system: "));report(statusDisk); // There is a card, it is formatted, it has onair/pages.all
		break;
	default:
		xputs(PSTR("Unknown command\n"));
		returncode=1;
	}
コード例 #11
0
ファイル: vbit.c プロジェクト: BackupGGCode/vbit
void testIni(void)
{
	xputs(PSTR("TestIni\n"));	
  char str[100];
  long n;
  int s, k;
  char section[50];

	xputs(PSTR("Test 1\n"));
  /* string reading */
  n = ini_gets("first", "string", "aap", str, sizearray(str), inifile);
	xprintf(PSTR("n=%d\n"),n);
	xprintf(PSTR("Test 1 str=%s (supposed to say noot)\n"),str);

//  assert(n==4 && strcmp(str,"noot")==0);
  n = ini_gets("second", "string", "aap", str, sizearray(str), inifile);
	xprintf(PSTR("Test 1 str=%s (supposed to say mies)\n"),str);
//  assert(n==4 && strcmp(str,"mies")==0);
  n = ini_gets("first", "dummy", "aap", str, sizearray(str), inifile);
//  assert(n==3 && strcmp(str,"aap")==0);
  xputs(PSTR("1. String reading tests passed\n"));

  /* value reading */
  n = ini_getl("first", "val", -1, inifile);
//  assert(n==1);
  n = ini_getl("second", "val", -1, inifile);
//  assert(n==2);
  n = ini_getl("first", "dummy", -1, inifile);
//  assert(n==-1);
  xputs(PSTR("2. Value reading tests passed\n"));

  /* string writing */
  n = ini_puts("first", "alt", "flagged as \"correct\"", inifile);
//  assert(n==1);
  n = ini_gets("first", "alt", "aap", str, sizearray(str), inifile);
//  assert(n==20 && strcmp(str,"flagged as \"correct\"")==0);
  /* ----- */
  n = ini_puts("second", "alt", "correct", inifile);
//  assert(n==1);
  n = ini_gets("second", "alt", "aap", str, sizearray(str), inifile);
//  assert(n==7 && strcmp(str,"correct")==0);
  /* ----- */
  n = ini_puts("third", "alt", "correct", inifile);
//  assert(n==1);
  n = ini_gets("third", "alt", "aap", str, sizearray(str), inifile);
//  assert(n==7 && strcmp(str,"correct")==0);
  /* ----- */
  xputs(PSTR("3. String writing tests passed\n"));

  /* section/key enumeration */
  for (s = 0; ini_getsection(s, section, sizearray(section), inifile) > 0; s++) {
    xprintf(PSTR("[%s]\n"), section);
    for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) {
      xprintf(PSTR("\t%s\n"), str);
    } /* for */
  } /* for */

  /* string deletion */
  n = ini_puts("first", "alt", NULL, inifile);
//  assert(n==1);
  n = ini_puts("second", "alt", NULL, inifile);
//  assert(n==1);
  n = ini_puts("third", NULL, NULL, inifile);
//  assert(n==1);
  xputs(PSTR("All done\n"));

}
コード例 #12
0
int TestMiniIni(void) {
  char str[100];
  long n;
  int s, k;
  char section[50];

  /* string reading */
  n = ini_gets("first", "string", "dummy", str, sizearray(str), inifile);
  Check(n==4 && UTIL1_strcmp(str,"noot")==0);
  n = ini_gets("second", "string", "dummy", str, sizearray(str), inifile);
  Check(n==4 && UTIL1_strcmp(str,"mies")==0);
  n = ini_gets("first", "undefined", "dummy", str, sizearray(str), inifile);
  Check(n==5 && UTIL1_strcmp(str,"dummy")==0);
  /* ----- */
  n = ini_gets("", "string", "dummy", str, sizearray(str), inifile2);
  Check(n==4 && UTIL1_strcmp(str,"noot")==0);
  n = ini_gets(NULL, "string", "dummy", str, sizearray(str), inifile2);
  Check(n==4 && UTIL1_strcmp(str,"noot")==0);
  /* ----- */
  SHELL_SendString((unsigned char*)"1. String reading tests passed\n");

  /* value reading */
  n = ini_getl("first", "val", -1, inifile);
  Check(n==1);
  n = ini_getl("second", "val", -1, inifile);
  Check(n==2);
  n = ini_getl("first", "undefined", -1, inifile);
  Check(n==-1);
  /* ----- */
  n = ini_getl(NULL, "val", -1, inifile2);
  Check(n==1);
  /* ----- */
  SHELL_SendString((unsigned char*)"2. Value reading tests passed\n");

  /* string writing */
  n = ini_puts("first", "alt", "flagged as \"correct\"", inifile);
  Check(n==1);
  n = ini_gets("first", "alt", "dummy", str, sizearray(str), inifile);
  Check(n==20 && UTIL1_strcmp(str,"flagged as \"correct\"")==0);
  /* ----- */
  n = ini_puts("second", "alt", "correct", inifile);
  Check(n==1);
  n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
  Check(n==7 && UTIL1_strcmp(str,"correct")==0);
  /* ----- */
  n = ini_puts("third", "test", "correct", inifile);
  Check(n==1);
  n = ini_gets("third", "test", "dummy", str, sizearray(str), inifile);
  Check(n==7 && UTIL1_strcmp(str,"correct")==0);
  /* ----- */
  n = ini_puts("second", "alt", "overwrite", inifile);
  Check(n==1);
  n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
  Check(n==9 && UTIL1_strcmp(str,"overwrite")==0);
  /* ----- */
  n = ini_puts(NULL, "alt", "correct", inifile2);
  Check(n==1);
  n = ini_gets(NULL, "alt", "dummy", str, sizearray(str), inifile2);
  Check(n==7 && UTIL1_strcmp(str,"correct")==0);
  /* ----- */
  SHELL_SendString((unsigned char*)"3. String writing tests passed\n");

  /* section/key enumeration */
  SHELL_SendString((unsigned char*)"4. Section/key enumeration, file contents follows\n");
  for (s = 0; ini_getsection(s, section, sizearray(section), inifile) > 0; s++) {
    SHELL_SendString((unsigned char*)"    [");
    SHELL_SendString((unsigned char*)section);
    SHELL_SendString((unsigned char*)"]\r\n");
    for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) {
      SHELL_SendString((unsigned char*)"\t");
      SHELL_SendString((unsigned char*)str);
      SHELL_SendString((unsigned char*)"\r\n");
    } /* for */
  } /* for */

  /* browsing through the file */
  SHELL_SendString((unsigned char*)"5. browse through all settings, file contents follows\n");
  ini_browse(Callback, NULL, inifile);

  /* string deletion */
  n = ini_puts("first", "alt", NULL, inifile);
  Check(n==1);
  n = ini_puts("second", "alt", NULL, inifile);
  Check(n==1);
  n = ini_puts("third", NULL, NULL, inifile);
  Check(n==1);
  /* ----- */
  n = ini_puts(NULL, "alt", NULL, inifile2);
  Check(n==1);
  SHELL_SendString((unsigned char*)"6. String deletion tests passed\n");

  return 0;
}
コード例 #13
0
ファイル: test.c プロジェクト: AaronMR/AaronMR_Robotic_Stack
int main(void)
{
  char str[100];
  long n;
  int s, k;
  char section[50];

  /* string reading */
  n = ini_gets("first", "string", "aap", str, sizearray(str), inifile);
  assert(n==4 && strcmp(str,"noot")==0);
  n = ini_gets("second", "string", "aap", str, sizearray(str), inifile);
  assert(n==4 && strcmp(str,"mies")==0);
  n = ini_gets("first", "dummy", "aap", str, sizearray(str), inifile);
  assert(n==3 && strcmp(str,"aap")==0);
  printf("1. String reading tests passed\n");

  /* value reading */
  n = ini_getl("first", "val", -1, inifile);
  assert(n==1);
  n = ini_getl("second", "val", -1, inifile);
  assert(n==2);
  n = ini_getl("first", "dummy", -1, inifile);
  assert(n==-1);
  printf("2. Value reading tests passed\n");

  /* string writing */
  n = ini_puts("first", "alt", "flagged as \"correct\"", inifile);
  assert(n==1);
  n = ini_gets("first", "alt", "aap", str, sizearray(str), inifile);
  assert(n==20 && strcmp(str,"flagged as \"correct\"")==0);
  /* ----- */
  n = ini_puts("second", "alt", "correct", inifile);
  assert(n==1);
  n = ini_gets("second", "alt", "aap", str, sizearray(str), inifile);
  assert(n==7 && strcmp(str,"correct")==0);
  /* ----- */
  n = ini_puts("third", "alt", "correct", inifile);
  assert(n==1);
  n = ini_gets("third", "alt", "aap", str, sizearray(str), inifile);
  assert(n==7 && strcmp(str,"correct")==0);
  /* ----- */
  printf("3. String writing tests passed\n");

  /* section/key enumeration */
  for (s = 0; ini_getsection(s, section, sizearray(section), inifile) > 0; s++) {
    printf("[%s]\n", section);
    for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) {
      printf("\t%s\n", str);
    } /* for */
  } /* for */

  /* string deletion */
  n = ini_puts("first", "alt", NULL, inifile);
  assert(n==1);
  n = ini_puts("second", "alt", NULL, inifile);
  assert(n==1);
  n = ini_puts("third", NULL, NULL, inifile);
  assert(n==1);

  return 0;
}
コード例 #14
0
ファイル: fanuc_adapter.cpp プロジェクト: princearora/adapter
void FanucAdapter::configMacrosAndPMC(const char *aIniFile)
{
  // Read adapter configuration
  mPort = ini_getl("adapter", "port",  mPort, aIniFile);
  ini_gets("adapter", "service", "MTConnect Fanuc Adapter", mName,
           SERVICE_NAME_LEN, aIniFile);

  ini_gets("focus", "host", mDeviceIP, mDeviceIP, MAX_HOST_LEN, aIniFile);
  mDevicePort = ini_getl("focus", "port", mDevicePort, aIniFile);

  // Read adapter.ini to get additional macro variables and
  // PMC registers
  char name[100];
  int idx;
  const static char *sDigits = "0123456789";

  mMacroMin = 99999;
  mMacroMax = 0;
          
  // First look for macro variables
  for (idx = 0;
       ini_getkey("macros", idx, name, sizeof(name), aIniFile) > 0 &&
             idx < MAX_MACROS;
       idx++)
  {
    char numbers[256];
    ini_gets("macros", name, "", numbers, 256, aIniFile);
    if (numbers[0] == '[')
    {
      // We have a path macro.
      int x, y, z;
      char *cp = numbers + 1, *n;
      x = strtol(cp, &n, 10);
      if (cp == n)
        continue;
      cp = n;
      y = strtol(cp, &n, 10);
      if (cp == n)
        continue;
      cp = n;
      z = strtol(cp, &n, 10);
      if (cp == n)
        continue;
      
      int i = mMacroPathCount++;
      mMacroPath[i] = new MacroPathPosition(name, x, y, z);
      addDatum(*mMacroPath[i]);

      printf("Adding path macro '%s' at location %d %d %d\n", name, x, y, z);

      if (x > mMacroMax) mMacroMax = x;
      if (x < mMacroMin) mMacroMin = x;
      if (y > mMacroMax) mMacroMax = y;
      if (y < mMacroMin) mMacroMin = y;
      if (z > mMacroMax) mMacroMax = z;
      if (z < mMacroMin) mMacroMin = z;
    }
    else
    {
      char *cp = numbers, *n;
      long v = strtol(cp, &n, 10);
      if (cp == n)
        continue;
      int i = mMacroSampleCount++;
      mMacroSample[i] = new MacroSample(name, v);
      addDatum(*mMacroSample[i]);

      printf("Adding sample macro '%s' at location %d\n", name, v);
      
      if (v > mMacroMax) mMacroMax = v;
      if (v < mMacroMin) mMacroMin = v;
    }
    
    
  }

  for (idx = 0;
       ini_getkey("pmc", idx, name, sizeof(name), aIniFile) > 0 &&
             idx < MAX_PMC;
       idx++)
  {
    long v = ini_getl("pmc", name, 0, aIniFile);
    mPMCVariable[idx] = new IntEvent(name);
    mPMCAddress[idx] = v;

    addDatum(*mPMCVariable[idx]);

    printf("Adding pmc '%s' at location %d\n", name, v);
  }
  mPMCCount = idx;
}