⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 signalpopup.c

📁 dgstation relook 400 sample code to run shared plugin process in background.
💻 C
字号:
///* Signal Popup for Relook400                          *////* Charles Putney                                                  *////* 18 Quinns Road                                                  *////* Shankill, Co. Dublin                                            *////* IRELAND                                                         *////*                                                                 *////* Change History                                                  *////*                                                                 *////* 24-01-2008 Start - this is free software///* 25-01-2008 Released to www.denktenk.com                                                   *////*  1-2-2008  Changed dB lookup for stv0299///*            Added turn off timer///*            Moved overlay so channel menu visible///*            Released to www.denktenk.com#include "linux/input.h"#include "sys/time.h"#include "/home/charlie/bin/Relook_Source_Revision_700/relook400/relook_src/include/timer.h"#include "/home/charlie/bin/Relook_Source_Revision_700/relook400/relook_src/include/mainmenu.h"#include "sys/types.h"#include "sys/stat.h"#include "/home/charlie/bin/Relook_Source_Revision_700/relook400/relook_src/include/directory.h"#include "stdio.h"#include "fcntl.h"#include "math.h"#include "/home/charlie/bin/Relook_Source_Revision_700/relook400/relook_src/include/text.h"#include "/home/charlie/bin/Relook_Source_Revision_700/relook400/relook_src/include/textbox.h"#include "/home/charlie/bin/Relook_Source_Revision_700/relook400/relook_src/include/simgr_tuner.h"#include "string.h"#include "pthread.h"#include "simgr_tuner.h"#include "unistd.h"#include "stv0299.h"#include "popup.h"#include "event.h"#include "time.h"extern int get_tuner_cn_stv0288(int);extern int get_tuner_ber_stv0288(int);extern int init_stv0288(int);extern void clearScreen( void );/// function declarationsstatic int stv0299_getTunerCN(int fd);  /// this is the DGS routinestatic int Display_Signal();/// Global variablesint Debug = 0;int telnet_fd, Tuner1_fd, Tuner2_fd;char msg[80];int timeout;char msg1[60], msg2[60], msg3[60],msg4[60];int child_pid;int plugin_msg_init( void ){	if (Debug)	{		telnet_fd = open("/dev/pts/0",O_WRONLY); 		if (telnet_fd < 0) telnet_fd = open("/dev/pts/1",O_WRONLY); 		if (telnet_fd < 0) telnet_fd = open("/dev/pts/2",O_WRONLY); 		if (telnet_fd < 0) telnet_fd = open("/dev/pts/3",O_WRONLY); 		sprintf(msg,"***** Starting Signal Popup *****\n"); write(telnet_fd,msg,strlen(msg));	}	timeout = 5;	return 0;}int plugin_msg_handler( int type, int code, int value ){		sprintf(msg1,"*** Signal Strength Popup Plugin ***");	strcpy(msg2,"");	sprintf(msg3,"Kill plugin after %d minutes",timeout);	sprintf(msg4,"Use arrow keys to change, OK to start");	InitNMsgBox (0, 0, 0, -1, 100, msg1, msg2, msg3, msg4, NULL, NULL,0, MSGBOX_MODE_TEMP);	if (value == 0) return 0;// do the actions when we press the remote, not release!  Without this we see double key	switch( code )	{		case KEY_MENU:		case KEY_BACK:			return -1; // Leave the plugin		case KEY_OK:			Display_Signal();			return -1; // Kill the parent process (if it comes back here ?)		case KEY_UP:		case KEY_RIGHT:			timeout++;			if (timeout > 30) timeout = 30;		break;		case KEY_DOWN:		case KEY_LEFT:			timeout--;			if (timeout < 1) timeout = 1;		break;	}	return 0; // leave }void plugin_msg_cleanup( void ){}static int Display_Signal(){	int child_pid;	int current_time, timeout_time;	int BER1, BER2, C_N1, C_N2;	int TunerType=0; // 0 = stv0299, 1 = stv0288	int TwoTuners=0; // 0 = 1 Tuner, 1 = two tuners	int ret;	// try to confuse the compiler and plugin loader so we don't have undefined references	int (*stv0288_CN) (int);	int (*stv0288_BER) (int);	int (*stv0288_Init) (int);	stv0288_CN = get_tuner_cn_stv0288;	stv0288_BER = get_tuner_ber_stv0288;	stv0288_Init = init_stv0288;	current_time=system_timer_tick();	timeout_time = 102*timeout+current_time; //  ticks per second - checked with debug statements	if (Debug) {sprintf(msg,"currrent_time = %d   timeout_time = %d\n",current_time, timeout_time); write(telnet_fd,msg,strlen(msg));}	child_pid = fork();	switch(child_pid)	{ 		case -1: // can't fork for some reason 		if (Debug) {sprintf(msg,"Cannot fork for some reason !\n"); write(telnet_fd,msg,strlen(msg));} 		return 0;		case 0: /* we're at child process. */		goto display;		default: /* we're at parent process. */		if (Debug) {sprintf(msg,"Successfully forked child process.  PID = %d  Exiting main process.\n", child_pid); write(telnet_fd,msg,strlen(msg));} 		return 0;	}display: child_pid = getpid();	current_time=system_timer_tick();	timeout_time = 102*60*timeout+current_time; //  ticks per second - checked with debug statements	if (Debug) {sprintf(msg,"currrent_time = %d   timeout_time = %d   child_pid = %d\n",current_time, timeout_time, child_pid); write(telnet_fd,msg,strlen(msg));}		Tuner1_fd = open( "/dev/stv0299-0", O_RDWR ); // Open the tuner     	if( Tuner1_fd < 0 )        {		/// must have tuner stv0288 		if (Debug) {sprintf(msg,"Tuner 1 initialisation failed. /dev/stv0299-0\n"); write(telnet_fd,msg,strlen(msg));}        	goto stv0288;        }	Tuner2_fd = open( "/dev/stv0299-1", O_RDWR ); // Open the tuner     	if( Tuner2_fd < 0 )        { 		/// must be a mutant		if (Debug) {sprintf(msg,"Tuner 2 initialisation failed. /dev/stv0299-1\n"); write(telnet_fd,msg,strlen(msg));}		TunerType=0; TwoTuners=0;        }	TunerType=0; TwoTuners=1;	goto start;stv0288:	Tuner1_fd = 0;  // stv288 tuner fd are 0 and 1	ret = stv0288_Init(Tuner1_fd);	if (ret < 0)	{		if (Debug) {sprintf(msg,"Tuner 1 not an stv0299 and did not initialise as stv0288 !!!\n"); write(telnet_fd,msg,strlen(msg));}		return -1;	}	TunerType=1; TwoTuners=1;	Tuner2_fd=1;	ret = stv0288_Init(Tuner2_fd);	if (ret < 0)	{		if (Debug) {sprintf(msg,"Tuner 2 not installed - must be a mutant\n"); write(telnet_fd,msg,strlen(msg));}		TwoTuners=0;	}	start:  while (1)  /// loop forever	{		if (TunerType == 0)		{			ioctl(Tuner1_fd, STV0299_GET_ERR_COUNT, &BER1); // Get BER for Tuner1			C_N1 = stv0299_getTunerCN(Tuner1_fd); // Get CN for Tuner1			sprintf(msg1, "Tuner 1 CN: %3.1f dB",(float)C_N1/1000);			sprintf(msg2, "Tuner 1 BER: %d X 10 -6\n",BER1);			if (TwoTuners == 1)			{				ioctl(Tuner2_fd, STV0299_GET_ERR_COUNT, &BER2); // Get BER for Tuner2				C_N2 = stv0299_getTunerCN(Tuner2_fd); // Get CN for Tuner2				sprintf(msg3, "Tuner 2 CN: %3.1f dB",(float)C_N2/1000);				sprintf(msg4, "Tuner 2 BER: %d X 10 -6\n",BER2);			}			else			{				strcpy(msg3,"");				strcpy(msg4,"");			}		}		else		{			C_N1 = stv0288_CN(Tuner1_fd);			BER1 = stv0288_BER(Tuner1_fd);			sprintf(msg1, "Tuner 1 CN: %3.1f dB",(float)C_N1/1000);			sprintf(msg2, "Tuner 1 BER: %d X 10 -6\n",BER1);			if (TwoTuners == 1)			{				C_N2 = stv0288_CN(Tuner2_fd);				BER2 = stv0288_BER(Tuner2_fd);				sprintf(msg3, "Tuner 2 CN: %3.1f dB",(float)C_N2/1000);				sprintf(msg4, "Tuner 2 BER: %d X 10 -6\n",BER2);			}			else			{				strcpy(msg3,"");				strcpy(msg4,"");			}		}			InitNMsgBox (0, 0, 0, -1, 100, msg1, msg2, msg3, msg4, NULL, NULL,0, MSGBOX_MODE_TEMP);			current_time = system_timer_tick();			if (current_time > timeout_time)			{				clearScreen(); // wait until it disappears (hopefully)				sprintf(msg1,"kill -9 %d",child_pid);				if (Debug) {sprintf(msg,"kill -9 %d\n",child_pid); write(telnet_fd,msg,strlen(msg));}				system(msg1); // bye bye			}			if (Debug) {sprintf(msg,"current_time = %d, timeout_time = %d\n", current_time, timeout_time); write(telnet_fd,msg,strlen(msg));}			sleep(1);	}}static int stv0299_getTunerCN(int fd)  /// this is the DGS routine{/// This is for the C/N lookup ------------------------#define MAXLOOKUPSIZE 50#define INRANGE(X,Y,Z) (((X<=Y) && (Y<=Z))||((Z<=Y) && (Y<=X)) ? 1 : 0)typedef struct{	int realval;		/*	real value (1000 x C/N or power )	*/	int regval;		/*	register value (C/N estimator value or AGC1 integrator value )	*/} LOOKPOINT;/*	Lookup table definition	*/typedef struct{	int size;			/*	Size of the lookup table	*/	LOOKPOINT table[MAXLOOKUPSIZE];	/*	Lookup table	*/} LOOKUP;/// changed lookup table to direct lookup and fixed lower limit to 1.0 dBLOOKUP lookup ={ 38,  {{500,15000},{700,14000},{900,12500},{2100, 10000},{2400, 9600},{2700, 9450},{3375, 9260},{4050, 9000},{4725, 8760},{5400, 8520},	{6075, 8250},{6750, 7970},{7425, 7690},{8100, 7360},{8775, 7080},{9450, 6770},{10125, 6470},{10800, 6200},{11475, 5900},{12150, 5670},	{12825, 5420},{13500, 5190},{14175, 4960},{14850, 4740},{15525, 4550},{16200, 4360},{16875, 4170},{17550, 4010},{18225, 3860},{18900, 3710},	{19575, 3580},{20250, 3440},{20925, 3320},{21600, 3210},{22950, 3020},{24300, 2860},{25650, 2700},{27000, 2600},{0,0}}};/// -------------------------------------------------	int regval;	int c_n;	int i;	int Imin, Imax;	ioctl(fd, STV0299_GET_CN, &regval);	if (Debug) {sprintf(msg,"CN Register = %d\n",regval); write(telnet_fd,msg,strlen(msg));}	if (regval > 15999) regval = 15999;	if (regval < 2601) regval = 2601;	Imin = 0;	Imax = lookup.size - 1;	if (INRANGE(lookup.table[Imin].regval,regval,lookup.table[Imax].regval))	{		while ((Imax - Imin) > 1)		{			i = (Imax + Imin) / 2;			if (INRANGE(lookup.table[Imin].regval,regval,lookup.table[i].regval))				Imax = i;			else				Imin = i;		}		c_n = ((regval - lookup.table[Imin].regval)				* (lookup.table[Imax].realval - lookup.table[Imin].realval) / (lookup.table[Imax].regval - lookup.table[Imin].regval)) + lookup.table[Imin].realval;	}	else if(lookup.table[Imin].regval < regval) // error prone enviroments		c_n = 1000;	else			// nearly no error		c_n = 27000;	return c_n;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -