Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-UC MODSERIAL mbed mbos
Fork of CDU_Mbed_30 by
Revision 5:99594f4ab659, committed 2012-12-08
- Comitter:
- LvdK
- Date:
- Sat Dec 08 20:37:05 2012 +0000
- Parent:
- 4:c23c570e4454
- Child:
- 6:e0bf3b244d7c
- Commit message:
- stabiel goed werkende versie met ALIVE en keymessage simulatie
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Sat Dec 08 20:37:05 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
--- a/USB_receive.cpp Sat Dec 01 20:53:05 2012 +0000
+++ b/USB_receive.cpp Sat Dec 08 20:37:05 2012 +0000
@@ -1,11 +1,12 @@
// L. van der Kolk, ELVEDEKA, Holland //
+// File: USB_receive.cpp version 1.0
#include "mbed.h"
#define TRUE 1
#define FALSE 0
-#define max_rx_buffer 500 // : length of main receiving cyclic buffer
+#define max_rx_buffer 1024 // : length of main receiving cyclic buffer
#define max_string_length 80 // : max length of string starting with $ and ending with CR/LF
#define min_string_length 10 // : min length of string starting with $ and ending with CR/LF
@@ -21,10 +22,10 @@
int start_pntr; // : pointer from where to read from buffer
int new_data; // : new_data in buffer counter
char data[max_rx_buffer]; // : main serial receiving cyclic array
- } rx_buf = { 0, 0, 0, '0'}; // : initialize pointers and 'new_data'
+ } rx_buf = { 0, 0, 0 }; // : initialize pointers and 'new_data'
-char string_received[max_string_length + 1]; // : contains a string starting with $ and ending with CR/LF
+char string_received[max_string_length + 2]; // : contains a string starting with $ and ending with CR/LF
int nr_of_received_char = 0;
int string_complete = FALSE; // : no complete string with $ and CR/LF
@@ -38,17 +39,18 @@
rx_buf.new_data++; // : incremnent new data counter
USB.putc(rx_char); // : echo character back to PC <<<<<<<<<<<<<<<<<<<<<<<<<<<TEST !
if (rx_buf.new_data >= max_rx_buffer) {
- // ERROR: receiving buffer overflow, FS data lost !
- // What to do ? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- USB.puts(" RxBUF_OVERFLOW "); // : echo overflow error back to PC <<<<<<<<<<<<<<<<<<<<<<<<<<<TEST !
+ // ERROR: receiving buffer overflow, FS data lost !
+ // What to do ? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+ USB.puts(" RxBUF_OVERFLOW "); // : echo overflow error back to PC <<<<<<<<<<<<<<<<<TEST !
}
}
void collect_decode_FSdata() {
- // Function reads data from cyclic RX buffer.
- // Also collects strings from read data, starting with $ and ending with CR/LF
- // Strings shorter than min_string_length are not collected.
+ // Function reads data from cyclic RX buffer
+ // and collects strings starting with $ and ending with CR/LF.
+ // Strings shorter than min_string_length or longer than
+ // max_string_length are ignored.
static int $_detected = FALSE; // : no begin of string detected, ONLY first call static init
static int string_pntr = 0; // : pointer at begin of string, ONLY first call static init
char rx_char;
@@ -69,25 +71,23 @@
string_received[string_pntr] = rx_char;
string_pntr++;
- if (string_pntr == max_string_length) {
- // command string is too long,
+ if (string_pntr >= max_string_length) {
+ // command string looks too long,
// start all over again:
string_pntr = 0; // : set pointer to begin of string_received[] buffer again
$_detected = FALSE;
}
- if ( rx_char == '\n' && $_detected == TRUE ) {
-
+ if ( rx_char == '\r' && $_detected == TRUE ) {
if ( string_pntr > min_string_length ) { // : check minimum string length
- // String is valid when:
+ // String is now valid when:
// it starts with '$' AND
// it ends on new-line AND
- // it has at least min_string_length
-
-
+ // it has at least min_string_length characters.
+ string_received[string_pntr] = '\0'; // : mark end of string
+
USB.printf("string_received : %s\n",string_received ); // show string >>>>>>>>>>>>>>>>( TEST !)
- string_complete = TRUE; // : set flag for decoder ! <<<<<<<<<<<<<<<<< NODIG ????????????
nr_of_received_char = string_pntr;
decode_string(); // : call decoder to check complete string received
@@ -97,6 +97,7 @@
nr_of_received_char = 0;
}
else {
+ $_detected = FALSE; // : <<<<<<<<<<<< toegevoegd !!!!
string_pntr = 0; // : set pointer to begin of string_received[] buffer again
nr_of_received_char = 0;
}
--- a/USB_setup.cpp Sat Dec 01 20:53:05 2012 +0000
+++ b/USB_setup.cpp Sat Dec 08 20:37:05 2012 +0000
@@ -1,14 +1,15 @@
+//
#include "mbed.h"
-Serial USB(USBTX, USBRX); // : declare USB serial communication on Mbed defined USB TX and RX lines
+Serial USB(USBTX, USBRX); // : declare USB communication defined by Mbed USB TX and RX lines
void char_received();
void init_USB()
{ // -- This function is the setup for the USB communication --
+ // Function char_received() is attached to Rx interrupt.
+
USB.baud(38400); // set initial baudrate to 38400
- //Attach function char_received to be called when a serial
- //receive interrupt is received:
- USB.attach(&char_received);
+ USB.attach(&char_received); // : attach function
}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/alive_timer.cpp Sat Dec 08 20:37:05 2012 +0000
@@ -0,0 +1,55 @@
+// L. van der Kolk, ELVEDEKA, Holland //
+// File: alive_timer.cpp version 1.0
+
+#include "mbed.h"
+
+#define TRUE 1
+#define FALSE 0
+
+extern Serial USB;
+
+Ticker alive_tick; // : define timer
+
+int alive_flag = FALSE; // : TRUE when 5 sec have been passed
+int seconds = 0;
+char alive_message[20] = "$PCDUALIVE,"; // : setup begin of alive message string
+
+void alive(){
+ static int previous_time = 0;
+ seconds++;
+ // Check for 5 sec interval:
+ if (seconds - previous_time == 5) {
+ previous_time = seconds;
+ alive_flag = TRUE;
+ }
+ seconds = seconds % 60;
+ previous_time = previous_time % 60;
+}
+
+void init_alivetimer(){
+ alive_tick.attach(&alive, 1); // : call alive() function each second
+}
+
+void check_alive() {
+ int i;
+ char byte_read;
+ char exor_byte = 0;
+ if ( alive_flag == TRUE) {
+ // Create alive message:
+ i = 11; // : i points to first place after $PCDUALIVE, string
+ // Add seconds in 2 dec digits and a '*' char :
+ sprintf(&alive_message[i],"%02d*",seconds);
+ // Calculate checksum now :
+ i = 1; // : i points to first place after '$'
+ do { byte_read = alive_message[i];
+ if (byte_read == '*') break; // : exclude '*' from calculation
+ exor_byte = exor_byte ^ byte_read;
+ i++;
+ } while ( i < 20 );
+ i++; // : i now points to first digit of checksum after '*'
+ // Add exor_byte in 2 hex digits and a CR + LF:
+ sprintf(&alive_message[i],"%02x\r\n",exor_byte); // : ! extra NULL char added by sprintf
+ USB.printf("%s",alive_message);
+ alive_flag = FALSE;
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/buttons.cpp Sat Dec 08 20:37:05 2012 +0000
@@ -0,0 +1,94 @@
+// L. van der Kolk, ELVEDEKA, Holland //
+// File: buttons.cpp version 1.0
+
+#include "mbed.h"
+
+#define TRUE 1
+#define FALSE 0
+
+extern Serial USB;
+
+int button_flag = 0;
+
+char key_message[20] = "$PCDUKEY,"; // : setup begin of key message string to FS
+
+BusInOut button(p24, p23, p22, p21); // : Mbed buttons as 4 bit bus
+
+void init_buttons_Mbed() {
+ // set button bus as input :
+ button.input();
+ // enable pull up resistors on inputs:
+ button.mode(PullUp);
+}
+
+void scan_buttons_Mbed() {
+static int pushed = FALSE;
+ switch (button) {
+ case 0xF : {
+ // nothing pushed, reset pushed flag:
+ pushed = FALSE;
+ break;
+ }
+
+ case 0x7 : {
+ // button 1 pushed:
+ if ( pushed == FALSE ) button_flag = 1;
+ pushed = TRUE;
+ break;
+ }
+
+ case 0xB : {
+ // button 2 pushed:
+ if ( pushed == FALSE ) button_flag = 2;
+ pushed = TRUE;
+ break;
+ }
+
+ case 0xD : {
+ // button 3 pushed:
+ if ( pushed == FALSE ) button_flag = 3;
+ pushed = TRUE;
+ break;
+ }
+
+ case 0xE : {
+ // button 4 pushed:
+ if ( pushed == FALSE ) button_flag = 4;
+ pushed = TRUE;
+ break;
+ }
+
+ default : break;
+
+ }
+}
+
+
+void collect_and_send_FSdata() {
+ int i;
+ char byte_read;
+ char exor_byte = 0;
+ if ( button_flag != 0 ) {
+ // Create key message:
+ i = 9; // : i points to first place after $PCDUKEY,
+ // Add key identifier 'SKEY' and a '*' char to key message string:
+ sprintf(&key_message[i],"%s","SKEY");
+ // Add 2 digit keynumber and a '*' char :
+ i = 13; // : i points to first place after $PCDUKEY,SKEY
+ sprintf(&key_message[i],"%02d*",button_flag);
+ // Calculate checksum now :
+ i = 1; // : i points to first place after '$'
+ do { byte_read = key_message[i];
+ if (byte_read == '*') break; // : exclude '*' from calculation
+ exor_byte = exor_byte ^ byte_read;
+ i++;
+ } while ( i < 20 );
+ i++; // : i now points to first digit of checksum after '*'
+ // Add exor_byte in 2 hex digits and a CR + LF:
+ sprintf(&key_message[i],"%02x\r\n",exor_byte); // : ! extra NULL char added by sprintf
+ USB.printf("%s",key_message);
+ button_flag = 0;
+ }
+}
+
+
--- a/data_structures.cpp Sat Dec 01 20:53:05 2012 +0000
+++ b/data_structures.cpp Sat Dec 08 20:37:05 2012 +0000
@@ -1,191 +1,465 @@
+// L. van der Kolk, ELVEDEKA, Holland //
+// File: data_structures.cpp version 1.0
+
#include "mbed.h"
-//#include "ctype.h"
+#include "ctype.h"
#define TRUE 1
#define FALSE 0
-#define max_text_length 40
+#define max_text_length 40 // : max length of text field
+#define max_style 6 // : max length of style text
extern char string_received[]; // : complete string starting with $ and ending with CR/LF
extern int nr_of_received_char; // : number of chars in string_receved[];
-extern int comma[]; // : array with pointers to all found commas
+extern int comma[]; // : array with pointers to all found commas in received string
+
extern Serial USB; // >>>>>>>>>>> alleen t.b.v TEST output !!
-
-// ---------- Data structures of received FS data---------------------------------------------------------
+// ---------- Data structures of received FS data ------------------------------------------------------
-struct { char text[max_text_length];// : maintext with max_text_length chars
- int font_size; // : fontsize can be 1 – 8
- char font_style; // : can be S,B,I,U,N
- int text_colour; // : colour number
+struct { char text[max_text_length];// : maintext with max_text_length chars, ending with '/0'
+ int font_size; // : fontsize can be 0 - 9
+ char font_style[max_style];// : can be S,B,I,U,N or combination, ending with '/0'
+ int text_colour; // : colour number 0 - 9
int updated; // : update flag, TRUE/FALSE
int locked; // : locked flag, TRUE/FALSE
} KEY_LEFT_MAINTEXT[10]; // : keys can be 0 - 9
-struct { char text[max_text_length];// : subtext with max_text_length chars
- int font_size; // : fontsize can be 1 – 8
- char font_style; // : can be S,B,I,U,N
- int text_colour; // : colour number
+struct { char text[max_text_length];// : subtext with max_text_length chars, ending with '/0'
+ int font_size; // : fontsize can be 0 - 9
+ char font_style[max_style];// : can be S,B,I,U,N or combination, ending with '/0'
+ int text_colour; // : colour number 0 - 9
int updated; // : update flag, TRUE/FALSE
int locked; // : locked flag, TRUE/FALSE
} KEY_LEFT_SUBTEXT[10]; // : keys can be 0 - 9
-struct { char text[max_text_length];// : maintext with max_text_length chars
- int font_size; // : fontsize can be 1 – 8
- char font_style; // : can be S,B,I,U,N
- int text_colour; // : colour number
+struct { char text[max_text_length];// : maintext with max_text_length chars, ending with '/0'
+ int font_size; // : fontsize can be 0 - 9
+ char font_style[max_style];// : can be S,B,I,U,N or combination, ending with '/0'
+ int text_colour; // : colour number 0 - 9
int updated; // : update flag, TRUE/FALSE
int locked; // : locked flag, TRUE/FALSE
} KEY_RIGHT_MAINTEXT[10]; // : keys can be 0 - 9
-struct { char text[max_text_length];// : subtext with max_text_length chars
- int font_size; // : fontsize can be 1 – 8
- char font_style; // : can be S,B,I,U,N
- int text_colour; // : colour number
+struct { char text[max_text_length];// : subtext with max_text_length chars, ending with '/0'
+ int font_size; // : fontsize can be 0 - 9
+ char font_style[max_style];// : can be S,B,I,U,N or combination, ending with '/0'
+ int text_colour; // : colour number 0 - 9
int updated; // : update flag, TRUE/FALSE
int locked; // : locked flag, TRUE/FALSE
} KEY_RIGHT_SUBTEXT[10]; // : keys can be 0 - 9
-struct { char text[max_text_length];// : text with max_text_length chars
- int font_size; // : fontsize can be 1 – 8
- char font_style; // : can be S,B,I,U,N
- int text_colour; // : colour number
+struct { char text[max_text_length];// : text with max_text_length chars, ending with '/0'
+ int font_size; // : fontsize can be 0 - 9
+ char font_style[max_style];// : can be S,B,I,U,N or combination, ending with '/0'
+ int text_colour; // : colour number 0 - 9
int updated; // : update flag, TRUE/FALSE
int locked; // : locked flag, TRUE/FALSE
} DBS_MESSAGE;
-struct { char text[max_text_length];// : Title text with max_text_length chars
- int font_size; // : fontsize can be 1 – 8
- char font_style; // : can be S,B,I,U,N
- int text_colour; // : colour number
+struct { char text[max_text_length];// : Title text with max_text_length chars, ending with '/0'
+ int font_size; // : fontsize can be 0 - 9
+ char font_style[max_style];// : can be S,B,I,U,N or combination, ending with '/0'
+ int text_colour; // : colour number 0 - 9
int updated; // : update flag, TRUE/FALSE
int locked; // : locked flag, TRUE/FALSE
- } TITLE_MESSAGE;
+ } TIT_MESSAGE;
-struct { char text[10]; // : text max. 10 ? chars
- int font_size; // : fontsize can be 1 – 8
- char font_style; // : can be S,B,I,U,N
- int text_colour; // : colour number
+struct { char text[10]; // : text max. 10 chars, ending with '/0'
+ int font_size; // : fontsize can be 0 - 9
+ char font_style[max_style];// : can be S,B,I,U,N or combination, ending with '/0'
+ int text_colour; // : colour number 0 - 9
int updated; // : update flag, TRUE/FALSE
int locked; // : locked flag, TRUE/FALSE
- } PAGE_NR_MESSAGE;
+ } PGE_MESSAGE;
-struct { char text[max_text_length];// : text with max_text_length chars
- int font_size; // : fontsize can be 1 – 8
- char font_style; // : can be S,B,I,U,N
- int text_colour; // : colour number
+struct { char text[max_text_length];// : text with max_text_length chars, ending with '/0'
+ int font_size; // : fontsize can be 0 - 9
+ char font_style[max_style];// : can be S,B,I,U,N or combination, ending with '/0'
+ int text_colour; // : colour number 0 - 9
int updated; // : update flag, TRUE/FALSE
int locked; // : locked flag, TRUE/FALSE
- } SCRATCH_MESSAGE;
+ } SPD_MESSAGE;
-struct { char text[max_text_length];// : text with max_text_length chars
- int x_pos; // :
- int y_pos; // :
- int text_size; // : fontsize can be 1 – 8
- char font_style; // : can be S,B,I,U,N
- int text_colour; // : colour number
- int updated; // : update flag, TRUE/FALSE
- int locked; // : locked flag, TRUE/FALSE
+struct { char text[max_text_length];// : text with max_text_length chars, ending with '/0'
+ int x_pos; // :
+ int y_pos; // :
+ int text_size; // : fontsize can be 0 - 9
+ char font_style[max_style];// : can be S,B,I,U,N or combination, ending with '/0'
+ int text_colour; // : colour number 0 - 9
+ int updated; // : update flag, TRUE/FALSE
+ int locked; // : locked flag, TRUE/FALSE
} PUT_STRING_MESSAGE;
-struct { char text[8]; // : text max. 8 chars
+struct { char text[10]; // : text max. 10 chars, ending with '/0'
int status_id; // : can be 0 or 1
int updated; // : update flag, TRUE/FALSE
int locked; // : locked flag, TRUE/FALSE
- } STATUS_MESSAGE;
+ } SID_MESSAGE;
-struct { char text[8]; // : text max. 8 ? chars
+struct { char text[10]; // : text max. 10 chars, ending with '/0'
int updated; // : update flag, TRUE/FALSE
int locked; // : locked flag, TRUE/FALSE
} SETVALUE_MESSAGE[10];
int GETVALUE_MESSAGE[10]; // : update flag, TRUE/FALSE
-int DO_CLR_SCREEN; // : update flag, TRUE/FALSE
-// -----------------------------------------------------------------------------
+int DO_CLR_SCREEN = FALSE; // : flag, TRUE/FALSE, to tell a clr screen message has been received
+
+int FSdata_updated_flag = FALSE; // : common flag, TRUE/FALSE, to tell one or more datastructures
+ // have been updated
+
+// ------------------------------------------------------------------------------------------
+
void (read_datafields(int command_number)) {
int char_pntr, a;
- char textchar, textfield[max_text_length];
+ char textchar;
switch ( command_number )
{
case 0:
- { // this is no valid commndnumber
+ { // 0 is no valid commndnumber
break;
}
- case 1:
- {
+ case 1: // DSB message
+ { // ---------------- locking ---------------------------------------------------
while (DBS_MESSAGE.locked == TRUE) {
// --- DO NOTHING, WAIT FOR UNLOCKING !! ---
// TAKE CARE : Program can HANG if not unlocked !!
}
+ DBS_MESSAGE.locked = TRUE; // : lock datastructure to prevent reading from it
+ // ----------------------------------------------------------------------------
- DBS_MESSAGE.locked = TRUE; // : lock datastructure to prevent reading from it
-
- // Read fontsize F0 - F9:
+ // Read fontsize 0 - 9:
char_pntr = comma[1] + 2; // : set char pointer to digit after 'F'
- DBS_MESSAGE.font_size = atoi(&string_received[char_pntr]);
-
- // Read fontstyle :
+ if (isdigit(string_received[char_pntr])) { // : test on digit
+ DBS_MESSAGE.font_size = atoi(&string_received[char_pntr]);
+ }
+ // Read fontstyle :
+ a = 0;
char_pntr = comma[2] + 1; // : set char pointer to fontstyle
- DBS_MESSAGE.font_style = string_received[char_pntr];
-
+ while ( a < max_style-1 && char_pntr < comma[3] ) {
+ textchar = string_received[char_pntr];
+ if (textchar=='S' || textchar=='B' || textchar=='I' || textchar== 'U' || textchar== 'N' )
+ { DBS_MESSAGE.font_style[a] = textchar; }
+ else DBS_MESSAGE.font_style[a] = '?'; // : unknown style char
+ char_pntr++;
+ a++;
+ }
+ DBS_MESSAGE.font_style[a] = '\0'; // : mark end of text
// Read text colour :
char_pntr = comma[3] + 1; // : set char pointer to textcolour
+ // test on digit ??? <<<<<<<<<<<<
if (string_received[char_pntr] != ',' ) { // : colour field not empty
- DBS_MESSAGE.text_colour = atoi(&string_received[char_pntr]);
+ DBS_MESSAGE.text_colour = atoi(&string_received[char_pntr]);
}
else DBS_MESSAGE.text_colour = 0; // : empty field means colour 0
-
// Read textfield :
a = 0;
char_pntr = comma[4] + 1; // : set char pointer to textfield
- do { textchar = string_received[char_pntr];
- if (textchar == '*') break; // : do not include * in text
- textfield[a] = textchar;
+ while ( a < max_text_length-1 )
+ { textchar = string_received[char_pntr];
+ if (textchar == '*') break; // : do not include * in text
+ DBS_MESSAGE.text[a] = textchar;
a++;
char_pntr++;
- } while ( a < max_text_length );
- strncpy(DBS_MESSAGE.text,textfield,a); // : copy chars to structure member, is a OK??? <<
+ }
+ DBS_MESSAGE.text[a] = '\0'; // : mark end of text
// Print all for TESTING : ------------------------------------- <<<<<<<<<<<<<<<<<
USB.printf("text is : %s\n",DBS_MESSAGE.text ); // show text
USB.printf("fontsize is : %d\n",DBS_MESSAGE.font_size ); // show fontsize
- USB.printf("fontstyle is : %c\n",DBS_MESSAGE.font_style ); // show fontstyle )
- USB.printf("textcolour is : %d\n",DBS_MESSAGE.text_colour ); // show textcolour
+ USB.printf("fontstyle is : %s\n",DBS_MESSAGE.font_style ); // show fontstyle )
+ USB.printf("textcolour is : %d\n\n",DBS_MESSAGE.text_colour ); // show textcolour
// END of TEST printing ---------------------------------------- <<<<<<<<<<<<<<<<<
DBS_MESSAGE.updated = TRUE; // : tell update of datastructure has been done
- DBS_MESSAGE.locked = FALSE; // : FREE datastructure for reading from it
+ FSdata_updated_flag = TRUE; // : set common update flag
+ DBS_MESSAGE.locked = FALSE; // : FREE datastructure for reading from it
break;
}
- case 2:
- {
-
+ case 2: // Title message
+ { // ---------------- locking ---------------------------------------------------
+ while (TIT_MESSAGE.locked == TRUE) {
+ // --- DO NOTHING, WAIT FOR UNLOCKING !! ---
+ // TAKE CARE : Program can HANG if not unlocked !!
+ }
+ TIT_MESSAGE.locked = TRUE; // : lock datastructure to prevent reading from it
+ // ----------------------------------------------------------------------------
+
+ // Read fontsize 0 - 9:
+ char_pntr = comma[1] + 2; // : set char pointer to digit after 'F'
+ if (isdigit(string_received[char_pntr])) { // : test on digit
+ TIT_MESSAGE.font_size = atoi(&string_received[char_pntr]);
+ }
+ // Read fontstyle :
+ a = 0;
+ char_pntr = comma[2] + 1; // : set char pointer to fontstyle
+ while ( a < max_style-1 && char_pntr < comma[3] ) {
+ textchar = string_received[char_pntr];
+ if (textchar=='S' || textchar=='B' || textchar=='I' || textchar== 'U' || textchar== 'N' )
+ { TIT_MESSAGE.font_style[a] = textchar; }
+ else TIT_MESSAGE.font_style[a] = '?'; // : unknown style char
+ char_pntr++;
+ a++;
+ }
+ TIT_MESSAGE.font_style[a] = '\0'; // : mark end of text
+ // Read text colour :
+ char_pntr = comma[3] + 1; // : set char pointer to textcolour
+ // test on digit ??? <<<<<<<<<<<<
+ if (string_received[char_pntr] != ',' ) { // : colour field not empty
+ TIT_MESSAGE.text_colour = atoi(&string_received[char_pntr]);
+ }
+ else TIT_MESSAGE.text_colour = 0; // : empty field means colour 0
+ // Read textfield :
+ a = 0;
+ char_pntr = comma[4] + 1; // : set char pointer to textfield
+ while ( a < max_text_length-1 )
+ { textchar = string_received[char_pntr];
+ if (textchar == '*') break; // : do not include * in text
+ TIT_MESSAGE.text[a] = textchar;
+ a++;
+ char_pntr++;
+ }
+ TIT_MESSAGE.text[a] = '\0'; // : mark end of text
+
+ // Print all for TESTING : ------------------------------------- <<<<<<<<<<<<<<<<<
+ USB.printf("text is : %s\n",TIT_MESSAGE.text ); // show text
+ USB.printf("fontsize is : %d\n",TIT_MESSAGE.font_size ); // show fontsize
+ USB.printf("fontstyle is : %s\n",TIT_MESSAGE.font_style ); // show fontstyle )
+ USB.printf("textcolour is : %d\n\n",TIT_MESSAGE.text_colour ); // show textcolour
+ // END of TEST printing ---------------------------------------- <<<<<<<<<<<<<<<<<
+
+ TIT_MESSAGE.updated = TRUE; // : tell update of datastructure has been done
+ FSdata_updated_flag = TRUE; // : set common update flag
+ TIT_MESSAGE.locked = FALSE; // : FREE datastructure for reading from it
+
break;
}
-
-
-
+
+ case 3: // PGE message
+ { // ---------------- locking ---------------------------------------------------
+ while (PGE_MESSAGE.locked == TRUE) {
+ // --- DO NOTHING, WAIT FOR UNLOCKING !! ---
+ // TAKE CARE : Program can HANG if not unlocked !!
+ }
+ PGE_MESSAGE.locked = TRUE; // : lock datastructure to prevent reading from it
+ // ----------------------------------------------------------------------------
+
+ // Read fontsize 0 - 9:
+ char_pntr = comma[1] + 2; // : set char pointer to digit after 'F'
+ if (isdigit(string_received[char_pntr])) { // : test on digit
+ PGE_MESSAGE.font_size = atoi(&string_received[char_pntr]);
+ }
+ // Read fontstyle :
+ a = 0;
+ char_pntr = comma[2] + 1; // : set char pointer to fontstyle
+ while ( a < max_style-1 && char_pntr < comma[3] ) {
+ textchar = string_received[char_pntr];
+ if (textchar=='S' || textchar=='B' || textchar=='I' || textchar== 'U' || textchar== 'N' )
+ { PGE_MESSAGE.font_style[a] = textchar; }
+ else PGE_MESSAGE.font_style[a] = '?'; // : unknown style char
+ char_pntr++;
+ a++;
+ }
+ PGE_MESSAGE.font_style[a] = '\0'; // : mark end of text
+ // Read text colour :
+ char_pntr = comma[3] + 1; // : set char pointer to textcolour
+ // test on digit ??? <<<<<<<<<<<<
+ if (string_received[char_pntr] != ',' ) { // : colour field not empty
+ PGE_MESSAGE.text_colour = atoi(&string_received[char_pntr]);
+ }
+ else PGE_MESSAGE.text_colour = 0; // : empty field means colour 0
+ // Read textfield :
+ a = 0;
+ char_pntr = comma[4] + 1; // : set char pointer to textfield
+ while ( a < max_text_length-1 )
+ { textchar = string_received[char_pntr];
+ if (textchar == '*') break; // : do not include * in text
+ PGE_MESSAGE.text[a] = textchar;
+ a++;
+ char_pntr++;
+ }
+ PGE_MESSAGE.text[a] = '\0'; // : mark end of text
+
+ // Print all for TESTING : ------------------------------------- <<<<<<<<<<<<<<<<<
+ USB.printf("text is : %s\n",PGE_MESSAGE.text ); // show text
+ USB.printf("fontsize is : %d\n",PGE_MESSAGE.font_size ); // show fontsize
+ USB.printf("fontstyle is : %s\n",PGE_MESSAGE.font_style ); // show fontstyle )
+ USB.printf("textcolour is : %d\n",PGE_MESSAGE.text_colour ); // show textcolour
+ // END of TEST printing ---------------------------------------- <<<<<<<<<<<<<<<<<
+
+ PGE_MESSAGE.updated = TRUE; // : tell update of datastructure has been done
+ FSdata_updated_flag = TRUE; // : set common update flag
+ PGE_MESSAGE.locked = FALSE; // : FREE datastructure for reading from it
+
+ break;
+ }
+ case 4: // SPD message
+ { // ---------------- locking ---------------------------------------------------
+ while (SPD_MESSAGE.locked == TRUE) {
+ // --- DO NOTHING, WAIT FOR UNLOCKING !! ---
+ // TAKE CARE : Program can HANG if not unlocked !!
+ }
+ SPD_MESSAGE.locked = TRUE; // : lock datastructure to prevent reading from it
+ // ----------------------------------------------------------------------------
+
+ // Read fontsize 0 - 9:
+ char_pntr = comma[1] + 2; // : set char pointer to digit after 'F'
+ if (isdigit(string_received[char_pntr])) { // : test on digit
+ SPD_MESSAGE.font_size = atoi(&string_received[char_pntr]);
+ }
+ // Read fontstyle :
+ a = 0;
+ char_pntr = comma[2] + 1; // : set char pointer to fontstyle
+ while ( a < max_style-1 && char_pntr < comma[3] ) {
+ textchar = string_received[char_pntr];
+ if (textchar=='S' || textchar=='B' || textchar=='I' || textchar== 'U' || textchar== 'N' )
+ { SPD_MESSAGE.font_style[a] = textchar; }
+ else SPD_MESSAGE.font_style[a] = '?'; // : unknown style char
+ char_pntr++;
+ a++;
+ }
+ SPD_MESSAGE.font_style[a] = '\0'; // : mark end of text
+ // Read text colour :
+ char_pntr = comma[3] + 1; // : set char pointer to textcolour
+ // test on digit ??? <<<<<<<<<<<<
+ if (string_received[char_pntr] != ',' ) { // : colour field not empty
+ SPD_MESSAGE.text_colour = atoi(&string_received[char_pntr]);
+ }
+ else SPD_MESSAGE.text_colour = 0; // : empty field means colour 0
+ // Read textfield :
+ a = 0;
+ char_pntr = comma[4] + 1; // : set char pointer to textfield
+ while ( a < max_text_length-1 )
+ { textchar = string_received[char_pntr];
+ if (textchar == '*') break; // : do not include * in text
+ SPD_MESSAGE.text[a] = textchar;
+ a++;
+ char_pntr++;
+ }
+ SPD_MESSAGE.text[a] = '\0'; // : mark end of text
+
+ // Print all for TESTING : ------------------------------------- <<<<<<<<<<<<<<<<<
+ USB.printf("text is : %s\n",SPD_MESSAGE.text ); // show text
+ USB.printf("fontsize is : %d\n",SPD_MESSAGE.font_size ); // show fontsize
+ USB.printf("fontstyle is : %s\n",SPD_MESSAGE.font_style ); // show fontstyle )
+ USB.printf("textcolour is : %d\n",SPD_MESSAGE.text_colour ); // show textcolour
+ // END of TEST printing ---------------------------------------- <<<<<<<<<<<<<<<<<
+
+ SPD_MESSAGE.updated = TRUE; // : tell update of datastructure has been done
+ FSdata_updated_flag = TRUE; // : set common update flag
+ SPD_MESSAGE.locked = FALSE; // : FREE datastructure for reading from it
+
+ break;
+ }
+ case 5: // CLS message
+ { DO_CLR_SCREEN = TRUE;
+ FSdata_updated_flag = TRUE; // : set common update flag
+ break;
+ }
+ case 6: // SID message
+ { // ---------------- locking ---------------------------------------------------
+ while (SID_MESSAGE.locked == TRUE) {
+ // --- DO NOTHING, WAIT FOR UNLOCKING !! ---
+ // TAKE CARE : Program can HANG if not unlocked !!
+ }
+ SID_MESSAGE.locked = TRUE; // : lock datastructure to prevent reading from it
+ // ----------------------------------------------------------------------------
+
+ // Read fontsize 0 - 9:
+ char_pntr = comma[1] + 2; // : set char pointer to digit after 'F'
+ //SID_MESSAGE.font_size = atoi(&string_received[char_pntr]);
+ // Read fontstyle :
+ char_pntr = comma[2] + 1; // : set char pointer to fontstyle
+ //SID_MESSAGE.font_style = string_received[char_pntr];
+ // Read text colour :
+ char_pntr = comma[3] + 1; // : set char pointer to textcolour
+ if (string_received[char_pntr] != ',' ) { // : colour field not empty
+ //SID_MESSAGE.text_colour = atoi(&string_received[char_pntr]);
+ }
+ //else SID_MESSAGE.text_colour = 0; // : empty field means colour 0
+ // Read textfield :
+
+
+ // Print all for TESTING : ------------------------------------- <<<<<<<<<<<<<<<<<
+ //USB.printf("text is : %s\n",SID_MESSAGE.text ); // show text
+ //USB.printf("fontsize is : %d\n",SID_MESSAGE.font_size ); // show fontsize
+ //USB.printf("fontstyle is : %s\n",SID_MESSAGE.font_style ); // show fontstyle )
+ //USB.printf("textcolour is : %d\n",SID_MESSAGE.text_colour ); // show textcolour
+ // END of TEST printing ---------------------------------------- <<<<<<<<<<<<<<<<<
+
+ SID_MESSAGE.updated = TRUE; // : tell update of datastructure has been done
+ FSdata_updated_flag = TRUE; // : set common update flag
+ SID_MESSAGE.locked = FALSE; // : FREE datastructure for reading from it
+
+ break;
+ }
+ case 7: // LxT message
+ {
+
+
+ FSdata_updated_flag = TRUE; // : set common update flag
+ break;
+ }
+ case 8: // LxS message
+ {
+
+ FSdata_updated_flag = TRUE; // : set common update flag
+ break;
+ }
+
+ case 9: // RxT message
+ {
+
+ FSdata_updated_flag = TRUE; // : set common update flag
+ break;
+ }
+
+ case 10: // RxS message
+ {
+ FSdata_updated_flag = TRUE; // : set common update flag
+ break;
+ }
+
+ case 11: // PUTS message
+ {
+ FSdata_updated_flag = TRUE; // : set common update flag
+ break;
+ }
+
+ case 12: // SETV message
+ {
+ FSdata_updated_flag = TRUE; // : set common update flag
+ break;
+ }
+
+ case 13: // GETV message
+ {
+ FSdata_updated_flag = TRUE; // : set common update flag
+ break;
+ }
default:
+
{
-
+ // illegal commandnumber !
break;
}
- } // end switch
+ }
}
--- a/decode_1.cpp Sat Dec 01 20:53:05 2012 +0000
+++ b/decode_1.cpp Sat Dec 08 20:37:05 2012 +0000
@@ -1,27 +1,28 @@
+// L. van der Kolk, ELVEDEKA, Holland //
+// File: decode_1.cpp version 1.0
+
#include "mbed.h"
#include "ctype.h"
#define TRUE 1
#define FALSE 0
-DigitalOut led4(LED4); // TEST Led4
+//DigitalOut led4(LED4); // TEST Led4
extern char string_received[]; // : complete string starting with $ and ending with CR/LF
extern int nr_of_received_char; // : number of chars in string_receved[];
-extern int string_complete;
+
extern Serial USB; // >>>>>>>>>>> alleen t.b.v TEST output !!
void read_datafields(int command_number);
int command_valid;
-int checksum_error;
+int checksum_error = FALSE;
char command_string[20]; // <<<<<<<<<< ?
-int command_number;
-int select_key_nr;
+int command_number = 0;
+int select_key_nr = 0;
-int comma[8]; // : array with pointers to all found commas
-
-
+int comma[8]; // : array with pointers to all found commas in received string
// Command headers are defined in an array command[] of command structures :
struct command_struct {
@@ -47,19 +48,14 @@
void decode_string()
-{
- // -- This decodes a received string in string_received[] --
-
- // char *first_comma_pntr;
+{ // -- This decodes a received string in array string_received[] --
int char_cntr,i,c;
int equal;
char key_id, byte_read;
- char checksum[2], exor_byte;
-
-
- if (string_complete == TRUE) { // : check flag first <<<<<<<<<<<<<<<<<<< niet meer nodig ?
- led4 = 1;
+ char checksum[3], exor_byte;
+
+ //led4 = 1; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< test
command_valid = FALSE;
key_id = '0';
select_key_nr = 0;
@@ -80,26 +76,21 @@
i++;
} while ( i < nr_of_received_char );
i++; // : i points now to checksum after * char
- // USB.printf("pointer i staat op : %c\n",string_received[i] ); // >>>>>>>>>>>>>>>>>>>>> ( TEST !
+ //USB.printf("pointer i staat op : %c\n",string_received[i] ); // >>>>>>>>>>>>>>>>>>>>> ( TEST !
strncpy(checksum,&string_received[i],2); // : copy 2 char checksum after *
- // if ( exor_byte == atoi(checksum) )
- USB.printf("exor_byte, checksum, aantal kar is : %02x, %s, %d\n",exor_byte, checksum, nr_of_received_char ); // >>>>>>>>>>>>>>>>>>>>> ( TEST !)
+ checksum[2] = '\0'; // : mark end of text
+
+ if (1==1) {
+ equal = (atoi(checksum));
+ USB.printf("exor_byte, ASCII checksum, atoi checksum dec : %02x, %s, %d\n",exor_byte, checksum, equal ); // >>>>>>>>>>>>>>>>>>>>> ( TEST !)
+ //USB.printf("exor_byte, checksum, aantal kar is : %02x, %s, %d\n",exor_byte, checksum, nr_of_received_char ); // >>>>>>>>>>>>>>>>>>>>> ( TEST !)
USB.printf("aantal comma's is : %d\n",c-1 ); // >>>>>>>>>>>>>>>>>>>>> ( TEST !)
-
-
- // ----------------------------------------------------------------------------------
// Check on 5 char "$PCDU" header:
equal = strncmp(string_received,"$PCDU",5);
if (equal != 0) {
- //USB.printf("header is not $PCDU but : %5s\n",string_received ); // print first 5 chars ( TEST !)
}
else {
- // find first comma :
- //first_comma_pntr = strchr(string_received,',');
- //if (first_comma_pntr != NULL) {
- //USB.printf("aantal char voor eerste komma : %d\n",first_comma_pntr - string_received ); // show string ( TEST !)
- //}
// Find first comma and find chars before comma:
char_cntr = 5; // : exclude first 5 chars because they have already been found
@@ -186,10 +177,9 @@
read_datafields(command_number);
}
- } // end of string complete test
-
+ } // end of checksum test
- string_complete = FALSE; // : reset flag again, because total string has been analyzed
- led4 = 0;
+
+ //led4 = 0;
}
\ No newline at end of file
--- a/main.cpp Sat Dec 01 20:53:05 2012 +0000
+++ b/main.cpp Sat Dec 08 20:37:05 2012 +0000
@@ -1,21 +1,58 @@
+// L. van der Kolk, ELVEDEKA, Holland //
+// File: main.cpp version 1.0
+
#include "mbed.h"
+#include "TextLCD.h"
+TextLCD lcd(p8, p9, p10, p11, p12, p13); // rs, e, d4-d7
-DigitalOut led1(LED1); // TEST Led1
+DigitalOut led1(LED1); // Led1, only for testing
+extern Serial USB; // >>>>>>>>>>> alleen t.b.v TEST output !!
void init_USB();
-//void decode_string();
+void init_alivetimer();
+void check_alive();
+
+void init_buttons_Mbed();
+void scan_buttons_Mbed();
+
void collect_decode_FSdata();
+void collect_and_send_FSdata();
+//void Braat_test_update_flag_van_LvdK_en_doet_wat_met_de_nieuwe_data();
main()
{
+// -- This is main.cpp created by LvdK to test all FS communication --
- init_USB(); // setup USB communication
+ init_USB(); // : setup USB communication and Rx interrupt
+ init_alivetimer(); // : setup alive message timer
+ init_buttons_Mbed(); // : <<<<<<<<<<<<<<<<<<<<< test only
+
+ lcd.cls(); // : clear LCD display
+ lcd.printf(" -- Mbed CDU --\n");
+ USB.printf(" --- Mbed CDU ---\n");
+
+
+ while (1==1) { // this is my endless main loop
+
+ led1 = !led1; // : toggle LED1 to show running program
+ //wait(0.02);
- while (1) { // this is my endless main loop :
- led1 = !led1; // : toggle LED1 to show running program
- wait(0.1); // : can be interrupted ???????????
- // decode_string(); // : call decoder to proces any valid command string received
+ // Check on new received characters from FS in filled Rx ringbuffer
+ // and decode to data if relevant:
collect_decode_FSdata();
+
+ // Proces new received FS data:
+ // Braat_test_update_flag_van_LvdK_en_doet_wat_met_de_nieuwe_data();
+
+ // Send relevant data to FS:
+ // LvdK test updates van data Braat en leest de data uit afgesproken datagebied
+ // en stuurt dit naar de FS:
+ scan_buttons_Mbed();
+
+ collect_and_send_FSdata();
+
+ check_alive(); // : if 5 sec passed, send alive message
+
}
}
\ No newline at end of file
