Subversion Repositories FlightCtrl

Rev

Rev 1207 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1207 Rev 1214
Line 83... Line 83...
83
FFFF 1F23F000A30426
83
FFFF 1F23F000A30426
84
FFFF 1F23F000A30426
84
FFFF 1F23F000A30426
85
FFFF 1F23F000A30426
85
FFFF 1F23F000A30426
86
*/
86
*/
Line 87... Line -...
87
 
-
 
-
 
87
 
88
 
88
#include <stdlib.h>
89
#include "dsl.h"
89
#include "dsl.h"
-
 
90
#include "rc.h"
-
 
91
#include "uart0.h"
90
#include "rc.h"
92
 
91
uint8_t dsl_RSSI = 0;
93
uint8_t dsl_RSSI = 0;
92
uint8_t dsl_Battery = 0;
94
uint8_t dsl_Battery = 0;
93
uint8_t dsl_Allocation = 0;
95
uint8_t dsl_Allocation = 0;
-
 
96
uint8_t PacketBuffer[6];
Line 94... Line 97...
94
uint8_t PacketBuffer[6];
97
uint8_t Jitter = 0; // same measurement as RC_Quality in rc.c
95
 
98
 
96
typedef union
99
typedef union
97
{
100
{
Line 108... Line 111...
108
void dsl_new_signal(uint8_t channel, int16_t signal)
111
void dsl_new_signal(uint8_t channel, int16_t signal)
109
{
112
{
110
    int16_t tmp;
113
    int16_t tmp;
111
    uint8_t index = channel + 1; // mk channels start with 1
114
    uint8_t index = channel + 1; // mk channels start with 1
Line -... Line 115...
-
 
115
 
-
 
116
        RC_Quality      = (212 * (uint16_t)dsl_RSSI) / 128; // have to be scaled approx. by a factor of 1.66 to get 200 at full level
Line 112... Line 117...
112
 
117
        if(RC_Quality > 255) RC_Quality = 255;
113
 
118
 
114
    // signal from  DSL-receiver is between 7373 (1ms) und 14745 (2ms).
119
    // signal from  DSL-receiver is between 7373 (1ms) und 14745 (2ms).
Line -... Line 120...
-
 
120
    signal-= 11059;     // shift to neutral
-
 
121
    signal/= 24;        // scale to mk rc resolution
-
 
122
 
-
 
123
        if(abs(signal-PPM_in[index]) < 6)
-
 
124
        {
-
 
125
                if(Jitter < 200) Jitter +=10;
115
    signal-= 11059;     // shift to neutral
126
                else Jitter = 200;
116
    signal/= 24;        // scale to mk rc resolution
127
        }
117
 
128
 
118
        // calculate exponential history for signal
129
        // calculate exponential history for signal
119
        tmp = (3 * (PPM_in[index]) + signal) / 4;
130
        tmp = (3 * (PPM_in[index]) + signal) / 4;
120
        if(tmp > signal+1) tmp--; else
131
        if(tmp > signal+1) tmp--; else
121
        if(tmp < signal-1) tmp++;
132
        if(tmp < signal-1) tmp++;
122
        // calculate signal difference on good signal level
133
        // calculate signal difference on good signal level
Line 123... Line 134...
123
        if(RC_Quality >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; // cut off lower 3 bit for noise reduction
134
        if(Jitter >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; // cut off lower 3 bit for noise reduction
124
        else PPM_diff[index] = 0;
135
        else PPM_diff[index] = 0;
125
        PPM_in[index] = tmp; // update channel value
136
        PPM_in[index] = tmp; // update channel value
126
 
-
 
127
    if(index == 4)
137
 
128
    {
138
    if(index == 4)
Line 129... Line 139...
129
                NewPpmData = 0;
139
    {
130
                NewRCFrames++;
140
                NewPpmData = 0;
Line 143... Line 153...
143
                if(PacketBuffer[0] == 0x1F) // separate status frame
153
                if(PacketBuffer[0] == 0x1F) // separate status frame
144
                {
154
                {
145
                        dsl_Allocation  = PacketBuffer[1]; // Get frequency allocation
155
                        dsl_Allocation  = PacketBuffer[1]; // Get frequency allocation
146
                        // ??                   = PacketBuffer[2];
156
                        // ??                   = PacketBuffer[2];
147
                        dsl_RSSI                = PacketBuffer[3]; // Get signal quality
157
                        dsl_RSSI                = PacketBuffer[3]; // Get signal quality
148
                        RC_Quality              = (212 * (uint16_t)dsl_RSSI) / 128; // have to be scaled approx. by a factor of 1.66 to get 200 at full level
-
 
149
                        if(RC_Quality > 255) RC_Quality = 255;
-
 
150
                        dsl_Battery     = PacketBuffer[4]; // Get voltage of battery supply
158
                        dsl_Battery     = PacketBuffer[4]; // Get voltage of battery supply
151
                        // ??                   = PacketBuffer[5];
159
                        // ??                   = PacketBuffer[5];
152
                        if(dsl_RSSI == 0)
160
                        if(dsl_RSSI == 0)
153
                        {
161
                        {
154
                                for (i = 0; i<5; i++)
162
                                for (i = 0; i<5; i++)