[Hardware Hacking General] AdamOutler:
In this version

Uses all 4 Arduino MEGA serial ports

"`" menu hotkey

Selectable hex output

real-time adjustable baud rate

/*
Arduino Serial Connector
Copyright 2011 Adam Outler

Licensed under the I Dont Give a **** License, Version 1.0 (the "License");
you may not use this file except in compliance with the License.

3. Send me an email if you find this helpful
If you're wondering where number 1 and 2 is, I don't give a ****.

-Adam Outler adamoutler, gmail.com

/*
HEXOUTPUT displays a line of hex output then
a line of normal text- activated by "`"
BAUD will be the computer's baud rate and the
inital baud rate set for all devices
*/
boolean HEXOUTPUT=true;
unsigned long BAUD=115200;

//begin sketch
String MESSAGE[4]; //Hexoutput messages dumped into this string array
unsigned long SerialPrintTimer[4]={0,0,0,0}; //Serial timers off
int inByte;//byte received from serials 1,2,3

void setup() {
Serial.begin(BAUD); //Initialize Computer baud
setSerialBaudRate(BAUD); //Initialize Serials 1,2,3 baud
Serial.print("Communications established");
}

/*
Loop will check if Serial(computer) has anything to
say to the Serial1(device), and then says it. It
will also print all values from Serial1, Serial2,
and Serial3 to Serial(computer)
If HEXOUTPUT formatting is requested by pressing the
"`" key, it will display output in hex format, then
output a line of human readable text
*/
void loop() {
if ( HEXOUTPUT ) { // if hex output is requested then use this
hexOutputHandling();
} else { //Serial1,Serial2, Serial3>Computer in byte format
standardOutputHandling();
}
serialInputHandler();//send to Serial1 and handle special keys
checkForUntruncatedSerial(); //timer to print serial lines in std output
}

/*
serialInputHandler reads keys comming from computer
makes decisions based on key numbers
sends output to Serial1
*/
void serialInputHandler() {
if (Serial.available()) { //User has commanded input
int IncommingSerial=Serial.read(); //read input to var
//turn on/off HEXOUTPUT with the "`" key
if (IncommingSerial == 96 ) displayMenu();
Serial1.print(IncommingSerial, BYTE); //Send var to Serial1
}
}

void displayMenu(){
Serial.println("");
Serial.println("Main Menu");
Serial.println("--------------------");
Serial.println("--HEX OUTPUT--");
Serial.println("`-toggle hex output"); //96
Serial.println("--BAUD RATE--");
Serial.println("a-115200");//97
Serial.println("b-57600");//98
Serial.println("c-38400");//99
Serial.println("d-28800");//100
Serial.println("e-19200");//101
Serial.println("f-14400");//102
Serial.println("g-9600");//103
Serial.println("h-4800");//104
Serial.println("i-2400");//105
Serial.println("j-1200");//106
Serial.println("k-300");//107
Serial.print("Select one, press enter");
int inkey;
Serial.flush();
while (inkey != 13 ){
inkey=-1;
if (Serial.available()) inkey=Serial.read();
switch (inkey) {
case 96: //`
HEXOUTPUT=(!HEXOUTPUT);
displayBlatentChangeMessage("HEX Output toggled");
break;
case 97: //a
setSerialBaudRate(115200);
displayBlatentChangeMessage("Baud 115200");
break;
case 98: //b
setSerialBaudRate(57600);
displayBlatentChangeMessage("Baud 57600");
break;
case 99: //c
setSerialBaudRate(38400);
displayBlatentChangeMessage("Baud 38400");
break;
case 100: //d
setSerialBaudRate(28800);
displayBlatentChangeMessage("Baud 28800");
break;
case 101: //e
setSerialBaudRate(19200);
displayBlatentChangeMessage("Baud 19200");
break;
case 102: //f
setSerialBaudRate(14400);
displayBlatentChangeMessage("Baud 14400");
break;
case 103: //g
setSerialBaudRate(9600);
displayBlatentChangeMessage("Baud 9600");
break;
case 104: //h
setSerialBaudRate(4800);
displayBlatentChangeMessage("Baud 4800");
break;
case 105: //i
setSerialBaudRate(2400);
displayBlatentChangeMessage("Baud 2400");
break;
case 106: //j
setSerialBaudRate(1200);
displayBlatentChangeMessage("Baud 1200");
break;
case 107: //k
setSerialBaudRate(300);
displayBlatentChangeMessage("Baud 300");
break;
case 13: //l
return;
break;
}
}
}

void displayBlatentChangeMessage(String Message){
for (int i = 0; i < 40; i++){
Serial.println(Message);
}
}

/*
checkForUntruncatedSerial reads timers put on
each serial line and if it has been greater then
the time allowed for a 0x13, then it will print the line
*/
void checkForUntruncatedSerial() {
double time=millis();
for ( int i = 1; i <= 3; i++){
if ( SerialPrintTimer[i] != 0 && SerialPrintTimer[i] < time ){
displayNormal(i);
}

}
}

void setSerialBaudRate(unsigned long baud){
if ( baud == 0.00 ) baud=BAUD;
Serial1.begin(baud);
Serial2.begin(baud);
Serial3.begin(baud);
}

/*
standardOutputHandling reads from Serial1
Serial2, and serial3 then outputs to computer
*/
void standardOutputHandling(){
if (Serial1.available()) Serial.print(Serial1.read(), BYTE);
if (Serial2.available()) Serial.print(Serial2.read(), BYTE);
if (Serial3.available()) Serial.print(Serial3.read(), BYTE);
}

/*
hexOutputHandling reads from Serial1, Serial2,
and Serial3 then sends to displayHex function
for processing. The output is stored in an
array and displayed on 0x13, or after timer
has elapsed
*/
void hexOutputHandling(){
if (Serial1.available()) {
inByte = Serial1.read();
displayHex(1); //Serial1>displayHexfunction>Computer
}
if (Serial2.available()) {
inByte = Serial2.read();
displayHex(2);//Serial2>displayHexfunction>Computer
}
if (Serial3.available()) {
inByte = Serial3.read();
displayHex(3);//Serial3>displayHexfunction>Computer
}
}

/*
displayNormal is called at the end of a line of hexoutput
or when serialPrintTimer has elapsed. It displays the
byte format output and the serial line which originated
the transaction
*/
void displayNormal( int SerialID ){
Serial.println("");
Serial.print(" SERIAL");
Serial.print(SerialID);
Serial.println(": " + MESSAGE[SerialID]);//Serial1:Message
MESSAGE[SerialID]="";//clear message
SerialPrintTimer[SerialID]=0;//reset print timer
}

/*
displayHex formats the hexoutput and the final message
which is displayed when char 13 is received or the timer
has elapsed
*/
void displayHex(int SerialID){

SerialPrintTimer[SerialID]=millis()+ 1000;//set timer for display
if ( inByte >= 19 ) MESSAGE[SerialID] = MESSAGE[SerialID] + " " + (char)inByte; //dump char into string
Serial.print("|");
Serial.print(inByte, HEX); //print character
if ( inByte == 13 ){ displayNormal( SerialID ); }//line ending dump string onto screen
}

here is an example

Communications established|10|31|A|D

SERIAL3: 1

|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|2D|A|D

SERIAL3: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

|20|20|20|53|61|6D|73|75|6E|67|20|50|72|69|6D|69|74|69|76|65|20|42|6F|6F|74|6C|6F|61|64|65|72|20|28|50|42|4C|29|20|76|33|2E|30|A|D

SERIAL3: S a m s u n g P r i m i t i v e B o o t l o a d e r ( P B L ) v 3 . 0

|20|20|20|43|6F|70|79|72|69|67|68|74|20|28|43|29|20|53|61|6D|73|75|6E|67|20|45|6C|65|63|74|72|6F|6E|69|63|73|20|43|6F|2E|2C|20|74|36|2D|2D|2D|2D|2D|2D|2D|2D|0

SERIAL3: C o p y r i g h t ( C ) S a m s u n g E l e c t r o n i c s C o . , t 6 - - - - - - - -

Main Menu

--------------------

--HEX OUTPUT--

`-toggle hex output

--BAUD RATE--

a-115200

b-57600

c-38400

d-28800

e-19200

f-14400

g-9600

h-4800

i-2400

j-1200

k-300

Select one, press enterHEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

HEX Output toggled

1

-----------------------------------------------------------

Samsung Primitive Bootloader (PBL) v3.0

Copyright (C) Samsung Electronics Co., Ltd. 2006-2010

-----------------------------------------------------------

+n1stVPN 2688

+nPgsPerBlk 64

PBL found bootable SBL: Partition(3).

Set cpu clk. from 400MHz to 800MHz.

OM=0x9, device=OnenandMux(Audi)

IROM e-fused - Non Secure Boot Version.

-----------------------------------------------------------

Samsung Secondary Bootloader (SBL) v3.0

Copyright (C) Samsung Electronics Co., Ltd. 2006-2010

Board Name: ARIES REV 03

Build On: Feb 1 2011 10:54:21

-----------------------------------------------------------

Re_partition: magic code(0x0)

[PAM: ] ++FSR_PAM_Init

[PAM: ] OneNAND physical base address : 0xb0000000

[PAM: ] OneNAND virtual base address : 0xb0000000

[PAM: ] OneNAND nMID=0xec : nDID=0x50

[PAM: ] --FSR_PAM_Init

fsr_bml_load_partition: pi->nNumOfPartEntry = 12

partitions loading success

board partition information update.. source: 0x0

Now Read Images - ID : 1

.Done.

read 1 units.

==== PARTITION INFORMATION ====

ID : IBL+PBL (0x0)

ATTR : RO SLC (0x1002)

FIRST_UNIT : 0

NO_UNITS : 1

===============================

ID : PIT (0x1)

ATTR : RO SLC (0x1002)

FIRST_UNIT : 1

NO_UNITS : 1

===============================

ID : EFS (0x14)

ATTR : RW STL SLC (0x1101)

FIRST_UNIT : 2

NO_UNITS : 40

===============================

ID : SBL (0x3)

ATTR : RO SLC (0x1002)

FIRST_UNIT : 42

NO_UNITS : 5

===============================

ID : SBL2 (0x4)

ATTR : RO SLC (0x1002)

FIRST_UNIT : 47

NO_UNITS : 5

===============================

ID : PARAM (0x15)

ATTR : RW STL SLC (0x1101)

FIRST_UNIT : 52

NO_UNITS : 20

===============================

ID : KERNEL (0x6)

ATTR : RO SLC (0x1002)

FIRST_UNIT : 72

NO_UNITS : 30

===============================

ID : RECOVERY (0x7)

ATTR : RO SLC (0x1002)

FIRST_UNIT : 102

NO_UNITS : 30

===============================

ID : FACTORYFS (0x16)

ATTR : RW STL SLC (0x1101)

FIRST_UNIT : 132

NO_UNITS : 1146

===============================

ID : DBDATAFS (0x17)

ATTR : RW STL SLC (0x1101)

FIRST_UNIT : 1278

NO_UNITS : 536

===============================

ID : CACHE (0x18)

ATTR : RW STL SLC (0x1101)

FIRST_UNIT : 1814

NO_UNITS : 140

===============================

ID : MODEM (0xb)

ATTR : RO SLC (0x1002)

FIRST_UNIT : 1954

NO_UNITS : 50

===============================

loke_init: j4fs_open success..

load_lfs_parameters valid magic code and version.

reading nps status file is successfully!.

nps status=0x504d4f43

load_debug_level reading debug level from file successfully(0x574f4c44).

init_fuel_gauge: vcell = 4141mV, soc = 102