コード例 #1
0
ファイル: tracker.c プロジェクト: cvansas/pits
int main(void)
{
	int fd, ReturnCode, i;
	unsigned long Sentence_Counter = 0;
	int ImagePacketCount, MaxImagePackets;
	char Sentence[100], Command[100];
	struct stat st = {0};
	struct TGPS GPS;
	pthread_t PredictionThread, LoRaThread, APRSThread, GPSThread, DS18B20Thread, ADCThread, CameraThread, BMP085Thread, BME280Thread, LEDThread, LogThread;
	
	if (prog_count("tracker") > 1)
	{
		printf("\nThe tracker program is already running!\n");
		printf("It is started automatically, with the camera script, when the Pi boots.\n\n");
		printf("If you just want the tracker software to run, it already is,\n");
		printf("and its output can be viewed on a monitor attached to a Pi video socket.\n\n");
		printf("If instead you want to view the tracker output via ssh,\n");
		printf("then you should first stop it by typing the following command:\n");
		printf("	sudo killall tracker\n\n");
		printf("and then restart manually with\n");
		printf("	sudo ./tracker\n\n");
		exit(1);
	}
	
	printf("\n\nRASPBERRY PI-IN-THE-SKY FLIGHT COMPUTER\n");
	printf(    "=======================================\n\n");

	Config.BoardType = GetBoardType();

	if (Config.BoardType)
	{
		if (Config.BoardType == 3)
		{
			printf("RPi Zero\n");
			printf("PITS Zero Board\n");
		}
		else
		{
			if (Config.BoardType == 2)
			{
				printf("RPi 2 B\n");
			}
			else
			{
				printf("RPi Model A+ or B+\n");
			}
			printf("PITS+ Board\n");
		}
				
		Config.LED_OK = 25;
		Config.LED_Warn = 24;
		
		Config.SDA = 2;
		Config.SCL = 3;
	}
	else
	{
		printf("RPi Model A or B\n");
		printf("PITS Board\n");

		Config.LED_OK = 11;
		Config.LED_Warn = 4;
		
		Config.SDA = 5;
		Config.SCL = 6;
	}
	
	printf("Device Tree is %s\n\n", devicetree() ? "enabled" : "disabled");

	LoadConfigFile(&Config);

	if (Config.DisableMonitor)
	{
		system("/opt/vc/bin/tvservice -off");
	}
	
	if (FileExists("/boot/clear.txt"))
	{
		// remove SSDV and other camera images, plus log files

		printf("Removing existing photo files\n");
		remove("gps.txt");
		remove("telemetry.txt");
		remove("/boot/clear.txt");
		system("rm -rf /home/pi/pits/tracker/images/*");
	}
		
	// Remove any old SSDV files
	system("rm -f ssdv*.bin");

	GPS.SecondsInDay = 0;
	GPS.Hours = 0;
	GPS.Minutes = 0;
	GPS.Seconds = 0;
	GPS.Longitude = 0.0;
	GPS.Latitude = 0.0;
	GPS.Altitude = 0;
	GPS.Satellites = 0;
	GPS.Speed = 0.0;
	GPS.Direction = 0.0;
	GPS.DS18B20Temperature[0] = 0.0;
	GPS.DS18B20Temperature[1] = 0.0;
	GPS.BatteryVoltage = 0.0;
	GPS.BMP180Temperature = 0.0;
	GPS.Pressure = 0.0;
	GPS.MaximumAltitude = 0.0;
	GPS.DS18B20Count = 0;

	
	// Set up I/O
	if (wiringPiSetup() == -1)
	{
		exit (1);
	}

	// Switch off the radio till it's configured
	pinMode (NTX2B_ENABLE, OUTPUT);
	digitalWrite (NTX2B_ENABLE, 0);
		
	// Switch on the GPS
	if (Config.BoardType == 0)
	{
		// Only PITS board had this, not PITS+
		pinMode (UBLOX_ENABLE, OUTPUT);
		digitalWrite (UBLOX_ENABLE, 0);
	}

	if (!Config.DisableRTTY)
	{
		if (*Config.Frequency)
		{
			SetFrequency(Config.Frequency);
		}
	
		fd = OpenSerialPort();

		digitalWrite (NTX2B_ENABLE, 1);
	}
	
	// Set up DS18B20
	system("sudo modprobe w1-gpio");
	system("sudo modprobe w1-therm");
	
	if (!devicetree())
	{
		// SPI for ADC (older boards), LoRa add-on board
		system("gpio load spi");
	}

	// SSDV Folders
	sprintf(Config.Channels[0].SSDVFolder, "%s/RTTY", SSDVFolder);
	*Config.Channels[1].SSDVFolder = '\0';										// No folder for APRS images
	sprintf(Config.Channels[2].SSDVFolder, "%s/LORA0", SSDVFolder);
	sprintf(Config.Channels[3].SSDVFolder, "%s/LORA1", SSDVFolder);
	sprintf(Config.Channels[4].SSDVFolder, "%s/FULL", SSDVFolder);
		
	if (Config.Camera)
	{
		// Create SSDV Folders
		if (stat(SSDVFolder, &st) == -1)
		{
			mkdir(SSDVFolder, 0777);
		}	
	
		for (i=0; i<5; i++)
		{
			if (*Config.Channels[i].SSDVFolder)
			{
				if (stat(Config.Channels[i].SSDVFolder, &st) == -1)
				{
					mkdir(Config.Channels[i].SSDVFolder, 0777);
				}
			}
		}

		// Filenames for SSDV
		for (i=0; i<5; i++)
		{
			sprintf(Config.Channels[i].take_pic, "take_pic_%d", i);
			// sprintf(Config.Channels[i].current_ssdv, "ssdv_%d.bin", i);
			// sprintf(Config.Channels[i].next_ssdv, "ssdv_%d.nxt", i);
			sprintf(Config.Channels[i].convert_file, "convert_%d", i);
			sprintf(Config.Channels[i].ssdv_done, "ssdv_done_%d", i);
			
			Config.Channels[i].SSDVImageNumber = -1;
			Config.Channels[i].SSDVPacketNumber = -1;
			
			Config.Channels[i].ImageFP = NULL;
		}
	}
	
	if (pthread_create(&GPSThread, NULL, GPSLoop, &GPS))
	{
		fprintf(stderr, "Error creating GPS thread\n");
		return 1;
	}

	if (*(Config.APRS_Callsign) && Config.APRS_ID && Config.APRS_Period)
	{
		if (pthread_create(&APRSThread, NULL, APRSLoop, &GPS))
		{
			fprintf(stderr, "Error creating APRS thread\n");
			return 1;
		}
	}
	
	if (Config.LoRaDevices[0].InUse || Config.LoRaDevices[1].InUse)
	{
		if (pthread_create(&LoRaThread, NULL, LoRaLoop, &GPS))
		{
			fprintf(stderr, "Error creating LoRa thread\n");
		}
	}
	
	if (pthread_create(&DS18B20Thread, NULL, DS18B20Loop, &GPS))
	{
		fprintf(stderr, "Error creating DS18B20s thread\n");
		return 1;
	}

	if (Config.BoardType != 3)
	{
		// Not a zero, so should have ADC on it
		if (I2CADCExists())
		{
			printf ("V2.4 or later board with I2C ADC\n");
			
			if (pthread_create(&ADCThread, NULL, I2CADCLoop, &GPS))
			{
				fprintf(stderr, "Error creating ADC thread\n");
				return 1;
			}
		}
		else
		{
			printf ("Older board with SPI ADC\n");
			
			if (pthread_create(&ADCThread, NULL, ADCLoop, &GPS))
			{
				fprintf(stderr, "Error creating ADC thread\n");
				return 1;
			}
		}
	}

	if (Config.Camera)
	{
		if (pthread_create(&CameraThread, NULL, CameraLoop, &GPS))
		{
			fprintf(stderr, "Error creating camera thread\n");
			return 1;
		}
	}

	if (pthread_create(&LEDThread, NULL, LEDLoop, &GPS))
	{
		fprintf(stderr, "Error creating LED thread\n");
		return 1;
	}

	if (Config.TelemetryFileUpdate > 0)
	{
		if (pthread_create(&LogThread, NULL, LogLoop, &GPS))
		{
			fprintf(stderr, "Error creating Log thread\n");
			return 1;
		}
	}
	
	if (Config.EnableBMP085)
	{
		if (pthread_create(&BMP085Thread, NULL, BMP085Loop, &GPS))
		{
			fprintf(stderr, "Error creating BMP085 thread\n");
			return 1;
		}
	}

	if (Config.EnableBME280)
	{
		if (pthread_create(&BME280Thread, NULL, BME280Loop, &GPS))
		{
			fprintf(stderr, "Error creating BME280 thread\n");
			return 1;
		}
	}

	if (Config.EnableLandingPrediction)
	{
		if (pthread_create(&PredictionThread, NULL, PredictionLoop, &GPS))
		{
			fprintf(stderr, "Error creating prediction thread\n");
		}
	}	
	
	if (!Config.DisableRTTY)
	{
		if (Config.InfoMessageCount < 0)
		{
			// Default number depends on baud rate
			Config.InfoMessageCount = (Config.TxSpeed < B300) ? 2 : 4;
		}
	
		for (i=0; i<Config.InfoMessageCount; i++)
		{
			SendIPAddress(fd);
			SendFreeSpace(fd);
		}
	}

	ImagePacketCount = 0;
	
	while (1)
	{
		static int CarrierOn=1;
		
		if (Config.DisableRTTY)
		{
			delayMilliseconds (200);
		}
		else if (LoRaUploadNow(&GPS, 10))
		{
			if (CarrierOn)
			{
				digitalWrite (NTX2B_ENABLE, 0);
				CarrierOn = 0;
				printf("Switching RTTY carrier off\n");
			}
			delayMilliseconds (200);
		}
		else
		{
			if (!CarrierOn)
			{
				digitalWrite (NTX2B_ENABLE, 1);
				printf("Switching RTTY carrier on\n");
				CarrierOn = 1;
			}
			
			MaxImagePackets = (GPS.Altitude > Config.SSDVHigh) ? Config.Channels[RTTY_CHANNEL].ImagePackets : 1;
			
			if (ImagePacketCount++ < MaxImagePackets)
			{
				SendRTTYImage(fd);
			}
			else
			{
				ImagePacketCount = 0;
				
				BuildSentence(Sentence, ++Sentence_Counter, &GPS);
			
				SendSentence(fd, Sentence);
			}
		}
	}
}
コード例 #2
0
ファイル: StepGenerator.cpp プロジェクト: ifplusor/sixgo
/**
 * MakeStepListForDefendDoubleEx - 防御双威胁等着法扩展生成器,用于扩展搜索
 * @myInfo:		执棋方当前局面综合信息
 * @denInfo:	对方当前局面综合信息
 * @limit:		生成着法的数量限制
 * @return:		返回着法列表
 */
vector<Step> MakeStepListForDefendDoubleEx(int side, unsigned int limit)
{
	int unside = 1 - side;
	SynInfo denInfo = GetBoardInfo(unside, TODEFENT);
	SynInfo tempMy, tempDen;//临时局面信息储存
	LineInfo tempLine[2][4], tempLine2[2][4];//临时线信息备份
	Step tempStep;
	vector<Step> stepList;//招法列表
	vector<Point> pointList;//点列表
	vector<Point>::iterator iterP, iterP2;
	vector<Step>::iterator iterS;
	int denType = GetBoardType(unside);

	if (denType >= 20)//对方存在多威胁线型或已胜线型,或存在两个以上双威胁线型,本方必败直接返回空招法列表
	{
		return stepList;
	}
	else if (denType == 10)//此局面只存在一个双威胁线型,故只将破解步作为备选招法加入招法列表
	{
		for (iterS = denInfo.defStepList.begin(); iterS != denInfo.defStepList.end(); iterS++)
			stepList.push_back(*iterS);
		//UniqueStep(stepList);
		for (iterS = stepList.begin(); iterS != stepList.end(); iterS++)
			iterS->value = CalculateStepValue(*iterS, side);
		sort(stepList.begin(), stepList.end(), cmpStepValue);
		return stepList;
	}
	else//含有单威胁线型的棋局,多个单威胁(可能存在伪双),一个双威胁加单威胁(可能存在伪多)
	{
		if (denType > 10 && denType < 20)//存在一个双威胁线型,同时存在单威胁线型(可能存在伪多威胁)
		{
			for (iterS = denInfo.defStepList.begin(); iterS != denInfo.defStepList.end(); iterS++)//以双威胁线型为主要成分,若可破解必使用双威胁线型的破解步
			{
				MakeMove(iterS->first, tempLine, side, 0);//查看是否可以破解威胁,只要求线的类型,故不用收集更新的点信息
				MakeMove(iterS->second, tempLine2, side, 0);
				if (GetBoardType(unside) == 0)//判断是否破解成功,可能因为THREAT_four_ADDITION的额外破解法当成双威胁
					stepList.push_back(*iterS);
				BackMove(iterS->second, tempLine2, side);
				BackMove(iterS->first, tempLine, side);
			}
			if (stepList.size() > 0)//可破解
			{
				UniqueStep(stepList);
				for (iterS = stepList.begin(); iterS != stepList.end(); iterS++)
					iterS->value = CalculateStepValue(*iterS, side);
				sort(stepList.begin(), stepList.end(), cmpStepValue);
			}
			return stepList;//包含不可破解局面,若不可破解返回空招法列表
		}
		else//只存在多个单威胁线型(可能存在伪双)
		{
			for (iterP = denInfo.defPointList.begin(); iterP != denInfo.defPointList.end(); iterP++)
			{
				tempStep.first = *iterP;
				MakeMove(tempStep.first, tempLine, side, TODUOTHREAT + TOSOLTHREAT);
				//一子试走后进行二次分析,这样可避免针对伪双威胁的招法的第二子出现单子破解状态,从而使第一子无用
				if (GetBoardType(unside) == 0)//一子破解,伪双威胁,按单威胁方案生成;根据无侥幸行棋逻辑,不存在可单子破解的三子以上威胁
				{
					tempMy = GetBoardInfo(side, TODUOTHREAT + TOSOLTHREAT);
					//将本方<双威胁点,单威胁点>
					for (iterP2 = tempMy.duoThreatList.begin(); iterP2 != tempMy.duoThreatList.end(); iterP2++)
						pointList.push_back(*iterP2);
					for (iterP2 = tempMy.solThreatList.begin(); iterP2 != tempMy.solThreatList.end(); iterP2++)
						pointList.push_back(*iterP2);
					//					UniquePoint(pointList);
					for (iterP2 = pointList.begin(); iterP2 != pointList.end(); iterP2++)
					{
						tempStep.second = *iterP2;
						stepList.push_back(tempStep);
					}
					pointList.clear();
				}
				else//两子破解,包括伪双威胁
				{
					tempDen = GetBoardInfo(unside, 2);
					for (iterP2 = tempDen.defPointList.begin(); iterP2 != tempDen.defPointList.end(); iterP2++)
					{
						MakeMove(*iterP2, tempLine2, side, 0);
						if (GetBoardType(unside) == 0)//判断是否破解成功
						{
							tempStep.second = *iterP2;
							stepList.push_back(tempStep);
						}
						BackMove(*iterP2, tempLine2, side);
					}
				}
				BackMove(tempStep.first, tempLine, side);
			}
			if (stepList.size() > 0)//可破解
			{
				UniqueStep(stepList);
				for (iterS = stepList.begin(); iterS != stepList.end(); iterS++)
					iterS->value = CalculateStepValue(*iterS, side);
				sort(stepList.begin(), stepList.end(), cmpStepValue);
				if (stepList.size() > limit)
					stepList.resize(limit);
			}
			return stepList;//包含不可破解局面,若不可破解返回空招法列表
		}
	}
}