33 encoded = latlon_in * ((double)(0x007FFFFFL) / 180.0);
34 encoded += (encoded > 0.0) ? 0.5 : -0.5;
37 out.as_long = (
long int)encoded;
39 return (out.as_compressed);
46 in.as_compressed = latlon_in;
48 if (in.as_long & 0x00800000L)
49 in.as_long |= ~0xFFFFFFL;
51 return (
double)in.as_long * (180.0 / (double)(0x007FFFFFL));
54unsigned char Encode_heading(
float heading)
56 return ((
unsigned char)(heading * 255.0 / 360.0 + 0.5));
59double Decode_heading(
unsigned char heading) {
return ((
double)heading * 360.0 / 255.0); }
65char Encode_est_velocity(
float est_velocity)
67 return ((
char)(est_velocity * 25.0 + 0.5));
70float Decode_est_velocity(
char est_velocity) {
return (est_velocity / 25.0); }
74unsigned char Encode_salinity(
float salinity)
81 output = (salinity - 20.0) * 10;
84 return ((
unsigned char)output);
88float Decode_salinity(
unsigned char sal)
92 return (((
float)sal / 10.0) + 20.0);
95unsigned short Encode_depth(
float depth)
104 return ((
short unsigned int)((depth + .05) * 1.0 / 0.1));
106 return ((
short unsigned int)(((depth - 100) + 0.1) * 1.0 / 0.2 + 1000));
108 return ((
short unsigned int)(((depth - 200) + 0.25) * 1.0 / 0.5 + 1500));
110 return ((
short unsigned int)(((depth - 1000) + 0.5) * 1.0 / 1.0 + 3100));
114float Decode_depth(
unsigned short depth)
121 unsigned short DEPTH_MODE_MASK = 0x1FFF;
122 depth &= DEPTH_MODE_MASK;
124 return (depth * 0.1 / 1.0);
125 else if (depth <= 1500)
126 return (100 + (depth - 1000) * 0.2 / 1.0);
127 else if (depth <= 3100)
128 return (200 + (depth - 1500) * 0.5 / 1.0);
129 else if (depth <= 8100)
130 return (1000 + (depth - 3100) * 1.0 / 1.0);
135unsigned char Encode_temperature(
float temperature)
137 if (temperature < -4)
140 temperature = temperature * 256.0 / 40.0 + 0.5;
141 if (temperature > 255)
143 return ((
unsigned char)temperature);
146float Decode_temperature(
unsigned char temperature) {
return (temperature * 40.0 / 256.0 - 4.0); }
148unsigned char Encode_sound_speed(
float sound_speed)
150 return ((
unsigned char)((sound_speed - 1425.0) * 2));
153float Decode_sound_speed(
unsigned char sound_speed) {
return ((
float)sound_speed / 2.0 + 1425.0); }
155unsigned short Encode_hires_altitude(
float alt)
163 return ((
unsigned short)alt);
166float Decode_hires_altitude(
unsigned short alt) {
return ((
float)alt / 100.0); }
168unsigned short Encode_gfi_pitch_oil(
float gfi,
float pitch,
float oil)
175 unsigned short result;
181 result = (
unsigned short)(gfi * 31.0 / 100.0);
187 result |= ((
unsigned short)oil << 5);
190 else if (pitch < -90)
192 pitch *= 63.0 / 180.0;
198 temp = ((short)pitch << 10);
199 result |= temp & 0xFC00;
203void Decode_gfi_pitch_oil(
unsigned short gfi_pitch_oil,
float* gfi,
float* pitch,
float* oil)
208 temp = (
unsigned int)((gfi_pitch_oil & 0x001F) * 100.0 / 31.0);
210 temp = (gfi_pitch_oil & 0x03E0) >> 5;
211 *oil = temp * 100.0 / 31.0;
212 temp_pitch = ((short)(gfi_pitch_oil & 0xFC00)) >> 10;
213 *pitch = temp_pitch * 180.0 / 63.0;
216TIME_DATE Encode_time_date(
long secs_since_1970)
230 time_t secs_since_1970_time_t(secs_since_1970);
231 tm = *gmtime(&secs_since_1970_time_t);
232 comp.as_long = (
unsigned long)tm.tm_sec >> 2;
233 comp.as_long += (
unsigned long)tm.tm_min << 4;
234 comp.as_long += (
unsigned long)tm.tm_hour << (4 + 6);
235 comp.as_long += (
unsigned long)tm.tm_mday << (4 + 6 + 5);
236 comp.as_long += (
unsigned long)(tm.tm_mon + 1) << (4 + 6 + 5 + 5);
237 return (comp.as_time_date);
240long Decode_time_date(
TIME_DATE input,
short* mon,
short* day,
short* hour,
short* min,
short* sec)
244 comp.as_time_date = input;
246 *mon = (short)((comp.as_long >> (4 + 6 + 5 + 5)) & 0x000F);
247 *day = (short)((comp.as_long >> (4 + 6 + 5)) & 0x001F);
248 *hour = (short)((comp.as_long >> (4 + 6)) & 0x001F);
249 *min = (short)((comp.as_long >> (4)) & 0x003F);
250 *sec = (short)(((comp.as_long) & 0x000F) * 4);
258unsigned char Encode_watts(
float volts,
float amps)
261 float watts = (volts * amps) / 4;
267 return ((
unsigned char)watts);
270float Decode_watts(
unsigned char watts_encoded) {
return ((
float)watts_encoded * 4.0); }
272char Encode_speed(SPEED_MODE mode,
float speed)
280 else if (speed < -127)
283 case SPEED_MODE_KNOTS:
285 case SPEED_MODE_MSEC:
289 else if (speed < -127)
294 speed += (speed > 0.0) ? 0.5 : -0.5;
296 return ((
char)speed);
299float Decode_speed(SPEED_MODE mode,
char speed)
303 case SPEED_MODE_RPM:
return (speed * 20.0);
304 case SPEED_MODE_MSEC:
return ((
float)speed / 30.0);
305 case SPEED_MODE_KNOTS:
311double DecodeRangerLL(
unsigned char c1,
unsigned char c2,
unsigned char c3,
unsigned char c4,
314 int deg100, deg10, deg1, min10, min1, minp1000, minp100, minp10, minp1, sign;
315 double fMin, fDeg, fSign, fRet;
318 deg100 = ((c1 & 0xf0) >> 4);
320 deg1 = ((c2 & 0xf0) >> 4);
321 fDeg = deg100 * 100.0 + deg10 * 10.0 + deg1 * 1.0;
325 if ((sign == 0x0c) || (sign == 0x0d))
331 min10 = ((c3 & 0xf0) >> 4);
333 minp1000 = ((c4 & 0xf0) >> 4);
335 minp10 = ((c5 & 0xf0) >> 4);
337 fMin = min10 * 10.0 + min1 * 1.0 + minp1000 * 0.1 + minp100 * 0.01 + minp10 * 0.001 +
340 fRet = (fDeg + (fMin / 60.0)) * fSign;
345double DecodeRangerBCD2(
unsigned char c1,
unsigned char c2)
347 int i1000, i100, i10, i1;
349 i1000 = ((c1 & 0xf0) >> 4);
351 i10 = ((c2 & 0xf0) >> 4);
354 return i1000 * 1000.0 + i100 * 100.0 + i10 * 10.0 + i1 * 1.0;
357double DecodeRangerBCD(
unsigned char c1)
361 i10 = ((c1 & 0xf0) >> 4);
364 return i10 * 10.0 + i1 * 1.0;