Skip to content

Commit

Permalink
closes #1 closes #2
Browse files Browse the repository at this point in the history
This commit adds the basic protocol for send and receive in the code. The file is in arduino_src > code > Protocol Prototype.
Send and receive uses 1 Serial line. The receive looks for a header 0xFC. Code still needs to be cleaned up
Further testing is still needed.
  • Loading branch information
ayeohmy committed Sep 7, 2014
1 parent 4ea6f08 commit 3fcd447
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 0 deletions.
48 changes: 48 additions & 0 deletions arduino_src/code/Protocol_prototype/IO_pad.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/********************************************************************************
* All rights are open to the public, to use, share, dump, spread for the *
* foreseeable future. This software and documentation constitutes purely *
* published and public work, and contains open source knowledge by a bunch *
* of college kids who just want to have fun. All the material and code may be *
* used, copied, duplicated, changed, disclosed... with any human's free will. *
* Have a nice day! :) *
********************************************************************************/

#include <Arduino.h>
#include "IO_pad.h"
#include "lib_types.h"
/*********************************************************************************
* L O C A L P R O T O T Y P E S *
********************************************************************************/





/*********************************************************************************
* G L O B A L F U N C T I O N S *
********************************************************************************/
Ret_E IO_set_pad( byte pad, byte value )
{
Ret_E success = RET_ERROR;
analogWrite(pad, value);
success = RET_OK;
return success;
}


Ret_E IO_set_state( byte pad, IO_state_e state)
{
Ret_E success = RET_ERROR;
digitalWrite(pad, state);
success = RET_OK;
return success;
}


/*********************************************************************************
* L O C A L F U N C T I O N S *
********************************************************************************/




29 changes: 29 additions & 0 deletions arduino_src/code/Protocol_prototype/IO_pad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/********************************************************************************
* All rights are open to the public, to use, share, dump, spread for the *
* foreseeable future. This software and documentation constitutes purely *
* published and public work, and contains open source knowledge by a bunch *
* of college kids who just want to have fun. All the material and code may be *
* used, copied, duplicated, changed, disclosed... with any human's free will. *
* Have a nice day! :) *
********************************************************************************/



#ifndef IO_PAD_H_
#define IO_PAD_H_
#include <Arduino.h>
#include "IO_types.h"
#include "lib_types.h"

#ifdef __cplusplus
extern "C"{
#endif


Ret_E IO_set_pad( byte pad, byte value);
Ret_E IO_set_state( byte pad, IO_state_e state );

#ifdef __cplusplus
}
#endif
#endif
30 changes: 30 additions & 0 deletions arduino_src/code/Protocol_prototype/IO_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/********************************************************************************
* All rights are open to the public, to use, share, dump, spread for the *
* foreseeable future. This software and documentation constitutes purely *
* published and public work, and contains open source knowledge by a bunch *
* of college kids who just want to have fun. All the material and code may be *
* used, copied, duplicated, changed, disclosed... with any human's free will. *
* Have a nice day! :) *
********************************************************************************/

#ifndef IO_TYPES_H_
#define IO_TYPES_H_

#include <Arduino.h>

#ifdef __cplusplus
extern "C"{
#endif

typedef enum
{
low,
high
}IO_state_e;



#ifdef __cplusplus
} // extern "C"
#endif
#endif
48 changes: 48 additions & 0 deletions arduino_src/code/Protocol_prototype/Protocol_prototype.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "IO_pad.h"
#include "lib_protocol.h"
#include "lib_types.h"

void setup() {
Serial.begin(9600);
}

void loop() {
// This is the tester
// It will continuously send a packet to the computer side
// Arduino -> Computer
byte index = 0x01;
unsigned int message = 0xDEAD;
unsigned long packet = protocol_send(index, message);

// TODO: should have a safe fault eg. packet != NULL
// Serial.print("The packet is: ");
// Serial.println(packet,HEX);


/************** RECEIVE PACKET ********************/
// if Serial is available read if there are any incoming messages
if (Serial.available()) {
// read the incoming byte:
byte incomingByte = Serial.read();

// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, HEX);

if(incomingByte == HEAD)
{
unsigned long pckt = incomingByte;
for(int i = 0; i < 3; i++)
{
pckt = pckt << ONE_BYTE_SIZE;
incomingByte = Serial.read();
pckt = pckt | incomingByte;
}
Serial.print("I received a packet! It is: ");
Serial.println(pckt, HEX);
}
// parse the byte?

}
delay(500);
}
6 changes: 6 additions & 0 deletions arduino_src/code/Protocol_prototype/issues.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Audrey Issues/ Questions:
- The Arduino Serial.write, will it just work if I include Arduino.h?
- C++ extern header needed?
- Receiving Protocol. Similar? When is it fired?
- Init protocol -> What is expected?
- Receiving on interrupt? Serial??? hmmm
84 changes: 84 additions & 0 deletions arduino_src/code/Protocol_prototype/lib_protocol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/********************************************************************************
* All rights are open to the public, to use, share, dump, spread for the *
* foreseeable future. This software and documentation constitutes purely *
* published and public work, and contains open source knowledge by a bunch *
* of college kids who just want to have fun. All the material and code may be *
* used, copied, duplicated, changed, disclosed... with any human's free will. *
* Have a nice day! :) *
********************************************************************************/

/* @author: Audrey Yeoh ([email protected])
* @date: 7/22/2014
*/

#include <Arduino.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "lib_types.h"


/********************************************************************************
* D E F I N I T I O N S
********************************************************************************/



/********************************************************************************
* L O C A L P R O T O T Y P E S
********************************************************************************/
//static unsigned long create_msg( byte id, unsigned int msg);
static Ret_E send_msg( unsigned long message ); // TODO: need to implement actual sending of message

/********************************************************************************
* G L O B A L F U N C T I O N S
********************************************************************************/
/* This will set up the head, and append all the messages ready to be sent and
* prepare the message
* And then send the message with a return state being ok if successful
*/
unsigned long protocol_send( byte id, unsigned int msg )
{
// Ret_E success = RET_ERROR;
// create the message
// unsigned long message = create_msg(id, msg);

unsigned long message = HEAD;
message = message << ONE_BYTE_SIZE;
message = message | id;
message = message << TWO_BYTE_SIZE;
message = message | msg;

// if more messages, append? << What do?

// send the message
//success = send_msg( message );
// return state

return message;

}


/********************************************************************************
* L O C A L F U N C T I O N S
********************************************************************************/

static unsigned long create_msg( byte id, unsigned int msg)
{
unsigned long message = HEAD;
message = message << ONE_BYTE_SIZE;
message = message | id;
message = message << TWO_BYTE_SIZE;
message = message | msg;
return message;
}

static Ret_E send_msg( unsigned long message )
{
Ret_E success = RET_ERROR;
// TODO!!!!! Send message

return success;
}
43 changes: 43 additions & 0 deletions arduino_src/code/Protocol_prototype/lib_protocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/********************************************************************************
* All rights are open to the public, to use, share, dump, spread for the *
* foreseeable future. This software and documentation constitutes purely *
* published and public work, and contains open source knowledge by a bunch *
* of college kids who just want to have fun. All the material and code may be *
* used, copied, duplicated, changed, disclosed... with any human's free will. *
* Have a nice day! :) *
********************************************************************************/

/* @author: Audrey Yeoh ([email protected])
* @date: 7/22/2014
*/



#ifndef LIB_PROTOCOL_H
#define LIB_PROTOCOL_H

#include <Arduino.h>

#ifdef __cplusplus
extern "C"{
#endif

#include "lib_types.h"


/* This will be the main structure of our packets:
*
* Head [0xFC] ID [ - ] Message[ - -] ... ID [ - ] Message[ - -]
* [ 1 byte ] [1 byte] [ 2 bytes ] ... [1 byte] [ 2 bytes ]
*/

Ret_E protocol_init( void ); // TODO: I'm not sure exactly what needs to be initialized yet
Ret_E protocol_run( void ); // TODO:
unsigned long protocol_send( byte id, unsigned int message); // Currently working on
unsigned long protocol_getMessage(unsigned long packet);
unsigned long protocol_getID(unsigned long packet);

#ifdef __cplusplus
}
#endif
#endif // LIB_PROTOCOL_H
38 changes: 38 additions & 0 deletions arduino_src/code/Protocol_prototype/lib_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/********************************************************************************
* All rights are open to the public, to use, share, dump, spread for the *
* foreseeable future. This software and documentation constitutes purely *
* published and public work, and contains open source knowledge by a bunch *
* of college kids who just want to have fun. All the material and code may be *
* used, copied, duplicated, changed, disclosed... with any human's free will. *
* Have a nice day! :) *
********************************************************************************/

/* @author: Audrey Yeoh ([email protected])
* @date: 7/22/2014
*/

#ifndef LIB_TYPES_H
#define LIB_TYPES_H
#ifdef __cplusplus
extern "C"{
#endif

#include <stdint.h>
#include <Arduino.h>

#define HEAD 0xFC
#define ONE_BYTE_SIZE 8
#define TWO_BYTE_SIZE 16

typedef enum
{
RET_OK,
RET_ERROR
}Ret_E;


#ifdef __cplusplus
}
#endif

#endif // LIB_TYPES_H

0 comments on commit 3fcd447

Please sign in to comment.