Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
805 - 1
// ///////////////////////////////////////////////////////////////////////////////
2
// Copyright (C) 2010, Frank Blumenberg
3
//
4
// See License.txt for complete licensing and attribution information.
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included in all
13
// copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
// THE SOFTWARE.
22
//
23
// ///////////////////////////////////////////////////////////////////////////////
24
 
25
#import "NSData+MKPayloadDecode.h"
26
#import "MKDataConstants.h"
27
 
28
@implementation NSData (MKPayloadDecodeSetting)
29
 
30
- (NSDictionary *) decodeReadSettingResponse {
31
 
32
  const char * bytes = [self bytes];
33
  NSNumber * index = [NSNumber numberWithChar:bytes[0]];
34
  NSNumber * version = [NSNumber numberWithChar:bytes[1]];
35
 
36
  MKSetting settings;
37
  memcpy((unsigned char *)&settings, (unsigned char *)(bytes + 2), sizeof(settings));
38
 
39
  NSMutableDictionary* d = [[[NSMutableDictionary alloc] initWithCapacity:112] autorelease];
40
 
41
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
42
 
43
  [d setObject:index forKey:kMKDataKeyIndex];
44
  [d setObject:version forKey:kMKDataKeyVersion];
45
 
46
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Kanalbelegung[0]] forKey:kKeyKanalbelegung00];
47
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Kanalbelegung[1]] forKey:kKeyKanalbelegung01];
48
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Kanalbelegung[2]] forKey:kKeyKanalbelegung02];
49
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Kanalbelegung[3]] forKey:kKeyKanalbelegung03];
50
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Kanalbelegung[4]] forKey:kKeyKanalbelegung04];
51
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Kanalbelegung[5]] forKey:kKeyKanalbelegung05];
52
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Kanalbelegung[6]] forKey:kKeyKanalbelegung06];
53
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Kanalbelegung[7]] forKey:kKeyKanalbelegung07];
54
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Kanalbelegung[8]] forKey:kKeyKanalbelegung08];
55
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Kanalbelegung[9]] forKey:kKeyKanalbelegung09];
56
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Kanalbelegung[10]] forKey:kKeyKanalbelegung10];
57
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Kanalbelegung[11]] forKey:kKeyKanalbelegung11];
58
 
59
  [d setObject:[NSNumber numberWithUnsignedChar:settings.GlobalConfig] forKey:kKeyGlobalConfig];
60
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.GlobalConfig & CFG_HOEHENREGELUNG       ) != 0] forKey:kKeyGlobalConfig_HOEHENREGELUNG       ];
61
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.GlobalConfig & CFG_HOEHEN_SCHALTER      ) != 0] forKey:kKeyGlobalConfig_HOEHEN_SCHALTER      ];
62
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.GlobalConfig & CFG_HEADING_HOLD         ) != 0] forKey:kKeyGlobalConfig_HEADING_HOLD         ];
63
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.GlobalConfig & CFG_KOMPASS_AKTIV        ) != 0] forKey:kKeyGlobalConfig_KOMPASS_AKTIV        ];
64
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.GlobalConfig & CFG_KOMPASS_FIX          ) != 0] forKey:kKeyGlobalConfig_KOMPASS_FIX          ];
65
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.GlobalConfig & CFG_GPS_AKTIV            ) != 0] forKey:kKeyGlobalConfig_GPS_AKTIV            ];
66
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.GlobalConfig & CFG_ACHSENKOPPLUNG_AKTIV ) != 0] forKey:kKeyGlobalConfig_ACHSENKOPPLUNG_AKTIV ];
67
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.GlobalConfig & CFG_DREHRATEN_BEGRENZER  ) != 0] forKey:kKeyGlobalConfig_DREHRATEN_BEGRENZER  ];
68
 
69
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Hoehe_MinGas] forKey:kKeyHoehe_MinGas ];
70
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Luftdruck_D] forKey:kKeyLuftdruck_D ];
71
  [d setObject:[NSNumber numberWithUnsignedChar:settings.MaxHoehe] forKey:kKeyMaxHoehe ];
72
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Hoehe_P] forKey:kKeyHoehe_P ];
73
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Hoehe_Verstaerkung] forKey:kKeyHoehe_Verstaerkung ];
74
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Hoehe_ACC_Wirkung] forKey:kKeyHoehe_ACC_Wirkung ];
75
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Hoehe_HoverBand] forKey:kKeyHoehe_HoverBand ];
76
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Hoehe_GPS_Z] forKey:kKeyHoehe_GPS_Z ];
77
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Hoehe_StickNeutralPoint] forKey:kKeyHoehe_StickNeutralPoint ];
78
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Stick_P] forKey:kKeyStick_P ];
79
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Stick_D] forKey:kKeyStick_D ];
80
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Gier_P] forKey:kKeyGier_P ];
81
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Gas_Min] forKey:kKeyGas_Min ];
82
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Gas_Max] forKey:kKeyGas_Max ];
83
  [d setObject:[NSNumber numberWithUnsignedChar:settings.GyroAccFaktor] forKey:kKeyGyroAccFaktor ];
84
  [d setObject:[NSNumber numberWithUnsignedChar:settings.KompassWirkung] forKey:kKeyKompassWirkung ];
85
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Gyro_P] forKey:kKeyGyro_P ];
86
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Gyro_I] forKey:kKeyGyro_I ];
87
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Gyro_D] forKey:kKeyGyro_D ];
88
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Gyro_Gier_P] forKey:kKeyGyro_Gier_P ];
89
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Gyro_Gier_I] forKey:kKeyGyro_Gier_I ];
90
  [d setObject:[NSNumber numberWithUnsignedChar:settings.UnterspannungsWarnung] forKey:kKeyUnterspannungsWarnung ];
91
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NotGas] forKey:kKeyNotGas ];
92
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NotGasZeit] forKey:kKeyNotGasZeit ];
93
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Receiver] forKey:kKeyReceiver ];
94
  [d setObject:[NSNumber numberWithUnsignedChar:settings.I_Faktor] forKey:kKeyI_Faktor ];
95
  [d setObject:[NSNumber numberWithUnsignedChar:settings.UserParam1] forKey:kKeyUserParam1 ];
96
  [d setObject:[NSNumber numberWithUnsignedChar:settings.UserParam2] forKey:kKeyUserParam2 ];
97
  [d setObject:[NSNumber numberWithUnsignedChar:settings.UserParam3] forKey:kKeyUserParam3 ];
98
  [d setObject:[NSNumber numberWithUnsignedChar:settings.UserParam4] forKey:kKeyUserParam4 ];
99
  [d setObject:[NSNumber numberWithUnsignedChar:settings.ServoNickControl] forKey:kKeyServoNickControl ];
100
  [d setObject:[NSNumber numberWithUnsignedChar:settings.ServoNickComp] forKey:kKeyServoNickComp ];
101
  [d setObject:[NSNumber numberWithUnsignedChar:settings.ServoNickMin] forKey:kKeyServoNickMin ];
102
  [d setObject:[NSNumber numberWithUnsignedChar:settings.ServoNickMax] forKey:kKeyServoNickMax ];
103
  [d setObject:[NSNumber numberWithUnsignedChar:settings.ServoRollControl] forKey:kKeyServoRollControl ];
104
  [d setObject:[NSNumber numberWithUnsignedChar:settings.ServoRollComp] forKey:kKeyServoRollComp ];
105
  [d setObject:[NSNumber numberWithUnsignedChar:settings.ServoRollMin] forKey:kKeyServoRollMin ];
106
  [d setObject:[NSNumber numberWithUnsignedChar:settings.ServoRollMax] forKey:kKeyServoRollMax ];
107
  [d setObject:[NSNumber numberWithUnsignedChar:settings.ServoNickRefresh] forKey:kKeyServoNickRefresh ];
108
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Servo3] forKey:kKeyServo3 ];
109
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Servo4] forKey:kKeyServo4 ];
110
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Servo5] forKey:kKeyServo5 ];
111
  [d setObject:[NSNumber numberWithUnsignedChar:settings.LoopGasLimit] forKey:kKeyLoopGasLimit ];
112
  [d setObject:[NSNumber numberWithUnsignedChar:settings.LoopThreshold] forKey:kKeyLoopThreshold ];
113
  [d setObject:[NSNumber numberWithUnsignedChar:settings.LoopHysterese] forKey:kKeyLoopHysterese ];
114
  [d setObject:[NSNumber numberWithUnsignedChar:settings.AchsKopplung1] forKey:kKeyAchsKopplung1 ];
115
  [d setObject:[NSNumber numberWithUnsignedChar:settings.AchsKopplung2] forKey:kKeyAchsKopplung2 ];
116
  [d setObject:[NSNumber numberWithUnsignedChar:settings.CouplingYawCorrection] forKey:kKeyCouplingYawCorrection ];
117
  [d setObject:[NSNumber numberWithUnsignedChar:settings.WinkelUmschlagNick] forKey:kKeyWinkelUmschlagNick ];
118
  [d setObject:[NSNumber numberWithUnsignedChar:settings.WinkelUmschlagRoll] forKey:kKeyWinkelUmschlagRoll ];
119
  [d setObject:[NSNumber numberWithUnsignedChar:settings.GyroAccAbgleich] forKey:kKeyGyroAccAbgleich ];
120
  [d setObject:[NSNumber numberWithUnsignedChar:settings.Driftkomp] forKey:kKeyDriftkomp ];
121
  [d setObject:[NSNumber numberWithUnsignedChar:settings.DynamicStability] forKey:kKeyDynamicStability ];
122
  [d setObject:[NSNumber numberWithUnsignedChar:settings.UserParam5] forKey:kKeyUserParam5 ];
123
  [d setObject:[NSNumber numberWithUnsignedChar:settings.UserParam6] forKey:kKeyUserParam6 ];
124
  [d setObject:[NSNumber numberWithUnsignedChar:settings.UserParam7] forKey:kKeyUserParam7 ];
125
  [d setObject:[NSNumber numberWithUnsignedChar:settings.UserParam8] forKey:kKeyUserParam8 ];
126
  [d setObject:[NSNumber numberWithUnsignedChar:settings.J16Bitmask] forKey:kKeyJ16Bitmask ];
127
  [d setObject:[NSNumber numberWithUnsignedChar:settings.J16Timing] forKey:kKeyJ16Timing ];
128
  [d setObject:[NSNumber numberWithUnsignedChar:settings.J17Bitmask] forKey:kKeyJ17Bitmask ];
129
  [d setObject:[NSNumber numberWithUnsignedChar:settings.J17Timing] forKey:kKeyJ17Timing ];
130
  [d setObject:[NSNumber numberWithUnsignedChar:settings.WARN_J16_Bitmask] forKey:kKeyWARN_J16_Bitmask ];
131
  [d setObject:[NSNumber numberWithUnsignedChar:settings.WARN_J17_Bitmask] forKey:kKeyWARN_J17_Bitmask ];
132
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviGpsModeControl] forKey:kKeyNaviGpsModeControl ];
133
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviGpsGain] forKey:kKeyNaviGpsGain ];
134
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviGpsP] forKey:kKeyNaviGpsP ];
135
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviGpsI] forKey:kKeyNaviGpsI ];
136
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviGpsD] forKey:kKeyNaviGpsD ];
137
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviGpsPLimit] forKey:kKeyNaviGpsPLimit ];
138
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviGpsILimit] forKey:kKeyNaviGpsILimit ];
139
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviGpsDLimit] forKey:kKeyNaviGpsDLimit ];
140
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviGpsACC] forKey:kKeyNaviGpsACC ];
141
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviGpsMinSat] forKey:kKeyNaviGpsMinSat ];
142
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviStickThreshold] forKey:kKeyNaviStickThreshold ];
143
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviWindCorrection] forKey:kKeyNaviWindCorrection ];
144
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviSpeedCompensation] forKey:kKeyNaviSpeedCompensation ];
145
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviOperatingRadius] forKey:kKeyNaviOperatingRadius ];
146
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviAngleLimitation] forKey:kKeyNaviAngleLimitation ];
147
  [d setObject:[NSNumber numberWithUnsignedChar:settings.NaviPH_LoginTime] forKey:kKeyNaviPH_LoginTime ];
148
  [d setObject:[NSNumber numberWithUnsignedChar:settings.ExternalControl] forKey:kKeyExternalControl ];
149
 
150
  [d setObject:[NSNumber numberWithUnsignedChar:settings.BitConfig] forKey:kKeyBitConfig];
151
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.BitConfig & CFG_LOOP_OBEN     ) != 0] forKey:kKeyBitConfig_LOOP_UP       ];
152
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.BitConfig & CFG_LOOP_UNTEN    ) != 0] forKey:kKeyBitConfig_LOOP_DOWN     ];
153
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.BitConfig & CFG_LOOP_LINKS    ) != 0] forKey:kKeyBitConfig_LOOP_LEFT     ];
154
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.BitConfig & CFG_LOOP_RECHTS   ) != 0] forKey:kKeyBitConfig_LOOP_RIGHT    ];
155
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.BitConfig & CFG_MOTOR_BLINK       ) != 0] forKey:kKeyBitConfig_MOTOR_BLINK   ];
156
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.BitConfig & CFG_MOTOR_OFF_LED1) != 0] forKey:kKeyBitConfig_MOTOR_OFF_LED1];
157
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.BitConfig & CFG_MOTOR_OFF_LED2) != 0] forKey:kKeyBitConfig_MOTOR_OFF_LED2];
158
 
159
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.BitConfig & CFG2_INVERT_NICK) != 0] forKey:kKeyServoCompInvert_Nick];
160
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.BitConfig & CFG2_INVERT_ROLL) != 0] forKey:kKeyServoCompInvert_ROLL];
161
 
162
  [d setObject:[NSNumber numberWithUnsignedChar:settings.ExtraConfig & CFG2_HEIGHT_LIMIT] forKey:kKeyExtraConfig];
163
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.ExtraConfig & CFG2_HEIGHT_LIMIT) != 0] forKey:kKeyExtraConfig_HEIGHT_LIMIT];
164
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.ExtraConfig & CFG2_VARIO_BEEP  ) != 0] forKey:kKeyExtraConfig_VARIO_BEEP  ];
165
  [d setObject:[NSNumber numberWithUnsignedChar:(settings.ExtraConfig & CFG_SENSITIVE_RC ) != 0] forKey:kKeyExtraConfig_SENSITIVE_RC];
166
 
167
  NSString* name=[NSString stringWithCString:settings.Name encoding:NSASCIIStringEncoding];
168
  [d setObject:name forKey:kKeyName];
169
 
170
  [pool drain];
171
 
172
  return d;
173
}
174
 
175
- (NSDictionary *) decodeWriteSettingResponse {
176
  const char * bytes = [self bytes];
177
  NSNumber * theIndex = [NSNumber numberWithChar:bytes[0]];
178
  return [NSDictionary dictionaryWithObjectsAndKeys:theIndex, kMKDataKeyIndex, nil];
179
}
180
 
181
- (NSDictionary *) decodeChangeSettingResponse {
182
  const char * bytes = [self bytes];
183
  NSNumber * theIndex = [NSNumber numberWithChar:bytes[0]];
184
  return [NSDictionary dictionaryWithObjectsAndKeys:theIndex, kMKDataKeyIndex, nil];
185
}
186
 
187
@end