Esempio n. 1
0
int main(int argc, char *argv[])
{
	gLogInit("NOTICE");

	LOG(ERROR) << " testing the logger.";
	LOG(WARN) << " testing the logger.";
	LOG(NOTICE) << " testing the logger.";
	LOG(INFO) << " testing the logger.";
	LOG(DEBUG) << " testing the logger.";
	LOG(DEEPDEBUG) << " testing the logger.";
    std::cout << "\n\n\n";
    std::cout << "testing Alarms - you should run apps/showalarms.py to check udp\n";
	LOG(ALARM) << " testing the logger alarm.";
    std::cout << "you should see one line:" << std::endl;
    printAlarms();
    std::cout << "----------- generating 20 alarms ----------" << std::endl;
    for (int i = 0 ; i < 20 ; ++i) {
        LOG(ALARM) << i;
    }
    std::cout << "you should see ten line with the numbers 10..19:" << std::endl;
    printAlarms();
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	int argCounter = 1;
	FILE *fp;
	int length;
	fp = fopen(file, "r");
	
	if(fp == NULL)
	{
		printf("Datei konnte nicht geoeffnet werden.\n");
		return 1;
	}
	fscanf(fp, "%d\n", &length);
	struct alarm alarms[length];

	for(int i=0; i< length; i++) 
	{
		fscanf(fp, formart, &alarms[i].ringTime, &alarms[i].weekdays, &alarms[i].on);
	}	
	fclose(fp);
	
	printAlarms(alarms,length);

	int mode = 0;
	if(argc > argCounter)
		mode=atoi(argv[argCounter++]);
	else
	{
		printf("\n1\tnew\n2\tremove\n3\tset on\nmode\t: ");
		scanf("%i",&mode);
	}
	switch(mode) {
		case 1: // New
			{
				int lengthNew = length + 1;
				struct alarm alarmsNew[lengthNew];
				for (int i = 0; i < length; ++i)
				{
					alarmsNew[i] = alarms[i];
				}
				struct alarm alarmNew = readIn();

				int h, min, sec;

				if(argc > argCounter)
					h=atoi(argv[argCounter++]);
				else
				{
					printf("h \t: ");
					scanf("%i",&h);
				}

				if(argc > argCounter)
					min=atoi(argv[argCounter++]);
				else
				{
					printf("min \t: ");
					scanf("%i",&min);
				}

				if(argc > argCounter)
					sec=atoi(argv[argCounter++]);
				else
				{
					printf("sec \t: ");
					scanf("%i",&sec);
				}

				alarmNew.ringTime = makeTime(h,min,sec);
				alarmNew.weekdays = 0;
				int answer = 0;
				for (int i = 0; i < 7; ++i)
				{
					if(argc > argCounter)
						answer=atoi(argv[argCounter++]);
					else
					{
						printf("%s \t: ", dayNames[i]);
						scanf("%i",&answer);
					}
					if(answer)
					{
						alarmNew.weekdays |= 1 << i;
					}
				}

				if(argc > argCounter)
					alarmNew.on=atoi(argv[argCounter++]);
				else
				{
					printf("on \t: ");
					scanf("%i",&alarmNew.on);
				}

				alarmsNew[lengthNew -1] = alarmNew;

				printAlarms(alarmsNew,lengthNew);
				save(alarmsNew,lengthNew);
			}
			break;
		case 2: // rm 
			{
				int index = 0;
				if(argc > argCounter)
					index=atoi(argv[argCounter++]);
				else
				{
					printf("index\t: ");
					scanf("%i",&index);
				}
				

				int lengthNew = length - 1;
				struct alarm alarmsNew[lengthNew];
				for (int i = 0; i < length; ++i)
				{
					alarmsNew[i] = alarms[i + (i >= index ? 1 : 0)];
				}

				printAlarms(alarmsNew,lengthNew);
				save(alarmsNew,lengthNew);
			}
			break;
		case 3: // set state 
			{
				int index = 0;
				if(argc > argCounter)
					index=atoi(argv[argCounter++]);
				else
				{
					printf("index\t: ");
					scanf("%i",&index);
				}

				if(argc > argCounter)
					alarms[index].on=atoi(argv[argCounter++]);
				else
				{
					printf("on \t: ");
					scanf("%i",&alarms[index].on);
				}

				printAlarms(alarms,length);
				save(alarms,length);
			}
			break;
	}
	return 0;
}