Waiting for the wind

programming memo in different platforms

「iPhone’s Road」分類文章彙整

iPhone serial port communication

發文作者 cotton5415 於 三月 17, 2011

http://devdot.wikispaces.com/Iphone+Serial+Port+Tutorial

Requirement:
1.Jailbroken Iphone with BSD Subsystem installed (Search the web for jailbreak tutorials)
2.Iphone development toolchain for Mac OSX, Linux, Windows (Cygwin) or other OS. I use this http://code.google.com/p/winchain/ in Windows.
3.Sparkfun Ipod connector or breakout board see http://www.sparkfun.com/commerce/product_info.php?products_id=633 or http://www.sparkfun.com/commerce/product_info.php?products_id=8295
4.PC USB UART – optional, but used in this tutorial. You will need either a 3.3V level UART for PC (see http://www.sparkfun.com/commerce/product_info.php?products_id=718) or you will need an old style 12V level serial cable with a level converter like this one http://www.compsys1.com/workbench/On_top_of_the_Bench/Max233_Adapter/max233_adapter.html (see warning below)
5.A soldering iron will help you out :)
6.Microsoft Visual Studio – optional, but used in the source code examples for the PC serial port communication.

WARNING! Do not try to use a 12V level RS232 port for this without a level converter to ~3V, it will severely damage your Iphone or render it non-functional.

Hardware:
The Dock Port
In the Ipod/Iphone dock port, the pins we are concerned with are as follows
Pin 1
Ground
Pin 18
3.3V Power (+)
Pin 12
TX also known as Serial Transmit
Pin 13
RX also known as Serial Receive

To see a full description of all of the pins in the dock connector, see here: http://pinouts.ru/Devices/ipod_pinout.shtml

Connections: iPhone/iPod Touch RX should connect to TX of the connected device, TX to RX of the connected device, and Ground to the Ground of the connected device. If your device can be powered by a low amperage, 3.3V power source you may chose to connect PIN 18 as well and power your device directly from the iPhone/iPod Touch.

Sample Codes:

#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
 
static struct termios gOriginalTTYAttrs;
 
static int OpenSerialPort()
{
    int        fileDescriptor = -1;
    int        handshake;
    struct termios  options;
 
    // Open the serial port read/write, with no controlling terminal, and don't wait for a connection.
    // The O_NONBLOCK flag also causes subsequent I/O on the device to be non-blocking.
    // See open(2) ("man 2 open") for details.
 
    fileDescriptor = open("/dev/tty.iap", O_RDWR | O_NOCTTY | O_NONBLOCK);
    if (fileDescriptor == -1)
    {
        printf("Error opening serial port %s - %s(%d).\n",
               "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }
 
    // Note that open() follows POSIX semantics: multiple open() calls to the same file will succeed
    // unless the TIOCEXCL ioctl is issued. This will prevent additional opens except by root-owned
    // processes.
    // See tty(4) ("man 4 tty") and ioctl(2) ("man 2 ioctl") for details.
 
    if (ioctl(fileDescriptor, TIOCEXCL) == -1)
    {
        printf("Error setting TIOCEXCL on %s - %s(%d).\n",
            "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }
 
    // Now that the device is open, clear the O_NONBLOCK flag so subsequent I/O will block.
    // See fcntl(2) ("man 2 fcntl") for details.
 
    if (fcntl(fileDescriptor, F_SETFL, 0) == -1)
    {
        printf("Error clearing O_NONBLOCK %s - %s(%d).\n",
            "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }
 
    // Get the current options and save them so we can restore the default settings later.
    if (tcgetattr(fileDescriptor, &gOriginalTTYAttrs) == -1)
    {
        printf("Error getting tty attributes %s - %s(%d).\n",
            "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }
 
    // The serial port attributes such as timeouts and baud rate are set by modifying the termios
    // structure and then calling tcsetattr() to cause the changes to take effect. Note that the
    // changes will not become effective without the tcsetattr() call.
    // See tcsetattr(4) ("man 4 tcsetattr") for details.
 
    options = gOriginalTTYAttrs;
 
    // Print the current input and output baud rates.
    // See tcsetattr(4) ("man 4 tcsetattr") for details.
 
    printf("Current input baud rate is %d\n", (int) cfgetispeed(&options));
    printf("Current output baud rate is %d\n", (int) cfgetospeed(&options));
 
    // Set raw input (non-canonical) mode, with reads blocking until either a single character
    // has been received or a one second timeout expires.
    // See tcsetattr(4) ("man 4 tcsetattr") and termios(4) ("man 4 termios") for details.
 
    cfmakeraw(&options);
    options.c_cc[VMIN] = 1;
    options.c_cc[VTIME] = 10;
 
    // The baud rate, word length, and handshake options can be set as follows:
 
    cfsetspeed(&options, B19200);    // Set 19200 baud
    options.c_cflag |= (CS8);  // RTS flow control of input
 
 
    printf("Input baud rate changed to %d\n", (int) cfgetispeed(&options));
    printf("Output baud rate changed to %d\n", (int) cfgetospeed(&options));
 
    // Cause the new options to take effect immediately.
    if (tcsetattr(fileDescriptor, TCSANOW, &options) == -1)
    {
        printf("Error setting tty attributes %s - %s(%d).\n",
            "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }
    // Success
    return fileDescriptor;
 
    // Failure "/dev/tty.iap"
error:
    if (fileDescriptor != -1)
    {
        close(fileDescriptor);
    }
 
    return -1;
}

發表於 iPhone's Road | 已加上的標籤: , , | 張貼留言 »

install ldid

發文作者 cotton5415 於 十一月 17, 2010

get binary from

http://svn.telesphoreo.org/trunk/data/ldid/ldid-1.0.610.tgz

% tar -zxf ldid-1.0.610.tgz
% cd ldid-1.0.610
% g++ -I . -o util/ldid{,.cpp} -x c util/{lookup2,sha1}.c
% sudo cp -a util/ldid /usr/bin

發表於 iPhone's Road, MAC OS X's Road | 已加上的標籤: , , , | 張貼留言 »

mac/iphone/obj-c programming note

發文作者 cotton5415 於 八月 21, 2010

Every method or function whose name includes “new”, “alloc”, “Create” or “copy” requires a balancing release/free

發表於 iPhone's Road, MAC OS X's Road | 張貼留言 »

how to restore SMS data in iPhone

發文作者 cotton5415 於 八月 11, 2010

referenced from : http://www.ihackintosh.com/2009/08/restore-sms-history-from-iphone-3g-to-iphone-3gs/

Windows User : C >> Users >> User Name >> AppData >> Roaming >> Apple >> Computer >> MobileSync >> Backup >>
Mac OS X User : ~/Libary » Applications Support » MobileSync » Backup.
In the backup folder there will be X number of folders according to number of phones you synced to your iTunes. For example i have two iPhone 2G and 3G so i have two folders named with 40 random hex characters. But i need to copy SMS from iPhone 3G so how do i identify?
To identify your particular iPhone backup sync both phones with 5 minutes of interval and note the time in your computer clock while syncing.
Now Sort the view by date–this will let you easily tell which subfolder belongs to which phone.
Now you knows the folder where your previous iPhone 3G backup is saved, so explore to that particular folder (iPhone 3G) and copy these two files to iPhone 3GS folder. Make sure you must synced new iPhone 3GS at least once so back up folder will be created.
3d0d7e5fb2ce288813306e4d4636395e047a3d28.mddata
3d0d7e5fb2ce288813306e4d4636395e047a3d28.mdinfo
Connect your new iPhone 3GS to the computer and launch the iTunes.
When your iPhone appears under Devices in your iTunes sidebar, Control-click it and select the ‘Restore from Backup…’ option.
Select the backup related to your device i mean iPhone 3GS.

發表於 iPhone's Road | 已加上的標籤: , | 張貼留言 »

downgrade iphone from 4.0 to 3.1.3

發文作者 cotton5415 於 八月 11, 2010

ref: http://www.blogsdna.com/9175/how-to-downgrade-iphone-3g-4-0-os-to-3-1-3-firmware-on-windows-mac.htm

1. download the firmware from ref.
2. use iTunes press option and Restore to restore the firmware which you downloaded in step1.
3. 1015 error appear, dont’ care click ok.
4. open console on mac:
cd Desktop
. / iRecovery -s
setenv auto-boot true
saveenv
fsboot
exit
5. Now unplug your iPhone and turn it off by pressing the home+power button
6. Once it is off, turn it on by pressing the power button. Plug-in your iPhone and load iTunes to continue with the activation.

發表於 iPhone's Road, MAC OS X's Road | 已加上的標籤: , , , , | 張貼留言 »

iPhone CodeSign error: a valid provisioning profile is required for product type ‘Application’ in SDK ‘Device – iPhone OS 2.0′

發文作者 cotton5415 於 五月 18, 2009

http://www.frogameleon.com/blog/iphone-sdk-codesign-error-a-valid-provisioning-profile-is-required-for-product-type-application-in-sdk-device-iphone-os-22

error occurs in building phase:
codesign error: avalid provisioning file is required for product t ype ‘Application’

  1. # cd ~/Library/Mobiledevice
  2. # grep <iPhone’s identifier&gh;
  3. copy the UUID (main file name) of the provision file
  4. goto your project, edit project.pbxproj file
  5. get the search the keyword “PROVISIONING_PROFILE[sdk=iphoneos*]
  6. replace the identifyer after PROVISIONING_PROFILE to which you want to apply

發表於 iPhone's Road | 張貼留言 »

iPhone and fork

發文作者 cotton5415 於 四月 21, 2009

in iPhone, use fork() always returns -1. and set errno to 1 (Operation not permitted )
.

發表於 iPhone's Road, MAC OS X's Road | 張貼留言 »

iPhone application icon in iTunes

發文作者 cotton5415 於 十一月 4, 2008

  • create a 512×512 JPEG image named ‘iTunesArtwork’ without any file extension.
  • Put it in your project Resources folder.
  • 發表於 iPhone's Road, MAC OS X's Road | 已加上的標籤: , , , , , , | 張貼留言 »

     
    Follow

    Get every new post delivered to your Inbox.