bosko lekovic
/
EthTCPclient_05_03
p1
PGSdisplay.cpp@5:ecaf089d1c8a, 2020-02-24 (annotated)
- Committer:
- bosko001
- Date:
- Mon Feb 24 13:55:09 2020 +0000
- Revision:
- 5:ecaf089d1c8a
- Parent:
- PGSdisplay.c@4:0aec01df33d2
- Child:
- 6:19e7658575fe
EthTCPclient_5
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 | |
bosko001 | 5:ecaf089d1c8a | 21 | void init_disp( void) |
bosko001 | 5:ecaf089d1c8a | 22 | { |
bosko001 | 5:ecaf089d1c8a | 23 | rs485.format(8,RawSerial::Even,1); |
bosko001 | 5:ecaf089d1c8a | 24 | |
bosko001 | 5:ecaf089d1c8a | 25 | putOnDisp("elcom", 3); |
bosko001 | 4:0aec01df33d2 | 26 | |
bosko001 | 4:0aec01df33d2 | 27 | |
bosko001 | 5:ecaf089d1c8a | 28 | } |
bosko001 | 5:ecaf089d1c8a | 29 | |
bosko001 | 5:ecaf089d1c8a | 30 | 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 | 31 | #define NO_BEFORE_DATA 13 |
bosko001 | 4:0aec01df33d2 | 32 | #define NO_WITH_DATA (NO_BEFORE_DATA + strlen(s)) |
bosko001 | 4:0aec01df33d2 | 33 | |
bosko001 | 4:0aec01df33d2 | 34 | void putOnDisp( char *s, char boja) |
bosko001 | 4:0aec01df33d2 | 35 | { |
bosko001 | 4:0aec01df33d2 | 36 | int ubb = NO_BEFORE_DATA+strlen(s)+1+1-4-2; // ubb = ukupan broj bajtova |
bosko001 | 4:0aec01df33d2 | 37 | buf_tel[NO_BEFORE_DATA-1]=boja; |
bosko001 | 4:0aec01df33d2 | 38 | memcpy(buf_tel+NO_BEFORE_DATA, s, strlen(s)+2); |
bosko001 | 4:0aec01df33d2 | 39 | |
bosko001 | 4:0aec01df33d2 | 40 | char suma=0; |
bosko001 | 4:0aec01df33d2 | 41 | for(int i = 4; i < NO_WITH_DATA; i++) { |
bosko001 | 4:0aec01df33d2 | 42 | suma +=buf_tel[i]; |
bosko001 | 4:0aec01df33d2 | 43 | } |
bosko001 | 4:0aec01df33d2 | 44 | |
bosko001 | 4:0aec01df33d2 | 45 | buf_tel[NO_WITH_DATA] = suma; |
bosko001 | 4:0aec01df33d2 | 46 | buf_tel[NO_WITH_DATA+1] = 22; |
bosko001 | 4:0aec01df33d2 | 47 | buf_tel[1]=ubb>>8; |
bosko001 | 4:0aec01df33d2 | 48 | buf_tel[2]=ubb; |
bosko001 | 4:0aec01df33d2 | 49 | |
bosko001 | 4:0aec01df33d2 | 50 | |
bosko001 | 4:0aec01df33d2 | 51 | tast=1; |
bosko001 | 4:0aec01df33d2 | 52 | rs485.write(buf_tel, NO_WITH_DATA+2+2,ev); |
bosko001 | 4:0aec01df33d2 | 53 | } |
bosko001 | 4:0aec01df33d2 | 54 | |
bosko001 | 4:0aec01df33d2 | 55 | void putOnDispNo(int broj, char boja) |
bosko001 | 4:0aec01df33d2 | 56 | { |
bosko001 | 4:0aec01df33d2 | 57 | char s[10]; |
bosko001 | 4:0aec01df33d2 | 58 | sprintf( s, "%d", broj); |
bosko001 | 4:0aec01df33d2 | 59 | putOnDisp( s, boja); |
bosko001 | 4:0aec01df33d2 | 60 | } |
bosko001 | 4:0aec01df33d2 | 61 | |
bosko001 | 4:0aec01df33d2 | 62 | |
bosko001 | 4:0aec01df33d2 | 63 | void slanjefun() |
bosko001 | 4:0aec01df33d2 | 64 | { |
bosko001 | 4:0aec01df33d2 | 65 | |
bosko001 | 4:0aec01df33d2 | 66 | int j=0; |
bosko001 | 4:0aec01df33d2 | 67 | |
bosko001 | 4:0aec01df33d2 | 68 | |
bosko001 | 4:0aec01df33d2 | 69 | while (true) { |
bosko001 | 4:0aec01df33d2 | 70 | // printf("disp thred %d\n\r",j); |
bosko001 | 5:ecaf089d1c8a | 71 | if(j >10 && j<15 ) putOnDisp((char*)"des",1); |
bosko001 | 4:0aec01df33d2 | 72 | else putOnDispNo(j,1); |
bosko001 | 4:0aec01df33d2 | 73 | j++; |
bosko001 | 4:0aec01df33d2 | 74 | thread_sleep_for(1000); |
bosko001 | 4:0aec01df33d2 | 75 | } |
bosko001 | 4:0aec01df33d2 | 76 | } |
bosko001 | 4:0aec01df33d2 | 77 | |
bosko001 | 4:0aec01df33d2 | 78 | |
bosko001 | 4:0aec01df33d2 | 79 | char * extract_string( char delimiter, char *ulazni_str, int n_str ) |
bosko001 | 4:0aec01df33d2 | 80 | { |
bosko001 | 4:0aec01df33d2 | 81 | int br_str=0; |
bosko001 | 4:0aec01df33d2 | 82 | char *ret_str=ulazni_str; |
bosko001 | 4:0aec01df33d2 | 83 | char* ptr = ulazni_str; |
bosko001 | 4:0aec01df33d2 | 84 | |
bosko001 | 4:0aec01df33d2 | 85 | while(*ptr) { |
bosko001 | 4:0aec01df33d2 | 86 | if(*ptr == delimiter) { |
bosko001 | 4:0aec01df33d2 | 87 | *ptr = 0; |
bosko001 | 4:0aec01df33d2 | 88 | if( br_str == n_str ) return ret_str; |
bosko001 | 4:0aec01df33d2 | 89 | else { |
bosko001 | 4:0aec01df33d2 | 90 | br_str++; |
bosko001 | 4:0aec01df33d2 | 91 | ret_str = ptr + 1; |
bosko001 | 4:0aec01df33d2 | 92 | } |
bosko001 | 4:0aec01df33d2 | 93 | } |
bosko001 | 4:0aec01df33d2 | 94 | ptr++; |
bosko001 | 4:0aec01df33d2 | 95 | } |
bosko001 | 4:0aec01df33d2 | 96 | if( br_str == n_str ) return ret_str; |
bosko001 | 4:0aec01df33d2 | 97 | return NULL; |
bosko001 | 4:0aec01df33d2 | 98 | } |
bosko001 | 4:0aec01df33d2 | 99 |