Check this one ! mbos setup changed, WTX hor pos changed, no font style check, no checksum check
Dependencies: 4DGL MODSERIAL mbed mbos
Fork of CDU_Mbed_21 by
CDU2FS_message_5.cpp@11:d60c746c097c, 2014-07-21 (annotated)
- Committer:
- WillemBraat
- Date:
- Mon Jul 21 14:24:15 2014 +0000
- Revision:
- 11:d60c746c097c
- Parent:
- 8:422544d24df3
screen_handler.cpp
; Added external flag S_Exec in procedure . Inhibits screen updates when 1. S_Exec is declared in line 77 of FS2CDU_data_5.cpp
;
; keyboard2.cpp
; Line 40. Added Key_led=0
;
; keyboard2.cpp "
; Added switch value in CDU_SET_BGL_INTENSIT...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
LvdK | 8:422544d24df3 | 1 | // L. van der Kolk, ELVEDEKA, Holland |
LvdK | 8:422544d24df3 | 2 | // File: CDU2FS_message_5.cpp |
LvdK | 8:422544d24df3 | 3 | // |
LvdK | 8:422544d24df3 | 4 | // -- Message handling from CDU to FS -- |
LvdK | 8:422544d24df3 | 5 | |
LvdK | 8:422544d24df3 | 6 | #include "mbed.h" |
LvdK | 8:422544d24df3 | 7 | #include "MODSERIAL.h" |
LvdK | 8:422544d24df3 | 8 | #include "keys.h" |
LvdK | 8:422544d24df3 | 9 | //#include "debug_lvdk.h" // : debug mode control |
LvdK | 8:422544d24df3 | 10 | |
LvdK | 8:422544d24df3 | 11 | extern MODSERIAL USB; |
LvdK | 8:422544d24df3 | 12 | extern MODSERIAL SERIAL_DEBUG; |
LvdK | 8:422544d24df3 | 13 | extern int CDU_FS_interface; |
LvdK | 8:422544d24df3 | 14 | |
LvdK | 8:422544d24df3 | 15 | int key_hit_ID = 0; // : number of key that was hit, 0 = no hit of any key. ( global flag ! ) |
LvdK | 8:422544d24df3 | 16 | |
LvdK | 8:422544d24df3 | 17 | char key_message[25] = "$PCDUKEY,"; // : setup begin of KEY message to FS |
LvdK | 8:422544d24df3 | 18 | char alive_message[25] = "$PCDUOKE,"; // : setup begin of ALIVE message to FS |
LvdK | 8:422544d24df3 | 19 | |
LvdK | 8:422544d24df3 | 20 | void send_message_to_FS(char *message_string) { |
LvdK | 8:422544d24df3 | 21 | // Common fnction to send a created message string (KEY or OKE) to the FS. |
LvdK | 8:422544d24df3 | 22 | // Parameter is pointer to char string that has to be sent. |
LvdK | 8:422544d24df3 | 23 | // Interface can be USB port or Ethernet port. |
LvdK | 8:422544d24df3 | 24 | int i = 0; |
LvdK | 8:422544d24df3 | 25 | if ( CDU_FS_interface == 0 ) { // : messages will be sent out by USB port |
LvdK | 8:422544d24df3 | 26 | while ( message_string[i] != '\0' ) { |
LvdK | 8:422544d24df3 | 27 | USB.putc(message_string[i]); |
LvdK | 8:422544d24df3 | 28 | i++; |
LvdK | 8:422544d24df3 | 29 | } |
LvdK | 8:422544d24df3 | 30 | } |
LvdK | 8:422544d24df3 | 31 | if ( CDU_FS_interface == 1 ) { |
LvdK | 8:422544d24df3 | 32 | // Messages will be sent out by Ehternet interface |
LvdK | 8:422544d24df3 | 33 | // -- Not implemented -- |
LvdK | 8:422544d24df3 | 34 | } |
LvdK | 8:422544d24df3 | 35 | } |
LvdK | 8:422544d24df3 | 36 | |
LvdK | 8:422544d24df3 | 37 | void Send_ALIVE_message(int seconds){ |
LvdK | 8:422544d24df3 | 38 | int i; |
LvdK | 8:422544d24df3 | 39 | char byte_read; |
LvdK | 8:422544d24df3 | 40 | char exor_byte = 0; |
LvdK | 8:422544d24df3 | 41 | //Create alive message: |
LvdK | 8:422544d24df3 | 42 | i = 9; // : i points to first place after "$PCDUOKE," |
LvdK | 8:422544d24df3 | 43 | // Add seconds in 2 dec digits and a '*' char : |
LvdK | 8:422544d24df3 | 44 | sprintf(&alive_message[i],"%02d*",seconds); |
LvdK | 8:422544d24df3 | 45 | // Calculate checksum now : |
LvdK | 8:422544d24df3 | 46 | i = 1; // : i points to first place after '$' |
LvdK | 8:422544d24df3 | 47 | do { byte_read = alive_message[i]; |
LvdK | 8:422544d24df3 | 48 | if (byte_read == '*') break; // : exclude '*' from exor calculation |
LvdK | 8:422544d24df3 | 49 | exor_byte = exor_byte ^ byte_read; |
LvdK | 8:422544d24df3 | 50 | i++; |
LvdK | 8:422544d24df3 | 51 | } while ( i < 20 ); |
LvdK | 8:422544d24df3 | 52 | i++; // : i now points to first digit of checksum after '*' |
LvdK | 8:422544d24df3 | 53 | // Add exor_byte in 2 hex chars (with upper case A-F) and a CR + LF: |
LvdK | 8:422544d24df3 | 54 | sprintf(&alive_message[i],"%02X\r\n",exor_byte); // : + extra NULL char added by sprintf |
LvdK | 8:422544d24df3 | 55 | send_message_to_FS(alive_message); // : send message to FS |
LvdK | 8:422544d24df3 | 56 | } |
LvdK | 8:422544d24df3 | 57 | |
LvdK | 8:422544d24df3 | 58 | void Send_KEY_message(int key_nr) { |
LvdK | 8:422544d24df3 | 59 | // Function creates a valid KEY message out of key_nr parameter. |
LvdK | 8:422544d24df3 | 60 | // Based on key_nr, a key char string is looked up and added to the message. |
LvdK | 8:422544d24df3 | 61 | // After adding a checksum, the total KEY message will be sent. |
LvdK | 8:422544d24df3 | 62 | int i; |
LvdK | 8:422544d24df3 | 63 | char byte_read; |
LvdK | 8:422544d24df3 | 64 | char exor_byte = 0; |
LvdK | 8:422544d24df3 | 65 | // Create key message, starting with "$PCDUKEY," message header |
LvdK | 8:422544d24df3 | 66 | i = 9; // : i points to first position after "$PCDUKEY," message header |
LvdK | 8:422544d24df3 | 67 | // Add key string to message string including '*' |
LvdK | 8:422544d24df3 | 68 | if ( key_nr != 0 && key_nr < max_keys_CDUpanel ) { |
LvdK | 8:422544d24df3 | 69 | strcpy(&key_message[i],key_value[key_nr]); |
LvdK | 8:422544d24df3 | 70 | // Calculate checksum now : |
LvdK | 8:422544d24df3 | 71 | i = 1; // : i points to first place after '$' in message |
LvdK | 8:422544d24df3 | 72 | do { byte_read = key_message[i]; |
LvdK | 8:422544d24df3 | 73 | if (byte_read == '*') break; // : exclude '*' from calculation |
LvdK | 8:422544d24df3 | 74 | exor_byte = exor_byte ^ byte_read; |
LvdK | 8:422544d24df3 | 75 | i++; |
LvdK | 8:422544d24df3 | 76 | } while ( i < 20 ); |
LvdK | 8:422544d24df3 | 77 | i++; // : i now points to first digit of checksum after '*' |
LvdK | 8:422544d24df3 | 78 | // Add exor_byte in 2 hex digits and a CR + LF: |
LvdK | 8:422544d24df3 | 79 | sprintf(&key_message[i],"%02X\r\n",exor_byte); // : extra NULL char added by sprintf |
LvdK | 8:422544d24df3 | 80 | send_message_to_FS(key_message); // : send message to FS |
LvdK | 8:422544d24df3 | 81 | } |
LvdK | 8:422544d24df3 | 82 | } |
LvdK | 8:422544d24df3 | 83 | |
LvdK | 8:422544d24df3 | 84 |