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: mbed
Revision 0:cc2f9ea8cd1f, committed 2019-06-16
- Comitter:
- foxbrianr
- Date:
- Sun Jun 16 00:36:06 2019 +0000
- Commit message:
- demo microcom
Changed in this revision
diff -r 000000000000 -r cc2f9ea8cd1f MicroCom.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MicroCom.h Sun Jun 16 00:36:06 2019 +0000
@@ -0,0 +1,127 @@
+/*
+1st Byte: Header byte: always 0x40.
+
+2nd Byte: Is a bit field: free_a7 :1, bit 7
+ Reserved (fire service) :1, bit 6
+ Reserved :1, bit 5
+ Reserved :1, bit 4
+ Reserved :1, bit 3
+ play strobe :1, bit 2
+ arrival_dn_arrow :1, bit 1
+ arrival_up_arrow :1, bit0
+
+3rd Byte: Scan_slot. zero is reserved, 1 through 254, (119 may be max value in some cases)
+
+4th Byte: Message_number. zero is no message, 1 through 126, (63 may be max value in some cases)
+
+5th Byte: Is a bit field: Rear arrival dn arr :1, bit 7
+ Rear arrival up arr :1, bit 6
+ Message level hi bit :1, bit 5
+ Message level low bit :1, bit 4
+ Passing chime :1, bit 3
+ Reserved :1, bit 2
+ traveling dn arrow :1, bit 1
+ traveling up arrow :1, bit 0
+
+6th Byte: ASCII floor char, msb.
+
+7th Btye: ASCII floor char, mid.
+
+8thByte: ASCII floor char, lsb.
+ Note: floor ASCII range is 0x30 through 0x5a (‘0’ – ‘Z’).
+ 0x3a through 0x40 are special characters with
+ 0x3b being the space or blank character(semicolon)
+ 0x3d is normally displayed as a minus character.
+9th Byte: ASCII Mess. char, msb.
+
+10th Byte: ASCII Mess. Char, mid.
+
+11th Byte: ASCII Mess. char, lsb.
+ Note: message ASCII range is 0x30 through 0x5b (‘0’ – ‘[’).
+ 0x3a through 0x40 are special characters with
+ 0x3b being the space or blank character(semicolon)
+ 0x5d is sent when there is no message (instead of spaces).
+ So bytes 9, 10, and 11 will each be ‘[‘ when no message.
+12th Byte: checksum, two’s complement of bytes 1 through 11.
+
+Example:
+ 0x40, header
+ 0x01, up arrow for lantern
+ 0x01, floor number 1,
+ 0x03, message number 3 activated
+ 0x11, message level 1, direction arrow is up
+ 0x4c, ascii floor character ‘L’
+ 0x42, ascii floor character ‘B,
+ 0x59, ascii floor character ‘Y’
+ 0x3b, ascii message character ‘;’ for space or blank
+ 0x4e, ascii message character ‘N’
+ 0x44, ascii message character ‘D’
+ 0xf6, checksum (two’s complement).
+ */
+
+class MicroComMessage
+{
+ public:
+ uint8_t message[12];
+
+ uint8_t * getMessage(){ return message;};
+
+
+
+ void SetFloor(char* floor) {};
+
+ void SetMessage( char* msg){};
+
+
+
+};
+
+/*
+Floor and Arrow Information (0x501)
+The floor and arrow information contains the current car position and hall arrows.
+Packet Data
+Byte 1
+Front arrows
+Bit 0 – Front arrival arrow up
+Bit 1 – Front arrival arrow down
+Bit 2 – Play Strobe
+Bit 3-5 – Reserved
+Bit 6 – Fire Warning Lamp
+Byte 2
+Floor Number. A floor number of 0 is not a valid.
+Byte 3
+Priority message number
+Byte 4
+Travel and rear arrows
+Bit 0 – Travel arrow up
+Bit 1 – Travel arrow down
+Bit 2 – unused
+Bit 3 – Passing Chime
+Bit 4 – Message Level Low Bit
+Bit 5 – Message Level High Bit
+Bit 6 – Rear arrival arrow up
+Bit 7 – Rear arrival arrow down
+Byte 5-8
+Reserved
+*/
+
+void GetMessage501(char * floor, char * msg, char lantern )
+{
+}
+/*
+Floor and Message characters (0x502)
+The floor and message characters packet contains the marking used to represent the floor or priority message on displays.
+Packet Data
+ Byte 1 Floor marking character (leftmost)
+ Byte 2 Floor marking character
+ Byte 3 Floor marking character (rightmost)
+ Byte 4 Message marking character (leftmost)
+ Byte 5 Message marking character
+ Byte 6 Message marking character (rightmost)
+ Byte 7 Lantern Position (ThyssenKrupp)
+ Byte 8 Unused
+
+*/
+void GetMessage502(char * floor, char * msg, char lantern )
+{
+}
\ No newline at end of file
diff -r 000000000000 -r cc2f9ea8cd1f emic2.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/emic2.h Sun Jun 16 00:36:06 2019 +0000
@@ -0,0 +1,41 @@
+#define speakf printf
+class emic2 : public Stream
+{
+public :
+ emic2(PinName tx, PinName rx): _cmd(tx,rx) {
+ _cmd.baud(9600);
+ _cmd.putc('X'); //stop talking if reset and not a power on
+ _cmd.putc('\r'); // Send a CR in case the system is already up
+ wait(1); //delay for emic power on boot or reset respone
+ while (_cmd.getc() != ':'); // When the Emic 2 has initialized and is ready, it will send a single ':'
+ while (_cmd.readable()) _cmd.getc();//flush out buffer just in case
+ };
+ void ready() {
+ while (_cmd.getc() != ':');
+ while (_cmd.readable()) _cmd.getc();//flush out recieve buffer just in case
+ };
+ int readable() {
+ return _cmd.readable();
+ };
+ int getc() {
+ return _cmd.getc();
+ }
+ void volume(int x) {
+ speakf("V%D\r",x);
+ ready();
+ }
+ void voice(int x) {
+ speakf("N%D\r",x);
+ ready();
+ }
+protected :
+ Serial _cmd;
+ //used by printf - supply it and printf works!
+ virtual int _putc(int c) {
+ _cmd.putc(c);
+ return 0;
+ };
+ virtual int _getc() {
+ return -1;
+ };
+};
diff -r 000000000000 -r cc2f9ea8cd1f main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sun Jun 16 00:36:06 2019 +0000
@@ -0,0 +1,135 @@
+#include "mbed.h"
+
+DigitalOut myled1(LED1);
+DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
+DigitalOut myled4(LED3);
+
+DigitalOut myled(LED1);
+#include "emic2.h"
+
+emic2 myVoice2Text(p28, p27); //serial RX,TX pins to emic
+
+Serial pc(USBTX, USBRX, 9600); //tx,rx,baud
+
+Serial rs485port1(p9, p10, 9600); //tx,rx,baud
+DigitalOut rs485port1mode (p11); //Transmit = 1, Receive = 0
+
+Serial rs485port2(p13, p14, 9600); //tx,rx,baud
+DigitalOut rs485port2mode (p12); //Transmit = 1, Receive = 0
+
+int dataRxCnt = 0;
+int dataRxBuffer[4] = {0};
+int cur_address = 0;
+
+char fault[4];
+
+void rx485Message() {
+ // Note: you need to actually read from the serial to clear the RX interrupt
+ int value = rs485port1.getc();
+
+ if (value){
+ dataRxBuffer[dataRxCnt++]=value;
+
+ if(dataRxCnt==4) {
+ cur_address = 10*(dataRxBuffer[0] -0x30) + (dataRxBuffer[1] -0x30);
+ pc.printf("Received >> %02d \n\r", cur_address);
+ memset(dataRxBuffer,0,sizeof(dataRxBuffer));
+ dataRxCnt=0;
+ }
+ }
+ myled4 = !myled4;
+}
+
+
+void tx485Message(int address) {
+
+ int sum =0;
+
+ char dataTxBuffer[12];
+ sum += dataTxBuffer[0] = 0x40;
+ sum += dataTxBuffer[1] = 0x01;
+ sum += dataTxBuffer[2] = address; // floor number
+ sum += dataTxBuffer[3] = 0x0;
+ sum += dataTxBuffer[4] = 0x0;
+ sum += dataTxBuffer[5] = 0x0;
+ sum += dataTxBuffer[6] = (0x30 + address / 10);
+ sum += dataTxBuffer[7] = (0x30 + address % 10);
+ ; //
+ sum += dataTxBuffer[8] = 0x0;
+ sum += dataTxBuffer[9] = 0x0;
+ sum += dataTxBuffer[10] = 0x0;
+ sum += dataTxBuffer[11] = (char)(~sum +1);
+
+ for(int i= 0;i<12;i++){
+ rs485port2.putc(dataTxBuffer[i]);
+ }
+
+}
+void say (char *format, ...)
+{
+ char buffer[128];
+ va_list args;
+ va_start(args, format);
+ vsprintf(buffer,format,args);
+
+ myVoice2Text.speakf("S");//Speak command starts with "S"
+ myVoice2Text.speakf(buffer);
+ myVoice2Text.speakf("\r");
+ myVoice2Text.ready();
+
+
+ va_end(args);
+}
+
+
+int main() {
+
+ pc.printf("\n\r");
+ pc.printf("------------------------\n\r");
+ pc.printf("Serial Test\n\r");
+ pc.printf("version = %s %s\n\r", __DATE__, __TIME__ );
+ pc.printf("------------------------\n\r");
+ rs485port1mode = 0; // Receive
+ rs485port2mode = 1; // Transmit
+
+
+ myVoice2Text.voice(2);
+ say("hello");
+
+ rs485port1.attach(&rx485Message);
+
+ while(1) {
+
+ myled1 != myled1;
+ wait(0.2);
+
+ myled2 = 0;
+ myled3 = 0;
+
+ #if 0
+ if(rs485port1.readable() ) {
+ memset(data,0,sizeof(data));
+ rs485port1.scanf("%2s", data);
+ for (int i = 0 ; i < sizeof(data);i++){
+ pc.printf("%02x ", data[i]);
+ }
+ pc.printf("\n\r");
+
+ myled2 = 1;
+ }
+ else {
+ pc.printf("No serial data on port 1.\r\n");
+ myled3 = 1;
+ }
+ #endif
+
+ if (cur_address)
+ {
+ tx485Message(cur_address);
+ say("%d is open", cur_address);
+ }
+
+ wait_ms(1000);
+ }
+}
diff -r 000000000000 -r cc2f9ea8cd1f mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Jun 16 00:36:06 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file