Skip to content

Commit

Permalink
4
Browse files Browse the repository at this point in the history
- fixed a compile error
- made gateway commands human-readable
  • Loading branch information
i-make-robots committed Apr 18, 2014
1 parent 16366cf commit 1913c1d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 74 deletions.
118 changes: 60 additions & 58 deletions near_MDB/near_MDB.ino
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,6 @@ struct MDB_Byte sendData[MDB_BUFFER_SIZE];
//----------------------------------------------------------------



void RPI_setup() {
RPI.begin(57600);
//RPI.print("Hello from near MDB!\n");
delay(100);
RPI.print("Hello, World!");
RPI_buffer_count=0;
}


void setup() {
RPI_setup();
MDB_setup();
Expand All @@ -184,6 +174,16 @@ void loop() {
}



void RPI_setup() {
RPI.begin(57600);
//RPI.print("Hello from near MDB!\n");
delay(100);
RPI.print("Hello, World!");
RPI_buffer_count=0;
}


void RPI_read() {
if(RPI.available()) {
char data = RPI.read();
Expand Down Expand Up @@ -225,6 +225,17 @@ void MDB_setup() {
}


void MDB_read() {
// is data availble?
if((UCSR0A & (1<<RXC0))) {
// read it
MDB_getByte(&recvData[0]);
//RPI.print(recvData[0]);
MDB_parse();
}
}


void MDB_getByte(struct MDB_Byte* mdbb) {
int b;
char tmpstr[7];
Expand All @@ -233,12 +244,11 @@ void MDB_getByte(struct MDB_Byte* mdbb) {
b = USART_Receive();
memcpy (mdbb, &b, 2);

if (mdbb->mode)
sprintf(tmpstr, "<%.2x*", mdbb->data);
else
sprintf(tmpstr, "<%.2x", mdbb->data);

// if (gDebug > 1) dbg_print(tmpstr);
/*if (gDebug > 1) {
if (b.mode) sprintf(tmpstr, ">%.2x*", b.data);
else sprintf(tmpstr, ">%.2x", b.data);
dbg_print(tmpstr);
}*/
}


Expand All @@ -261,51 +271,12 @@ int USART_Receive() {
return -1;
}

/* Filter the 9th bit, then return */
// Filter the 9th bit, then return
resh = (resh >> 1) & 0x01;
return ((resh << 8) | resl);
}


void MDB_write(int data) {
char tmpstr[7];
struct MDB_Byte b;

memcpy(&b, &data, 2);

serial_write(b);

//if (debug) {
//if (b.mode) sprintf(tmpstr, ">%.2x*", b.data);
//else sprintf(tmpstr, ">%.2x", b.data);
//if (gDebug > 1) dbg_print(tmpstr);
//}
}


void serial_write(struct MDB_Byte mdbb) {
while ( !( UCSR0A & (1<<UDRE0)));

UCSR0B &= ~(1<<TXB80);

if (mdbb.mode) {
UCSR0B |= (1<<TXB80);
}

UDR0 = mdbb.data;
}


void MDB_read() {
// is data availble?
if((UCSR0A & (1<<RXC0))) {
// read it
MDB_getByte(&recvData[0]);
//RPI.print(recvData[0]);
MDB_parse();
}
}

void MDB_parse() {
// send it to the intermediary
RPI.write(recvData[0].mode);
Expand Down Expand Up @@ -335,14 +306,14 @@ byte MDB_checksumGenerate(struct MDB_Byte* data, byte length) {
}




byte MDB_transmitData(struct MDB_Byte* data, byte length) {
int transmitState;
struct MDB_Byte mdbb;
int tx;
char tmpstr[7];

//if (debug) dbg_println("(");

do
{
mdbb.data = MDB_checksumGenerate(data, length);
Expand Down Expand Up @@ -374,3 +345,34 @@ byte MDB_transmitData(struct MDB_Byte* data, byte length) {
}


void MDB_write(int data) {
char tmpstr[7];
struct MDB_Byte b;

memcpy(&b, &data, 2);

serial_write(b);

/*if (gDebug > 1) {
if (b.mode) sprintf(tmpstr, ">%.2x*", b.data);
else sprintf(tmpstr, ">%.2x", b.data);
dbg_print(tmpstr);
}*/
}


void serial_write(struct MDB_Byte mdbb) {
while ( !( UCSR0A & (1<<UDRE0)));

if (mdbb.mode) {
// turn on bit 9
UCSR0B |= (1<<TXB80);
} else {
// turn off bit 9
UCSR0B &= ~(1<<TXB80);
}

UDR0 = mdbb.data;
}


5 changes: 4 additions & 1 deletion near_PC/display.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//------------------------------------------------------------------------------


#define CMD_DISPLAY_RESET (0x00)


//------------------------------------------------------------------------------
// METHODS
Expand All @@ -13,7 +15,8 @@
void DISPLAY_parse() {
Serial.print(F("Display "));

switch(msg_address) {
switch(msg_address & COMMAND_MASK) {
case CMD_DISPLAY_RESET: Serial.print(F("Self-reset")); break;
default:
Serial.print(F("CMD #"));
Serial.print((int)(msg_address & COMMAND_MASK));
Expand Down
21 changes: 14 additions & 7 deletions near_PC/gateway.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
// Copyright at end of file.
//------------------------------------------------------------------------------

#define CMD_GATEWAY_RESET (0x18 & COMMAND_MASK)
#define CMD_GATEWAY_SETUP (0x19 & COMMAND_MASK)
#define CMD_GATEWAY_POLL (0x1A & COMMAND_MASK)
#define CMD_GATEWAY_REPORT (0x1B & COMMAND_MASK)
#define CMD_GATEWAY_CONTROL (0x1C & COMMAND_MASK)
#define CMD_GATEWAY_EXTRA (0x1F & COMMAND_MASK)


//------------------------------------------------------------------------------
// METHODS
Expand All @@ -13,19 +20,19 @@
void GATEWAY_parse() {
Serial.print(F("Communication Gateway "));

switch(msg_address) {
case 0x18: Serial.print(F("Self-reset")); break;
case 0x19: Serial.print(F("Setup")); break;
case 0x1A: Serial.print(F("Poll")); break;
case 0x1B: Serial.print(F("Report")); break;
case 0x1C: Serial.print(F("Control"));
switch(msg_address & COMMAND_MASK) {
case CMD_GATEWAY_RESET: Serial.print(F("Self-reset")); break;
case CMD_GATEWAY_SETUP: Serial.print(F("Setup")); break;
case CMD_GATEWAY_POLL: Serial.print(F("Poll")); break;
case CMD_GATEWAY_REPORT: Serial.print(F("Report")); break;
case CMD_GATEWAY_CONTROL: Serial.print(F("Control"));
switch(msg_data[0]) {
case 0x00: Serial.print(F(" Disable")); break;
case 0x01: Serial.print(F(" Enable")); break;
case 0x02: Serial.print(F(" Transmit")); break;
}
break;
case 0x1A: Serial.print(F("Extra"));
case CMD_GATEWAY_EXTRA: Serial.print(F("Extra"));
switch(msg_data[0]) {
case 0x00: Serial.print(F(" Ident")); break;
case 0x01: Serial.print(F(" Feature enable(d)")); break;
Expand Down
8 changes: 0 additions & 8 deletions near_PC/near_PC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ void parse_message() {
}


switch(msg_data[0]) {
case 0x00: Serial.print(F("")); break;
case 0x00: Serial.print(F("")); break;
case 0x00: Serial.print(F("")); break;
case 0x00: Serial.print(F("")); break;
}


/**
* Displays byte in binary. Useful for debugging comms at the start.
*/
Expand Down

0 comments on commit 1913c1d

Please sign in to comment.