File: AltosEepromRecordMotor.java

package info (click to toggle)
altos 1.9.22-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 83,712 kB
  • sloc: ansic: 120,853; java: 42,921; makefile: 8,573; sh: 4,995; xml: 2,154; pascal: 2,008
file content (103 lines) | stat: -rw-r--r-- 3,355 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Copyright © 2020 Keith Packard <keithp@keithp.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

package org.altusmetrum.altoslib_14;

public class AltosEepromRecordMotor extends AltosEepromRecord {
	public static final int	record_length = 16;

	private int log_format;

	/* AO_LOG_FLIGHT elements */
	private int flight() { return data16(0); }
	private int ground_accel() { return data16(2); }
	private int ground_accel_along() { return data16(4); }
	private int ground_accel_across() { return data16(6); }
	private int ground_accel_through() { return data16(8); }
	private int ground_motor_pressure() { return data16(10); }

	/* AO_LOG_STATE elements */
	private int state() { return data16(0); }
	private int reason() { return data16(2); }

	/* AO_LOG_SENSOR elements */
	private int motor_pres() { return data16(0); }
	private int v_batt() { return data16(2); }
	private int accel() { return data16(4); }
	private int accel_across() { return data16(6); }
	private int accel_along() { return -data16(8); }
	private int accel_through() { return data16(10); }

	private int imu_type() {
		switch (log_format) {
		case AltosLib.AO_LOG_FORMAT_EASYMOTOR:
			return AltosIMU.imu_type_easymotor_v2;
		default:
			return AltosLib.MISSING;
		}
	}

	public void provide_data(AltosDataListener listener, AltosCalData cal_data) {
		super.provide_data(listener, cal_data);

		cal_data.set_imu_type(imu_type());

		switch (cmd()) {
		case AltosLib.AO_LOG_FLIGHT:
			cal_data.set_flight(flight());
			cal_data.set_ground_accel(ground_accel());
			listener.set_accel_ground(cal_data.accel_along(ground_accel_along()),
						  cal_data.accel_across(ground_accel_across()),
						  cal_data.accel_through(ground_accel_through()));
			cal_data.set_ground_motor_pressure(ground_motor_pressure());
			break;
		case AltosLib.AO_LOG_STATE:
			listener.set_state(state());
			break;
		case AltosLib.AO_LOG_SENSOR:
			AltosConfigData config_data = eeprom.config_data();

			listener.set_battery_voltage(AltosConvert.easy_motor_3_voltage(v_batt()));
			double pa = AltosConvert.easy_motor_3_motor_pressure(motor_pres(), cal_data.ground_motor_pressure);
			listener.set_motor_pressure(pa);

			int	accel_along = accel_along();
			int	accel_across = accel_across();
			int	accel_through = accel_through();

			listener.set_accel(cal_data.accel_along(accel_along),
					   cal_data.accel_across(accel_across),
					   cal_data.accel_through(accel_through));

			listener.set_acceleration(cal_data.acceleration(accel()));
			break;
		}
	}

	public AltosEepromRecord next() {
		int	s = next_start();
		if (s < 0)
			return null;
		return new AltosEepromRecordMotor(eeprom, s);
	}

	public AltosEepromRecordMotor(AltosEeprom eeprom, int start) {
		super(eeprom, start, record_length);
		log_format = eeprom.config_data().log_format;
	}

	public AltosEepromRecordMotor(AltosEeprom eeprom) {
		this(eeprom, 0);
	}
}