p1

Committer:
bosko001
Date:
Thu Jun 18 15:20:34 2020 +0000
Revision:
7:0939ac3d73af
Parent:
6:19e7658575fe
p1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bosko001 4:0aec01df33d2 1
bosko001 4:0aec01df33d2 2 //#include "mbed.h"
bosko001 4:0aec01df33d2 3 //#include "platform/mbed_thread.h"
bosko001 4:0aec01df33d2 4
bosko001 5:ecaf089d1c8a 5 #include "mbed.h"
bosko001 4:0aec01df33d2 6
bosko001 4:0aec01df33d2 7 #include "PGSdisplay.h"
bosko001 5:ecaf089d1c8a 8
bosko001 5:ecaf089d1c8a 9 #define DISP_ADR 40
bosko001 4:0aec01df33d2 10
bosko001 5:ecaf089d1c8a 11 DigitalOut tast(PTB19,0);
bosko001 5:ecaf089d1c8a 12 ////RawSerial rs485(PTC17,PTC16);
bosko001 7:0939ac3d73af 13 Serial rs485(PTD3,PTD2);
bosko001 7:0939ac3d73af 14 DigitalOut led(LED2,1);
bosko001 7:0939ac3d73af 15
bosko001 7:0939ac3d73af 16 char cc;
bosko001 7:0939ac3d73af 17
bosko001 7:0939ac3d73af 18
bosko001 4:0aec01df33d2 19
bosko001 4:0aec01df33d2 20
bosko001 7:0939ac3d73af 21 void rc(void)
bosko001 7:0939ac3d73af 22 {
bosko001 7:0939ac3d73af 23 led = !led;
bosko001 7:0939ac3d73af 24 cc=rs485.getc();
bosko001 7:0939ac3d73af 25 }
bosko001 7:0939ac3d73af 26
bosko001 7:0939ac3d73af 27 void tast_on( int )
bosko001 7:0939ac3d73af 28 {
bosko001 7:0939ac3d73af 29 // rs485.attach( NULL, Serial::RxIrq );
bosko001 7:0939ac3d73af 30 tast = 1;
bosko001 7:0939ac3d73af 31 }
bosko001 7:0939ac3d73af 32
bosko001 7:0939ac3d73af 33 void tast_off(void)
bosko001 4:0aec01df33d2 34 {
bosko001 4:0aec01df33d2 35 tast=0;
bosko001 7:0939ac3d73af 36 // rs485.attach( rc, Serial::RxIrq );
bosko001 4:0aec01df33d2 37 }
bosko001 4:0aec01df33d2 38
bosko001 7:0939ac3d73af 39
bosko001 7:0939ac3d73af 40
bosko001 7:0939ac3d73af 41 #define FLAG_1 1
bosko001 7:0939ac3d73af 42 EventFlags ef;
bosko001 7:0939ac3d73af 43
bosko001 7:0939ac3d73af 44
markoc 6:19e7658575fe 45 uint8_t rs[100];
bosko001 5:ecaf089d1c8a 46 void init_disp( void)
bosko001 5:ecaf089d1c8a 47 {
bosko001 7:0939ac3d73af 48 rs485.format(8,SerialBase::Even,1);
bosko001 7:0939ac3d73af 49 // rs485.attach( tast_off, Serial::TxIrq );
bosko001 7:0939ac3d73af 50 // rs485.attach( rc, Serial::RxIrq );
bosko001 7:0939ac3d73af 51
bosko001 7:0939ac3d73af 52
bosko001 7:0939ac3d73af 53 // rs485.enable_input(true);
bosko001 7:0939ac3d73af 54 // if(rs485.readable()) rs485.getc();
bosko001 7:0939ac3d73af 55
bosko001 7:0939ac3d73af 56
bosko001 7:0939ac3d73af 57 //printf("ODGOVOR: %x \n\r",rs485.getc());
bosko001 7:0939ac3d73af 58
bosko001 7:0939ac3d73af 59 putOnDisp("elcom", 3);
bosko001 7:0939ac3d73af 60 printf("slanje na displej \n\r");
bosko001 7:0939ac3d73af 61 //wait(0.010);
bosko001 7:0939ac3d73af 62 // rs485.attach( (rc), Serial::RxIrq );
bosko001 7:0939ac3d73af 63 //printf("attachovanje \n\r");
bosko001 7:0939ac3d73af 64
bosko001 7:0939ac3d73af 65 //wait(0.110);
bosko001 7:0939ac3d73af 66 //// while(!rs485.readable());
bosko001 7:0939ac3d73af 67 ////printf("readable gotov \n\r");
bosko001 7:0939ac3d73af 68 //fflush(stdout);
bosko001 7:0939ac3d73af 69 //
bosko001 7:0939ac3d73af 70 char c[10];
bosko001 7:0939ac3d73af 71 int i,j=1;
bosko001 7:0939ac3d73af 72 //{ i=rs485.read( (uint8_t*)c,5, /*callback(ve)*/NULL ); j++;}
bosko001 7:0939ac3d73af 73
bosko001 7:0939ac3d73af 74 //while( !(i=rs485.read( (uint8_t*)&c,1, callback(ve),SERIAL_EVENT_RX_COMPLETE )) ){j++;};
bosko001 7:0939ac3d73af 75 //i=rs485.read( (uint8_t*)&c,1, callback(ve),SERIAL_EVENT_RX_COMPLETE ) ;
bosko001 7:0939ac3d73af 76 //printf("ODGOVOR: c=%x %x i=%x j=%d\n\r", c[0],c[1], i, j );
bosko001 7:0939ac3d73af 77
bosko001 7:0939ac3d73af 78 printf("primljeno cc =%x \n\r", cc);
bosko001 7:0939ac3d73af 79
bosko001 7:0939ac3d73af 80
bosko001 7:0939ac3d73af 81
bosko001 7:0939ac3d73af 82
bosko001 7:0939ac3d73af 83 // char c = rs485.getc();
bosko001 7:0939ac3d73af 84 // wait(0.5);
bosko001 7:0939ac3d73af 85 //thread_sleep_for(500);
bosko001 7:0939ac3d73af 86 //printf("odgovor = %x\n\r", cc);
bosko001 7:0939ac3d73af 87
bosko001 7:0939ac3d73af 88 //uint8_t c;
bosko001 7:0939ac3d73af 89 // if( rs485.readable()) printf("ODGOVOR: %d %x\n\r",rs485.read( &c, 1, ve), c);
bosko001 7:0939ac3d73af 90
bosko001 5:ecaf089d1c8a 91 }
bosko001 5:ecaf089d1c8a 92
bosko001 7:0939ac3d73af 93
bosko001 5:ecaf089d1c8a 94 unsigned char buf_tel[100] = {0x71,0x00,0x0D,0x71,0x43,DISP_ADR,0x1B,0x4A,0x01,0x01, /*0x1b,0x45,0x1,*/ 0x1B,0x43,1,0x33,0xD5,0x16};
bosko001 4:0aec01df33d2 95 #define NO_BEFORE_DATA 13
bosko001 4:0aec01df33d2 96 #define NO_WITH_DATA (NO_BEFORE_DATA + strlen(s))
bosko001 4:0aec01df33d2 97
bosko001 4:0aec01df33d2 98 void putOnDisp( char *s, char boja)
bosko001 4:0aec01df33d2 99 {
bosko001 4:0aec01df33d2 100 int ubb = NO_BEFORE_DATA+strlen(s)+1+1-4-2; // ubb = ukupan broj bajtova
bosko001 4:0aec01df33d2 101 buf_tel[NO_BEFORE_DATA-1]=boja;
bosko001 4:0aec01df33d2 102 memcpy(buf_tel+NO_BEFORE_DATA, s, strlen(s)+2);
bosko001 4:0aec01df33d2 103
bosko001 4:0aec01df33d2 104 char suma=0;
bosko001 4:0aec01df33d2 105 for(int i = 4; i < NO_WITH_DATA; i++) {
bosko001 4:0aec01df33d2 106 suma +=buf_tel[i];
bosko001 4:0aec01df33d2 107 }
bosko001 4:0aec01df33d2 108
bosko001 4:0aec01df33d2 109 buf_tel[NO_WITH_DATA] = suma;
bosko001 4:0aec01df33d2 110 buf_tel[NO_WITH_DATA+1] = 22;
bosko001 4:0aec01df33d2 111 buf_tel[1]=ubb>>8;
bosko001 4:0aec01df33d2 112 buf_tel[2]=ubb;
bosko001 4:0aec01df33d2 113
bosko001 4:0aec01df33d2 114
bosko001 7:0939ac3d73af 115 tast_on(1);
bosko001 7:0939ac3d73af 116 // rs485.write((const void*)buf_tel, (size_t)(NO_WITH_DATA+2+2)/*, tast_off, SERIAL_EVENT_TX_COMPLETE*/);
bosko001 7:0939ac3d73af 117 for(int i=0; i< NO_WITH_DATA+2+2; i++ ) rs485.putc(buf_tel[i]);
bosko001 4:0aec01df33d2 118 }
bosko001 4:0aec01df33d2 119
bosko001 4:0aec01df33d2 120 void putOnDispNo(int broj, char boja)
bosko001 4:0aec01df33d2 121 {
bosko001 4:0aec01df33d2 122 char s[10];
bosko001 4:0aec01df33d2 123 sprintf( s, "%d", broj);
bosko001 4:0aec01df33d2 124 putOnDisp( s, boja);
bosko001 4:0aec01df33d2 125 }
bosko001 4:0aec01df33d2 126
bosko001 4:0aec01df33d2 127
bosko001 4:0aec01df33d2 128 void slanjefun()
bosko001 4:0aec01df33d2 129 {
bosko001 4:0aec01df33d2 130
bosko001 4:0aec01df33d2 131 int j=0;
bosko001 4:0aec01df33d2 132
bosko001 4:0aec01df33d2 133
bosko001 4:0aec01df33d2 134 while (true) {
bosko001 4:0aec01df33d2 135 // printf("disp thred %d\n\r",j);
bosko001 5:ecaf089d1c8a 136 if(j >10 && j<15 ) putOnDisp((char*)"des",1);
bosko001 4:0aec01df33d2 137 else putOnDispNo(j,1);
bosko001 4:0aec01df33d2 138 j++;
bosko001 4:0aec01df33d2 139 thread_sleep_for(1000);
bosko001 4:0aec01df33d2 140 }
bosko001 4:0aec01df33d2 141 }
bosko001 4:0aec01df33d2 142
bosko001 4:0aec01df33d2 143
bosko001 4:0aec01df33d2 144 char * extract_string( char delimiter, char *ulazni_str, int n_str )
bosko001 4:0aec01df33d2 145 {
bosko001 4:0aec01df33d2 146 int br_str=0;
bosko001 4:0aec01df33d2 147 char *ret_str=ulazni_str;
bosko001 4:0aec01df33d2 148 char* ptr = ulazni_str;
bosko001 4:0aec01df33d2 149
bosko001 4:0aec01df33d2 150 while(*ptr) {
bosko001 4:0aec01df33d2 151 if(*ptr == delimiter) {
bosko001 4:0aec01df33d2 152 *ptr = 0;
bosko001 4:0aec01df33d2 153 if( br_str == n_str ) return ret_str;
bosko001 4:0aec01df33d2 154 else {
bosko001 4:0aec01df33d2 155 br_str++;
bosko001 4:0aec01df33d2 156 ret_str = ptr + 1;
bosko001 4:0aec01df33d2 157 }
bosko001 4:0aec01df33d2 158 }
bosko001 4:0aec01df33d2 159 ptr++;
bosko001 4:0aec01df33d2 160 }
bosko001 4:0aec01df33d2 161 if( br_str == n_str ) return ret_str;
bosko001 4:0aec01df33d2 162 return NULL;
bosko001 4:0aec01df33d2 163 }
bosko001 4:0aec01df33d2 164