bosko lekovic
/
EthTCPclient_05_02
p1
PGSdisplay.cpp@6:19e7658575fe, 2020-02-24 (annotated)
- Committer:
- markoc
- Date:
- Mon Feb 24 17:14:44 2020 +0000
- Revision:
- 6:19e7658575fe
- Parent:
- 5:ecaf089d1c8a
- Child:
- 7:6a700c98b9b5
init_disp problem
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:ecaf089d1c8a | 13 | RawSerial rs485(PTD3,PTD2); |
bosko001 | 4:0aec01df33d2 | 14 | |
bosko001 | 4:0aec01df33d2 | 15 | |
bosko001 | 4:0aec01df33d2 | 16 | void ev(int) |
bosko001 | 4:0aec01df33d2 | 17 | { |
bosko001 | 4:0aec01df33d2 | 18 | tast=0; |
bosko001 | 4:0aec01df33d2 | 19 | } |
bosko001 | 4:0aec01df33d2 | 20 | |
markoc | 6:19e7658575fe | 21 | uint8_t rs[100]; |
bosko001 | 5:ecaf089d1c8a | 22 | void init_disp( void) |
bosko001 | 5:ecaf089d1c8a | 23 | { |
markoc | 6:19e7658575fe | 24 | rs485.format(8,RawSerial::Even,1); |
markoc | 6:19e7658575fe | 25 | while(rs485.readable()) |
markoc | 6:19e7658575fe | 26 | { |
markoc | 6:19e7658575fe | 27 | rs485.read(rs,1,NULL); |
markoc | 6:19e7658575fe | 28 | } |
bosko001 | 5:ecaf089d1c8a | 29 | putOnDisp("elcom", 3); |
markoc | 6:19e7658575fe | 30 | int i =0; |
markoc | 6:19e7658575fe | 31 | //while(rs485.readable()==0); |
markoc | 6:19e7658575fe | 32 | wait(0.5); |
markoc | 6:19e7658575fe | 33 | if(rs485.readable()) |
markoc | 6:19e7658575fe | 34 | { |
markoc | 6:19e7658575fe | 35 | |
markoc | 6:19e7658575fe | 36 | rs485.read(rs+i,1,NULL); |
markoc | 6:19e7658575fe | 37 | i++; |
markoc | 6:19e7658575fe | 38 | } |
markoc | 6:19e7658575fe | 39 | printf("ODGOVOR: %X - %d\n\r",rs[0],i); |
markoc | 6:19e7658575fe | 40 | //int i=0; |
markoc | 6:19e7658575fe | 41 | // |
markoc | 6:19e7658575fe | 42 | // printf("%d\n\r",rs485.readable()); |
markoc | 6:19e7658575fe | 43 | // if(rs485.readable()) |
markoc | 6:19e7658575fe | 44 | // { |
markoc | 6:19e7658575fe | 45 | // printf("\n\rRECEIVE: "); |
markoc | 6:19e7658575fe | 46 | // while(rs485.readable()) |
markoc | 6:19e7658575fe | 47 | // { |
markoc | 6:19e7658575fe | 48 | // rs[i++] = rs485.getc(); |
markoc | 6:19e7658575fe | 49 | // } |
markoc | 6:19e7658575fe | 50 | // printf("%X: RECEIVED %d: \n\r",rs[0], i); |
markoc | 6:19e7658575fe | 51 | // } |
bosko001 | 5:ecaf089d1c8a | 52 | } |
bosko001 | 5:ecaf089d1c8a | 53 | |
bosko001 | 5:ecaf089d1c8a | 54 | 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 | 55 | #define NO_BEFORE_DATA 13 |
bosko001 | 4:0aec01df33d2 | 56 | #define NO_WITH_DATA (NO_BEFORE_DATA + strlen(s)) |
bosko001 | 4:0aec01df33d2 | 57 | |
bosko001 | 4:0aec01df33d2 | 58 | void putOnDisp( char *s, char boja) |
bosko001 | 4:0aec01df33d2 | 59 | { |
bosko001 | 4:0aec01df33d2 | 60 | int ubb = NO_BEFORE_DATA+strlen(s)+1+1-4-2; // ubb = ukupan broj bajtova |
bosko001 | 4:0aec01df33d2 | 61 | buf_tel[NO_BEFORE_DATA-1]=boja; |
bosko001 | 4:0aec01df33d2 | 62 | memcpy(buf_tel+NO_BEFORE_DATA, s, strlen(s)+2); |
bosko001 | 4:0aec01df33d2 | 63 | |
bosko001 | 4:0aec01df33d2 | 64 | char suma=0; |
bosko001 | 4:0aec01df33d2 | 65 | for(int i = 4; i < NO_WITH_DATA; i++) { |
bosko001 | 4:0aec01df33d2 | 66 | suma +=buf_tel[i]; |
bosko001 | 4:0aec01df33d2 | 67 | } |
bosko001 | 4:0aec01df33d2 | 68 | |
bosko001 | 4:0aec01df33d2 | 69 | buf_tel[NO_WITH_DATA] = suma; |
bosko001 | 4:0aec01df33d2 | 70 | buf_tel[NO_WITH_DATA+1] = 22; |
bosko001 | 4:0aec01df33d2 | 71 | buf_tel[1]=ubb>>8; |
bosko001 | 4:0aec01df33d2 | 72 | buf_tel[2]=ubb; |
bosko001 | 4:0aec01df33d2 | 73 | |
bosko001 | 4:0aec01df33d2 | 74 | |
bosko001 | 4:0aec01df33d2 | 75 | tast=1; |
bosko001 | 4:0aec01df33d2 | 76 | rs485.write(buf_tel, NO_WITH_DATA+2+2,ev); |
markoc | 6:19e7658575fe | 77 | |
bosko001 | 4:0aec01df33d2 | 78 | } |
bosko001 | 4:0aec01df33d2 | 79 | |
bosko001 | 4:0aec01df33d2 | 80 | void putOnDispNo(int broj, char boja) |
bosko001 | 4:0aec01df33d2 | 81 | { |
bosko001 | 4:0aec01df33d2 | 82 | char s[10]; |
bosko001 | 4:0aec01df33d2 | 83 | sprintf( s, "%d", broj); |
bosko001 | 4:0aec01df33d2 | 84 | putOnDisp( s, boja); |
bosko001 | 4:0aec01df33d2 | 85 | } |
bosko001 | 4:0aec01df33d2 | 86 | |
bosko001 | 4:0aec01df33d2 | 87 | |
bosko001 | 4:0aec01df33d2 | 88 | void slanjefun() |
bosko001 | 4:0aec01df33d2 | 89 | { |
bosko001 | 4:0aec01df33d2 | 90 | |
bosko001 | 4:0aec01df33d2 | 91 | int j=0; |
bosko001 | 4:0aec01df33d2 | 92 | |
bosko001 | 4:0aec01df33d2 | 93 | |
bosko001 | 4:0aec01df33d2 | 94 | while (true) { |
bosko001 | 4:0aec01df33d2 | 95 | // printf("disp thred %d\n\r",j); |
bosko001 | 5:ecaf089d1c8a | 96 | if(j >10 && j<15 ) putOnDisp((char*)"des",1); |
bosko001 | 4:0aec01df33d2 | 97 | else putOnDispNo(j,1); |
bosko001 | 4:0aec01df33d2 | 98 | j++; |
bosko001 | 4:0aec01df33d2 | 99 | thread_sleep_for(1000); |
bosko001 | 4:0aec01df33d2 | 100 | } |
bosko001 | 4:0aec01df33d2 | 101 | } |
bosko001 | 4:0aec01df33d2 | 102 | |
bosko001 | 4:0aec01df33d2 | 103 | |
bosko001 | 4:0aec01df33d2 | 104 | char * extract_string( char delimiter, char *ulazni_str, int n_str ) |
bosko001 | 4:0aec01df33d2 | 105 | { |
bosko001 | 4:0aec01df33d2 | 106 | int br_str=0; |
bosko001 | 4:0aec01df33d2 | 107 | char *ret_str=ulazni_str; |
bosko001 | 4:0aec01df33d2 | 108 | char* ptr = ulazni_str; |
bosko001 | 4:0aec01df33d2 | 109 | |
bosko001 | 4:0aec01df33d2 | 110 | while(*ptr) { |
bosko001 | 4:0aec01df33d2 | 111 | if(*ptr == delimiter) { |
bosko001 | 4:0aec01df33d2 | 112 | *ptr = 0; |
bosko001 | 4:0aec01df33d2 | 113 | if( br_str == n_str ) return ret_str; |
bosko001 | 4:0aec01df33d2 | 114 | else { |
bosko001 | 4:0aec01df33d2 | 115 | br_str++; |
bosko001 | 4:0aec01df33d2 | 116 | ret_str = ptr + 1; |
bosko001 | 4:0aec01df33d2 | 117 | } |
bosko001 | 4:0aec01df33d2 | 118 | } |
bosko001 | 4:0aec01df33d2 | 119 | ptr++; |
bosko001 | 4:0aec01df33d2 | 120 | } |
bosko001 | 4:0aec01df33d2 | 121 | if( br_str == n_str ) return ret_str; |
bosko001 | 4:0aec01df33d2 | 122 | return NULL; |
bosko001 | 4:0aec01df33d2 | 123 | } |
bosko001 | 4:0aec01df33d2 | 124 |