Changeset - 2a60a19d0303
[Not reviewed]
default
0 1 0
Ethan Zonca - 8 years ago 2017-09-23 11:08:30
ez@ethanzonca.com
Fix encoding, add some dummy values, code compiles and might work now
1 file changed with 15 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/wspr.c
Show inline comments
 
@@ -90,69 +90,75 @@ void wspr_transmit(uint8_t* grid_locator
 
        ////////////////////////////////////////////
 
        // Encode extended maidenhead and altitude
 
        ////////////////////////////////////////////
 
        call[0] = '0';
 

	
 
        // Split into chunks of valmax 36, 26, 26, 26
 

	
 
        // Mask off following 3 26valmax fields
 
        uint32_t chunk = subalt / 26 / 26 / 26; 
 

	
 
        // Encode to callsign
 
        if(chunk < 10)
 
            call[1] = '0' + chunk
 
            call[1] = '0' + chunk;
 
        else
 
            call[1] = chunk - 10 + 'A';
 

	
 
        // Subtract off previous portion
 
        subalt -= (chunk * 26 * 26 * 26);
 

	
 
        // Mask off following 2 26bit values
 
        chunk = (subalt / 26 / 26);
 

	
 
        call[3] = 'A' + chunk;
 

	
 
        // Subtract off previous portion
 
        subalt -= (chunk * 26 * 26)
 
        subalt -= (chunk * 26 * 26);
 

	
 
        // Mask off following 1 26bit values
 
        chunk = (subalt / 26);
 

	
 
        call[4] = 'A' + chunk;
 

	
 
        // Subtract off previous portion
 
        subalt -= (chunk * 26);
 

	
 
        // Remainder is the last call char
 
        call[5] = 'A' + subalt;
 
 
 

	
 
        ////////////////////////////////////////
 
        // Composite temp/batt/speed/gps 
 
        ////////////////////////////////////////
 

	
 
        // Encode value from -50C to 39C => 0-89. TODO: Bounds!
 
        uint8_t temp_enc = 0 + 50;
 
        uint8_t temp_enc = 12 + 50;
 

	
 
        // Encode value from 0-39 with some scalar/offset/etc
 
        uint8_t batt_enc = 0; 
 
        uint8_t batt_enc = 16; 
 

	
 
        // Encode speed in knots from 0-82 to 0-41
 
        uint8_t speed_enc = gpsdata()->speed / 2;
 
        uint8_t speed_enc = gps_getdata()->speed / 2;
 
        if(speed_enc > 41)
 
            speed_enc = 41;
 

	
 
        // Encode GPS status
 
        uint8_t gps_status = 0b00; // MSB is valid fix, lsb is sats > 8
 

	
 
        if(gps_getdata()->fixtype == 2 || gps_getdata()->fixtype == 3)
 
            gps_status |= 0b10;
 

	
 
        if(gps_getdata()->sats_in_solution > 5)
 
            gps_status |= 0b01;
 

	
 
        uint32_t engdata = gps_status + 2 * (speed_enc + 42 * (batt_enc + 40 * temp_enc));
 

	
 
        ////////////////////////////////////////////
 
        // Encode temp/batt/speed/gps
 
        ////////////////////////////////////////////
 

	
 
        // Mask off fields
 
        chunk = engdata / 18 / 10 / 10 / 19;  
 

	
 
        // Encode to grid locator
 
        grid_locator[0] = 'A' + chunk;
 

	
 
@@ -163,44 +169,46 @@ void wspr_transmit(uint8_t* grid_locator
 
        chunk = engdata / 10 / 10 / 19;  
 

	
 
        // Encode to grid locator
 
        grid_locator[1] = 'A' + chunk;
 

	
 
        // Subtract off previous portion
 
        engdata -= (chunk * 10 * 10 * 19);  
 

	
 
        // Mask off fields
 
        chunk = engdata / 10 / 19;  
 

	
 
        // Encode
 
        grid_locater[2] = '0' + chunk;
 
        grid_locator[2] = '0' + chunk;
 

	
 
        // Subtract
 
        engdata -= (chunk * 10 * 19);  
 

	
 
        // Mask off
 
        chunk = engdata / 19;  
 

	
 
        // Encode
 
        grid_locator[3] = chunk;
 

	
 
        // Subtract
 
        engdata -= (chunk * 19);  
 

	
 
        // Mask off
 
        chunk = engdata;  
 

	
 
        // Encode
 
        uint8_t powers[] = {0, 3, 7, 10, 13, 17, 20, 23, 27, 30, 33, 37, 40, 43, 47, 50, 53, 57, 60}
 
        uint8_t powers[] = {0, 3, 7, 10, 13, 17, 20, 23, 27, 30, 33, 37, 40, 43, 47, 50, 53, 57, 60};
 
        dbm = powers[chunk];
 

	
 

	
 
    }
 
    else
 
    {
 
        call[0] = call_orig[0];
 
        call[1] = call_orig[1];
 
        call[2] = call_orig[2];
 
        call[3] = call_orig[3];
 
        call[4] = call_orig[4];
 
        call[5] = call_orig[5];
 
        call[6] = call_orig[6];
 

	
 
        dbm = DBM_ORIG; 
0 comments (0 inline, 0 general)