コード例 #1
0
ファイル: TSDRLibrary.c プロジェクト: suduma/TempestSDR
 int tsdr_getsamplerate(tsdr_lib_t * tsdr) {
	if (!tsdr->plugin.initialized) RETURN_EXCEPTION(tsdr, "Cannot change sample rate. Plugin not loaded yet.", TSDR_ERR_PLUGIN);

	tsdr->samplerate_real = tsdr->plugin.tsdrplugin_getsamplerate();

	if (tsdr->samplerate_real == 0 || tsdr->samplerate_real > 500e6) RETURN_EXCEPTION(tsdr, "Invalid/unsupported value for sample rate.", TSDR_SAMPLE_RATE_WRONG);

	set_internal_samplerate(tsdr, tsdr->samplerate_real);

	RETURN_OK(tsdr);

	return 0; // to avoid getting warning from stupid Eclpse
}
コード例 #2
0
ファイル: linux.c プロジェクト: hufsm/tu_gen2_libserialport
SP_PRIV enum sp_return get_port_details(struct sp_port *port)
{
	/*
	 * Description limited to 127 char, anything longer
	 * would not be user friendly anyway.
	 */
	char description[128];
	int bus, address;
	unsigned int vid, pid;
	char manufacturer[128], product[128], serial[128];
	char baddr[32];
	const char dir_name[] = "/sys/class/tty/%s/device/%s%s";
	char sub_dir[32] = "", file_name[PATH_MAX];
	char *ptr, *dev = port->name + 5;
	FILE *file;
	int i, count;
	struct stat statbuf;

	if (strncmp(port->name, "/dev/", 5))
		RETURN_ERROR(SP_ERR_ARG, "Device name not recognized");

	snprintf(file_name, sizeof(file_name), "/sys/class/tty/%s", dev);
	if (lstat(file_name, &statbuf) == -1)
		RETURN_ERROR(SP_ERR_ARG, "Device not found");
	if (!S_ISLNK(statbuf.st_mode))
		snprintf(file_name, sizeof(file_name), "/sys/class/tty/%s/device", dev);
	count = readlink(file_name, file_name, sizeof(file_name));
	if (count <= 0 || count >= (int)(sizeof(file_name) - 1))
		RETURN_ERROR(SP_ERR_ARG, "Device not found");
	file_name[count] = 0;
	if (strstr(file_name, "bluetooth"))
		port->transport = SP_TRANSPORT_BLUETOOTH;
	else if (strstr(file_name, "usb"))
		port->transport = SP_TRANSPORT_USB;

	if (port->transport == SP_TRANSPORT_USB) {
		for (i = 0; i < 5; i++) {
			strcat(sub_dir, "../");

			snprintf(file_name, sizeof(file_name), dir_name, dev, sub_dir, "busnum");
			if (!(file = fopen(file_name, "r")))
				continue;
			count = fscanf(file, "%d", &bus);
			fclose(file);
			if (count != 1)
				continue;

			snprintf(file_name, sizeof(file_name), dir_name, dev, sub_dir, "devnum");
			if (!(file = fopen(file_name, "r")))
				continue;
			count = fscanf(file, "%d", &address);
			fclose(file);
			if (count != 1)
				continue;

			snprintf(file_name, sizeof(file_name), dir_name, dev, sub_dir, "idVendor");
			if (!(file = fopen(file_name, "r")))
				continue;
			count = fscanf(file, "%4x", &vid);
			fclose(file);
			if (count != 1)
				continue;

			snprintf(file_name, sizeof(file_name), dir_name, dev, sub_dir, "idProduct");
			if (!(file = fopen(file_name, "r")))
				continue;
			count = fscanf(file, "%4x", &pid);
			fclose(file);
			if (count != 1)
				continue;

			port->usb_bus = bus;
			port->usb_address = address;
			port->usb_vid = vid;
			port->usb_pid = pid;

			snprintf(file_name, sizeof(file_name), dir_name, dev, sub_dir, "product");
			if ((file = fopen(file_name, "r"))) {
				if ((ptr = fgets(description, sizeof(description), file))) {
					ptr = description + strlen(description) - 1;
					if (ptr >= description && *ptr == '\n')
						*ptr = 0;
					port->description = strdup(description);
				}
				fclose(file);
			}
			if (!file || !ptr)
				port->description = strdup(dev);

			snprintf(file_name, sizeof(file_name), dir_name, dev, sub_dir, "manufacturer");
			if ((file = fopen(file_name, "r"))) {
				if ((ptr = fgets(manufacturer, sizeof(manufacturer), file))) {
					ptr = manufacturer + strlen(manufacturer) - 1;
					if (ptr >= manufacturer && *ptr == '\n')
						*ptr = 0;
					port->usb_manufacturer = strdup(manufacturer);
				}
				fclose(file);
			}

			snprintf(file_name, sizeof(file_name), dir_name, dev, sub_dir, "product");
			if ((file = fopen(file_name, "r"))) {
				if ((ptr = fgets(product, sizeof(product), file))) {
					ptr = product + strlen(product) - 1;
					if (ptr >= product && *ptr == '\n')
						*ptr = 0;
					port->usb_product = strdup(product);
				}
				fclose(file);
			}

			snprintf(file_name, sizeof(file_name), dir_name, dev, sub_dir, "serial");
			if ((file = fopen(file_name, "r"))) {
				if ((ptr = fgets(serial, sizeof(serial), file))) {
					ptr = serial + strlen(serial) - 1;
					if (ptr >= serial && *ptr == '\n')
						*ptr = 0;
					port->usb_serial = strdup(serial);
				}
				fclose(file);
			}

			/* If present, add serial to description for better identification. */
			if (port->usb_serial && strlen(port->usb_serial)) {
				snprintf(description, sizeof(description),
					"%s - %s", port->description, port->usb_serial);
				if (port->description)
					free(port->description);
				port->description = strdup(description);
			}

			break;
		}
	} else {
		port->description = strdup(dev);

		if (port->transport == SP_TRANSPORT_BLUETOOTH) {
			snprintf(file_name, sizeof(file_name), dir_name, dev, "", "address");
			if ((file = fopen(file_name, "r"))) {
				if ((ptr = fgets(baddr, sizeof(baddr), file))) {
					ptr = baddr + strlen(baddr) - 1;
					if (ptr >= baddr && *ptr == '\n')
						*ptr = 0;
					port->bluetooth_address = strdup(baddr);
				}
				fclose(file);
			}
		}
	}

	RETURN_OK();
}
コード例 #3
0
ファイル: main.cpp プロジェクト: eindacor/utilities
solution solve(string &c, bigNumber previous, settings &user)
{
    c += '$';
    PTYPE pType=ERROR;
    
    vector<int> first;
    vector<int> second;
    bigNumber bn1;
    bigNumber bn2;
    bigNumber temp;
    
    bn1.setBase(user.getBase());
    bn2.setBase(user.getBase());
    temp.setBase(user.getBase());

    int decimalCount1=0;
    int decimalCount2=0;
    int commaNumbers=0;
    int numbers=0;

    bool decimal=false;
	bool comma=false;
	bool negative1=false;
	bool negative2=false;
    bool done=false;
	bool printExact=false;
	bool printStats=false;

    bigNumber* targetBN = &bn1;
    vector<int>* targetVec = &first;
    int* targetDec = &decimalCount1;
	bool* targetNegative = &negative1;
    
    int counter = c.size();
    
    for (int i=0; i<counter; i++)
    {
        if (checkWord(c, i, "pi"))
        {
            if (numbers>0 || comma==true || decimal==true)
            {
                RETURN_ERROR;
            }
            
            else
            {
                string piString(PI);
		
				for (int piMarker=PRECISION; piMarker>=0; piMarker--)
				{
					char piChar = '0';
					int piNum = piString[PRECISION-piMarker] - piChar;
				
					(*targetVec).push_back(piNum);
				}
                
                done=true;
				*targetDec = PRECISION;
                
                numbers += (PRECISION+1);
                counter += 2;
                i += 2;
            }
        }
        
        if (checkWord(c, i, "theta"))
        {
            if (numbers>0 || comma==true || decimal==true)
            {
                RETURN_ERROR;
            }
            
            else
            {
                string thetaString(THETA);
		
				for (int thetaMarker=PRECISION; thetaMarker>=0; thetaMarker--)
				{
					char thetaChar = '0';
					int thetaNum = thetaString[PRECISION-thetaMarker] - thetaChar;
				
					(*targetVec).push_back(thetaNum);
				}
                
                done=true;
				*targetDec = PRECISION;
                
                numbers += (PRECISION+1);
                counter += 5;
                i += 5;
            }
        }
        
		//if it isn't a space, number, symbol, end marker, or decimal point, return error
		if (checkSpace(c[i])==false && 
			isNumber(c[i], user)==false && 
			isSymbol(c[i])==false && 
			c[i] != '$' && 
			c[i] != ',' && 
			c[i] != '.')
		{
			RETURN_ERROR;
		}

		if (c[i]==',')
		{
			if (comma==false)
			{
				if (decimal==true || numbers==0 || numbers > 3 || done==true)
					RETURN_ERROR;

				else comma = true;
			}

			else if (commaNumbers != 3)
			    RETURN_ERROR;
			    
			commaNumbers=0;    
		}
			
		//if it's a space
		else if (checkSpace(c[i])==true)
		{
			//if it's preceeded by a number, number is complete
			if (isNumber(c[i-1], user))
		    {
		        done = true;
		    }
		    
		    //if negative is set, and it is preceeded by a minus symbol, return error
		    else if (checkSymbol(c[i-1]) == SUBTRACT && *targetNegative == true)
		    {
		        RETURN_ERROR;
		    }
		}

        //if it's a number
        else if (isNumber(c[i], user))
        {        
            //if number was complete, return error
            if (done==true)
			{
                RETURN_ERROR;
			}
			
		    if (comma==true)
		        commaNumbers++;
                
            //otherwise add number to target vector, add decimal count if needed
            (*targetVec).push_back(checkNumber(c[i]));
                numbers++;
                
            if (decimal==true)
			{
                (*targetDec)++;
			}
        }
        
        //if it's a minus symbol
        else if (checkSymbol(c[i]) == SUBTRACT)
        {
            //if no numbers have been added
            if (numbers==0)
            {
                //if target isn't negative, make target negative
                if ((*targetNegative)==false)
                {
                    (*targetNegative) = true;
                    (*targetBN).setNegative();
                }
                
                //if target is negative, no numbers have been added, and the target is the first number: 
				//there are two minus symbols, which means the intent is to 
				//subtract a negative number from previous
                else if (targetBN == &bn1)
                {
                    pType = SUBTRACT;
                    targetBN = &bn2;
                    numbers=0;
					commaNumbers=0;
					comma=false;
                    bn2.setNegative(); //sets 2nd number to negative
					negative2=true; //sets 2nd number to negative
                    targetNegative= &negative2;
                    done=false;
                    targetDec = &decimalCount2;
                    targetVec = &second;
                    decimal=false;
                }
                
                else 
				{
					RETURN_ERROR;
				}
            }
            
            //if numbers have been added, and the target is the first number, the problem type is subtraction
            else if (targetBN == &bn1)
            {
                if (comma==true && decimal==false && commaNumbers != 3)
                    RETURN_ERROR;
                
                pType = SUBTRACT;
                numbers=0;
				commaNumbers=0;
				comma=false;
                done=false;
                targetBN = &bn2;
				targetNegative= &negative2;
                targetDec = &decimalCount2;
                targetVec = &second;
                decimal=false;
            }
            
            //if numbers have been added, and the target is the second number, return error
            else 
			{
				RETURN_ERROR;
			}
        }
        
        //if it's a symbol other than minus
        else if (checkSymbol(c[i]) != ERROR && checkSymbol(c[i]) != SUBTRACT)
        {
            //if the type is already established, return error
            if (pType != ERROR)
			{
            	RETURN_ERROR;
			}
                
            //otherwise, set problem type based on symbol and reset figures
            else 
            {
                if (comma==true && decimal==false && commaNumbers != 3)
                    RETURN_ERROR;
                
                pType = checkSymbol(c[i]);
                targetBN = &bn2;
                numbers=0;
				commaNumbers=0;
				comma=false;
                done=false;
				targetNegative = &negative2;
                targetDec = &decimalCount2;
                targetVec = &second;
                decimal=false;
            }
        }
        
        //if it's a decimal point
        else if (c[i]=='.')
        {
            //if there's already been a decimal point, return error
            if (decimal==true)
			{
                RETURN_ERROR;
			}
                
            else decimal = true;
            
            if (comma==true && commaNumbers != 3)
                RETURN_ERROR;
        }
        
        //if it's an endline character
        else if (c[i] == '$')
        {
            if (comma==true && decimal==false && commaNumbers != 3)
                    RETURN_ERROR;
                    
			//if both numbers are empty
			if (first.size()==0 && second.size()==0)
			{
				if (pType==FACTORIAL)
				{
					bn1 = previous;
				}

				else RETURN_ERROR;
			}

			//if first number is empty, set bn1 to previous
			if (first.size()==0)
			{
				bn1 = previous;
			}

			//otherwise create bn1 from entered and print it as is
            else
            {   
				bn1 = numberFromVector(first, negative1, decimalCount1, user);
				printExact=true;
            }
            
            //if second number is empty
            if (second.size()==0)
            {               
                //if first number is negative and pType is undefined, subtract number from previous
                if (negative1==true && pType == ERROR)
                {
					bn1.setPositive();
                    temp = previous - bn1;

					cout << "Entered: "; 
					displayNumber(previous, user, false, false);
					cout << " - "; 
					displayNumber(bn1, user, true, false);

					RETURN_OK(temp);
					//return solution(temp, 0);
                }
                
                //if first number isn't negative and no problem type has been declared, return that number
                else if (pType == ERROR)
                {
					cout << "Entered: "; 
					displayNumber(bn1, user, true, false);
					RETURN_OK(bn1);
                    //return solution(bn1, 0);
                }
               
                else if (pType != FACTORIAL)
                {
                    RETURN_ERROR;
                }
            }
                
            //otherwise take ints from second vector and use to set bigNumber2
            else 
            {
                bn2 = numberFromVector(second, negative2, decimalCount2, user);
            }

			cout << "Entered: ";
			displayNumber(bn1, user, printExact, printStats);
			
			break;
        }
    }
    
    //use problem type to calculate solution, return with no errors if valid
    switch(pType)
    {
        case ERROR: RETURN_ERROR;
        
        case ADD: cout << " + "; bn2.printNumber();
            temp = bn1 + bn2;
			RETURN_OK(temp);
        
        case SUBTRACT: cout << " - "; bn2.printNumber();
			temp = bn1 - bn2;
			RETURN_OK(temp);
                
        case MULTIPLY: cout << " * "; bn2.printNumber();
			temp = bn1 * bn2;
			RETURN_OK(temp);
                
        case DIVIDE: cout << " / "; bn2.printNumber();
            if (bn2==0)
            {
                RETURN_ERROR;
            }
            temp = bn1 / bn2;
			RETURN_OK(temp);
                
        case FACTORIAL: 
			if (bn1<0 || bn1.getDecimalCount() > 0)
            {
				RETURN_ERROR;
            }
            
            else if (bn1==0)
            {
				cout << "!";
				bigNumber fact(1);
				fact.setBase(user.getBase());
				RETURN_OK(fact);
            }
            
            temp = bigNumber::factorial(bn1);
			cout << "!";
			RETURN_OK(temp);    
           
        case EXPONENT: cout << "^"; bn2.printNumber();
			temp = bigNumber::exponent(bn1, bn2);
			RETURN_OK(temp);
        
        case ITERATION: cout << "c"; bn2.printNumber();
			temp = bigNumber::iterations(bn1, bn2);
			RETURN_OK(temp);
        
        default: RETURN_ERROR;
    }

}
コード例 #4
0
ファイル: TSDRPlugin_Mirics.c プロジェクト: suduma/TempestSDR
int TSDRPLUGIN_API __stdcall tsdrplugin_init(const char * params) {
    RETURN_OK();
}
コード例 #5
0
ファイル: TSDRPlugin_Mirics.c プロジェクト: suduma/TempestSDR
int TSDRPLUGIN_API __stdcall tsdrplugin_setgain(float gain) {
    desiredgainred = 102 - (int) (gain * 102);
    if (desiredgainred < 0) desiredgainred = 0;
    else if (desiredgainred > 102) desiredgainred = 102;
    RETURN_OK();
}
コード例 #6
0
ファイル: TSDRPlugin_Mirics.c プロジェクト: suduma/TempestSDR
int TSDRPLUGIN_API __stdcall tsdrplugin_stop(void) {
    working = 0;
    RETURN_OK();
}
コード例 #7
0
ファイル: TSDRPlugin_Mirics.c プロジェクト: suduma/TempestSDR
int TSDRPLUGIN_API __stdcall tsdrplugin_setbasefreq(uint32_t freq) {
    desiredfreq = freq;
    RETURN_OK();
}
コード例 #8
0
ファイル: test.cpp プロジェクト: andyspb/cpp-test
int main(int argc, char **argv) {
  __SCOPE_LOG__;
  assert(algorithms::test());
//  assert(array_::test());
//  assert(binary_tree::test());
//  assert(bits::test());
//  assert(blockchain::test());
//  assert(cast::test());
//  assert(cpp1x::test());
//  assert(cci4::test());
//  assert(cci5::test());
//  assert(clock_::test());
//  assert(diff::test());
//  assert(exceptions::test());
//  assert(epam::test() );
//  assert(facebook::test());
//  assert(fast_io::test());
//  assert(functors::test());
//  assert(futures::test());
//  assert(google_2::test());
//  assert(graph::test());
//  assert(hash_::test());
//  assert(hashmap::test());
//  assert(hrank::test());
//  assert(http::test());
//  assert(ipc::test());
//  assert(json::test());
//  assert(lambda::test());
//  assert(language::test());
//  assert(last_1::test());
//  assert(leap::test());
//  assert(lock_free::test());
//  assert(logger::test());
//  assert(lge::test());
//  assert(mem_test::test());
//  assert(memory::test());
//  assert(moto::test());
//  assert(ms::test() );
//  assert(net::test());
//  assert(overloading::test());
//  assert(parser::test());
//  assert(patterns::test());
//  assert(quiz::test());
//  assert(serialization::test());
//  assert(smart_ptr_::test());
//  assert(spb::test());
//  assert(sqllite::test());
//  assert(sqrt_::test());
//  assert(stackoverflow::test());
//  assert(static_::test());
//  assert(stl::test());
//  assert(templates::test());
//  assert(terramind::test());
//  assert(virtuals::test());
//  assert(clock_::test());
//  assert(test_examples::test());
//  assert(threads::test());
//  assert(virtuals::test());
//  assert(yandex::test());
//  assert(test_examples::test());
//  assert(templates::test());
  RETURN_OK();
}