diff --git a/firmware/config/engines/mazda_miata_1_6.cpp b/firmware/config/engines/mazda_miata_1_6.cpp
index 9a545ea134..cf6371d392 100644
--- a/firmware/config/engines/mazda_miata_1_6.cpp
+++ b/firmware/config/engines/mazda_miata_1_6.cpp
@@ -55,12 +55,74 @@ static const float hardCodedveTable[16][16] = {
};
/* Generated by TS2C on Sun Aug 02 10:02:25 EDT 2020*/
-static void setVeTable(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
+static void setMapVeTable(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
MEMCPY(config->veLoadBins, hardCodedveLoadBins);
MEMCPY(config->veRpmBins, hardCodedveRpmBins);
MEMCPY(config->veTable, hardCodedveTable);
}
+static const float hardCodedVafveLoadBins[16] = {10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 120.0, 140.0, 160.0, 180.0, 210.0, 240.0};
+
+static const float hardCodedVafveRpmBins[16] = {650.0, 950.0, 1250.0, 1600.0, 1950.0, 2350.0, 2750.0, 3200.0, 3700.0, 4200.0, 4700.0, 5200.0, 5800.0, 6400.0, 7100.0, 7800.0};
+
+static const float hardCodedVafveTable[16][16] = {
+/* Generated by TS2C on Tue Aug 11 21:13:28 EDT 2020*/
+{/* 0 10.000 *//* 0 650.0*/94.016, /* 1 950.0*/93.954, /* 2 1250.0*/95.236, /* 3 1600.0*/90.000, /* 4 1950.0*/90.000, /* 5 2350.0*/90.000, /* 6 2750.0*/90.000, /* 7 3200.0*/90.000, /* 8 3700.0*/90.000, /* 9 4200.0*/90.000, /* 10 4700.0*/90.000, /* 11 5200.0*/90.000, /* 12 5800.0*/100.000, /* 13 6400.0*/100.000, /* 14 7100.0*/100.000, /* 15 7800.0*/100.000, },
+{/* 1 20.000 *//* 0 650.0*/94.252, /* 1 950.0*/97.953, /* 2 1250.0*/97.464, /* 3 1600.0*/93.974, /* 4 1950.0*/92.828, /* 5 2350.0*/90.537, /* 6 2750.0*/92.175, /* 7 3200.0*/95.727, /* 8 3700.0*/93.761, /* 9 4200.0*/93.135, /* 10 4700.0*/95.107, /* 11 5200.0*/97.489, /* 12 5800.0*/103.177, /* 13 6400.0*/104.594, /* 14 7100.0*/99.771, /* 15 7800.0*/100.000, },
+{/* 2 30.000 *//* 0 650.0*/93.629, /* 1 950.0*/93.688, /* 2 1250.0*/96.133, /* 3 1600.0*/97.065, /* 4 1950.0*/97.139, /* 5 2350.0*/94.842, /* 6 2750.0*/92.312, /* 7 3200.0*/94.436, /* 8 3700.0*/92.063, /* 9 4200.0*/92.249, /* 10 4700.0*/98.657, /* 11 5200.0*/101.718, /* 12 5800.0*/103.337, /* 13 6400.0*/103.717, /* 14 7100.0*/99.317, /* 15 7800.0*/100.000, },
+{/* 3 40.000 *//* 0 650.0*/100.501, /* 1 950.0*/97.962, /* 2 1250.0*/99.009, /* 3 1600.0*/97.556, /* 4 1950.0*/94.598, /* 5 2350.0*/91.408, /* 6 2750.0*/91.921, /* 7 3200.0*/93.813, /* 8 3700.0*/92.850, /* 9 4200.0*/91.802, /* 10 4700.0*/94.952, /* 11 5200.0*/99.911, /* 12 5800.0*/104.543, /* 13 6400.0*/104.758, /* 14 7100.0*/100.000, /* 15 7800.0*/100.000, },
+{/* 4 50.000 *//* 0 650.0*/101.737, /* 1 950.0*/97.028, /* 2 1250.0*/98.010, /* 3 1600.0*/94.714, /* 4 1950.0*/92.342, /* 5 2350.0*/93.533, /* 6 2750.0*/94.615, /* 7 3200.0*/95.763, /* 8 3700.0*/94.563, /* 9 4200.0*/93.040, /* 10 4700.0*/94.561, /* 11 5200.0*/100.756, /* 12 5800.0*/104.128, /* 13 6400.0*/104.572, /* 14 7100.0*/100.000, /* 15 7800.0*/100.000, },
+{/* 5 60.000 *//* 0 650.0*/102.922, /* 1 950.0*/100.975, /* 2 1250.0*/97.825, /* 3 1600.0*/95.090, /* 4 1950.0*/95.527, /* 5 2350.0*/94.089, /* 6 2750.0*/93.743, /* 7 3200.0*/95.578, /* 8 3700.0*/96.213, /* 9 4200.0*/95.254, /* 10 4700.0*/95.956, /* 11 5200.0*/101.235, /* 12 5800.0*/103.827, /* 13 6400.0*/104.644, /* 14 7100.0*/100.000, /* 15 7800.0*/100.000, },
+{/* 6 70.000 *//* 0 650.0*/104.127, /* 1 950.0*/103.686, /* 2 1250.0*/99.314, /* 3 1600.0*/97.568, /* 4 1950.0*/97.018, /* 5 2350.0*/94.230, /* 6 2750.0*/94.440, /* 7 3200.0*/95.486, /* 8 3700.0*/95.658, /* 9 4200.0*/97.501, /* 10 4700.0*/97.398, /* 11 5200.0*/99.068, /* 12 5800.0*/101.898, /* 13 6400.0*/104.591, /* 14 7100.0*/99.949, /* 15 7800.0*/100.000, },
+{/* 7 80.000 *//* 0 650.0*/104.298, /* 1 950.0*/104.159, /* 2 1250.0*/101.911, /* 3 1600.0*/99.695, /* 4 1950.0*/97.075, /* 5 2350.0*/94.926, /* 6 2750.0*/94.845, /* 7 3200.0*/94.111, /* 8 3700.0*/93.594, /* 9 4200.0*/95.821, /* 10 4700.0*/97.757, /* 11 5200.0*/99.181, /* 12 5800.0*/102.013, /* 13 6400.0*/104.072, /* 14 7100.0*/99.417, /* 15 7800.0*/100.000, },
+{/* 8 90.000 *//* 0 650.0*/105.000, /* 1 950.0*/103.823, /* 2 1250.0*/103.648, /* 3 1600.0*/100.150, /* 4 1950.0*/97.824, /* 5 2350.0*/96.431, /* 6 2750.0*/95.481, /* 7 3200.0*/94.151, /* 8 3700.0*/90.334, /* 9 4200.0*/92.140, /* 10 4700.0*/95.487, /* 11 5200.0*/99.686, /* 12 5800.0*/103.082, /* 13 6400.0*/104.592, /* 14 7100.0*/99.531, /* 15 7800.0*/100.000, },
+{/* 9 100.000 *//* 0 650.0*/105.000, /* 1 950.0*/103.188, /* 2 1250.0*/103.291, /* 3 1600.0*/103.080, /* 4 1950.0*/98.700, /* 5 2350.0*/99.850, /* 6 2750.0*/98.309, /* 7 3200.0*/92.768, /* 8 3700.0*/88.657, /* 9 4200.0*/89.541, /* 10 4700.0*/94.960, /* 11 5200.0*/100.362, /* 12 5800.0*/103.777, /* 13 6400.0*/104.583, /* 14 7100.0*/100.006, /* 15 7800.0*/100.000, },
+{/* 10 120.000 *//* 0 650.0*/105.000, /* 1 950.0*/104.711, /* 2 1250.0*/104.571, /* 3 1600.0*/104.130, /* 4 1950.0*/104.417, /* 5 2350.0*/105.597, /* 6 2750.0*/103.658, /* 7 3200.0*/97.445, /* 8 3700.0*/92.979, /* 9 4200.0*/93.606, /* 10 4700.0*/100.061, /* 11 5200.0*/103.715, /* 12 5800.0*/104.756, /* 13 6400.0*/104.908, /* 14 7100.0*/100.000, /* 15 7800.0*/100.000, },
+{/* 11 140.000 *//* 0 650.0*/100.000, /* 1 950.0*/100.000, /* 2 1250.0*/100.000, /* 3 1600.0*/100.000, /* 4 1950.0*/100.000, /* 5 2350.0*/100.000, /* 6 2750.0*/100.000, /* 7 3200.0*/102.931, /* 8 3700.0*/102.446, /* 9 4200.0*/100.000, /* 10 4700.0*/100.000, /* 11 5200.0*/100.000, /* 12 5800.0*/100.000, /* 13 6400.0*/100.000, /* 14 7100.0*/100.000, /* 15 7800.0*/100.000, },
+{/* 12 160.000 *//* 0 650.0*/100.000, /* 1 950.0*/100.000, /* 2 1250.0*/100.000, /* 3 1600.0*/100.000, /* 4 1950.0*/100.000, /* 5 2350.0*/100.000, /* 6 2750.0*/100.000, /* 7 3200.0*/101.509, /* 8 3700.0*/101.252, /* 9 4200.0*/100.000, /* 10 4700.0*/100.000, /* 11 5200.0*/100.000, /* 12 5800.0*/100.000, /* 13 6400.0*/100.000, /* 14 7100.0*/100.000, /* 15 7800.0*/100.000, },
+{/* 13 180.000 *//* 0 650.0*/100.000, /* 1 950.0*/100.000, /* 2 1250.0*/100.000, /* 3 1600.0*/100.000, /* 4 1950.0*/100.000, /* 5 2350.0*/100.000, /* 6 2750.0*/100.000, /* 7 3200.0*/100.000, /* 8 3700.0*/100.000, /* 9 4200.0*/100.000, /* 10 4700.0*/100.000, /* 11 5200.0*/100.000, /* 12 5800.0*/100.000, /* 13 6400.0*/100.000, /* 14 7100.0*/100.000, /* 15 7800.0*/100.000, },
+{/* 14 210.000 *//* 0 650.0*/100.000, /* 1 950.0*/100.000, /* 2 1250.0*/100.000, /* 3 1600.0*/100.000, /* 4 1950.0*/100.000, /* 5 2350.0*/100.000, /* 6 2750.0*/100.000, /* 7 3200.0*/100.000, /* 8 3700.0*/100.000, /* 9 4200.0*/100.000, /* 10 4700.0*/100.000, /* 11 5200.0*/100.000, /* 12 5800.0*/100.000, /* 13 6400.0*/100.000, /* 14 7100.0*/100.000, /* 15 7800.0*/100.000, },
+{/* 15 240.000 *//* 0 650.0*/100.000, /* 1 950.0*/100.000, /* 2 1250.0*/100.000, /* 3 1600.0*/100.000, /* 4 1950.0*/100.000, /* 5 2350.0*/100.000, /* 6 2750.0*/100.000, /* 7 3200.0*/100.000, /* 8 3700.0*/100.000, /* 9 4200.0*/100.000, /* 10 4700.0*/100.000, /* 11 5200.0*/100.000, /* 12 5800.0*/100.000, /* 13 6400.0*/100.000, /* 14 7100.0*/100.000, /* 15 7800.0*/100.000, },
+};
+
+/* Generated by TS2C on Tue Aug 11 21:13:28 EDT 2020*/
+static void setVafVeTable(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
+ MEMCPY(config->veLoadBins, hardCodedVafveLoadBins);
+ MEMCPY(config->veRpmBins, hardCodedVafveRpmBins);
+ MEMCPY(config->veTable, hardCodedVafveTable);
+}
+
+static const float hardCodedVafignitionLoadBins[16] = {10.0, 16.0, 21.0, 26.0, 32.0, 39.0, 47.0, 56.0, 66.0, 77.0, 89.0, 101.0, 113.0, 125.0, 137.0, 149.0};
+
+static const float hardCodedVafignitionRpmBins[16] = {500.0, 900.0, 1200.0, 1500.0, 1800.0, 2300.0, 2900.0, 3400.0, 3900.0, 4300.0, 4800.0, 5300.0, 5900.0, 6500.0, 7200.0, 8000.0};
+
+static const float hardCodedVafignitionTable[16][16] = {
+/* Generated by TS2C on Tue Aug 11 21:13:28 EDT 2020*/
+{/* 0 10.000 *//* 0 500.0*/15.000, /* 1 900.0*/7.000, /* 2 1200.0*/14.300, /* 3 1500.0*/23.160, /* 4 1800.0*/31.500, /* 5 2300.0*/34.400, /* 6 2900.0*/35.300, /* 7 3400.0*/36.300, /* 8 3900.0*/37.300, /* 9 4300.0*/37.600, /* 10 4800.0*/38.000, /* 11 5300.0*/38.100, /* 12 5900.0*/38.800, /* 13 6500.0*/39.500, /* 14 7200.0*/40.300, /* 15 8000.0*/41.000, },
+{/* 1 16.000 *//* 0 500.0*/15.000, /* 1 900.0*/7.000, /* 2 1200.0*/14.070, /* 3 1500.0*/23.580, /* 4 1800.0*/31.500, /* 5 2300.0*/34.400, /* 6 2900.0*/35.300, /* 7 3400.0*/36.300, /* 8 3900.0*/37.300, /* 9 4300.0*/37.600, /* 10 4800.0*/38.000, /* 11 5300.0*/38.100, /* 12 5900.0*/38.800, /* 13 6500.0*/39.500, /* 14 7200.0*/40.300, /* 15 8000.0*/41.000, },
+{/* 2 21.000 *//* 0 500.0*/15.000, /* 1 900.0*/7.000, /* 2 1200.0*/13.970, /* 3 1500.0*/23.640, /* 4 1800.0*/31.297, /* 5 2300.0*/34.086, /* 6 2900.0*/34.955, /* 7 3400.0*/35.894, /* 8 3900.0*/36.826, /* 9 4300.0*/37.126, /* 10 4800.0*/37.526, /* 11 5300.0*/37.634, /* 12 5900.0*/38.334, /* 13 6500.0*/39.042, /* 14 7200.0*/39.849, /* 15 8000.0*/40.541, },
+{/* 3 26.000 *//* 0 500.0*/15.000, /* 1 900.0*/7.000, /* 2 1200.0*/14.370, /* 3 1500.0*/23.800, /* 4 1800.0*/31.095, /* 5 2300.0*/33.772, /* 6 2900.0*/34.610, /* 7 3400.0*/35.488, /* 8 3900.0*/36.353, /* 9 4300.0*/36.653, /* 10 4800.0*/37.053, /* 11 5300.0*/37.167, /* 12 5900.0*/37.868, /* 13 6500.0*/38.583, /* 14 7200.0*/39.398, /* 15 8000.0*/40.082, },
+{/* 4 32.000 *//* 0 500.0*/15.000, /* 1 900.0*/7.000, /* 2 1200.0*/15.180, /* 3 1500.0*/24.100, /* 4 1800.0*/30.852, /* 5 2300.0*/33.396, /* 6 2900.0*/34.196, /* 7 3400.0*/35.001, /* 8 3900.0*/35.784, /* 9 4300.0*/36.084, /* 10 4800.0*/36.484, /* 11 5300.0*/36.608, /* 12 5900.0*/37.308, /* 13 6500.0*/38.032, /* 14 7200.0*/38.856, /* 15 8000.0*/39.531, },
+{/* 5 39.000 *//* 0 500.0*/15.000, /* 1 900.0*/7.000, /* 2 1200.0*/16.040, /* 3 1500.0*/24.400, /* 4 1800.0*/30.568, /* 5 2300.0*/32.956, /* 6 2900.0*/33.712, /* 7 3400.0*/34.432, /* 8 3900.0*/35.121, /* 9 4300.0*/35.421, /* 10 4800.0*/35.821, /* 11 5300.0*/35.956, /* 12 5900.0*/36.656, /* 13 6500.0*/37.390, /* 14 7200.0*/38.225, /* 15 8000.0*/38.889, },
+{/* 6 47.000 *//* 0 500.0*/15.000, /* 1 900.0*/7.000, /* 2 1200.0*/17.250, /* 3 1500.0*/24.550, /* 4 1800.0*/30.244, /* 5 2300.0*/32.454, /* 6 2900.0*/33.160, /* 7 3400.0*/33.783, /* 8 3900.0*/34.363, /* 9 4300.0*/34.663, /* 10 4800.0*/35.063, /* 11 5300.0*/35.210, /* 12 5900.0*/35.910, /* 13 6500.0*/36.656, /* 14 7200.0*/37.503, /* 15 8000.0*/38.154, },
+{/* 7 56.000 *//* 0 500.0*/16.000, /* 1 900.0*/8.000, /* 2 1200.0*/18.670, /* 3 1500.0*/24.640, /* 4 1800.0*/29.879, /* 5 2300.0*/31.889, /* 6 2900.0*/32.539, /* 7 3400.0*/33.052, /* 8 3900.0*/33.511, /* 9 4300.0*/33.811, /* 10 4800.0*/34.210, /* 11 5300.0*/34.371, /* 12 5900.0*/35.071, /* 13 6500.0*/35.831, /* 14 7200.0*/36.691, /* 15 8000.0*/37.328, },
+{/* 8 66.000 *//* 0 500.0*/17.300, /* 1 900.0*/9.300, /* 2 1200.0*/20.020, /* 3 1500.0*/24.820, /* 4 1800.0*/29.474, /* 5 2300.0*/31.261, /* 6 2900.0*/31.849, /* 7 3400.0*/32.240, /* 8 3900.0*/32.563, /* 9 4300.0*/32.863, /* 10 4800.0*/33.263, /* 11 5300.0*/33.438, /* 12 5900.0*/34.138, /* 13 6500.0*/34.914, /* 14 7200.0*/35.789, /* 15 8000.0*/36.410, },
+{/* 9 77.000 *//* 0 500.0*/18.400, /* 1 900.0*/13.290, /* 2 1200.0*/21.780, /* 3 1500.0*/25.230, /* 4 1800.0*/29.028, /* 5 2300.0*/30.570, /* 6 2900.0*/31.090, /* 7 3400.0*/31.347, /* 8 3900.0*/31.521, /* 9 4300.0*/31.821, /* 10 4800.0*/32.221, /* 11 5300.0*/32.413, /* 12 5900.0*/33.113, /* 13 6500.0*/33.904, /* 14 7200.0*/34.796, /* 15 8000.0*/35.400, },
+{/* 10 89.000 *//* 0 500.0*/19.300, /* 1 900.0*/16.450, /* 2 1200.0*/23.070, /* 3 1500.0*/25.560, /* 4 1800.0*/28.542, /* 5 2300.0*/29.817, /* 6 2900.0*/30.261, /* 7 3400.0*/30.372, /* 8 3900.0*/30.384, /* 9 4300.0*/30.684, /* 10 4800.0*/31.084, /* 11 5300.0*/31.294, /* 12 5900.0*/31.994, /* 13 6500.0*/32.804, /* 14 7200.0*/33.713, /* 15 8000.0*/34.298, },
+{/* 11 101.000 *//* 0 500.0*/19.400, /* 1 900.0*/20.420, /* 2 1200.0*/23.650, /* 3 1500.0*/25.710, /* 4 1800.0*/28.055, /* 5 2300.0*/29.063, /* 6 2900.0*/29.433, /* 7 3400.0*/29.398, /* 8 3900.0*/29.247, /* 9 4300.0*/29.547, /* 10 4800.0*/29.947, /* 11 5300.0*/30.175, /* 12 5900.0*/30.875, /* 13 6500.0*/31.703, /* 14 7200.0*/32.631, /* 15 8000.0*/33.197, },
+{/* 12 113.000 *//* 0 500.0*/19.000, /* 1 900.0*/21.560, /* 2 1200.0*/23.900, /* 3 1500.0*/25.600, /* 4 1800.0*/27.569, /* 5 2300.0*/28.310, /* 6 2900.0*/28.605, /* 7 3400.0*/28.423, /* 8 3900.0*/28.111, /* 9 4300.0*/28.411, /* 10 4800.0*/28.811, /* 11 5300.0*/29.056, /* 12 5900.0*/29.756, /* 13 6500.0*/30.602, /* 14 7200.0*/31.548, /* 15 8000.0*/32.095, },
+{/* 13 125.000 *//* 0 500.0*/19.000, /* 1 900.0*/21.390, /* 2 1200.0*/23.370, /* 3 1500.0*/25.340, /* 4 1800.0*/27.083, /* 5 2300.0*/27.557, /* 6 2900.0*/27.777, /* 7 3400.0*/27.449, /* 8 3900.0*/26.974, /* 9 4300.0*/27.274, /* 10 4800.0*/27.674, /* 11 5300.0*/27.938, /* 12 5900.0*/28.638, /* 13 6500.0*/29.501, /* 14 7200.0*/30.465, /* 15 8000.0*/30.993, },
+{/* 14 137.000 *//* 0 500.0*/18.000, /* 1 900.0*/20.920, /* 2 1200.0*/23.420, /* 3 1500.0*/24.970, /* 4 1800.0*/26.596, /* 5 2300.0*/26.803, /* 6 2900.0*/26.948, /* 7 3400.0*/26.474, /* 8 3900.0*/25.837, /* 9 4300.0*/26.137, /* 10 4800.0*/26.537, /* 11 5300.0*/26.819, /* 12 5900.0*/27.519, /* 13 6500.0*/28.401, /* 14 7200.0*/29.383, /* 15 8000.0*/29.892, },
+{/* 15 149.000 *//* 0 500.0*/16.800, /* 1 900.0*/20.150, /* 2 1200.0*/22.920, /* 3 1500.0*/24.390, /* 4 1800.0*/26.110, /* 5 2300.0*/26.050, /* 6 2900.0*/26.120, /* 7 3400.0*/25.500, /* 8 3900.0*/24.700, /* 9 4300.0*/25.000, /* 10 4800.0*/25.400, /* 11 5300.0*/25.700, /* 12 5900.0*/26.400, /* 13 6500.0*/27.300, /* 14 7200.0*/28.300, /* 15 8000.0*/28.790, },
+};
+
+/* Generated by TS2C on Tue Aug 11 21:13:28 EDT 2020*/
+static void setVafIgnitionTable(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
+ MEMCPY(config->ignitionLoadBins, hardCodedVafignitionLoadBins);
+ MEMCPY(config->ignitionRpmBins, hardCodedVafignitionRpmBins);
+ MEMCPY(config->ignitionTable, hardCodedVafignitionTable);
+}
+
#if IGN_LOAD_COUNT == DEFAULT_IGN_LOAD_COUNT
static const ignition_table_t mapBased16IgnitionTable = {
@@ -134,7 +196,7 @@ static void setMiataNA6_settings(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
engineConfiguration->isFasterEngineSpinUpEnabled = true;
- setVeTable(PASS_CONFIG_PARAMETER_SIGNATURE);
+ setMapVeTable(PASS_CONFIG_PARAMETER_SIGNATURE);
engineConfiguration->idleMode = IM_AUTO;
// below 20% this valve seems to be opening for fail-safe idle air
@@ -298,49 +360,16 @@ void setMiataNA6_VAF_Frankenso(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
* set engine_type 12
*/
void setMiataNA6_VAF_MRE(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
- setMiataNA6_settings(PASS_CONFIG_PARAMETER_SIGNATURE);
- miataNAcommonEngineSettings(PASS_CONFIG_PARAMETER_SIGNATURE);
+ setMiataNA6_MAP_MRE(PASS_CONFIG_PARAMETER_SIGNATURE);
+
+ engineConfiguration->fuelAlgorithm = LM_REAL_MAF;
+
+
+ setVafVeTable(PASS_CONFIG_PARAMETER_SIGNATURE);
+ setVafIgnitionTable(PASS_CONFIG_PARAMETER_SIGNATURE);
#if (BOARD_TLE8888_COUNT > 0)
- // idle.solenoidPin output is inherited from boards/microrusefi/board_configuration.cpp
- // CLT: "18 - AN temp 1"
- // IAT: "23 - AN temp 2"
- // MAF/VAF: "19 - AN volt 4"
- engineConfiguration->mafAdcChannel = EFI_ADC_12;
-
- //engineConfiguration->triggerInputPins[0] = GPIOC_6;
- engineConfiguration->triggerInputPins[1] = GPIOA_5;
- engineConfiguration->camInputs[0] = GPIO_UNASSIGNED;
-
- engineConfiguration->ignitionPins[0] = GPIOD_7;
- engineConfiguration->ignitionPins[1] = GPIO_UNASSIGNED;
- engineConfiguration->ignitionPins[2] = GPIOD_6;
- engineConfiguration->ignitionPins[3] = GPIO_UNASSIGNED;
-
- engineConfiguration->injectionPins[2] = GPIO_UNASSIGNED;
- engineConfiguration->injectionPins[3] = GPIO_UNASSIGNED;
-
- // tps = "20 - AN volt 5"
- //engineConfiguration->tps1_1AdcChannel = EFI_ADC_13;
- engineConfiguration->tps1_1AdcChannel = EFI_ADC_NONE;
-
-
-
- // TLE8888_PIN_24: "43 - GP Out 4"
- // MIL check engine
- // NA6 check engine light is just a normal low side driver
- engineConfiguration->malfunctionIndicatorPin = TLE8888_PIN_24;
-
- // IAC: GPIOE_9: "7 - Lowside 1"
-
-
- // 0.2#3 has wrong R139
- // 56k high side/10k low side multiplied by above analogInputDividerCoefficient = 11
-// engineConfiguration->vbattDividerCoeff = (66.0f / 10.0f) * engineConfiguration->analogInputDividerCoefficient;
-
-
- engineConfiguration->isHip9011Enabled = false;
engineConfiguration->isSdCardEnabled = true;
#endif /* BOARD_TLE8888_COUNT */
}
@@ -356,6 +385,8 @@ void setMiataNA6_MAP_MRE(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
engineConfiguration->fuelPumpPin = GPIO_UNASSIGNED;
+ engineConfiguration->twoWireBatchInjection = true;
+
engineConfiguration->useIacTableForCoasting = true;
engineConfiguration->idlePidDeactivationTpsThreshold = 90;
diff --git a/firmware/controllers/can/obd2.cpp b/firmware/controllers/can/obd2.cpp
index ec623102ff..7a0a736a4e 100644
--- a/firmware/controllers/can/obd2.cpp
+++ b/firmware/controllers/can/obd2.cpp
@@ -38,6 +38,7 @@
#include "engine_math.h"
#include "fuel_math.h"
#include "thermistors.h"
+#include "ego.h"
EXTERN_ENGINE;
@@ -46,6 +47,7 @@ static const int16_t supportedPids0120[] = {
PID_FUEL_SYSTEM_STATUS,
PID_ENGINE_LOAD,
PID_COOLANT_TEMP,
+ PID_STFT_BANK1,
PID_INTAKE_MAP,
PID_RPM,
PID_SPEED,
@@ -56,6 +58,7 @@ static const int16_t supportedPids0120[] = {
};
static const int16_t supportedPids2140[] = {
+ PID_FUEL_AIR_RATIO_1,
-1
};
@@ -128,6 +131,9 @@ static void handleGetDataRequest(const CANRxFrame& rx) {
case PID_COOLANT_TEMP:
obdSendValue(1, pid, 1, Sensor::get(SensorType::Clt).value_or(0) + 40.0f);
break;
+ case PID_STFT_BANK1:
+ obdSendValue(1, pid, 1, 128 * ENGINE(engineState.running.pidCorrection));
+ break;
case PID_INTAKE_MAP:
obdSendValue(1, pid, 1, getMap(PASS_ENGINE_PARAMETER_SIGNATURE));
break;
@@ -152,7 +158,16 @@ static void handleGetDataRequest(const CANRxFrame& rx) {
case PID_THROTTLE:
obdSendValue(1, pid, 1, Sensor::get(SensorType::Tps1).value_or(0) * 2.55f); // (A*100/255)
break;
- case PID_FUEL_RATE:
+ case PID_FUEL_AIR_RATIO_1: {
+ float afr = getAfr(PASS_ENGINE_PARAMETER_SIGNATURE);
+ // phi = 1 / lambda
+ float phi = clampF(0, 14.7f / afr, 1.99f);
+
+ uint16_t scaled = phi * 32768;
+
+ obdSendPacket(1, pid, 4, scaled << 16);
+ break;
+ } case PID_FUEL_RATE:
obdSendValue(1, pid, 2, engine->engineState.fuelConsumption.perSecondConsumption * 20.0f); // L/h. (A*256+B)/20
break;
default:
diff --git a/firmware/controllers/can/obd2.h b/firmware/controllers/can/obd2.h
index c6131db412..b986cc61c3 100644
--- a/firmware/controllers/can/obd2.h
+++ b/firmware/controllers/can/obd2.h
@@ -22,6 +22,7 @@
#define PID_FUEL_SYSTEM_STATUS 0x03
#define PID_ENGINE_LOAD 0x04
#define PID_COOLANT_TEMP 0x05
+#define PID_STFT_BANK1 0x06
#define PID_FUEL_PRESSURE 0x0A
#define PID_INTAKE_MAP 0x0B
#define PID_RPM 0x0C
@@ -32,6 +33,7 @@
#define PID_THROTTLE 0x11
#define PID_SUPPORTED_PIDS_REQUEST_21_40 0x20
+#define PID_FUEL_AIR_RATIO_1 0x24
#define PID_SUPPORTED_PIDS_REQUEST_41_60 0x40
#define PID_FUEL_RATE 0x5E
diff --git a/firmware/controllers/date_stamp.h b/firmware/controllers/date_stamp.h
index e4eea32189..ab6cc8ebca 100644
--- a/firmware/controllers/date_stamp.h
+++ b/firmware/controllers/date_stamp.h
@@ -1,2 +1,2 @@
#pragma once
-#define VCS_DATE 20200808
+#define VCS_DATE 20200813
diff --git a/java_console/bin/help.sh b/java_console/bin/help.sh
old mode 100644
new mode 100755
diff --git a/java_console/bin/set_auth_token.sh b/java_console/bin/set_auth_token.sh
old mode 100644
new mode 100755
diff --git a/java_console/bin/update_bundle.sh b/java_console/bin/update_bundle.sh
old mode 100644
new mode 100755
diff --git a/java_console/build.xml b/java_console/build.xml
index ce2fdae450..584678a652 100644
--- a/java_console/build.xml
+++ b/java_console/build.xml
@@ -2,7 +2,7 @@
-
+
diff --git a/java_console/io/build.gradle b/java_console/io/build.gradle
index ae43245028..9ebb9d5ed2 100644
--- a/java_console/io/build.gradle
+++ b/java_console/io/build.gradle
@@ -23,4 +23,5 @@ dependencies {
// junit 4.13 does not mix well with httpclient :(
testImplementation group: 'junit', name: 'junit', version: '4.8.2'
+ testImplementation group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
}
\ No newline at end of file
diff --git a/java_console/io/io.iml b/java_console/io/io.iml
index c94a8e44b5..392d963789 100644
--- a/java_console/io/io.iml
+++ b/java_console/io/io.iml
@@ -15,5 +15,6 @@
+
\ No newline at end of file
diff --git a/java_console/io/src/test/java/com/rusefi/TestHelper.java b/java_console/io/src/test/java/com/rusefi/TestHelper.java
index c6c1d26a43..ee8a4fd4a4 100644
--- a/java_console/io/src/test/java/com/rusefi/TestHelper.java
+++ b/java_console/io/src/test/java/com/rusefi/TestHelper.java
@@ -16,6 +16,7 @@ import com.rusefi.server.SessionDetails;
import com.rusefi.server.rusEFISSLContext;
import com.rusefi.tune.xml.Constant;
import org.jetbrains.annotations.NotNull;
+import org.mockito.stubbing.Answer;
import java.io.IOException;
import java.net.Socket;
@@ -32,6 +33,9 @@ public class TestHelper {
public static final ControllerInfo CONTROLLER_INFO = new ControllerInfo("name", "make", "code", Fields.TS_SIGNATURE);
public static final String TEST_TOKEN_1 = "00000000-1234-1234-1234-123456789012";
public static final String TEST_TOKEN_3 = "33333333-3333-1234-1234-123456789012";
+ public static final Answer> NEGATIVE_ANSWER = invocation -> {
+ throw new UnsupportedOperationException("Not mocked " + invocation);
+ };
@NotNull
public static ScalarIniField createIniField(Field field) {
diff --git a/java_console/lib/mockito-all-1.10.19.jar b/java_console/lib/mockito-all-1.10.19.jar
new file mode 100644
index 0000000000..c831489cd9
Binary files /dev/null and b/java_console/lib/mockito-all-1.10.19.jar differ
diff --git a/java_console/shared_ui/src/com/rusefi/tools/online/Online.java b/java_console/shared_ui/src/com/rusefi/tools/online/Online.java
index 496227ed64..f136976a68 100644
--- a/java_console/shared_ui/src/com/rusefi/tools/online/Online.java
+++ b/java_console/shared_ui/src/com/rusefi/tools/online/Online.java
@@ -1,5 +1,6 @@
package com.rusefi.tools.online;
+import com.devexperts.logging.Logging;
import com.rusefi.shared.FileUtil;
import com.rusefi.tune.xml.Msq;
import com.rusefi.ui.AuthTokenPanel;
@@ -12,6 +13,7 @@ import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.jetbrains.annotations.Nullable;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;
@@ -22,6 +24,8 @@ import java.io.File;
import java.io.IOException;
public class Online {
+ private final static Logging log = Logging.getLogging(Online.class);
+
public static final String outputXmlFileName = FileUtil.RUSEFI_SETTINGS_FOLDER + File.separator + "output.msq";
private static final String url = "https://rusefi.com/online/upload.php";
@@ -29,10 +33,11 @@ public class Online {
* blocking call for http file upload
*/
public static UploadResult upload(File fileName, String authTokenValue) {
- try {
- HttpClient httpclient = new DefaultHttpClient();
- HttpPost httpPost = new HttpPost(url);
+ HttpClient httpclient = new DefaultHttpClient();
+ HttpPost httpPost = new HttpPost(url);
+ String responseString;
+ try {
FileBody uploadFilePart = new FileBody(fileName);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("upload-file", uploadFilePart);
@@ -41,51 +46,61 @@ public class Online {
httpPost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httpPost);
- System.out.println("response=" + response);
- System.out.println("code " + response.getStatusLine().getStatusCode());
+ log.debug("response=" + response);
+ log.debug("code " + response.getStatusLine().getStatusCode());
+ responseString = HttpUtil.getResponse(response);
- JSONObject object = HttpUtil.getJsonResponse(HttpUtil.getResponse(response));
+ } catch (IOException e) {
+ return new UploadResult(true, "Upload io ERROR " + e);
+ }
- System.out.println("object=" + object);
+ try {
+ JSONObject object = HttpUtil.getJsonResponse(responseString);
+
+ log.debug("object=" + object);
JSONArray info = (JSONArray) object.get("info");
JSONArray error = (JSONArray) object.get("error");
if (error != null) {
- System.out.println("error " + error);
+ log.error("error " + error);
return new UploadResult(true, error);
} else {
- System.out.println("info " + info);
+ log.debug("info " + info);
return new UploadResult(false, info);
}
- } catch (IOException | ParseException e) {
- return new UploadResult(true, "Error " + e);
+ } catch (ParseException e) {
+ return new UploadResult(true, "Upload Error " + responseString);
}
}
+ /**
+ * we are here in case of individual tune upload
+ */
public static BasicFuture uploadTune(Msq tune, AuthTokenPanel authTokenPanel, JComponent parent, FutureCallback callback) {
+ try {
+ tune.writeXmlFile(outputXmlFileName);
+ } catch (JAXBException | IOException e) {
+ throw new IllegalStateException("While writing tune", e);
+ }
+
+ return uploadFile(parent, callback, outputXmlFileName);
+ }
+
+ @Nullable
+ public static BasicFuture uploadFile(JComponent parent, FutureCallback callback, final String fileName) {
BasicFuture result = new BasicFuture<>(callback);
- String authToken = authTokenPanel.getToken();
- if (!authTokenPanel.hasToken()) {
- authTokenPanel.showError(parent);
+ String authToken = AuthTokenPanel.getAuthToken();
+ if (!AuthTokenPanel.hasToken()) {
+ AuthTokenPanel.showError(parent);
return null;
}
new Thread(new Runnable() {
@Override
public void run() {
- UploadResult array = doUpload(authToken, tune);
+ UploadResult array = upload(new File(fileName), authToken);
result.completed(array);
}
}).start();
return result;
}
-
- private static UploadResult doUpload(String authToken, Msq tune) {
- try {
- tune.writeXmlFile(outputXmlFileName);
- // todo: network upload should not happen on UI thread
- return upload(new File(outputXmlFileName), authToken);
- } catch (JAXBException | IOException ex) {
- return new UploadResult(true, "IO error " + ex);
- }
- }
}
diff --git a/java_console/shared_ui/src/com/rusefi/ui/AuthTokenPanel.java b/java_console/shared_ui/src/com/rusefi/ui/AuthTokenPanel.java
index e0b700fe7f..039e3ccbf1 100644
--- a/java_console/shared_ui/src/com/rusefi/ui/AuthTokenPanel.java
+++ b/java_console/shared_ui/src/com/rusefi/ui/AuthTokenPanel.java
@@ -127,15 +127,15 @@ public class AuthTokenPanel {
return content;
}
- public boolean hasToken() {
- return AutoTokenUtil.isToken(authTokenTestField.getText());
+ public static boolean hasToken() {
+ return AutoTokenUtil.isToken(getAuthToken());
}
public String getToken() {
return authTokenTestField.getText();
}
- public void showError(JComponent parent) {
+ public static void showError(JComponent parent) {
JOptionPane.showMessageDialog(parent, "Does not work without auth token, see below.");
}
}
diff --git a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/LogUploadSelector.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/LogUploadSelector.java
index 3a32fae2c2..b972fe5a76 100644
--- a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/LogUploadSelector.java
+++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/LogUploadSelector.java
@@ -1,27 +1,110 @@
package com.rusefi.ts_plugin;
+import com.efiAnalytics.plugin.ecu.ControllerAccess;
import com.rusefi.TsTuneReader;
-import com.rusefi.ui.util.FrameHelper;
+import com.rusefi.autoupdate.AutoupdateUtil;
+import com.rusefi.tools.online.Online;
+import com.rusefi.tools.online.UploadResult;
+import org.apache.http.concurrent.FutureCallback;
import org.jetbrains.annotations.NotNull;
import org.putgemin.VerticalFlowLayout;
import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
import java.io.File;
+import java.util.Objects;
+import java.util.function.Supplier;
public class LogUploadSelector {
- private final JPanel content = new JPanel(new VerticalFlowLayout());
+ private final JPanel content = new JPanel(new BorderLayout());
+ private final JLabel uploadState = new JLabel();
- public static void main(String[] args) {
- new FrameHelper().showFrame(new LogUploadSelector().getContent());
+ private final JPanel fileList = new JPanel(new VerticalFlowLayout());
+
+ private final Supplier controllerAccessSupplier;
+
+ public LogUploadSelector(Supplier controllerAccessSupplier) {
+ this.controllerAccessSupplier = controllerAccessSupplier;
+
+ JButton refresh = new JButton("Refresh");
+ refresh.addActionListener(new AbstractAction() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ refresh();
+ }
+ });
+
+ JPanel topPanel = new JPanel(new FlowLayout());
+ topPanel.add(refresh);
+
+ JPanel filePanel = new JPanel(new BorderLayout());
+ filePanel.add(fileList, BorderLayout.CENTER);
+
+ JScrollPane fileScroll = new JScrollPane(filePanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+
+ content.add(topPanel, BorderLayout.NORTH);
+ content.add(fileScroll, BorderLayout.CENTER);
+ content.add(uploadState, BorderLayout.SOUTH);
+ refresh();
}
- public LogUploadSelector() {
- String projectName = "dev";
- String folder = getLogsFolderDir(projectName);
+ private void refresh() {
+ fileList.removeAll();
- for (String fileName : new File(folder).list((dir, name) -> name.endsWith(".mlg"))) {
- System.out.println(fileName);
+ String folder = getLogsFolderDir(controllerAccessSupplier.get().getEcuConfigurationNames()[0]);
+
+ for (String fileName : Objects.requireNonNull(new File(folder).list((dir, name) -> name.endsWith(".mlg")))) {
+ JPanel panel = new JPanel(new FlowLayout());
+ JButton delete = new JButton("Delete");
+ JButton upload = new JButton("Upload");
+ final String fullFileName = folder + File.separator + fileName;
+
+ panel.add(delete);
+ panel.add(upload);
+
+ delete.addActionListener(new AbstractAction() {
+ @SuppressWarnings("ResultOfMethodCallIgnored")
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ int result = JOptionPane.showConfirmDialog(null, "Are you sure you want to remove " + fileName,
+ "rusEfi", JOptionPane.YES_NO_OPTION);
+ if (result == JOptionPane.YES_OPTION) {
+ new File(fullFileName).delete();
+ }
+ }
+ });
+
+ upload.addActionListener(new AbstractAction() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+
+ Online.uploadFile(content, new FutureCallback() {
+ @Override
+ public void completed(UploadResult uploadResult) {
+ SwingUtilities.invokeLater(() -> UploadView.setResult(uploadResult, uploadState));
+ }
+
+ @Override
+ public void failed(Exception e) {
+
+ }
+
+ @Override
+ public void cancelled() {
+
+ }
+ }, fullFileName);
+
+ }
+ });
+
+
+ panel.add(new JLabel(fileName));
+ fileList.add(panel);
}
+
+ AutoupdateUtil.trueLayout(content);
}
@NotNull
@@ -29,8 +112,7 @@ public class LogUploadSelector {
return TsTuneReader.getProjectsDir() + File.separator + projectName + File.separator + "DataLogs";
}
- private JComponent getContent() {
+ public JComponent getContent() {
return content;
}
-
}
diff --git a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/PluginEntry.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/PluginEntry.java
index ce18825073..e10c4844d6 100644
--- a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/PluginEntry.java
+++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/PluginEntry.java
@@ -12,7 +12,7 @@ import java.util.function.Supplier;
/**
* {@link TsPluginLauncher} creates an instance of this class via reflection.
- * @see UploadTab upload tune & TODO upload logs
+ * @see TuneUploadTab upload tune & TODO upload logs
* @see RemoteTab remote ECU access & control
* @see BroadcastTab offer your ECU for remove access & control
* @see PluginBodySandbox
@@ -35,16 +35,19 @@ public class PluginEntry implements TsPluginBody {
System.out.println("PluginEntry init " + this);
if (isLauncherTooOld()) {
- content.add(new JLabel("Please manually install latest plugin version"));
+ content.add(new JLabel("Please manually install latest plugin version
Usually we can update to latest version but this time there was a major change.
" +
+ "Please use TunerStudio controls to update to plugin from recent rusEFI bundle."));
return;
}
- UploadTab uploadTab = new UploadTab(controllerAccessSupplier);
+ TuneUploadTab tuneUploadTab = new TuneUploadTab(controllerAccessSupplier);
+ LogUploadSelector logUploadTab = new LogUploadSelector(controllerAccessSupplier);
BroadcastTab broadcastTab = new BroadcastTab();
RemoteTab remoteTab = new RemoteTab();
JTabbedPane tabbedPane = new JTabbedPane();
- tabbedPane.addTab("Upload", uploadTab.getContent());
+ tabbedPane.addTab("Tune Upload", tuneUploadTab.getContent());
+ tabbedPane.addTab("Log Upload", logUploadTab.getContent());
tabbedPane.addTab("Broadcast", broadcastTab.getContent());
tabbedPane.addTab("Remote ECU", remoteTab.getContent());
tabbedPane.addTab("Read SD Card", new SdCardReader(controllerAccessSupplier).getContent());
diff --git a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadTab.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/TuneUploadTab.java
similarity index 89%
rename from java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadTab.java
rename to java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/TuneUploadTab.java
index 6b36fa6f75..c9e3a2c0a1 100644
--- a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadTab.java
+++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/TuneUploadTab.java
@@ -6,7 +6,6 @@ import com.efiAnalytics.plugin.ecu.ControllerParameterChangeListener;
import com.opensr5.ini.IniFileModel;
import com.opensr5.ini.field.IniField;
import com.rusefi.TsTuneReader;
-import com.rusefi.autoupdate.AutoupdateUtil;
import com.rusefi.config.generated.Fields;
import com.rusefi.tools.online.Online;
import com.rusefi.tools.online.UploadResult;
@@ -24,7 +23,10 @@ import java.util.Date;
import java.util.Map;
import java.util.function.Supplier;
-public class UploadTab {
+/**
+ *
+ */
+public class TuneUploadTab {
private final JComponent content = new JPanel(new VerticalFlowLayout());
// 2 seconds aggregation by default
private static final int AUTO_UPDATE_AGGREGATION = Integer.parseInt(System.getProperty("autoupload.aggregation", "2000"));
@@ -38,9 +40,9 @@ public class UploadTab {
private final JButton upload = new JButton("Upload Current Tune");
- private String currentConfiguration;
+ private String projectName;
- private UploaderStatus uploaderStatus = new UploaderStatus();
+ private final UploaderStatus uploaderStatus = new UploaderStatus();
private final Timer timer = new Timer(AUTO_UPDATE_AGGREGATION, new AbstractAction() {
@Override
@@ -48,14 +50,14 @@ public class UploadTab {
// System.out.println("Timer! " + System.currentTimeMillis() + " " + timer + " " + e);
if (UploadView.isAutoUpload()) {
System.out.println(new Date() + ": enqueue tune");
- UploadQueue.enqueue(controllerAccessSupplier.get(), currentConfiguration);
+ UploadQueue.enqueue(controllerAccessSupplier.get(), projectName);
}
}
});
private final ControllerParameterChangeListener listener;
- public UploadTab(Supplier controllerAccessSupplier) {
+ public TuneUploadTab(Supplier controllerAccessSupplier) {
this.controllerAccessSupplier = controllerAccessSupplier;
timer.stop();
@@ -72,8 +74,8 @@ public class UploadTab {
public void run() {
while (true) {
String configurationName = getConfigurationName();
- if ((currentConfiguration == null && configurationName != null)
- || !currentConfiguration.equals(configurationName)) {
+ if ((projectName == null && configurationName != null)
+ || !projectName.equals(configurationName)) {
handleConfigurationChange(configurationName, controllerAccessSupplier.get());
}
@@ -119,7 +121,7 @@ public class UploadTab {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
- uploadView.setResult(array);
+ UploadView.setResult(array, uploadView.uploadState);
}
});
}
@@ -151,16 +153,16 @@ public class UploadTab {
/**
* This method is invoked every time we defect a switch between projects
*/
- private void handleConfigurationChange(String configurationName, ControllerAccess controllerAccess) {
- uploaderStatus.readTuneState(configurationName);
+ private void handleConfigurationChange(String projectName, ControllerAccess controllerAccess) {
+ uploaderStatus.readTuneState(projectName);
- if (configurationName != null) {
- subscribeToUpdates(configurationName, controllerAccess);
+ if (projectName != null) {
+ subscribeToUpdates(projectName, controllerAccess);
}
updateUploadEnabled();
- currentConfiguration = configurationName;
+ this.projectName = projectName;
}
private void updateUploadEnabled() {
diff --git a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadQueue.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadQueue.java
index 262b36bb36..f0e81d75b2 100644
--- a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadQueue.java
+++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadQueue.java
@@ -1,5 +1,6 @@
package com.rusefi.ts_plugin;
+import com.devexperts.logging.Logging;
import com.efiAnalytics.plugin.ecu.ControllerAccess;
import com.rusefi.shared.FileUtil;
import com.rusefi.tools.online.Online;
@@ -9,13 +10,14 @@ import com.rusefi.ui.AuthTokenPanel;
import javax.xml.bind.JAXBException;
import java.io.File;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.util.concurrent.LinkedBlockingDeque;
public class UploadQueue {
+ private final static Logging log = Logging.getLogging(UploadQueue.class);
+
public static final String OUTBOX_FOLDER = FileUtil.RUSEFI_SETTINGS_FOLDER + File.separator + "outbox";
- private static final LinkedBlockingDeque queue = new LinkedBlockingDeque<>(128);
+ private static final LinkedBlockingDeque queue = new LinkedBlockingDeque<>(128);
private static boolean isStarted;
@@ -37,12 +39,7 @@ public class UploadQueue {
File folder = new File(OUTBOX_FOLDER);
if (!folder.exists())
return;
- String[] files = folder.list(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(".msq");
- }
- });
+ String[] files = folder.list((dir, name) -> name.endsWith(".msq"));
if (files == null)
return;
@@ -51,8 +48,7 @@ public class UploadQueue {
return;
System.out.println(UploadQueue.class.getSimpleName() + " readOutbox " + file);
try {
- String fileName = OUTBOX_FOLDER + File.separator + file;
- queue.put(fileName);
+ queue.put(new FileAndFolder(OUTBOX_FOLDER, file));
} catch (Exception e) {
e.printStackTrace();
}
@@ -60,33 +56,36 @@ public class UploadQueue {
System.out.println(UploadQueue.class.getSimpleName() + " readOutbox got " + queue.size());
}
+ @SuppressWarnings("InfiniteLoopStatement")
private static void uploadLoop() throws InterruptedException {
while (true) {
- String fileName = queue.take();
+ FileAndFolder file = queue.take();
- UploadResult result = Online.upload(new File(fileName), AuthTokenPanel.getAuthToken());
+ UploadResult result = Online.upload(new File(file.getFullName()), AuthTokenPanel.getAuthToken());
System.out.println("isError " + result.isError());
System.out.println("first " + result.getFirstMessage());
if (result.isError() && result.getFirstMessage().contains("This file already exists")) {
System.out.println(UploadQueue.class.getSimpleName() + " No need to re-try this one");
- delete(fileName);
+ file.postUpload();
// do not retry this error
continue;
}
if (result.isError()) {
- System.out.println(UploadQueue.class.getSimpleName() + " Re-queueing " + fileName);
- queue.put(fileName);
+ System.out.println(UploadQueue.class.getSimpleName() + " Re-queueing " + file.getFullName());
+ queue.put(file);
continue;
}
- delete(fileName);
+ file.postUpload();
}
}
+ @SuppressWarnings("ResultOfMethodCallIgnored")
private static void delete(String fileName) {
System.out.println(UploadQueue.class.getSimpleName() + " Deleting " + fileName);
new File(fileName).delete();
}
+ @SuppressWarnings("ResultOfMethodCallIgnored")
public static void enqueue(ControllerAccess controllerAccess, String configurationName) {
start();
if (queue.size() > 100) {
@@ -94,14 +93,46 @@ public class UploadQueue {
return;
}
Msq msq = TuneUploder.grabTune(controllerAccess, configurationName);
+ if (msq == null) {
+ log.error("Error saving tune");
+ return;
+ }
msq.bibliography.setTuneComment("Auto-saved");
try {
new File(OUTBOX_FOLDER).mkdirs();
- String fileName = OUTBOX_FOLDER + File.separator + System.currentTimeMillis() + ".msq";
- msq.writeXmlFile(fileName);
- queue.put(fileName);
+ String fileName = System.currentTimeMillis() + ".msq";
+ String fullFileName = OUTBOX_FOLDER + File.separator + fileName;
+ msq.writeXmlFile(fullFileName);
+ queue.put(new FileAndFolder(OUTBOX_FOLDER, fileName));
} catch (InterruptedException | JAXBException | IOException e) {
throw new IllegalStateException(e);
}
}
+
+ static class FileAndFolder {
+ private static final boolean DEBUG_SAVE_UPLOADED = false;
+ private final String folder;
+ private final String file;
+
+ public FileAndFolder(String folder, String file) {
+ this.folder = folder;
+ this.file = file;
+ }
+
+ public String getFullName() {
+ return folder + File.separator + file;
+ }
+
+ @SuppressWarnings("ResultOfMethodCallIgnored")
+ public void postUpload() {
+ if (DEBUG_SAVE_UPLOADED) {
+ log.info("Renaming file " + file);
+ String uploadedDir = folder + File.separator + "uploaded";
+ new File(uploadedDir).mkdirs();
+ new File(getFullName()).renameTo(new File(uploadedDir + File.separator + file));
+ } else {
+ delete(getFullName());
+ }
+ }
+ }
}
diff --git a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadView.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadView.java
index 4b2b812334..90dcd957c4 100644
--- a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadView.java
+++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/UploadView.java
@@ -39,7 +39,7 @@ public class UploadView {
return PersistentConfiguration.getConfig().getRoot().getBoolProperty(AUTO_UPLOAD, false);
}
- public void setResult(UploadResult result) {
+ public static void setResult(UploadResult result, JLabel uploadState) {
uploadState.setText(result.getFirstMessage());
uploadState.setVisible(true);
}
diff --git a/java_tools/ts_plugin/src/test/java/com/rusefi/ts_plugin/LogUploadSelectorSandbox.java b/java_tools/ts_plugin/src/test/java/com/rusefi/ts_plugin/LogUploadSelectorSandbox.java
new file mode 100644
index 0000000000..2eaa9544d4
--- /dev/null
+++ b/java_tools/ts_plugin/src/test/java/com/rusefi/ts_plugin/LogUploadSelectorSandbox.java
@@ -0,0 +1,19 @@
+package com.rusefi.ts_plugin;
+
+import com.efiAnalytics.plugin.ecu.ControllerAccess;
+import com.rusefi.TestHelper;
+import com.rusefi.ui.util.FrameHelper;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+public class LogUploadSelectorSandbox {
+ public static void main(String[] args) {
+ String projectName = "mre_f4";
+ ControllerAccess controllerAccess = mock(ControllerAccess.class, TestHelper.NEGATIVE_ANSWER);
+ doReturn(new String[]{projectName}).when(controllerAccess).getEcuConfigurationNames();
+
+ new FrameHelper().showFrame(new LogUploadSelector(() -> controllerAccess).getContent());
+ }
+
+}
diff --git a/java_tools/ts_plugin/src/test/java/com/rusefi/ts_plugin/PluginBodySandbox.java b/java_tools/ts_plugin/src/test/java/com/rusefi/ts_plugin/PluginBodySandbox.java
index c7fdacc9be..4161a6b41d 100644
--- a/java_tools/ts_plugin/src/test/java/com/rusefi/ts_plugin/PluginBodySandbox.java
+++ b/java_tools/ts_plugin/src/test/java/com/rusefi/ts_plugin/PluginBodySandbox.java
@@ -1,6 +1,7 @@
package com.rusefi.ts_plugin;
import com.efiAnalytics.plugin.ecu.ControllerAccess;
+import com.efiAnalytics.plugin.ecu.ControllerException;
import com.efiAnalytics.plugin.ecu.servers.ControllerParameterServer;
import com.opensr5.ini.IniFileModel;
import com.rusefi.TsTuneReader;
@@ -9,9 +10,9 @@ import com.rusefi.ui.util.FrameHelper;
import java.util.ArrayList;
import java.util.Objects;
+import static com.rusefi.TestHelper.NEGATIVE_ANSWER;
import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
/**
* Sandbox for plugin body
@@ -22,25 +23,22 @@ public class PluginBodySandbox {
private static final String PROJECT_NAME = "dev";
- public static void main(String[] args) {
+ public static void main(String[] args) throws ControllerException {
String iniFile = TsTuneReader.getProjectModeFileName(PROJECT_NAME);
IniFileModel model = new IniFileModel().readIniFile(iniFile);
Objects.requireNonNull(model, "model");
java.util.List fieldNamesList = new ArrayList<>(model.allIniFields.keySet());
String[] parameterNames = fieldNamesList.toArray(new String[0]);
+ ControllerParameterServer controllerParameterServer = mock(ControllerParameterServer.class, NEGATIVE_ANSWER);
+ doReturn(parameterNames).when(controllerParameterServer).getParameterNames(any());
+ doNothing().when(controllerParameterServer).subscribe(any(), any(), any());
- ControllerParameterServer controllerParameterServer = mock(ControllerParameterServer.class);
- when(controllerParameterServer.getParameterNames(any())).thenReturn(parameterNames);
+ ControllerAccess controllerAccess = mock(ControllerAccess.class, NEGATIVE_ANSWER);
+ doReturn(new String[]{PROJECT_NAME}).when(controllerAccess).getEcuConfigurationNames();
+ doReturn(controllerParameterServer).when(controllerAccess).getControllerParameterServer();
- ControllerAccess controllerAccess = mock(ControllerAccess.class);
- when(controllerAccess.getEcuConfigurationNames()).thenReturn(new String[]{PROJECT_NAME});
- when(controllerAccess.getControllerParameterServer()).thenReturn(controllerParameterServer);
-
-
- new FrameHelper().showFrame(new PluginEntry(() -> {
- return controllerAccess;
- }).getContent());
+ new FrameHelper().showFrame(new PluginEntry(() -> controllerAccess).getContent());
}
}