dandycheung / microbridge

Automatically exported from code.google.com/p/microbridge
0 stars 0 forks source link

Shell Example #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Running Shell Example, uploaded to Uno with Oleg's USB HS
2. Open Serial Monitor at 57600 baud, and carriage return
3. Type ls. press send.

What is the expected output? What do you see instead?
I expected to see a list of files and directories
.
..
/bin
/root
/etc

What I see instead is..
$ Shell not openl
l: permission denied
$ 

What version of the product are you using? On what operating system?
I tried on Ubunto 10.4, and Windows XP. Same operation.

Please provide any additional information below.

Arduino Uno,
Oleg's USB Host Shield
Logcat example works on windows side, but not with Ubuntu.

Original issue reported on code.google.com by chrisisi...@gmail.com on 1 Jul 2011 at 8:31

GoogleCodeExporter commented 9 years ago
root your device..

Original comment by sanctuar...@gmail.com on 5 Jul 2011 at 2:18

GoogleCodeExporter commented 9 years ago
same problem, and the device is already rooted, when plugged into ubuntu, adb 
shell can return all the directories in response to ls.
U8800 with circuits@home USB host shield

Original comment by jingle.y...@gmail.com on 25 Jul 2011 at 2:05

GoogleCodeExporter commented 9 years ago
Same problem. Device (G1 1.6) is rooted. Adb from ubuntu shell works as 
expected. Arduino Uno, Oleg's USB Shield. 

Tracked the problem to an incorrect assumption in the loop of the example. It 
assumes that the only valid value that it should see for shell->status is 
ADB_OPEN, but it can see others, and does see ADB_WRITING after sending the 
first character. 

If you look at the original error report, you can see that it is complaining 
that "l" cannot be executed because it does not have execute permissions.

In the loop function of the example, immediately after the Serial.read() call, 
loop on poll as long as the status is one of the "busy" flavors:

    while (shell->status == ADB_RECEIVING || shell->status == ADB_WRITING) {
      ADB::poll();
    }

Original comment by dennis.p...@gmail.com on 18 Sep 2011 at 1:32

GoogleCodeExporter commented 9 years ago
Part of my last comment was not clear. The reason for the permission denied 
message in the original description is that the "l" from the "ls" command was 
sent and interpreted by the shell on the Android side as a command. As I 
experimented with line ending settings on the "serial monitor" in the Adruino 
studio and with details of sending I observed this happening. The sequence was:

1. The 'l' was read by Serial.read()
2. The shell->write call worked
3. The ADB::poll() at the end of the loop function occurred before the Android 
sent the "okay" message, so the shell connection was still in state ADB_WRITING.
4. The loop ran again, before the Android "okay" arrived. The "s" was read by 
the Serial.read() call. 
5. The shell->write was not attempted because the shell->status value was 
ADB_WRITING instead of ADB_OPEN. This meant that the "s" character was lost.
6. The ADB::poll() at the end of the loop was called, and the "okay" message 
was processed, setting the status to ADB_OPEN when it was done.
7. The loop was entered again, and the newline was read by Serial.read(). 
8. The newline was sent, so the shell on Android tried to execute the command 
'l' and received the permission denied.

The moral of this story is that Adruino code must be written with an awareness 
of the fact that the processing model is a form of single threaded cooperative 
multitasking based on an event model. When you write code in this model, you 
must always consider how your code interacts with the even system and all the 
states and event listeners. You must ensure that any event listeners that 
provide services to your loop function get the opportunity to run, which means 
you need to ensure that the even source gets filled.

Original comment by dennis.p...@gmail.com on 18 Sep 2011 at 3:50

GoogleCodeExporter commented 9 years ago
Sorry for the slightly out-of-scope question but did anyone get the shell 
example to run on the Duemilanove? I manage to upload the app to the arduino 
but then keep getting: Shell not openl (not even l: permission denied).

Also: my android device (HTC Hero 1.5) is not rooted, is that really required 
for microbridge to work? Do you guys know why? 

Cheers

Original comment by mister...@gmail.com on 21 Sep 2011 at 4:12

GoogleCodeExporter commented 9 years ago
I Running Shell Example, uploaded to DFRduino with arduino ADK shield for 
android and i getting: Shell not openl.
but i try to modify Shell Example loop to be like this:

void loop()
{
  byte ch;

  // Check for incoming serial data
  if (Serial.available() > 0)
  {
    // read the incoming byte:
    ch = Serial.read();

    // Write to shell
    if (shell->status == ADB_OPEN)
      shell->writeString("ls\n");
    else
      Serial.print("Shell not open");

  }

  // Poll the ADB subsystem.
  ADB::poll();
}

it's works every time i press send any character and i see a list of files and 
directories.

i am using huawei ideos s7

Original comment by jodyzach...@gmail.com on 3 Oct 2011 at 4:40

GoogleCodeExporter commented 9 years ago
We had the same issues with an Arduino Uno and a Host Shield.

attached is our working solution.
We tried many different approaches, this was the only one that worked

#include <SPI.h>
#include <Adb.h>

Connection * shell;

// Event handler for the shell connection. 
void adbEventHandler(Connection * connection, adb_eventType event, uint16_t 
length, uint8_t * data)
{
  int i;

  if (event == ADB_CONNECTION_RECEIVE)
    for (i=0; i<length; i++)
      Serial.print(data[i]);

}

void setup()
{

  // Initialise serial port
  Serial.begin(57600);

  // Initialise the ADB subsystem.  
  ADB::init();

  // Open an ADB stream to the phone's shell. Auto-reconnect
  shell = ADB::addConnection("shell:", true, adbEventHandler);  

}

void loop()
{
  ADB::poll();
  byte ch;

  // Check for incoming serial data
  if (Serial.available() > 0)
  {
    // read the incoming byte:
    ch = Serial.read();

    // Write to shell
    if (shell->status == ADB_OPEN)
      shell->write(1, &ch);
    else
      Serial.print("Shell not open");

  }

  // Poll the ADB subsystem.
  while(shell->status == ADB_RECEIVING || shell->status == ADB_WRITING) 
  {    
    ADB::poll();
  }
}

Original comment by Matthias...@gmail.com on 10 Nov 2011 at 8:19

GoogleCodeExporter commented 9 years ago
Hallo,

using MEGA ADK, Arduino 1.0 and LG Optimus One, ADB library from 
http://labs.arduino.cc/uploads/ADK/GettingStarted/arduino_bundle_ADB.zip

The solution from Matthias works beautifully.

I just have a problem with the echo char from ADB, it is printed as a number 
instead of a char.
I replaced

      Serial.print(data[i]);

with

      Serial.print((char)data[i]);

and I have the correct display.
Wonder why you never had this issue, I guess Arduino 1.0 libraries?

Original comment by antonio....@gmail.com on 4 Apr 2012 at 4:52

GoogleCodeExporter commented 9 years ago
Hi guys ,

Trying to get a usb host connection on a arduino pro mini 3.3v from sparkfun 
coupled with Oleg's usb host mini.

The usb shell returns "shell not open" to both the default implementation 
provided
in the adb library (from here : 
http://labs.arduino.cc/uploads/ADK/GettingStarted/arduino_bundle_ADB.zip) and 
Matthias's version as well.

I've spent 2 nights trying to pin this down... 
I've also tried to run some other basic examples such as 
http://mitchtech.net/android-arduino-usb-host-simple-digital-input/

But cannot establish a connection between my device and the arduino.
if you have any advice, i'd appreciate it.

Kind regards,
arie

Original comment by arie.co...@gmail.com on 7 Mar 2013 at 10:34

GoogleCodeExporter commented 9 years ago
Hi guys,
same as arie said. The problem is that still says shell not open and if I try 
to force to execute shell->write(1, &ch); without the if condition, it returns 
-1.

Any suggestion? 

Original comment by marco.br...@gmail.com on 27 May 2014 at 5:07

GoogleCodeExporter commented 9 years ago
Solution for android >4.2 here:

http://forum.arduino.cc/index.php?topic=243029.0

hope it helps!

Original comment by marco.br...@gmail.com on 27 May 2014 at 9:30