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;
200 temp = (
unsigned short)((
unsigned int)(
unsigned short)(
short)pitch << 10);
201 result |= temp & 0xFC00;
205void Decode_gfi_pitch_oil(
unsigned short gfi_pitch_oil,
float* gfi,
float* pitch,
float* oil)
210 temp = (
unsigned int)((gfi_pitch_oil & 0x001F) * 100.0 / 31.0);
212 temp = (gfi_pitch_oil & 0x03E0) >> 5;
213 *oil = temp * 100.0 / 31.0;
214 temp_pitch = ((short)(gfi_pitch_oil & 0xFC00)) >> 10;
215 *pitch = temp_pitch * 180.0 / 63.0;
218TIME_DATE Encode_time_date(
long secs_since_1970)
232 time_t secs_since_1970_time_t(secs_since_1970);
233 tm = *gmtime(&secs_since_1970_time_t);
234 comp.as_long = (
unsigned long)tm.tm_sec >> 2;
235 comp.as_long += (
unsigned long)tm.tm_min << 4;
236 comp.as_long += (
unsigned long)tm.tm_hour << (4 + 6);
237 comp.as_long += (
unsigned long)tm.tm_mday << (4 + 6 + 5);
238 comp.as_long += (
unsigned long)(tm.tm_mon + 1) << (4 + 6 + 5 + 5);
239 return (comp.as_time_date);
242long Decode_time_date(
TIME_DATE input,
short* mon,
short* day,
short* hour,
short* min,
short* sec)
246 comp.as_time_date = input;
248 *mon = (short)((comp.as_long >> (4 + 6 + 5 + 5)) & 0x000F);
249 *day = (short)((comp.as_long >> (4 + 6 + 5)) & 0x001F);
250 *hour = (short)((comp.as_long >> (4 + 6)) & 0x001F);
251 *min = (short)((comp.as_long >> (4)) & 0x003F);
252 *sec = (short)(((comp.as_long) & 0x000F) * 4);
260unsigned char Encode_watts(
float volts,
float amps)
263 float watts = (volts * amps) / 4;
269 return ((
unsigned char)watts);
272float Decode_watts(
unsigned char watts_encoded) {
return ((
float)watts_encoded * 4.0); }
274char Encode_speed(SPEED_MODE mode,
float speed)
282 else if (speed < -127)
285 case SPEED_MODE_KNOTS:
287 case SPEED_MODE_MSEC:
291 else if (speed < -127)
296 speed += (speed > 0.0) ? 0.5 : -0.5;
298 return ((
char)speed);
301float Decode_speed(SPEED_MODE mode,
char speed)
305 case SPEED_MODE_RPM:
return (speed * 20.0);
306 case SPEED_MODE_MSEC:
return ((
float)speed / 30.0);
307 case SPEED_MODE_KNOTS:
313double DecodeRangerLL(
unsigned char c1,
unsigned char c2,
unsigned char c3,
unsigned char c4,
316 int deg100, deg10, deg1, min10, min1, minp1000, minp100, minp10, minp1, sign;
317 double fMin, fDeg, fSign, fRet;
320 deg100 = ((c1 & 0xf0) >> 4);
322 deg1 = ((c2 & 0xf0) >> 4);
323 fDeg = deg100 * 100.0 + deg10 * 10.0 + deg1 * 1.0;
327 if ((sign == 0x0c) || (sign == 0x0d))
333 min10 = ((c3 & 0xf0) >> 4);
335 minp1000 = ((c4 & 0xf0) >> 4);
337 minp10 = ((c5 & 0xf0) >> 4);
339 fMin = min10 * 10.0 + min1 * 1.0 + minp1000 * 0.1 + minp100 * 0.01 + minp10 * 0.001 +
342 fRet = (fDeg + (fMin / 60.0)) * fSign;
347double DecodeRangerBCD2(
unsigned char c1,
unsigned char c2)
349 int i1000, i100, i10, i1;
351 i1000 = ((c1 & 0xf0) >> 4);
353 i10 = ((c2 & 0xf0) >> 4);
356 return i1000 * 1000.0 + i100 * 100.0 + i10 * 10.0 + i1 * 1.0;
359double DecodeRangerBCD(
unsigned char c1)
363 i10 = ((c1 & 0xf0) >> 4);
366 return i10 * 10.0 + i1 * 1.0;