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+MKPayloadEncode.h" |
||
26 | #import "MKDatatypes.h" |
||
27 | #import "MKDataConstants.h" |
||
28 | |||
29 | @implementation NSData (MKPayloadEncodeSetting) |
||
30 | |||
31 | + (NSData *) payloadForWriteSettingRequest:(NSDictionary *)theDictionary; |
||
32 | { |
||
33 | MKSetting setting; |
||
34 | setting.Kanalbelegung[ 0]=[[theDictionary objectForKey:kKeyKanalbelegung00] unsignedCharValue]; |
||
35 | setting.Kanalbelegung[ 1]=[[theDictionary objectForKey:kKeyKanalbelegung01] unsignedCharValue]; |
||
36 | setting.Kanalbelegung[ 2]=[[theDictionary objectForKey:kKeyKanalbelegung02] unsignedCharValue]; |
||
37 | setting.Kanalbelegung[ 3]=[[theDictionary objectForKey:kKeyKanalbelegung03] unsignedCharValue]; |
||
38 | setting.Kanalbelegung[ 4]=[[theDictionary objectForKey:kKeyKanalbelegung04] unsignedCharValue]; |
||
39 | setting.Kanalbelegung[ 5]=[[theDictionary objectForKey:kKeyKanalbelegung05] unsignedCharValue]; |
||
40 | setting.Kanalbelegung[ 6]=[[theDictionary objectForKey:kKeyKanalbelegung06] unsignedCharValue]; |
||
41 | setting.Kanalbelegung[ 7]=[[theDictionary objectForKey:kKeyKanalbelegung07] unsignedCharValue]; |
||
42 | setting.Kanalbelegung[ 8]=[[theDictionary objectForKey:kKeyKanalbelegung08] unsignedCharValue]; |
||
43 | setting.Kanalbelegung[ 9]=[[theDictionary objectForKey:kKeyKanalbelegung09] unsignedCharValue]; |
||
44 | setting.Kanalbelegung[10]=[[theDictionary objectForKey:kKeyKanalbelegung10] unsignedCharValue]; |
||
45 | setting.Kanalbelegung[11]=[[theDictionary objectForKey:kKeyKanalbelegung11] unsignedCharValue]; |
||
46 | |||
47 | setting.GlobalConfig=0; |
||
48 | setting.GlobalConfig|= [[theDictionary objectForKey:kKeyGlobalConfig_HOEHENREGELUNG ] boolValue]?CFG_HOEHENREGELUNG :0; |
||
49 | setting.GlobalConfig|= [[theDictionary objectForKey:kKeyGlobalConfig_HOEHEN_SCHALTER ] boolValue]?CFG_HOEHEN_SCHALTER :0; |
||
50 | setting.GlobalConfig|= [[theDictionary objectForKey:kKeyGlobalConfig_HEADING_HOLD ] boolValue]?CFG_HEADING_HOLD :0; |
||
51 | setting.GlobalConfig|= [[theDictionary objectForKey:kKeyGlobalConfig_KOMPASS_AKTIV ] boolValue]?CFG_KOMPASS_AKTIV :0; |
||
52 | setting.GlobalConfig|= [[theDictionary objectForKey:kKeyGlobalConfig_KOMPASS_FIX ] boolValue]?CFG_KOMPASS_FIX :0; |
||
53 | setting.GlobalConfig|= [[theDictionary objectForKey:kKeyGlobalConfig_GPS_AKTIV ] boolValue]?CFG_GPS_AKTIV :0; |
||
54 | setting.GlobalConfig|= [[theDictionary objectForKey:kKeyGlobalConfig_ACHSENKOPPLUNG_AKTIV] boolValue]?CFG_ACHSENKOPPLUNG_AKTIV:0; |
||
55 | setting.GlobalConfig|= [[theDictionary objectForKey:kKeyGlobalConfig_DREHRATEN_BEGRENZER ] boolValue]?CFG_DREHRATEN_BEGRENZER :0; |
||
56 | |||
57 | setting.Hoehe_MinGas=[[theDictionary objectForKey:kKeyHoehe_MinGas ] unsignedCharValue]; |
||
58 | setting.Luftdruck_D=[[theDictionary objectForKey:kKeyLuftdruck_D ] unsignedCharValue]; |
||
59 | setting.MaxHoehe=[[theDictionary objectForKey:kKeyMaxHoehe ] unsignedCharValue]; |
||
60 | setting.Hoehe_P=[[theDictionary objectForKey:kKeyHoehe_P ] unsignedCharValue]; |
||
61 | setting.Hoehe_Verstaerkung=[[theDictionary objectForKey:kKeyHoehe_Verstaerkung ] unsignedCharValue]; |
||
62 | setting.Hoehe_ACC_Wirkung=[[theDictionary objectForKey:kKeyHoehe_ACC_Wirkung ] unsignedCharValue]; |
||
63 | setting.Hoehe_HoverBand=[[theDictionary objectForKey:kKeyHoehe_HoverBand ] unsignedCharValue]; |
||
64 | setting.Hoehe_GPS_Z=[[theDictionary objectForKey:kKeyHoehe_GPS_Z ] unsignedCharValue]; |
||
65 | setting.Hoehe_StickNeutralPoint=[[theDictionary objectForKey:kKeyHoehe_StickNeutralPoint ] unsignedCharValue]; |
||
66 | setting.Stick_P=[[theDictionary objectForKey:kKeyStick_P ] unsignedCharValue]; |
||
67 | setting.Stick_D=[[theDictionary objectForKey:kKeyStick_D ] unsignedCharValue]; |
||
68 | setting.Gier_P=[[theDictionary objectForKey:kKeyGier_P ] unsignedCharValue]; |
||
69 | setting.Gas_Min=[[theDictionary objectForKey:kKeyGas_Min ] unsignedCharValue]; |
||
70 | setting.Gas_Max=[[theDictionary objectForKey:kKeyGas_Max ] unsignedCharValue]; |
||
71 | setting.GyroAccFaktor=[[theDictionary objectForKey:kKeyGyroAccFaktor ] unsignedCharValue]; |
||
72 | setting.KompassWirkung=[[theDictionary objectForKey:kKeyKompassWirkung ] unsignedCharValue]; |
||
73 | setting.Gyro_P=[[theDictionary objectForKey:kKeyGyro_P ] unsignedCharValue]; |
||
74 | setting.Gyro_I=[[theDictionary objectForKey:kKeyGyro_I ] unsignedCharValue]; |
||
75 | setting.Gyro_D=[[theDictionary objectForKey:kKeyGyro_D ] unsignedCharValue]; |
||
76 | setting.Gyro_Gier_P=[[theDictionary objectForKey:kKeyGyro_Gier_P ] unsignedCharValue]; |
||
77 | setting.Gyro_Gier_I=[[theDictionary objectForKey:kKeyGyro_Gier_I ] unsignedCharValue]; |
||
78 | setting.UnterspannungsWarnung=[[theDictionary objectForKey:kKeyUnterspannungsWarnung ] unsignedCharValue]; |
||
79 | setting.NotGas=[[theDictionary objectForKey:kKeyNotGas ] unsignedCharValue]; |
||
80 | setting.NotGasZeit=[[theDictionary objectForKey:kKeyNotGasZeit ] unsignedCharValue]; |
||
81 | setting.Receiver=[[theDictionary objectForKey:kKeyReceiver ] unsignedCharValue]; |
||
82 | setting.I_Faktor=[[theDictionary objectForKey:kKeyI_Faktor ] unsignedCharValue]; |
||
83 | setting.UserParam1=[[theDictionary objectForKey:kKeyUserParam1 ] unsignedCharValue]; |
||
84 | setting.UserParam2=[[theDictionary objectForKey:kKeyUserParam2 ] unsignedCharValue]; |
||
85 | setting.UserParam3=[[theDictionary objectForKey:kKeyUserParam3 ] unsignedCharValue]; |
||
86 | setting.UserParam4=[[theDictionary objectForKey:kKeyUserParam4 ] unsignedCharValue]; |
||
87 | setting.ServoNickControl=[[theDictionary objectForKey:kKeyServoNickControl ] unsignedCharValue]; |
||
88 | setting.ServoNickComp=[[theDictionary objectForKey:kKeyServoNickComp ] unsignedCharValue]; |
||
89 | setting.ServoNickMin=[[theDictionary objectForKey:kKeyServoNickMin ] unsignedCharValue]; |
||
90 | setting.ServoNickMax=[[theDictionary objectForKey:kKeyServoNickMax ] unsignedCharValue]; |
||
91 | setting.ServoRollControl=[[theDictionary objectForKey:kKeyServoRollControl ] unsignedCharValue]; |
||
92 | setting.ServoRollComp=[[theDictionary objectForKey:kKeyServoRollComp ] unsignedCharValue]; |
||
93 | setting.ServoRollMin=[[theDictionary objectForKey:kKeyServoRollMin ] unsignedCharValue]; |
||
94 | setting.ServoRollMax=[[theDictionary objectForKey:kKeyServoRollMax ] unsignedCharValue]; |
||
95 | setting.ServoNickRefresh=[[theDictionary objectForKey:kKeyServoNickRefresh ] unsignedCharValue]; |
||
96 | setting.Servo3=[[theDictionary objectForKey:kKeyServo3 ] unsignedCharValue]; |
||
97 | setting.Servo4=[[theDictionary objectForKey:kKeyServo4 ] unsignedCharValue]; |
||
98 | setting.Servo5=[[theDictionary objectForKey:kKeyServo5 ] unsignedCharValue]; |
||
99 | setting.LoopGasLimit=[[theDictionary objectForKey:kKeyLoopGasLimit ] unsignedCharValue]; |
||
100 | setting.LoopThreshold=[[theDictionary objectForKey:kKeyLoopThreshold ] unsignedCharValue]; |
||
101 | setting.LoopHysterese=[[theDictionary objectForKey:kKeyLoopHysterese ] unsignedCharValue]; |
||
102 | setting.AchsKopplung1=[[theDictionary objectForKey:kKeyAchsKopplung1 ] unsignedCharValue]; |
||
103 | setting.AchsKopplung2=[[theDictionary objectForKey:kKeyAchsKopplung2 ] unsignedCharValue]; |
||
104 | setting.CouplingYawCorrection=[[theDictionary objectForKey:kKeyCouplingYawCorrection ] unsignedCharValue]; |
||
105 | setting.WinkelUmschlagNick=[[theDictionary objectForKey:kKeyWinkelUmschlagNick ] unsignedCharValue]; |
||
106 | setting.WinkelUmschlagRoll=[[theDictionary objectForKey:kKeyWinkelUmschlagRoll ] unsignedCharValue]; |
||
107 | setting.GyroAccAbgleich=[[theDictionary objectForKey:kKeyGyroAccAbgleich ] unsignedCharValue]; |
||
108 | setting.Driftkomp=[[theDictionary objectForKey:kKeyDriftkomp ] unsignedCharValue]; |
||
109 | setting.DynamicStability=[[theDictionary objectForKey:kKeyDynamicStability ] unsignedCharValue]; |
||
110 | setting.UserParam5=[[theDictionary objectForKey:kKeyUserParam5 ] unsignedCharValue]; |
||
111 | setting.UserParam6=[[theDictionary objectForKey:kKeyUserParam6 ] unsignedCharValue]; |
||
112 | setting.UserParam7=[[theDictionary objectForKey:kKeyUserParam7 ] unsignedCharValue]; |
||
113 | setting.UserParam8=[[theDictionary objectForKey:kKeyUserParam8 ] unsignedCharValue]; |
||
114 | setting.J16Bitmask=[[theDictionary objectForKey:kKeyJ16Bitmask ] unsignedCharValue]; |
||
115 | setting.J16Timing=[[theDictionary objectForKey:kKeyJ16Timing ] unsignedCharValue]; |
||
116 | setting.J17Bitmask=[[theDictionary objectForKey:kKeyJ17Bitmask ] unsignedCharValue]; |
||
117 | setting.J17Timing=[[theDictionary objectForKey:kKeyJ17Timing ] unsignedCharValue]; |
||
118 | setting.WARN_J16_Bitmask=[[theDictionary objectForKey:kKeyWARN_J16_Bitmask ] unsignedCharValue]; |
||
119 | setting.WARN_J17_Bitmask=[[theDictionary objectForKey:kKeyWARN_J17_Bitmask ] unsignedCharValue]; |
||
120 | setting.NaviGpsModeControl=[[theDictionary objectForKey:kKeyNaviGpsModeControl ] unsignedCharValue]; |
||
121 | setting.NaviGpsGain=[[theDictionary objectForKey:kKeyNaviGpsGain ] unsignedCharValue]; |
||
122 | setting.NaviGpsP=[[theDictionary objectForKey:kKeyNaviGpsP ] unsignedCharValue]; |
||
123 | setting.NaviGpsI=[[theDictionary objectForKey:kKeyNaviGpsI ] unsignedCharValue]; |
||
124 | setting.NaviGpsD=[[theDictionary objectForKey:kKeyNaviGpsD ] unsignedCharValue]; |
||
125 | setting.NaviGpsPLimit=[[theDictionary objectForKey:kKeyNaviGpsPLimit ] unsignedCharValue]; |
||
126 | setting.NaviGpsILimit=[[theDictionary objectForKey:kKeyNaviGpsILimit ] unsignedCharValue]; |
||
127 | setting.NaviGpsDLimit=[[theDictionary objectForKey:kKeyNaviGpsDLimit ] unsignedCharValue]; |
||
128 | setting.NaviGpsACC=[[theDictionary objectForKey:kKeyNaviGpsACC ] unsignedCharValue]; |
||
129 | setting.NaviGpsMinSat=[[theDictionary objectForKey:kKeyNaviGpsMinSat ] unsignedCharValue]; |
||
130 | setting.NaviStickThreshold=[[theDictionary objectForKey:kKeyNaviStickThreshold ] unsignedCharValue]; |
||
131 | setting.NaviWindCorrection=[[theDictionary objectForKey:kKeyNaviWindCorrection ] unsignedCharValue]; |
||
132 | setting.NaviSpeedCompensation=[[theDictionary objectForKey:kKeyNaviSpeedCompensation ] unsignedCharValue]; |
||
133 | setting.NaviOperatingRadius=[[theDictionary objectForKey:kKeyNaviOperatingRadius ] unsignedCharValue]; |
||
134 | setting.NaviAngleLimitation=[[theDictionary objectForKey:kKeyNaviAngleLimitation ] unsignedCharValue]; |
||
135 | setting.NaviPH_LoginTime=[[theDictionary objectForKey:kKeyNaviPH_LoginTime ] unsignedCharValue]; |
||
136 | setting.ExternalControl=[[theDictionary objectForKey:kKeyExternalControl ] unsignedCharValue]; |
||
137 | |||
138 | setting.BitConfig=0; |
||
139 | setting.BitConfig|= [[theDictionary objectForKey:kKeyBitConfig_LOOP_UP ] boolValue]?CFG_LOOP_OBEN :0; |
||
140 | setting.BitConfig|= [[theDictionary objectForKey:kKeyBitConfig_LOOP_DOWN ] boolValue]?CFG_LOOP_UNTEN :0; |
||
141 | setting.BitConfig|= [[theDictionary objectForKey:kKeyBitConfig_LOOP_LEFT ] boolValue]?CFG_LOOP_LINKS :0; |
||
142 | setting.BitConfig|= [[theDictionary objectForKey:kKeyBitConfig_LOOP_RIGHT ] boolValue]?CFG_LOOP_RECHTS :0; |
||
143 | setting.BitConfig|= [[theDictionary objectForKey:kKeyBitConfig_MOTOR_BLINK ] boolValue]?CFG_MOTOR_BLINK :0; |
||
144 | setting.BitConfig|= [[theDictionary objectForKey:kKeyBitConfig_MOTOR_OFF_LED1] boolValue]?CFG_MOTOR_OFF_LED1:0; |
||
145 | setting.BitConfig|= [[theDictionary objectForKey:kKeyBitConfig_MOTOR_OFF_LED2] boolValue]?CFG_MOTOR_OFF_LED2:0; |
||
146 | |||
147 | setting.ServoCompInvert=0; |
||
148 | setting.ServoCompInvert|= [[theDictionary objectForKey:kKeyServoCompInvert_Nick] boolValue]?CFG2_INVERT_NICK:0; |
||
149 | setting.ServoCompInvert|= [[theDictionary objectForKey:kKeyServoCompInvert_ROLL] boolValue]?CFG2_INVERT_ROLL:0; |
||
150 | |||
151 | setting.ExtraConfig=0; |
||
152 | setting.ExtraConfig|= [[theDictionary objectForKey:kKeyExtraConfig_HEIGHT_LIMIT] boolValue]?CFG2_HEIGHT_LIMIT:0; |
||
153 | setting.ExtraConfig|= [[theDictionary objectForKey:kKeyExtraConfig_VARIO_BEEP ] boolValue]?CFG2_VARIO_BEEP :0; |
||
154 | setting.ExtraConfig|= [[theDictionary objectForKey:kKeyExtraConfig_SENSITIVE_RC] boolValue]?CFG_SENSITIVE_RC :0; |
||
155 | |||
156 | NSString* name=[theDictionary objectForKey:kKeyName]; |
||
157 | |||
158 | memset(setting.Name, 0, 12); |
||
159 | |||
160 | [name getBytes:(void*)setting.Name |
||
161 | maxLength:12 |
||
162 | usedLength:NULL |
||
163 | encoding:NSASCIIStringEncoding |
||
164 | options:0 |
||
165 | range:NSMakeRange(0,[name length]) |
||
166 | remainingRange:NULL]; |
||
167 | |||
168 | |||
169 | unsigned char payloadData[sizeof(MKSetting)+2]; |
||
170 | |||
171 | payloadData[0]=[[theDictionary objectForKey:kMKDataKeyIndex] unsignedCharValue]; |
||
172 | payloadData[1]=[[theDictionary objectForKey:kMKDataKeyVersion] unsignedCharValue]; |
||
173 | |||
174 | memcpy((unsigned char *)(payloadData + 2),(unsigned char *)&setting,sizeof(MKSetting)); |
||
175 | |||
176 | return [NSData dataWithBytes:payloadData length:sizeof(payloadData)]; |
||
177 | } |
||
178 | |||
179 | @end |