我可以写信到 NXT 上的邮箱,但(还)不能从中读取。
设置是使用来自 GitHub 的 MindDroid 作为启动器。
sendBTCmessage(0, BTCommunicator.START_PROGRAM, "bt1.rxe");
sendBTCmessage(1000, BTCommunicator.SENDMAILBOX, "Kilroy was here");
sendBTCmessage(3000, BTCommunicator.READMAILBOX,"",1);
SendBTCmessage (int,int,String,int) 是新的...
void sendBTCmessage(int delay, int message, String name, int mBox) { Bundle myBundle = new Bundle(); myBundle.putInt("消息", 消息); myBundle.putString("name", name); myBundle.putInt("邮箱",mBox); 消息 myMessage = myHandler.obtainMessage(); myMessage.setData(myBundle); Log.d(TAG,String.format("sendBTCmessageStringMbox %d %d %s mBox=%d",delay, message,name,mBox));
if (delay == 0)
btcHandler.sendMessage(myMessage);
else
btcHandler.sendMessageDelayed(myMessage, delay);
}
这会将请求发送到处理程序,其中...
case SENDMAILBOX:
Log.d(TAG,String.format("case SENDMAILBOX %d %s",myMessage.getData().getInt("value1"), myMessage.getData().getString("name")));
sendMailbox(myMessage.getData().getInt("MailBox"),myMessage.getData().getString("name"));
break;
case READMAILBOX:
Log.d(TAG,String.format("case ReadMAILBOX %d %s",myMessage.getData().getInt("MailBox"), myMessage.getData().getString("name")));
readMailbox(myMessage.getData().getInt("MailBox"));
break;
case START_PROGRAM:
startProgram(myMessage.getData().getString("name"));
break;
消息已进一步准备,“startProgram”是标准的并且工作正常......
private void startProgram(String programName) {
byte[] message = LCPMessage.getStartProgramMessage(programName);
Log.d(TAG,String.format("startProgram %s %s",programName,LCPMessage.getStartProgramMessage(programName)));
sendMessageAndState(message);
}
private void readMailbox(int mBox){
byte[] message = LCPMessage.getReadMailboxMessage(mBox);
Log.d(TAG,String.format("readMailbox %d",mBox));
logByteArray(TAG,"sendMailBox",message);
sendMessageAndState(message);
}
private void sendMailbox(int mBox,String text){
byte[] message = LCPMessage.getMailBoxMessage(mBox,text);
Log.d(TAG,String.format("mail box message %s %d",text,message.length));
logByteArray(TAG,"sendMailBox",message);
sendMessageAndState(message);
}
最后的准备是...
public static byte[] getMailBoxMessage(int mBox, String text){
byte[] message = new byte[text.length()+5];
message[0] = DIRECT_COMMAND_NOREPLY;
message[1] = MESSAGE_WRITE;
message[2] = (byte)mBox;
message[3] = (byte)(text.length()+1);
for (int pos=0; pos<text.length(); pos++)
message[4+pos] = (byte) text.charAt(pos);
message[text.length()+4] = 0;
return message;
}
public static byte[] getReadMailboxMessage(int mBox){
byte[] message = new byte[5];
message[0] = DIRECT_COMMAND_REPLY;
message[1] = MESSAGE_READ;
message[2] = (byte)(mBox+10);
message[3] = (byte)mBox;
message[4] = (byte)0x01; //true
return message;
}
public static byte[] getStartProgramMessage(String programName) {
byte[] message = new byte[22];
message[0] = DIRECT_COMMAND_NOREPLY;
message[1] = START_PROGRAM;
// copy programName and end with 0 delimiter
for (int pos=0; pos<programName.length(); pos++)
message[2+pos] = (byte) programName.charAt(pos);
message[programName.length()+2] = 0;
return message;
}
我遇到的问题是接收消息的 NXT 程序工作正常,但我不知道如何读取邮箱中的内容 http://www.android-tele-health.com/bt1.rbt是正在运行的程序在NXT。
任何帮助表示赞赏...谢谢约翰