本文介绍了用于升级外部主板的 Android 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

我们创建了一个 Android 应用程序,该应用程序当前通过蓝牙连接与外部主板进行通信.该板依次发出命令以不同速度运行一个或多个电机.(此应用程序是为海洋工业中的特定任务而构建的)

We created an Android app that currently communicates with an external mother board via Bluetooth connection. The board in-turn issues commands to run one or more motor(s) at different speeds. (This application was built for a specific task in the marine industry)

我们的目标是增强应用程序,以便 android 移动用户(将来)能够通过在通过蓝牙连接的应用程序上发出命令来升级主板的固件.

Our goal is to enhance the application so that android mobile users (in the future) will be able to upgrade the motherboard's firmware by issuing a command on the application connected via Bluetooth.

主板使用一种名为YMODEM 的旧标准通信协议.http://en.wikipedia.org/wiki/YMODEM 主板支持此功能,我们目前能够在 windows 平台上使用超级终端处理固件升级.

The motherboard uses an old standard communications protocol called YMODEM. http://en.wikipedia.org/wiki/YMODEM The mother board supports this function and we are currently able to handle the firmware upgrade using hyper terminal on a windows platform.

我的问题是:

是否可以在android应用中使用YMODEM协议进行重新刷机?

Is it possible to use the YMODEM protocol in an android application to perform a re-flash?

如果是,如何?任何帮助将不胜感激!感谢您对此进行调查!

If yes, how? Any help would be appreciated!!Thanks for looking into this!

推荐答案

对于迟到的回复深表歉意,但它可能会有所帮助...是的,这绝对是可能的.我已经使用 nexus 7 和带有 ARM 处理器的外部设备完成了这项工作.nexus 7 必须在启用 USB 调试的情况下扎根.我使用了 wugfresh 的 nexus root 工具包——非常简单.

Apologies for the late response, but it might be helpful... Yes, it is definitely possible. I have done exactly this with a nexus 7 and an external device with an ARM processor. The nexus 7 must be rooted with USB debugging enabled. I used wugfresh's nexus root toolkit -- it was very easy.

接下来(请坐好),您必须编写应用程序以使用 YModem 协议.一种选择是使用android NDK(本机开发工具包)编译用C/C++编写的YModem协议(试试Tixy 的).如果您使用的是 Windows,则在安装 NDK 之前需要 cygwinmingw.

Next (hold onto your seats), you must write your application to use the YModem protocol. One option is to use the android NDK (Native development kit) to compile a YModem protocol written in C/C++ (Try Tixy's). You'll need cygwin or mingw before you install the NDK if you're working with Windows.

假设您使用 Windows,并且您在 c:android-ndk-r8b-windowsandroid-ndk-r8b 中安装了 NDK.您可以在安装了 adt 插件的情况下使用 Eclipse,假设项目的新工作区是 c:android-workspace.您可以使用批处理文件从您的项目 (c:android-workspaceatch.bat) 中执行 NDK make:

So let's say your using windows and you have the NDK installed in c:android-ndk-r8b-windowsandroid-ndk-r8b. You can use Eclipse with the adt plugin installed, and let's say your new workspace for the project is c:android-workspace. You can use a batch file to execute NDK make from your project (c:android-workspaceatch.bat):

C:android-ndk-r8b-windowsandroid-ndk-r8b
dk-build.cmd
PAUSE

只要确保您导出 C/C++ 函数,以便您的 JAVA android 应用程序可以使用它们.

Just make sure you export the C/C++ functions so that they can be used by your JAVA android application.

接口.cpp:

#include <string.h>
#include <jni.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "ymodem_tx.h"
#include "ymodem_main.h"

extern "C" {

JNIEXPORT int JNICALL Java_com_example_ymupload_MainActivity_ymodemSent( JNIEnv* env, jobject obj, int portNumber, jstring fileName)
{
    int status = 0;
    if (portNumber >= 0)
    {
        const char* input = env->GetStringUTFChars(fileName, 0);

        status = ymodem_sentFile(portNumber, input);

        env->ReleaseStringUTFChars(fileName, input);
    }
    else
    {
        status = 0xFF;
    }

    return status;
}


JNIEXPORT int JNICALL Java_com_example_ymupload_MainActivity_YmodemGetTotalSize( JNIEnv* env, jobject obj)
{
    return ymodem_getTotalSize();
}


JNIEXPORT int JNICALL Java_com_example_ymupload_MainActivity_YmodemGetTransferredSize( JNIEnv* env, jobject obj)
{
    return ymodem_getTransferredSize();
}



JNIEXPORT bool JNICALL Java_com_example_ymupload_MainActivity_YmodemIsSending( JNIEnv* env, jobject obj)
{
    return ymodem_bIsSending();
}

JNIEXPORT int JNICALL Java_com_example_ymupload_MainActivity_YmodemGetStatus( JNIEnv* env, jobject obj)
{
return ymodem_uGetStatus();
}


JNIEXPORT jstring JNICALL Java_com_example_ymupload_MainActivity_YmodemGetFileName( JNIEnv* env, jobject obj)
{
    return env->NewStringUTF(ymodem_pGetFileName());
}


}

还要确保将该文件和其他.c.cpp.h 文件放在jni文件夹,例如c:android-workspaceprog-namejni,以及一个 Android.mk 文件(关于 Android.mk 文件).

Also make sure you put that file and other .c, .cpp, .h files in the jni folder in your project folder, e.g. c:android-workspaceprog-namejni, along with an Android.mk file (there are plenty of other stack questions about Android.mk files).

您可以将要闪存的二进制文件放在 /sdcard/ 上的文件夹中.下载文件浏览器以查看它们.

You can put the binaries that you want to flash in a folder on the /sdcard/. Download a file browser to see them.

这篇关于用于升级外部主板的 Android 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 04:43