From 2cfc22e1ea5140861499ee5b7142766fb8f754f7 Mon Sep 17 00:00:00 2001 From: yy1717 <fctom1215@outlook.com> Date: 星期二, 29 九月 2020 15:53:20 +0800 Subject: [PATCH] 坐标 --- lib/src/main/cpp/driver_test.cpp | 2 lib/src/main/cpp/test_items/stop_and_start.cpp | 2 lib/src/main/cpp/master/comm_if.h | 8 ++ lib/src/main/cpp/test_items/park_bottom.cpp | 16 +-- lib/src/main/cpp/test_items/park_edge.cpp | 5 lib/src/main/cpp/rtk_platform/platform.h | 3 lib/src/main/java/com/anyun/exam/lib/util/ProperUtil.java | 25 ++++++ lib/src/main/cpp/master/comm_if.cpp | 21 +++++ lib/src/main/cpp/native-lib.cpp | 17 ++++ lib/src/main/cpp/utils/xconvert.h | 4 + lib/src/main/cpp/utils/xconvert.cpp | 22 +++++ lib/src/main/cpp/mcu/mcu_if.cpp | 4 + lib/src/main/cpp/rtk_platform/platform.cpp | 48 ++++++++++++ lib/src/main/java/com/anyun/exam/lib/RemoteService.java | 47 +++++++++++ 14 files changed, 210 insertions(+), 14 deletions(-) diff --git a/lib/src/main/cpp/driver_test.cpp b/lib/src/main/cpp/driver_test.cpp index a9208fb..fa24fec 100644 --- a/lib/src/main/cpp/driver_test.cpp +++ b/lib/src/main/cpp/driver_test.cpp @@ -386,7 +386,7 @@ return; } - type = TEST_TYPE_ROAD_CALIBRATE; +// type = TEST_TYPE_ROAD_CALIBRATE; if (AreaMapList.size() == 0 && type == TEST_TYPE_AREA) { DEBUG("娌℃湁鍦鸿�冨湴鍥�"); diff --git a/lib/src/main/cpp/master/comm_if.cpp b/lib/src/main/cpp/master/comm_if.cpp index ca951fa..6009256 100644 --- a/lib/src/main/cpp/master/comm_if.cpp +++ b/lib/src/main/cpp/master/comm_if.cpp @@ -69,6 +69,8 @@ #define ID_SM_CROSSING_BRIEF 0x0016 // 绉戠洰涓夐」鐩爣瀹氾紝鎺ヨ繎/椹剁鏌愬悇璺彛鐨勬彁绀� #define ID_MS_INQ_ROAD_CROSSING 0x8018 // Master鏌ヨ褰撳墠璺鍜岃矾鍙� +#define ID_SM_CAN_BRIEF 0x0021 + #define MA_OUT_GPS_BRIEF 0x0001 #define MA_OUT_RTK_BRIEF 0x0002 #define MA_OUT_CAR_BRIEF 0x0004 @@ -445,6 +447,25 @@ SendMsgToMainProcIndep(ID_SM_DISTANCE, sb.GetString()); } +void MA_SendCanStatus(const struct canBrief *brief) +{ + StringBuffer sb; + Writer<StringBuffer> writer(sb); + + writer.StartObject(); + writer.Key("gpio"); + writer.Int(brief->gpio); + writer.Key("rpm"); + writer.Int(brief->rpm); + writer.Key("speed"); + writer.Int(brief->speed); + writer.Key("voltage"); + writer.Int(brief->voltage); + writer.EndObject(); + + SendMsgToMainProcIndep(ID_SM_CAN_BRIEF, sb.GetString()); +} + void MA_SendRoadStatus(const struct roadStatusBrief *brief) { StringBuffer sb; diff --git a/lib/src/main/cpp/master/comm_if.h b/lib/src/main/cpp/master/comm_if.h index a5355e0..9eacc38 100644 --- a/lib/src/main/cpp/master/comm_if.h +++ b/lib/src/main/cpp/master/comm_if.h @@ -17,6 +17,13 @@ char sn[20]; }; +struct canBrief { + int gpio; + int rpm; + double speed; + double voltage; +}; + struct carSensorBrief { int odo; int trip; @@ -144,5 +151,6 @@ void MA_SendRoadStatus(const struct roadStatusBrief *brief); void MA_SendCrossingStatus(const struct crossingStatusBrief *brief); +void MA_SendCanStatus(const struct canBrief *brief); #endif //MYAPPLICATION2_COMM_IF_H diff --git a/lib/src/main/cpp/mcu/mcu_if.cpp b/lib/src/main/cpp/mcu/mcu_if.cpp index 732db69..492cd4d 100644 --- a/lib/src/main/cpp/mcu/mcu_if.cpp +++ b/lib/src/main/cpp/mcu/mcu_if.cpp @@ -303,6 +303,10 @@ switch (id) { case ID_MC_MCU_BOOT: DEBUG("MCU BOOT"); + if (lenth == 8) { + PlatformStatusChanged(CAN_UPDATE_EVT, data, lenth); + } + break; case ID_MC_DFU_RSP: DEBUG("ID_MC_DFU_RSP %d len %d", data[0], lenth); diff --git a/lib/src/main/cpp/native-lib.cpp b/lib/src/main/cpp/native-lib.cpp index 6eedb68..823ca99 100644 --- a/lib/src/main/cpp/native-lib.cpp +++ b/lib/src/main/cpp/native-lib.cpp @@ -383,3 +383,20 @@ TTSCallBack.erase(it); } } + +extern "C" +JNIEXPORT void JNICALL +Java_com_anyun_exam_lib_RemoteService_UpgradeMcu(JNIEnv *env, jobject thiz, jstring vercode, + jbyteArray rom) { + // TODO: implement UpgradeMcu() + if (vercode != NULL && rom != NULL) { + const char *str = env->GetStringUTFChars(vercode, 0); + jbyte *c_dat = env->GetByteArrayElements(rom, NULL); + int len = env->GetArrayLength(rom); + + LoadDefaultMcuRom(str, (uint8_t *)c_dat, len); + + env->ReleaseStringUTFChars(vercode, str); + env->ReleaseByteArrayElements(rom, c_dat, NULL); + } +} diff --git a/lib/src/main/cpp/rtk_platform/platform.cpp b/lib/src/main/cpp/rtk_platform/platform.cpp index 6060868..a3b0098 100644 --- a/lib/src/main/cpp/rtk_platform/platform.cpp +++ b/lib/src/main/cpp/rtk_platform/platform.cpp @@ -63,6 +63,13 @@ void *data; }; +struct default_mcu_rom_t { + int more; + char verCode[70]; + uint8_t *rom; + int length; +} defaultMcuRom; + static struct event_queue_t { struct event_t event; struct event_queue_t *next; @@ -174,6 +181,7 @@ memset(&gbf, 0, sizeof(gbf)); memset(&rbf, 0, sizeof(rbf)); + memset(&defaultMcuRom, 0, sizeof(defaultMcuRom)); pthread_mutex_init(&platform_tx_mutex, NULL); pthread_mutex_init(&events_mutex, NULL); @@ -420,7 +428,31 @@ MA_SendMcuBrief(&brief); + if (defaultMcuRom.more > 0) { + char str[64] = {0}; + + memcpy(str, data, 32); + + vector<string> ver = split(str, "_"); + + if (strlen(defaultMcuRom.verCode) > 0 && ver.size() >= 4 && strcmp(defaultMcuRom.verCode, ver[3].c_str()) != 0 && defaultMcuRom.rom != NULL) { + UploadDfuFile(defaultMcuRom.rom, defaultMcuRom.length); + delete []defaultMcuRom.rom; + defaultMcuRom.rom = NULL; + } + defaultMcuRom.more = 0; + } // UpdateSensor(brief.gpio, brief.speed, brief.engine); + } + if (events & CAN_UPDATE_EVT) { + struct canBrief brief; + + brief.gpio = BUILD_UINT16(data[1], data[0]); + brief.rpm = BUILD_UINT16(data[3], data[2]); + brief.speed = (double) BUILD_UINT16(data[5], data[4]) / 10.0; + brief.voltage = (double) BUILD_UINT16(data[7], data[6]) / 10.0; + + MA_SendCanStatus(&brief); } if (events & CAR_SENSOR_UPDATE_EVT) { struct carSensorBrief brief; @@ -735,3 +767,19 @@ { SendRTKStop(); } + +void LoadDefaultMcuRom(const char *verCode, const uint8_t *rom, int length) +{ + DEBUG("鍐呯疆鍗曠墖鏈簉om %s len %ld", verCode, length); + strcpy(defaultMcuRom.verCode, verCode); + + if (length > 0 && rom != NULL) { + defaultMcuRom.length = length; + if (defaultMcuRom.rom != NULL) + delete []defaultMcuRom.rom; + + defaultMcuRom.more = 1; + defaultMcuRom.rom = new uint8_t[length]; + memcpy(defaultMcuRom.rom, rom, length); + } +} diff --git a/lib/src/main/cpp/rtk_platform/platform.h b/lib/src/main/cpp/rtk_platform/platform.h index f48eb4e..241d133 100644 --- a/lib/src/main/cpp/rtk_platform/platform.h +++ b/lib/src/main/cpp/rtk_platform/platform.h @@ -18,6 +18,7 @@ #define PLAY_TTS_DONE_EVT 0x0100 #define CAR_SENSOR_UPDATE_EVT 0x0200 #define MASTER_COMM_EVT 0x0400 +#define CAN_UPDATE_EVT 0x0800 typedef struct { char domain_name[32]; @@ -45,4 +46,6 @@ void RequestRtkDownload(const gpsStatus_t *gps, uint16_t rtk_pkt_interval); void StopRtkDownload(void); +void LoadDefaultMcuRom(const char *verCode, const uint8_t *rom, int length); + #endif //RTKDRIVERTEST_PLATFORM_H diff --git a/lib/src/main/cpp/test_items/park_bottom.cpp b/lib/src/main/cpp/test_items/park_bottom.cpp index 7872b06..5854125 100644 --- a/lib/src/main/cpp/test_items/park_bottom.cpp +++ b/lib/src/main/cpp/test_items/park_bottom.cpp @@ -33,6 +33,8 @@ static int mapIndex = 0; const uint32_t STOP_CAR_TIME = D_SEC(2); +const uint32_t CHECK_PARK_DELAY = 400; + static uint32_t stopTimepoint; static int prevMoveDirect, storeMoveDirectBeforeStop; static bool occurCrashRedLine; @@ -165,7 +167,7 @@ stopTimepoint = tp; storeMoveDirectBeforeStop = prevMoveDirect; if (prevMoveDirect == -1) { - checkPartStatus = true; + checkPartStatus = true; // 姣忔鍊掕溅鍋滄锛岃Е鍙戝叆搴撴鏌� } DEBUG("鍋滆溅浜� %d %d %d %d %d %d %d", rtkTime->YY, rtkTime->MM, rtkTime->DD, rtkTime->hh, rtkTime->mm, rtkTime->ss, rtkTime->mss); @@ -198,14 +200,10 @@ } } else { // 鍒囨崲涓哄墠杩� - if (tp - stopTimepoint >= STOP_CAR_TIME) { + DEBUG("鍒囨崲涓哄墠杩�"); + + if (tp - stopTimepoint >= CHECK_PARK_DELAY) { if (crossCtrlLineSw) { - if (checkPartStatus) { - if (EnterParking(map, car)) { - parkStatus[parkCount] = 1; - } - checkPartStatus = false; - } if (parkStatus[parkCount] != 1) { // 鍊掑簱涓嶅叆锛屼笉鍚堟牸 reportParkFail = true; @@ -234,7 +232,7 @@ firstReverseTimepoint = tp; } } else if (moveDirect == 0 && crossCtrlLineSw) { - if (tp - stopTimepoint >= STOP_CAR_TIME && checkPartStatus) { + if (tp - stopTimepoint >= CHECK_PARK_DELAY && checkPartStatus) { if (EnterParking(map, car)) { parkStatus[parkCount] = 1; } diff --git a/lib/src/main/cpp/test_items/park_edge.cpp b/lib/src/main/cpp/test_items/park_edge.cpp index 987dd0f..fab68ea 100644 --- a/lib/src/main/cpp/test_items/park_edge.cpp +++ b/lib/src/main/cpp/test_items/park_edge.cpp @@ -22,6 +22,7 @@ const int PARK_TIMEOUT = D_SEC(90); const uint32_t STOP_CAR_TIME = D_SEC(2); +const uint32_t CHECK_PARK_DELAY = 400; static int mapIndex = 0; static bool reportExamTimeout; @@ -151,7 +152,7 @@ } } else { // 鍊掕溅鍒囨崲鍒板墠杩� - if (moveStatus == 1 && tp - stopTimepoint >= STOP_CAR_TIME) { + if (moveStatus == 1 && tp - stopTimepoint >= CHECK_PARK_DELAY) { if (parkStatus == 0) { if (EnterParking(map, car)) { parkStatus = 1; @@ -187,7 +188,7 @@ } else if (moveStatus == 0 && parkStatus == 0) { uint32_t tp = TimeMakeComposite(rtkTime->hh, rtkTime->mm, rtkTime->ss, rtkTime->mss*10); - if (tp - stopTimepoint >= STOP_CAR_TIME) { + if (tp - stopTimepoint >= CHECK_PARK_DELAY) { if (EnterParking(map, car)) { parkStatus = 1; parkSuccess = true; diff --git a/lib/src/main/cpp/test_items/stop_and_start.cpp b/lib/src/main/cpp/test_items/stop_and_start.cpp index 6af91c7..d75ed70 100644 --- a/lib/src/main/cpp/test_items/stop_and_start.cpp +++ b/lib/src/main/cpp/test_items/stop_and_start.cpp @@ -25,7 +25,7 @@ const double SLIDE_DISTANCE_THRESHOLD_RED = 0.3; const double SLIDE_DISTANCE_THRESHOLD_YELLOW = 0.1; const uint32_t CAR_START_TIMEOUT = D_SEC(30); -const uint32_t STOP_CAR_TIME = D_SEC(2); +const uint32_t STOP_CAR_TIME = D_SEC(1); const double EPSILON = 1e-3; diff --git a/lib/src/main/cpp/utils/xconvert.cpp b/lib/src/main/cpp/utils/xconvert.cpp index 66869c0..b411ffb 100644 --- a/lib/src/main/cpp/utils/xconvert.cpp +++ b/lib/src/main/cpp/utils/xconvert.cpp @@ -5,6 +5,10 @@ #include "xconvert.h" #include <cstdint> #include <cstring> +#include <vector> +#include <string> + +using namespace std; #define SECONDS_PER_MINUTE 60 #define SECONDS_PER_HOUR 3600 @@ -141,3 +145,21 @@ TimeMakeComposite(hour2, minute2, second2, msecond2)) % (SECONDS_PER_DAY * 1000); } +vector<string> split(string str, string pattern) +{ + string::size_type pos; + vector<string> result; + str += pattern; + + int size=str.size(); + + for(int i=0; i<size; i++) { + pos=str.find(pattern,i); + if(pos<size) { + string s=str.substr(i,pos-i); + result.push_back(s); + i=pos+pattern.size()-1; + } + } + return result; +} diff --git a/lib/src/main/cpp/utils/xconvert.h b/lib/src/main/cpp/utils/xconvert.h index 9821df7..27e0bdd 100644 --- a/lib/src/main/cpp/utils/xconvert.h +++ b/lib/src/main/cpp/utils/xconvert.h @@ -6,6 +6,8 @@ #define MYAPPLICATION2_XCONVERT_H #include <cstdint> +#include <string> +#include <vector> double ConvertKMh2Ms(int kmh); double ConvertMs2KMh(double ms); @@ -17,4 +19,6 @@ uint32_t TimeMakeComposite(int hour, int minute, int second, int msecond); uint32_t TimeGetDiff(int hour1, int minute1, int second1, int msecond1, int hour2, int minute2, int second2, int msecond2); +std::vector<std::string> split(std::string str, std::string pattern); + #endif //MYAPPLICATION2_XCONVERT_H diff --git a/lib/src/main/java/com/anyun/exam/lib/RemoteService.java b/lib/src/main/java/com/anyun/exam/lib/RemoteService.java index 0fd34d3..76ec97f 100644 --- a/lib/src/main/java/com/anyun/exam/lib/RemoteService.java +++ b/lib/src/main/java/com/anyun/exam/lib/RemoteService.java @@ -19,14 +19,18 @@ import com.anyun.exam.lib.util.DESUtil; import com.anyun.exam.lib.util.NetUtils; +import com.anyun.exam.lib.util.ProperUtil; import com.anyun.exam.lib.util.Speaker; import com.anyun.exam.lib.util.SpeakerCallback; import androidx.annotation.Nullable; +import java.io.IOException; +import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Properties; import java.util.concurrent.atomic.AtomicBoolean; /** @@ -77,7 +81,7 @@ Log.d(TAG, "UnsupportedEncodingException"); } } else { - Log.d(TAG, "Process " + Process.myPid() + " Thread " + Thread.currentThread().getId() + " RecvMsgFromMainProc cmd = " + String.format(" %04X ", cmd) + " length " + value.length() + " value " + value.trim()); + Log.d(TAG, "Process " + Process.myPid() + " Thread " + Thread.currentThread().getId() + " RecvMsgFromMainProc cmd = " + String.format(" %04X ", cmd) + " length " + value.length()); MainProcMsgEntry(cmd, value.trim()); } } @@ -98,6 +102,8 @@ new Thread(new TestThread()).start(); + new Thread(new AutoUpdateMcuThread(this)).start(); + upgrade = Upgrade.getInstance(getApplicationContext()); upgrade.CheckUpgrade(); @@ -108,6 +114,44 @@ Log.d(TAG, "鍩哄甫鐗堟湰 " + getBaseband_Ver()); String ver = getBaseband_Ver(); + } + + class AutoUpdateMcuThread implements Runnable { + private Context context; + + public AutoUpdateMcuThread(Context context) { + this.context = context; + } + + @Override + public void run() { + Properties proper = ProperUtil.getProperties(getApplicationContext()); + if (proper != null) { + String assetVer = proper.getProperty("mcuVersion"); + + if (assetVer != null) { + try { + InputStream inputStream = context.getAssets().open("dfu.bin"); + + if (inputStream != null) { + int fileLength = inputStream.available(); + Log.d(TAG, "AutoUpdateMcu " + fileLength); + + if (fileLength > 0) { + byte[] temp = new byte[fileLength]; + inputStream.read(temp); + + UpgradeMcu(assetVer, temp); + } + inputStream.close(); + } + } catch (IOException e) { + + } + } + } + + } } private void LimitMaxMinVolume() { @@ -326,5 +370,6 @@ public native void startNative(); public native void MainProcMsgEntry(int cmd, String value); public native void MainProcBinMsgEntry(int cmd, byte []data, int length); + public native void UpgradeMcu(String vercode, byte []rom); public native void TextSpeakEnd(int id); } diff --git a/lib/src/main/java/com/anyun/exam/lib/util/ProperUtil.java b/lib/src/main/java/com/anyun/exam/lib/util/ProperUtil.java new file mode 100644 index 0000000..49c48fc --- /dev/null +++ b/lib/src/main/java/com/anyun/exam/lib/util/ProperUtil.java @@ -0,0 +1,25 @@ +package com.anyun.exam.lib.util; + +import android.content.Context; + +import java.io.InputStream; +import java.util.Properties; + +public class ProperUtil { + public static Properties getProperties(Context c){ + Properties props = null; + + try { + InputStream in = c.getAssets().open("appConfig"); + if (in != null) { + props = new Properties(); + props.load(in); + in.close(); + } + } catch (Exception e1) { + // TODO Auto-generated catch block + } + + return props; + } +} -- Gitblit v1.8.0