This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Reading GPS power options problem?

Hello, 

I have a problem of reading GPS options for "NRF_SO_GNSS_POWER_SAVE_MODE" 

This is the code:

retval = nrf_getsockopt(gnss_fd, NRF_SOL_GNSS, NRF_SO_GNSS_POWER_SAVE_MODE, &psm, &psm_len);
if (retval != 0) {
	printk("Failed to send AGNSS data, type:(err: %d)\n", errno);
	return -1;
}

I always get -1, and errno value 22. This function works for "NRF_SO_GNSS_FIX_INTERVAL" option. 

Can you look into it? 

Thank you.

Parents
  • Hi!

    The function call you mention works for me, given that the definition of psm and psm_len look like this:

        nrf_gnss_power_save_mode_t psm;
        nrf_socklen_t psm_len = sizeof(psm);

    Also, make sure to set the option beforehand, before you read try to read it. 

        int retval = nrf_setsockopt(gnss_fd,
                        NRF_SOL_GNSS,
                        NRF_SO_GNSS_POWER_SAVE_MODE,
                        &psm, &psm_len);

    Best regards,

    Heidi

Reply
  • Hi!

    The function call you mention works for me, given that the definition of psm and psm_len look like this:

        nrf_gnss_power_save_mode_t psm;
        nrf_socklen_t psm_len = sizeof(psm);

    Also, make sure to set the option beforehand, before you read try to read it. 

        int retval = nrf_setsockopt(gnss_fd,
                        NRF_SOL_GNSS,
                        NRF_SO_GNSS_POWER_SAVE_MODE,
                        &psm, &psm_len);

    Best regards,

    Heidi

Children
  • Hello, 

    This is something I have already tried, and it doesn't work.  And as I mentioned in the first reply the function: nrf_getsocketopt, even when it returns 0 (like everything is fine, but isn't) for other parameters (not just NRG_SO_GNSS_POWER_SAVE_MODE) doesn't update the values correctly. 

    Do I need to add some configurations in prj.conf file or something similar to be make it work?

    Best regards, 

    Ivan 

  • I see. What value are you reading from &psm and what were you expecting to see? Could you please provide the full code where you set the socket option as well?

    Best regards,

    Heidi

  • I am not reading anything the value remains unchanged, the one I set it to be once I create the variable. I expect to see one of three values possible and those are 0 PSM_DISABLED, 1 PSM_DUTY_CYCLING_PERFORMANCE or 2 PSM_DUTY_CYCLING_POWER. Of course I can:

    static int            gnss_fd; //Global variable in the same file 
    static int gnss_ctrl(uint32_t ctrl)
    {
    	int retval;
    	nrf_gnss_power_save_mode_t psm = NRF_GNSS_PSM_DUTY_CYCLING_PERFORMANCE;
    	nrf_gnss_fix_interval_t fix_interval = 1; 
    	nrf_gnss_fix_retry_t    fix_retry    = 60;	
    	nrf_gnss_delete_mask_t	delete_mask  = 0;
    	nrf_gnss_nmea_mask_t	nmea_mask    = NRF_GNSS_NMEA_GSV_MASK |
    					       NRF_GNSS_NMEA_GSA_MASK |
    					       NRF_GNSS_NMEA_GLL_MASK |
    					       NRF_GNSS_NMEA_GGA_MASK |
    					       NRF_GNSS_NMEA_RMC_MASK;	
    	nrf_socklen_t length;
    	if (ctrl == GNSS_INIT_AND_START) {
    		gnss_fd = nrf_socket(NRF_AF_LOCAL,
    			NRF_SOCK_DGRAM,
    			NRF_PROTO_GNSS);
    
    		if (gnss_fd >= 0) {
    			printk("GPS Socket created\n");
    		}
    		else {
    			printk("Could not init socket (err: %d)\n", gnss_fd);
    			return -1;
    		}
    		retval = nrf_setsockopt(gnss_fd,
    			NRF_SOL_GNSS,
    			NRF_SO_GNSS_FIX_RETRY, 
    			&fix_retry,
    			sizeof(fix_retry));
    		if (retval != 0) {
    			printk("Failed to set fix retry value\n");
    			return -1;
    		}
    		
    		length = sizeof(nrf_gnss_power_save_mode_t);
    		retval = nrf_setsockopt(gnss_fd, NRF_SOL_GNSS, NRF_SO_GNSS_POWER_SAVE_MODE, &psm, length);
    		if (retval != 0) {
    			printk("Failed to set power save mode value\n");
    			return -1;
    		}
    		retval = nrf_getsockopt(gnss_fd, NRF_SOL_GNSS, NRF_SO_GNSS_POWER_SAVE_MODE, &psm, &length);
    		if (retval != 0) {
    			printk("Failed to read power_save_mode(err: %d)\n", errno);
    			return -1;
    		}
    
    		retval = nrf_setsockopt(gnss_fd,
    			NRF_SOL_GNSS,
    			NRF_SO_GNSS_FIX_INTERVAL,
    			&fix_interval,
    			sizeof(fix_interval));
    		if (retval != 0) {
    			printk("Failed to set fix interval value\n");
    			return -1;
    		}
    		
    		retval = nrf_setsockopt(gnss_fd,
    			NRF_SOL_GNSS,
    			NRF_SO_GNSS_NMEA_MASK,
    			&nmea_mask,
    			sizeof(nmea_mask));
    		if (retval != 0) {
    			printk("Failed to set nmea mask\n");
    			return -1;
    		}
    	}
    	if ((ctrl == GNSS_INIT_AND_START) ||
    	    (ctrl == GNSS_RESTART)) {
    		retval = nrf_setsockopt(gnss_fd,
    			NRF_SOL_GNSS,
    			NRF_SO_GNSS_START,
    			&delete_mask,
    			sizeof(delete_mask));
    		if (retval != 0) {
    			printk("Failed to start GPS\n");
    			return -1;
    		}
    	}
    
    	if (ctrl == GNSS_STOP) {
    		retval = nrf_setsockopt(gnss_fd,
    			NRF_SOL_GNSS,
    			NRF_SO_GNSS_STOP,
    			&delete_mask,
    			sizeof(delete_mask));
    		if (retval != 0) {
    			printk("Failed to stop GPS\n");
    			return -1;
    		}
    	}
    
    	return 0;
    }

    As I stated before, I can't read any other parameters even tough nrf_getsockopt returns 0, again no changes to the passed variable. 

    Can you zip the project that works for you and send it so I can see if that works for me?

    P.S. I am using SDK 1.4.2 and modem FW 1.2.3 if this information is of any use. I have tested some previous versions of SDK and FW in different combinations, and continue to have problems.

    Best regards,

    Ivan

  • Hi again

    It looks like reading out this value hasn't been implemented yet which is why it isn't working. Setting it works fine, but for now, you can't read it out.

    That should be in the documentation so I'll talk to someone about adding that in. 

    Best regards,

    Heidi

Related