Program Kunci
Dependencies: BufferedSoftSerial Noritake iButton CRC16Modbus Displays Audio
main.cpp@0:0cd00ee4dd93, 2020-07-09 (annotated)
- Committer:
- mauuuuul
- Date:
- Thu Jul 09 09:04:32 2020 +0000
- Revision:
- 0:0cd00ee4dd93
Key Controller;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mauuuuul | 0:0cd00ee4dd93 | 1 | #include "mbed.h" |
mauuuuul | 0:0cd00ee4dd93 | 2 | #include "EthernetInterface.h" |
mauuuuul | 0:0cd00ee4dd93 | 3 | #include <string> |
mauuuuul | 0:0cd00ee4dd93 | 4 | #include <vector> |
mauuuuul | 0:0cd00ee4dd93 | 5 | #include "Audio.h" |
mauuuuul | 0:0cd00ee4dd93 | 6 | #include "iButton.h" |
mauuuuul | 0:0cd00ee4dd93 | 7 | #include <bitset> |
mauuuuul | 0:0cd00ee4dd93 | 8 | #include "CRC16Modbus.h" |
mauuuuul | 0:0cd00ee4dd93 | 9 | #include "BufferedSoftSerial.h" |
mauuuuul | 0:0cd00ee4dd93 | 10 | #include "Displays.h" |
mauuuuul | 0:0cd00ee4dd93 | 11 | #include <list> |
mauuuuul | 0:0cd00ee4dd93 | 12 | #include <algorithm> |
mauuuuul | 0:0cd00ee4dd93 | 13 | |
mauuuuul | 0:0cd00ee4dd93 | 14 | // Network interface |
mauuuuul | 0:0cd00ee4dd93 | 15 | TCPSocket socket; |
mauuuuul | 0:0cd00ee4dd93 | 16 | |
mauuuuul | 0:0cd00ee4dd93 | 17 | Thread thdFindConnection; |
mauuuuul | 0:0cd00ee4dd93 | 18 | Thread thd_Cek_Ibutton; |
mauuuuul | 0:0cd00ee4dd93 | 19 | Thread thd_RS485_Recv; |
mauuuuul | 0:0cd00ee4dd93 | 20 | Thread thd_Buzzer; |
mauuuuul | 0:0cd00ee4dd93 | 21 | Thread thd_LCD; |
mauuuuul | 0:0cd00ee4dd93 | 22 | |
mauuuuul | 0:0cd00ee4dd93 | 23 | MyAudio buzz(D7); |
mauuuuul | 0:0cd00ee4dd93 | 24 | Displays dsp(PTC8,PTC1); |
mauuuuul | 0:0cd00ee4dd93 | 25 | uint8_t LCD_Step = 0; |
mauuuuul | 0:0cd00ee4dd93 | 26 | uint8_t LCD_Step_4 = 0; |
mauuuuul | 0:0cd00ee4dd93 | 27 | |
mauuuuul | 0:0cd00ee4dd93 | 28 | #define IP "192.168.0.6" |
mauuuuul | 0:0cd00ee4dd93 | 29 | #define GATEWAY "192.168.0.1" |
mauuuuul | 0:0cd00ee4dd93 | 30 | #define MASK "255.255.255.0" |
mauuuuul | 0:0cd00ee4dd93 | 31 | |
mauuuuul | 0:0cd00ee4dd93 | 32 | char cmd_resets[] = "R00"; |
mauuuuul | 0:0cd00ee4dd93 | 33 | char cek_con[] = "P"; |
mauuuuul | 0:0cd00ee4dd93 | 34 | |
mauuuuul | 0:0cd00ee4dd93 | 35 | uint8_t Key_On_Process = 0; |
mauuuuul | 0:0cd00ee4dd93 | 36 | |
mauuuuul | 0:0cd00ee4dd93 | 37 | Serial dbg(USBTX,USBRX); |
mauuuuul | 0:0cd00ee4dd93 | 38 | BufferedSoftSerial dv(PTB19,PTB18); |
mauuuuul | 0:0cd00ee4dd93 | 39 | DigitalOut rede(PTC9,0); |
mauuuuul | 0:0cd00ee4dd93 | 40 | iButton ibutton(D4); |
mauuuuul | 0:0cd00ee4dd93 | 41 | |
mauuuuul | 0:0cd00ee4dd93 | 42 | bool tap = false; |
mauuuuul | 0:0cd00ee4dd93 | 43 | bool lasttap = false; |
mauuuuul | 0:0cd00ee4dd93 | 44 | |
mauuuuul | 0:0cd00ee4dd93 | 45 | uint8_t board_number; |
mauuuuul | 0:0cd00ee4dd93 | 46 | uint8_t baris; |
mauuuuul | 0:0cd00ee4dd93 | 47 | uint8_t kolom; |
mauuuuul | 0:0cd00ee4dd93 | 48 | uint8_t real_id; |
mauuuuul | 0:0cd00ee4dd93 | 49 | uint8_t real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 50 | uint8_t real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 51 | uint8_t real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 52 | uint8_t real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 53 | uint8_t real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 54 | uint8_t blinking_now = 0; |
mauuuuul | 0:0cd00ee4dd93 | 55 | |
mauuuuul | 0:0cd00ee4dd93 | 56 | uint8_t ids; |
mauuuuul | 0:0cd00ee4dd93 | 57 | |
mauuuuul | 0:0cd00ee4dd93 | 58 | typedef uint8_t byte; |
mauuuuul | 0:0cd00ee4dd93 | 59 | //r0,r1,r2,r3,r4,r5,r6,r7 |
mauuuuul | 0:0cd00ee4dd93 | 60 | byte Row_Board1_Last[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 61 | byte Row_Board2_Last[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 62 | byte Row_Board3_Last[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 63 | byte Row_Board4_Last[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 64 | byte Row_Board5_Last[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 65 | |
mauuuuul | 0:0cd00ee4dd93 | 66 | byte Row_Board1_Now[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 67 | byte Row_Board2_Now[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 68 | byte Row_Board3_Now[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 69 | byte Row_Board4_Now[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 70 | byte Row_Board5_Now[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 71 | |
mauuuuul | 0:0cd00ee4dd93 | 72 | byte Row_Board1_Predict[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 73 | byte Row_Board2_Predict[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 74 | byte Row_Board3_Predict[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 75 | byte Row_Board4_Predict[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 76 | byte Row_Board5_Predict[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 77 | |
mauuuuul | 0:0cd00ee4dd93 | 78 | uint8_t board_88[8][8]= { |
mauuuuul | 0:0cd00ee4dd93 | 79 | {0,1,2,3,4,5,6,7}, |
mauuuuul | 0:0cd00ee4dd93 | 80 | {8,9,10,11,12,13,14,15}, |
mauuuuul | 0:0cd00ee4dd93 | 81 | {16,17,18,19,20,21,22,23}, |
mauuuuul | 0:0cd00ee4dd93 | 82 | {24,25,26,27,28,29,30,31}, |
mauuuuul | 0:0cd00ee4dd93 | 83 | {32,33,34,35,36,37,38,39}, |
mauuuuul | 0:0cd00ee4dd93 | 84 | {40,41,42,43,44,45,46,47}, |
mauuuuul | 0:0cd00ee4dd93 | 85 | {48,49,50,51,52,53,54,55}, |
mauuuuul | 0:0cd00ee4dd93 | 86 | {56,57,58,59,60,61,62,63} |
mauuuuul | 0:0cd00ee4dd93 | 87 | }; |
mauuuuul | 0:0cd00ee4dd93 | 88 | |
mauuuuul | 0:0cd00ee4dd93 | 89 | string TCP_Cek_Data_Last_Sent; |
mauuuuul | 0:0cd00ee4dd93 | 90 | string TCP_Data_Last_Sent; |
mauuuuul | 0:0cd00ee4dd93 | 91 | string TCP_Ibutton_Last_Sent; |
mauuuuul | 0:0cd00ee4dd93 | 92 | |
mauuuuul | 0:0cd00ee4dd93 | 93 | unsigned char buffer_crc[2]; |
mauuuuul | 0:0cd00ee4dd93 | 94 | unsigned short _crc; |
mauuuuul | 0:0cd00ee4dd93 | 95 | |
mauuuuul | 0:0cd00ee4dd93 | 96 | byte respon_from_slave_temp[17]; |
mauuuuul | 0:0cd00ee4dd93 | 97 | |
mauuuuul | 0:0cd00ee4dd93 | 98 | bool intr_Done = false; |
mauuuuul | 0:0cd00ee4dd93 | 99 | uint8_t board_sum; |
mauuuuul | 0:0cd00ee4dd93 | 100 | |
mauuuuul | 0:0cd00ee4dd93 | 101 | struct frame_data { |
mauuuuul | 0:0cd00ee4dd93 | 102 | string ids; |
mauuuuul | 0:0cd00ee4dd93 | 103 | string key_on = ""; |
mauuuuul | 0:0cd00ee4dd93 | 104 | string key_off = ""; |
mauuuuul | 0:0cd00ee4dd93 | 105 | }Frame_To_Send; |
mauuuuul | 0:0cd00ee4dd93 | 106 | |
mauuuuul | 0:0cd00ee4dd93 | 107 | struct Frame_Data_Received { |
mauuuuul | 0:0cd00ee4dd93 | 108 | uint8_t ids; |
mauuuuul | 0:0cd00ee4dd93 | 109 | string ibutton; |
mauuuuul | 0:0cd00ee4dd93 | 110 | uint8_t _key_id; |
mauuuuul | 0:0cd00ee4dd93 | 111 | uint8_t cmd_id; |
mauuuuul | 0:0cd00ee4dd93 | 112 | } frm_data_received; |
mauuuuul | 0:0cd00ee4dd93 | 113 | |
mauuuuul | 0:0cd00ee4dd93 | 114 | byte respon_from_slave[32]; |
mauuuuul | 0:0cd00ee4dd93 | 115 | |
mauuuuul | 0:0cd00ee4dd93 | 116 | uint8_t step = 0; |
mauuuuul | 0:0cd00ee4dd93 | 117 | bool Done = false; |
mauuuuul | 0:0cd00ee4dd93 | 118 | bool isConnected = false; |
mauuuuul | 0:0cd00ee4dd93 | 119 | |
mauuuuul | 0:0cd00ee4dd93 | 120 | string salah_taruh1; |
mauuuuul | 0:0cd00ee4dd93 | 121 | string salah_ambil1; |
mauuuuul | 0:0cd00ee4dd93 | 122 | string salah_taruh2; |
mauuuuul | 0:0cd00ee4dd93 | 123 | string salah_ambil2; |
mauuuuul | 0:0cd00ee4dd93 | 124 | string salah_taruh3; |
mauuuuul | 0:0cd00ee4dd93 | 125 | string salah_ambil3; |
mauuuuul | 0:0cd00ee4dd93 | 126 | string salah_taruh4; |
mauuuuul | 0:0cd00ee4dd93 | 127 | string salah_ambil4; |
mauuuuul | 0:0cd00ee4dd93 | 128 | string salah_taruh5; |
mauuuuul | 0:0cd00ee4dd93 | 129 | string salah_ambil5; |
mauuuuul | 0:0cd00ee4dd93 | 130 | |
mauuuuul | 0:0cd00ee4dd93 | 131 | bool done_1 = true; |
mauuuuul | 0:0cd00ee4dd93 | 132 | bool done_2 = true; |
mauuuuul | 0:0cd00ee4dd93 | 133 | bool done_3 = true; |
mauuuuul | 0:0cd00ee4dd93 | 134 | bool done_4 = true; |
mauuuuul | 0:0cd00ee4dd93 | 135 | bool done_5 = true; |
mauuuuul | 0:0cd00ee4dd93 | 136 | |
mauuuuul | 0:0cd00ee4dd93 | 137 | vector<uint8_t> lst_salah; |
mauuuuul | 0:0cd00ee4dd93 | 138 | vector<uint8_t> lst_salah_hst; |
mauuuuul | 0:0cd00ee4dd93 | 139 | vector<uint8_t>::iterator it; |
mauuuuul | 0:0cd00ee4dd93 | 140 | vector<uint8_t> to_remove; |
mauuuuul | 0:0cd00ee4dd93 | 141 | |
mauuuuul | 0:0cd00ee4dd93 | 142 | string to_sends; |
mauuuuul | 0:0cd00ee4dd93 | 143 | string to_sends_cek; |
mauuuuul | 0:0cd00ee4dd93 | 144 | string salah_ambil_resultant; |
mauuuuul | 0:0cd00ee4dd93 | 145 | string salah_taruh_resultant; |
mauuuuul | 0:0cd00ee4dd93 | 146 | |
mauuuuul | 0:0cd00ee4dd93 | 147 | string ibutton_code; |
mauuuuul | 0:0cd00ee4dd93 | 148 | vector<string> split(const string str, const string separator) |
mauuuuul | 0:0cd00ee4dd93 | 149 | { |
mauuuuul | 0:0cd00ee4dd93 | 150 | char *cstr = const_cast<char*>(str.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 151 | char *current; |
mauuuuul | 0:0cd00ee4dd93 | 152 | |
mauuuuul | 0:0cd00ee4dd93 | 153 | std::vector<std::string>arr; |
mauuuuul | 0:0cd00ee4dd93 | 154 | current = strtok(cstr, separator.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 155 | while(current != NULL) { |
mauuuuul | 0:0cd00ee4dd93 | 156 | arr.push_back(current); |
mauuuuul | 0:0cd00ee4dd93 | 157 | current = strtok(NULL, separator.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 158 | } |
mauuuuul | 0:0cd00ee4dd93 | 159 | return arr; |
mauuuuul | 0:0cd00ee4dd93 | 160 | } |
mauuuuul | 0:0cd00ee4dd93 | 161 | bool waiting_resp = false; |
mauuuuul | 0:0cd00ee4dd93 | 162 | |
mauuuuul | 0:0cd00ee4dd93 | 163 | void Cek_Ibutton(); |
mauuuuul | 0:0cd00ee4dd93 | 164 | void Cek_Salah_Buzzer(); |
mauuuuul | 0:0cd00ee4dd93 | 165 | string Byte_to_StringBinary(byte data_byte); |
mauuuuul | 0:0cd00ee4dd93 | 166 | uint8_t StringBinary_to_Byte(string data_binary); |
mauuuuul | 0:0cd00ee4dd93 | 167 | uint8_t Get_Row(uint8_t key_id); |
mauuuuul | 0:0cd00ee4dd93 | 168 | unsigned short Get_CRC_Modbus(byte data_byte[]); |
mauuuuul | 0:0cd00ee4dd93 | 169 | void Send_RS485(uint8_t board,uint8_t key_id,uint8_t key_id_blinking,bool Cek_Respon); |
mauuuuul | 0:0cd00ee4dd93 | 170 | void Make_Prediction(uint8_t board_number,uint8_t baris, uint8_t kolom); |
mauuuuul | 0:0cd00ee4dd93 | 171 | void Cek_LCD_State(); |
mauuuuul | 0:0cd00ee4dd93 | 172 | |
mauuuuul | 0:0cd00ee4dd93 | 173 | string First_Update(); |
mauuuuul | 0:0cd00ee4dd93 | 174 | vector<string> temp_data; |
mauuuuul | 0:0cd00ee4dd93 | 175 | uint8_t res_cmp = 0; |
mauuuuul | 0:0cd00ee4dd93 | 176 | string bin_string_now; |
mauuuuul | 0:0cd00ee4dd93 | 177 | string bin_string_predict; |
mauuuuul | 0:0cd00ee4dd93 | 178 | uint8_t keys; |
mauuuuul | 0:0cd00ee4dd93 | 179 | bool First_Run = true; |
mauuuuul | 0:0cd00ee4dd93 | 180 | |
mauuuuul | 0:0cd00ee4dd93 | 181 | void FindingServer() |
mauuuuul | 0:0cd00ee4dd93 | 182 | { |
mauuuuul | 0:0cd00ee4dd93 | 183 | printf("Finding Server.....\r\n\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 184 | |
mauuuuul | 0:0cd00ee4dd93 | 185 | RECONNECT1: |
mauuuuul | 0:0cd00ee4dd93 | 186 | EthernetInterface net; |
mauuuuul | 0:0cd00ee4dd93 | 187 | net.set_network(IP,MASK,GATEWAY); |
mauuuuul | 0:0cd00ee4dd93 | 188 | uint8_t stat1 = net.connect(); |
mauuuuul | 0:0cd00ee4dd93 | 189 | //printf("stat1 = %d\r\n",stat1); |
mauuuuul | 0:0cd00ee4dd93 | 190 | if(stat1 != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 191 | goto RECONNECT1; |
mauuuuul | 0:0cd00ee4dd93 | 192 | } |
mauuuuul | 0:0cd00ee4dd93 | 193 | // Show the network address |
mauuuuul | 0:0cd00ee4dd93 | 194 | const char *ip = net.get_ip_address(); |
mauuuuul | 0:0cd00ee4dd93 | 195 | |
mauuuuul | 0:0cd00ee4dd93 | 196 | while(1) { |
mauuuuul | 0:0cd00ee4dd93 | 197 | RECONNECT2: |
mauuuuul | 0:0cd00ee4dd93 | 198 | // Open a socket on the network interface, and create a TCP connection to mbed.org |
mauuuuul | 0:0cd00ee4dd93 | 199 | TCPSocket socket; |
mauuuuul | 0:0cd00ee4dd93 | 200 | socket.open(&net); |
mauuuuul | 0:0cd00ee4dd93 | 201 | socket.set_blocking(false); |
mauuuuul | 0:0cd00ee4dd93 | 202 | uint8_t stat2 = socket.connect("192.168.0.89", 12345); |
mauuuuul | 0:0cd00ee4dd93 | 203 | //printf("stat2 = %d\r\n",stat2); |
mauuuuul | 0:0cd00ee4dd93 | 204 | wait(1); |
mauuuuul | 0:0cd00ee4dd93 | 205 | if(stat2 != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 206 | socket.close(); |
mauuuuul | 0:0cd00ee4dd93 | 207 | goto RECONNECT2; |
mauuuuul | 0:0cd00ee4dd93 | 208 | } |
mauuuuul | 0:0cd00ee4dd93 | 209 | |
mauuuuul | 0:0cd00ee4dd93 | 210 | isConnected = true; |
mauuuuul | 0:0cd00ee4dd93 | 211 | printf("Connected to Server....\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 212 | |
mauuuuul | 0:0cd00ee4dd93 | 213 | if(First_Run) { |
mauuuuul | 0:0cd00ee4dd93 | 214 | printf("Process Start..\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 215 | //socket.send(cmd_resets, sizeof(cmd_resets)); |
mauuuuul | 0:0cd00ee4dd93 | 216 | |
mauuuuul | 0:0cd00ee4dd93 | 217 | string data_frame = First_Update(); |
mauuuuul | 0:0cd00ee4dd93 | 218 | |
mauuuuul | 0:0cd00ee4dd93 | 219 | socket.send(data_frame.c_str(), data_frame.length()); |
mauuuuul | 0:0cd00ee4dd93 | 220 | First_Run = false; |
mauuuuul | 0:0cd00ee4dd93 | 221 | wait(0.05); |
mauuuuul | 0:0cd00ee4dd93 | 222 | dsp.step0(); |
mauuuuul | 0:0cd00ee4dd93 | 223 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 224 | if(blinking_now == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 225 | //printf("Process Start..\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 226 | //socket.send(cmd_resets, sizeof(cmd_resets)); |
mauuuuul | 0:0cd00ee4dd93 | 227 | |
mauuuuul | 0:0cd00ee4dd93 | 228 | string data_frame = First_Update(); |
mauuuuul | 0:0cd00ee4dd93 | 229 | step = 0; |
mauuuuul | 0:0cd00ee4dd93 | 230 | if(frm_data_received.ids == 3) { |
mauuuuul | 0:0cd00ee4dd93 | 231 | dsp.step4(to_string(frm_data_received._key_id).c_str(),false); |
mauuuuul | 0:0cd00ee4dd93 | 232 | } else if(frm_data_received.ids== 1) { |
mauuuuul | 0:0cd00ee4dd93 | 233 | dsp.step0(); |
mauuuuul | 0:0cd00ee4dd93 | 234 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 235 | dsp.step0(); |
mauuuuul | 0:0cd00ee4dd93 | 236 | } |
mauuuuul | 0:0cd00ee4dd93 | 237 | socket.send(data_frame.c_str(), data_frame.length()); |
mauuuuul | 0:0cd00ee4dd93 | 238 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 239 | dsp.step5(to_string(blinking_now).c_str(),true); |
mauuuuul | 0:0cd00ee4dd93 | 240 | } |
mauuuuul | 0:0cd00ee4dd93 | 241 | } |
mauuuuul | 0:0cd00ee4dd93 | 242 | |
mauuuuul | 0:0cd00ee4dd93 | 243 | //printf("%s\r\n",data_frame.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 244 | while(isConnected) { |
mauuuuul | 0:0cd00ee4dd93 | 245 | |
mauuuuul | 0:0cd00ee4dd93 | 246 | //TODO : CekData Locker Terkini |
mauuuuul | 0:0cd00ee4dd93 | 247 | |
mauuuuul | 0:0cd00ee4dd93 | 248 | switch(step) { |
mauuuuul | 0:0cd00ee4dd93 | 249 | case 0: { |
mauuuuul | 0:0cd00ee4dd93 | 250 | |
mauuuuul | 0:0cd00ee4dd93 | 251 | uint8_t res_cek = socket.send(cek_con,sizeof(cek_con)); |
mauuuuul | 0:0cd00ee4dd93 | 252 | |
mauuuuul | 0:0cd00ee4dd93 | 253 | if(res_cek <= 0) { |
mauuuuul | 0:0cd00ee4dd93 | 254 | printf("Server Has Been Closed..\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 255 | isConnected = false; |
mauuuuul | 0:0cd00ee4dd93 | 256 | socket.close(); |
mauuuuul | 0:0cd00ee4dd93 | 257 | dsp.init(); |
mauuuuul | 0:0cd00ee4dd93 | 258 | continue; |
mauuuuul | 0:0cd00ee4dd93 | 259 | } |
mauuuuul | 0:0cd00ee4dd93 | 260 | |
mauuuuul | 0:0cd00ee4dd93 | 261 | for(uint8_t i = 0; i<board_sum; i++) { |
mauuuuul | 0:0cd00ee4dd93 | 262 | wait_ms(50); |
mauuuuul | 0:0cd00ee4dd93 | 263 | //printf("%d %d %d %d %d\r\n",real_blink_id_1,real_blink_id_2,real_blink_id_3,real_blink_id_4,real_blink_id_5); |
mauuuuul | 0:0cd00ee4dd93 | 264 | if(i == 0) Send_RS485(i,64,real_blink_id_1,true); |
mauuuuul | 0:0cd00ee4dd93 | 265 | else if(i == 1) Send_RS485(i,64,real_blink_id_2,true); |
mauuuuul | 0:0cd00ee4dd93 | 266 | else if(i == 2) Send_RS485(i,64,real_blink_id_3,true); |
mauuuuul | 0:0cd00ee4dd93 | 267 | else if(i == 3) Send_RS485(i,64,real_blink_id_4,true); |
mauuuuul | 0:0cd00ee4dd93 | 268 | else if(i == 4) Send_RS485(i,64,real_blink_id_5,true); |
mauuuuul | 0:0cd00ee4dd93 | 269 | |
mauuuuul | 0:0cd00ee4dd93 | 270 | for(uint8_t a = 4; a<12; a++) { |
mauuuuul | 0:0cd00ee4dd93 | 271 | uint8_t temp_id = a; |
mauuuuul | 0:0cd00ee4dd93 | 272 | |
mauuuuul | 0:0cd00ee4dd93 | 273 | switch(i) { |
mauuuuul | 0:0cd00ee4dd93 | 274 | case 0: { |
mauuuuul | 0:0cd00ee4dd93 | 275 | Row_Board1_Now[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 276 | //printf("Resp : %02X || BoardLast %d : %02X\r\n",respon_from_slave[a],i+1,Row_Board1_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 277 | } |
mauuuuul | 0:0cd00ee4dd93 | 278 | break; |
mauuuuul | 0:0cd00ee4dd93 | 279 | case 1: { |
mauuuuul | 0:0cd00ee4dd93 | 280 | Row_Board2_Now[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 281 | //printf("Resp : %02X || BoardLast %d : %02X\r\n",respon_from_slave[a],i+1,Row_Board2_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 282 | } |
mauuuuul | 0:0cd00ee4dd93 | 283 | break; |
mauuuuul | 0:0cd00ee4dd93 | 284 | case 2: { |
mauuuuul | 0:0cd00ee4dd93 | 285 | Row_Board3_Now[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 286 | //printf("Resp : %02X || BoardLast %d : %02X\r\n",respon_from_slave[a],i+1,Row_Board3_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 287 | } |
mauuuuul | 0:0cd00ee4dd93 | 288 | break; |
mauuuuul | 0:0cd00ee4dd93 | 289 | case 3: { |
mauuuuul | 0:0cd00ee4dd93 | 290 | Row_Board4_Now[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 291 | //printf("Resp : %02X || BoardLast %d : %02X\r\n",respon_from_slave[a],i+1,Row_Board4_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 292 | } |
mauuuuul | 0:0cd00ee4dd93 | 293 | break; |
mauuuuul | 0:0cd00ee4dd93 | 294 | case 4: { |
mauuuuul | 0:0cd00ee4dd93 | 295 | Row_Board5_Now[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 296 | //printf("Resp : %02X || BoardLast %d : %02X\r\n",respon_from_slave[a],i+1,Row_Board5_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 297 | } |
mauuuuul | 0:0cd00ee4dd93 | 298 | break; |
mauuuuul | 0:0cd00ee4dd93 | 299 | } |
mauuuuul | 0:0cd00ee4dd93 | 300 | } |
mauuuuul | 0:0cd00ee4dd93 | 301 | } |
mauuuuul | 0:0cd00ee4dd93 | 302 | |
mauuuuul | 0:0cd00ee4dd93 | 303 | salah_ambil1 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 304 | salah_taruh1 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 305 | salah_ambil2 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 306 | salah_taruh2 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 307 | salah_ambil3 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 308 | salah_taruh3 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 309 | salah_ambil4 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 310 | salah_taruh4 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 311 | salah_ambil5 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 312 | salah_taruh5 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 313 | |
mauuuuul | 0:0cd00ee4dd93 | 314 | lst_salah.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 315 | to_remove.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 316 | for(uint8_t i = 0; i<board_sum; i++) { |
mauuuuul | 0:0cd00ee4dd93 | 317 | switch(i) { |
mauuuuul | 0:0cd00ee4dd93 | 318 | case 0: { |
mauuuuul | 0:0cd00ee4dd93 | 319 | res_cmp = 0; |
mauuuuul | 0:0cd00ee4dd93 | 320 | res_cmp = memcmp(Row_Board1_Now,Row_Board1_Last, sizeof(Row_Board1_Now)); |
mauuuuul | 0:0cd00ee4dd93 | 321 | if(res_cmp != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 322 | for(uint8_t j = 0; j<8; j++) { |
mauuuuul | 0:0cd00ee4dd93 | 323 | if(Row_Board1_Now[j] != Row_Board1_Last[j]) { |
mauuuuul | 0:0cd00ee4dd93 | 324 | bin_string_now = ""; |
mauuuuul | 0:0cd00ee4dd93 | 325 | bin_string_predict = ""; |
mauuuuul | 0:0cd00ee4dd93 | 326 | keys = 0; |
mauuuuul | 0:0cd00ee4dd93 | 327 | bin_string_now = Byte_to_StringBinary(Row_Board1_Now[j]); |
mauuuuul | 0:0cd00ee4dd93 | 328 | bin_string_predict = Byte_to_StringBinary(Row_Board1_Last[j]); |
mauuuuul | 0:0cd00ee4dd93 | 329 | |
mauuuuul | 0:0cd00ee4dd93 | 330 | for (uint8_t k = 0; k < 8; k++) { |
mauuuuul | 0:0cd00ee4dd93 | 331 | if(bin_string_now[abs(k-7)] != bin_string_predict[abs(k-7)]) { |
mauuuuul | 0:0cd00ee4dd93 | 332 | keys = (40*j)+k+(8*i)+1; |
mauuuuul | 0:0cd00ee4dd93 | 333 | done_1 = false; |
mauuuuul | 0:0cd00ee4dd93 | 334 | lst_salah.push_back(keys); |
mauuuuul | 0:0cd00ee4dd93 | 335 | |
mauuuuul | 0:0cd00ee4dd93 | 336 | if(bin_string_predict[abs(k-7)] == '0') { |
mauuuuul | 0:0cd00ee4dd93 | 337 | salah_taruh1 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 338 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 339 | salah_ambil1 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 340 | } |
mauuuuul | 0:0cd00ee4dd93 | 341 | } |
mauuuuul | 0:0cd00ee4dd93 | 342 | } |
mauuuuul | 0:0cd00ee4dd93 | 343 | } |
mauuuuul | 0:0cd00ee4dd93 | 344 | } |
mauuuuul | 0:0cd00ee4dd93 | 345 | } else if (res_cmp == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 346 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 347 | salah_ambil1 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 348 | salah_taruh1 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 349 | done_1 = true; |
mauuuuul | 0:0cd00ee4dd93 | 350 | |
mauuuuul | 0:0cd00ee4dd93 | 351 | //memcpy(Row_Board1_Last,Row_Board1_Now,sizeof(Row_Board1_Last)); |
mauuuuul | 0:0cd00ee4dd93 | 352 | |
mauuuuul | 0:0cd00ee4dd93 | 353 | Send_RS485(i,64,64,false); |
mauuuuul | 0:0cd00ee4dd93 | 354 | } |
mauuuuul | 0:0cd00ee4dd93 | 355 | |
mauuuuul | 0:0cd00ee4dd93 | 356 | } |
mauuuuul | 0:0cd00ee4dd93 | 357 | break; |
mauuuuul | 0:0cd00ee4dd93 | 358 | case 1: { |
mauuuuul | 0:0cd00ee4dd93 | 359 | res_cmp = 0; |
mauuuuul | 0:0cd00ee4dd93 | 360 | res_cmp = memcmp(Row_Board2_Now,Row_Board2_Last, sizeof(Row_Board2_Now)); |
mauuuuul | 0:0cd00ee4dd93 | 361 | if(res_cmp != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 362 | for(uint8_t j = 0; j<8; j++) { |
mauuuuul | 0:0cd00ee4dd93 | 363 | if(Row_Board2_Now[j] != Row_Board2_Last[j]) { |
mauuuuul | 0:0cd00ee4dd93 | 364 | bin_string_now = ""; |
mauuuuul | 0:0cd00ee4dd93 | 365 | bin_string_predict = ""; |
mauuuuul | 0:0cd00ee4dd93 | 366 | keys = 0; |
mauuuuul | 0:0cd00ee4dd93 | 367 | bin_string_now = Byte_to_StringBinary(Row_Board2_Now[j]); |
mauuuuul | 0:0cd00ee4dd93 | 368 | bin_string_predict = Byte_to_StringBinary(Row_Board2_Last[j]); |
mauuuuul | 0:0cd00ee4dd93 | 369 | |
mauuuuul | 0:0cd00ee4dd93 | 370 | for (uint8_t k = 0; k < 8; k++) { |
mauuuuul | 0:0cd00ee4dd93 | 371 | if(bin_string_now[abs(k-7)] != bin_string_predict[abs(k-7)]) { |
mauuuuul | 0:0cd00ee4dd93 | 372 | keys = (40*j)+k+(8*i)+1; |
mauuuuul | 0:0cd00ee4dd93 | 373 | lst_salah.push_back(keys); |
mauuuuul | 0:0cd00ee4dd93 | 374 | done_2 = false; |
mauuuuul | 0:0cd00ee4dd93 | 375 | |
mauuuuul | 0:0cd00ee4dd93 | 376 | if(bin_string_predict[abs(k-7)] == '0') { |
mauuuuul | 0:0cd00ee4dd93 | 377 | salah_taruh2 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 378 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 379 | salah_ambil2 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 380 | } |
mauuuuul | 0:0cd00ee4dd93 | 381 | } |
mauuuuul | 0:0cd00ee4dd93 | 382 | } |
mauuuuul | 0:0cd00ee4dd93 | 383 | } |
mauuuuul | 0:0cd00ee4dd93 | 384 | } |
mauuuuul | 0:0cd00ee4dd93 | 385 | } else if (res_cmp == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 386 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 387 | salah_ambil2 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 388 | salah_taruh2 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 389 | done_2 = true; |
mauuuuul | 0:0cd00ee4dd93 | 390 | |
mauuuuul | 0:0cd00ee4dd93 | 391 | //memcpy(Row_Board2_Last,Row_Board2_Now,sizeof(Row_Board2_Last)); |
mauuuuul | 0:0cd00ee4dd93 | 392 | |
mauuuuul | 0:0cd00ee4dd93 | 393 | Send_RS485(i,64,64,false); |
mauuuuul | 0:0cd00ee4dd93 | 394 | } |
mauuuuul | 0:0cd00ee4dd93 | 395 | } |
mauuuuul | 0:0cd00ee4dd93 | 396 | break; |
mauuuuul | 0:0cd00ee4dd93 | 397 | case 2: { |
mauuuuul | 0:0cd00ee4dd93 | 398 | res_cmp = 0; |
mauuuuul | 0:0cd00ee4dd93 | 399 | res_cmp = memcmp(Row_Board3_Now,Row_Board3_Last, sizeof(Row_Board3_Now)); |
mauuuuul | 0:0cd00ee4dd93 | 400 | if(res_cmp != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 401 | for(uint8_t j = 0; j<8; j++) { |
mauuuuul | 0:0cd00ee4dd93 | 402 | if(Row_Board3_Now[j] != Row_Board3_Last[j]) { |
mauuuuul | 0:0cd00ee4dd93 | 403 | bin_string_now = ""; |
mauuuuul | 0:0cd00ee4dd93 | 404 | bin_string_predict = ""; |
mauuuuul | 0:0cd00ee4dd93 | 405 | keys = 0; |
mauuuuul | 0:0cd00ee4dd93 | 406 | bin_string_now = Byte_to_StringBinary(Row_Board3_Now[j]); |
mauuuuul | 0:0cd00ee4dd93 | 407 | bin_string_predict = Byte_to_StringBinary(Row_Board3_Last[j]); |
mauuuuul | 0:0cd00ee4dd93 | 408 | |
mauuuuul | 0:0cd00ee4dd93 | 409 | for (uint8_t k = 0; k < 8; k++) { |
mauuuuul | 0:0cd00ee4dd93 | 410 | if(bin_string_now[abs(k-7)] != bin_string_predict[abs(k-7)]) { |
mauuuuul | 0:0cd00ee4dd93 | 411 | keys = (40*j)+k+(8*i)+1; |
mauuuuul | 0:0cd00ee4dd93 | 412 | lst_salah.push_back(keys); |
mauuuuul | 0:0cd00ee4dd93 | 413 | done_3 = false; |
mauuuuul | 0:0cd00ee4dd93 | 414 | |
mauuuuul | 0:0cd00ee4dd93 | 415 | if(bin_string_predict[abs(k-7)] == '0') { |
mauuuuul | 0:0cd00ee4dd93 | 416 | salah_taruh3 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 417 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 418 | salah_ambil3 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 419 | } |
mauuuuul | 0:0cd00ee4dd93 | 420 | } |
mauuuuul | 0:0cd00ee4dd93 | 421 | } |
mauuuuul | 0:0cd00ee4dd93 | 422 | } |
mauuuuul | 0:0cd00ee4dd93 | 423 | } |
mauuuuul | 0:0cd00ee4dd93 | 424 | } else if (res_cmp == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 425 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 426 | salah_ambil3 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 427 | salah_taruh3 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 428 | done_3 = true; |
mauuuuul | 0:0cd00ee4dd93 | 429 | |
mauuuuul | 0:0cd00ee4dd93 | 430 | //memcpy(Row_Board3_Last,Row_Board3_Now,sizeof(Row_Board3_Last)); |
mauuuuul | 0:0cd00ee4dd93 | 431 | |
mauuuuul | 0:0cd00ee4dd93 | 432 | Send_RS485(i,64,64,false); |
mauuuuul | 0:0cd00ee4dd93 | 433 | } |
mauuuuul | 0:0cd00ee4dd93 | 434 | } |
mauuuuul | 0:0cd00ee4dd93 | 435 | break; |
mauuuuul | 0:0cd00ee4dd93 | 436 | case 3: { |
mauuuuul | 0:0cd00ee4dd93 | 437 | res_cmp = 0; |
mauuuuul | 0:0cd00ee4dd93 | 438 | res_cmp = memcmp(Row_Board4_Now,Row_Board4_Last, sizeof(Row_Board4_Now)); |
mauuuuul | 0:0cd00ee4dd93 | 439 | if(res_cmp != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 440 | for(uint8_t j = 0; j<8; j++) { |
mauuuuul | 0:0cd00ee4dd93 | 441 | if(Row_Board4_Now[j] != Row_Board4_Last[j]) { |
mauuuuul | 0:0cd00ee4dd93 | 442 | bin_string_now = ""; |
mauuuuul | 0:0cd00ee4dd93 | 443 | bin_string_predict = ""; |
mauuuuul | 0:0cd00ee4dd93 | 444 | keys = 0; |
mauuuuul | 0:0cd00ee4dd93 | 445 | bin_string_now = Byte_to_StringBinary(Row_Board4_Now[j]); |
mauuuuul | 0:0cd00ee4dd93 | 446 | bin_string_predict = Byte_to_StringBinary(Row_Board4_Last[j]); |
mauuuuul | 0:0cd00ee4dd93 | 447 | |
mauuuuul | 0:0cd00ee4dd93 | 448 | for (uint8_t k = 0; k < 8; k++) { |
mauuuuul | 0:0cd00ee4dd93 | 449 | if(bin_string_now[abs(k-7)] != bin_string_predict[abs(k-7)]) { |
mauuuuul | 0:0cd00ee4dd93 | 450 | keys = (40*j)+k+(8*i)+1; |
mauuuuul | 0:0cd00ee4dd93 | 451 | lst_salah.push_back(keys); |
mauuuuul | 0:0cd00ee4dd93 | 452 | done_4 = false; |
mauuuuul | 0:0cd00ee4dd93 | 453 | |
mauuuuul | 0:0cd00ee4dd93 | 454 | if(bin_string_predict[abs(k-7)] == '0') { |
mauuuuul | 0:0cd00ee4dd93 | 455 | salah_taruh4 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 456 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 457 | salah_ambil4 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 458 | } |
mauuuuul | 0:0cd00ee4dd93 | 459 | } |
mauuuuul | 0:0cd00ee4dd93 | 460 | } |
mauuuuul | 0:0cd00ee4dd93 | 461 | } |
mauuuuul | 0:0cd00ee4dd93 | 462 | } |
mauuuuul | 0:0cd00ee4dd93 | 463 | } else if (res_cmp == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 464 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 465 | salah_ambil4 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 466 | salah_taruh4 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 467 | done_4 = true; |
mauuuuul | 0:0cd00ee4dd93 | 468 | |
mauuuuul | 0:0cd00ee4dd93 | 469 | //memcpy(Row_Board3_Last,Row_Board3_Now,sizeof(Row_Board3_Last)); |
mauuuuul | 0:0cd00ee4dd93 | 470 | |
mauuuuul | 0:0cd00ee4dd93 | 471 | Send_RS485(i,64,64,false); |
mauuuuul | 0:0cd00ee4dd93 | 472 | } |
mauuuuul | 0:0cd00ee4dd93 | 473 | } |
mauuuuul | 0:0cd00ee4dd93 | 474 | break; |
mauuuuul | 0:0cd00ee4dd93 | 475 | case 4: { |
mauuuuul | 0:0cd00ee4dd93 | 476 | res_cmp = 0; |
mauuuuul | 0:0cd00ee4dd93 | 477 | res_cmp = memcmp(Row_Board5_Now,Row_Board5_Last, sizeof(Row_Board5_Now)); |
mauuuuul | 0:0cd00ee4dd93 | 478 | if(res_cmp != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 479 | for(uint8_t j = 0; j<8; j++) { |
mauuuuul | 0:0cd00ee4dd93 | 480 | if(Row_Board5_Now[j] != Row_Board5_Last[j]) { |
mauuuuul | 0:0cd00ee4dd93 | 481 | bin_string_now = ""; |
mauuuuul | 0:0cd00ee4dd93 | 482 | bin_string_predict = ""; |
mauuuuul | 0:0cd00ee4dd93 | 483 | keys = 0; |
mauuuuul | 0:0cd00ee4dd93 | 484 | bin_string_now = Byte_to_StringBinary(Row_Board5_Now[j]); |
mauuuuul | 0:0cd00ee4dd93 | 485 | bin_string_predict = Byte_to_StringBinary(Row_Board5_Last[j]); |
mauuuuul | 0:0cd00ee4dd93 | 486 | |
mauuuuul | 0:0cd00ee4dd93 | 487 | for (uint8_t k = 0; k < 8; k++) { |
mauuuuul | 0:0cd00ee4dd93 | 488 | if(bin_string_now[abs(k-7)] != bin_string_predict[abs(k-7)]) { |
mauuuuul | 0:0cd00ee4dd93 | 489 | keys = (40*j)+k+(8*i)+1; |
mauuuuul | 0:0cd00ee4dd93 | 490 | lst_salah.push_back(keys); |
mauuuuul | 0:0cd00ee4dd93 | 491 | done_5 = false; |
mauuuuul | 0:0cd00ee4dd93 | 492 | |
mauuuuul | 0:0cd00ee4dd93 | 493 | if(bin_string_predict[abs(k-7)] == '0') { |
mauuuuul | 0:0cd00ee4dd93 | 494 | salah_taruh5 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 495 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 496 | salah_ambil5 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 497 | } |
mauuuuul | 0:0cd00ee4dd93 | 498 | } |
mauuuuul | 0:0cd00ee4dd93 | 499 | } |
mauuuuul | 0:0cd00ee4dd93 | 500 | } |
mauuuuul | 0:0cd00ee4dd93 | 501 | } |
mauuuuul | 0:0cd00ee4dd93 | 502 | } else if (res_cmp == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 503 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 504 | salah_ambil5 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 505 | salah_taruh5 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 506 | done_5 = true; |
mauuuuul | 0:0cd00ee4dd93 | 507 | |
mauuuuul | 0:0cd00ee4dd93 | 508 | //memcpy(Row_Board3_Last,Row_Board3_Now,sizeof(Row_Board3_Last)); |
mauuuuul | 0:0cd00ee4dd93 | 509 | |
mauuuuul | 0:0cd00ee4dd93 | 510 | Send_RS485(i,64,64,false); |
mauuuuul | 0:0cd00ee4dd93 | 511 | } |
mauuuuul | 0:0cd00ee4dd93 | 512 | } |
mauuuuul | 0:0cd00ee4dd93 | 513 | break; |
mauuuuul | 0:0cd00ee4dd93 | 514 | } |
mauuuuul | 0:0cd00ee4dd93 | 515 | } |
mauuuuul | 0:0cd00ee4dd93 | 516 | |
mauuuuul | 0:0cd00ee4dd93 | 517 | salah_ambil_resultant = ""; |
mauuuuul | 0:0cd00ee4dd93 | 518 | salah_taruh_resultant = ""; |
mauuuuul | 0:0cd00ee4dd93 | 519 | |
mauuuuul | 0:0cd00ee4dd93 | 520 | if(lst_salah.size() > 0) { |
mauuuuul | 0:0cd00ee4dd93 | 521 | |
mauuuuul | 0:0cd00ee4dd93 | 522 | uint8_t blink_id = 64; |
mauuuuul | 0:0cd00ee4dd93 | 523 | |
mauuuuul | 0:0cd00ee4dd93 | 524 | bool ada = false; |
mauuuuul | 0:0cd00ee4dd93 | 525 | |
mauuuuul | 0:0cd00ee4dd93 | 526 | if(lst_salah_hst.size() > 0) { |
mauuuuul | 0:0cd00ee4dd93 | 527 | |
mauuuuul | 0:0cd00ee4dd93 | 528 | printf("jumlah hst = %d\r\n",lst_salah_hst.size()); |
mauuuuul | 0:0cd00ee4dd93 | 529 | for(uint8_t q = 0; q<lst_salah_hst.size(); q++) { |
mauuuuul | 0:0cd00ee4dd93 | 530 | ada = false; |
mauuuuul | 0:0cd00ee4dd93 | 531 | printf("lst_hst_recent%d = %d\r\n",q+1,lst_salah_hst[q]); |
mauuuuul | 0:0cd00ee4dd93 | 532 | |
mauuuuul | 0:0cd00ee4dd93 | 533 | for(uint8_t r = 0; r<lst_salah.size(); r++) { |
mauuuuul | 0:0cd00ee4dd93 | 534 | if(lst_salah[r] == lst_salah_hst[q]) { |
mauuuuul | 0:0cd00ee4dd93 | 535 | ada = true; |
mauuuuul | 0:0cd00ee4dd93 | 536 | } |
mauuuuul | 0:0cd00ee4dd93 | 537 | } |
mauuuuul | 0:0cd00ee4dd93 | 538 | if(!ada) { |
mauuuuul | 0:0cd00ee4dd93 | 539 | to_remove.push_back(lst_salah_hst[q]); |
mauuuuul | 0:0cd00ee4dd93 | 540 | } |
mauuuuul | 0:0cd00ee4dd93 | 541 | } |
mauuuuul | 0:0cd00ee4dd93 | 542 | |
mauuuuul | 0:0cd00ee4dd93 | 543 | if(to_remove.size() > 0) { |
mauuuuul | 0:0cd00ee4dd93 | 544 | for(uint8_t t = 0; t<to_remove.size(); t++) { |
mauuuuul | 0:0cd00ee4dd93 | 545 | lst_salah_hst.erase(remove(lst_salah_hst.begin(), lst_salah_hst.end(), to_remove[t]), lst_salah_hst.end()); |
mauuuuul | 0:0cd00ee4dd93 | 546 | } |
mauuuuul | 0:0cd00ee4dd93 | 547 | } |
mauuuuul | 0:0cd00ee4dd93 | 548 | |
mauuuuul | 0:0cd00ee4dd93 | 549 | for(uint8_t w = 0; w<lst_salah.size(); w++) { |
mauuuuul | 0:0cd00ee4dd93 | 550 | it = find (lst_salah_hst.begin(), lst_salah_hst.end(), lst_salah[w]); |
mauuuuul | 0:0cd00ee4dd93 | 551 | if (it != lst_salah_hst.end()) { |
mauuuuul | 0:0cd00ee4dd93 | 552 | continue; |
mauuuuul | 0:0cd00ee4dd93 | 553 | } |
mauuuuul | 0:0cd00ee4dd93 | 554 | lst_salah_hst.push_back(lst_salah[w]); |
mauuuuul | 0:0cd00ee4dd93 | 555 | } |
mauuuuul | 0:0cd00ee4dd93 | 556 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 557 | for(uint8_t u = 0; u<lst_salah.size(); u++) { |
mauuuuul | 0:0cd00ee4dd93 | 558 | lst_salah_hst.push_back(lst_salah[u]); |
mauuuuul | 0:0cd00ee4dd93 | 559 | } |
mauuuuul | 0:0cd00ee4dd93 | 560 | |
mauuuuul | 0:0cd00ee4dd93 | 561 | } |
mauuuuul | 0:0cd00ee4dd93 | 562 | |
mauuuuul | 0:0cd00ee4dd93 | 563 | blink_id = lst_salah_hst[lst_salah_hst.size()-1]; |
mauuuuul | 0:0cd00ee4dd93 | 564 | |
mauuuuul | 0:0cd00ee4dd93 | 565 | uint8_t board_number_blink = (blink_id - 1)%40; |
mauuuuul | 0:0cd00ee4dd93 | 566 | |
mauuuuul | 0:0cd00ee4dd93 | 567 | if(board_number_blink>= 0 && board_number_blink<= 7)board_number_blink = 0; |
mauuuuul | 0:0cd00ee4dd93 | 568 | else if(board_number_blink>= 8 && board_number_blink<= 15)board_number_blink = 1; |
mauuuuul | 0:0cd00ee4dd93 | 569 | else if(board_number_blink>= 16 && board_number_blink<= 23)board_number_blink = 2; |
mauuuuul | 0:0cd00ee4dd93 | 570 | else if(board_number_blink>= 24 && board_number_blink<= 31)board_number_blink = 3; |
mauuuuul | 0:0cd00ee4dd93 | 571 | else if(board_number_blink>= 32 && board_number_blink<= 39)board_number_blink = 4; |
mauuuuul | 0:0cd00ee4dd93 | 572 | |
mauuuuul | 0:0cd00ee4dd93 | 573 | //printf("board_number_blink = %d\r\n",board_number_blink); |
mauuuuul | 0:0cd00ee4dd93 | 574 | |
mauuuuul | 0:0cd00ee4dd93 | 575 | uint8_t baris_blink = (blink_id - 1)/40; |
mauuuuul | 0:0cd00ee4dd93 | 576 | uint8_t kolom_blink = (blink_id - 1)%8; |
mauuuuul | 0:0cd00ee4dd93 | 577 | blink_id = board_88[baris_blink][kolom_blink]; |
mauuuuul | 0:0cd00ee4dd93 | 578 | |
mauuuuul | 0:0cd00ee4dd93 | 579 | //printf("Board blink : %d,Kolom blink : %d, Baris blink : %d\r\n",board_number_blink,kolom_blink,baris_blink); |
mauuuuul | 0:0cd00ee4dd93 | 580 | if(board_number_blink == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 581 | real_blink_id_1 = blink_id; |
mauuuuul | 0:0cd00ee4dd93 | 582 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 583 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 584 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 585 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 586 | } else if(board_number_blink == 1) { |
mauuuuul | 0:0cd00ee4dd93 | 587 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 588 | real_blink_id_2 = blink_id; |
mauuuuul | 0:0cd00ee4dd93 | 589 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 590 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 591 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 592 | } else if(board_number_blink == 2) { |
mauuuuul | 0:0cd00ee4dd93 | 593 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 594 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 595 | real_blink_id_3 = blink_id; |
mauuuuul | 0:0cd00ee4dd93 | 596 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 597 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 598 | } else if(board_number_blink == 3) { |
mauuuuul | 0:0cd00ee4dd93 | 599 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 600 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 601 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 602 | real_blink_id_4 = blink_id; |
mauuuuul | 0:0cd00ee4dd93 | 603 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 604 | } else if(board_number_blink == 4) { |
mauuuuul | 0:0cd00ee4dd93 | 605 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 606 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 607 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 608 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 609 | real_blink_id_5 = blink_id; |
mauuuuul | 0:0cd00ee4dd93 | 610 | } |
mauuuuul | 0:0cd00ee4dd93 | 611 | blinking_now = lst_salah_hst[lst_salah_hst.size()-1]; |
mauuuuul | 0:0cd00ee4dd93 | 612 | |
mauuuuul | 0:0cd00ee4dd93 | 613 | salah_ambil_resultant = salah_ambil1 + salah_ambil2 + salah_ambil3 + salah_ambil4 + salah_ambil5; |
mauuuuul | 0:0cd00ee4dd93 | 614 | salah_taruh_resultant = salah_taruh1 + salah_taruh2 + salah_taruh3 + salah_taruh4 + salah_taruh5; |
mauuuuul | 0:0cd00ee4dd93 | 615 | |
mauuuuul | 0:0cd00ee4dd93 | 616 | if(salah_ambil_resultant == "") salah_ambil_resultant = "0-"; |
mauuuuul | 0:0cd00ee4dd93 | 617 | if(salah_taruh_resultant == "") salah_taruh_resultant = "0-"; |
mauuuuul | 0:0cd00ee4dd93 | 618 | |
mauuuuul | 0:0cd00ee4dd93 | 619 | to_sends_cek = "2;"+salah_ambil_resultant + ";" +salah_taruh_resultant+";" + to_string(blinking_now) +";~"; |
mauuuuul | 0:0cd00ee4dd93 | 620 | printf("Unprosedur : %s\r\n",to_sends_cek.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 621 | |
mauuuuul | 0:0cd00ee4dd93 | 622 | if(TCP_Cek_Data_Last_Sent.find(to_sends_cek) == -1) { |
mauuuuul | 0:0cd00ee4dd93 | 623 | dsp.step5(to_string(blinking_now).c_str(),true); |
mauuuuul | 0:0cd00ee4dd93 | 624 | socket.send(to_sends_cek.c_str(), to_sends_cek.length()); |
mauuuuul | 0:0cd00ee4dd93 | 625 | |
mauuuuul | 0:0cd00ee4dd93 | 626 | TCP_Cek_Data_Last_Sent = to_sends_cek; |
mauuuuul | 0:0cd00ee4dd93 | 627 | } |
mauuuuul | 0:0cd00ee4dd93 | 628 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 629 | if(done_1 && done_2 && done_3 && done_4 && done_5) { |
mauuuuul | 0:0cd00ee4dd93 | 630 | lst_salah_hst.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 631 | blinking_now = 0; |
mauuuuul | 0:0cd00ee4dd93 | 632 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 633 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 634 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 635 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 636 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 637 | |
mauuuuul | 0:0cd00ee4dd93 | 638 | salah_ambil_resultant = "0;"; |
mauuuuul | 0:0cd00ee4dd93 | 639 | salah_taruh_resultant = "0"; |
mauuuuul | 0:0cd00ee4dd93 | 640 | |
mauuuuul | 0:0cd00ee4dd93 | 641 | step = 1; |
mauuuuul | 0:0cd00ee4dd93 | 642 | |
mauuuuul | 0:0cd00ee4dd93 | 643 | to_sends_cek = "2;0-;0-;~"; |
mauuuuul | 0:0cd00ee4dd93 | 644 | |
mauuuuul | 0:0cd00ee4dd93 | 645 | if(TCP_Cek_Data_Last_Sent.find(to_sends_cek) == -1) { |
mauuuuul | 0:0cd00ee4dd93 | 646 | if(frm_data_received.ids == 3) { |
mauuuuul | 0:0cd00ee4dd93 | 647 | dsp.step4(to_string(frm_data_received._key_id).c_str(),false); |
mauuuuul | 0:0cd00ee4dd93 | 648 | } else if(frm_data_received.ids== 1) { |
mauuuuul | 0:0cd00ee4dd93 | 649 | dsp.step0(); |
mauuuuul | 0:0cd00ee4dd93 | 650 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 651 | dsp.step0(); |
mauuuuul | 0:0cd00ee4dd93 | 652 | } |
mauuuuul | 0:0cd00ee4dd93 | 653 | //wait_ms(50); |
mauuuuul | 0:0cd00ee4dd93 | 654 | socket.send(to_sends_cek.c_str(), to_sends_cek.length()); |
mauuuuul | 0:0cd00ee4dd93 | 655 | TCP_Cek_Data_Last_Sent = to_sends_cek; |
mauuuuul | 0:0cd00ee4dd93 | 656 | } |
mauuuuul | 0:0cd00ee4dd93 | 657 | |
mauuuuul | 0:0cd00ee4dd93 | 658 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 659 | blinking_now = 0; |
mauuuuul | 0:0cd00ee4dd93 | 660 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 661 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 662 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 663 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 664 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 665 | } |
mauuuuul | 0:0cd00ee4dd93 | 666 | } |
mauuuuul | 0:0cd00ee4dd93 | 667 | } |
mauuuuul | 0:0cd00ee4dd93 | 668 | break; |
mauuuuul | 0:0cd00ee4dd93 | 669 | |
mauuuuul | 0:0cd00ee4dd93 | 670 | case 1: { |
mauuuuul | 0:0cd00ee4dd93 | 671 | char rbuffer[64]; |
mauuuuul | 0:0cd00ee4dd93 | 672 | |
mauuuuul | 0:0cd00ee4dd93 | 673 | uint8_t rcount = socket.recv(rbuffer, sizeof rbuffer); |
mauuuuul | 0:0cd00ee4dd93 | 674 | if(rcount < 0) { |
mauuuuul | 0:0cd00ee4dd93 | 675 | step = 0; |
mauuuuul | 0:0cd00ee4dd93 | 676 | } else if(rcount > 0) { |
mauuuuul | 0:0cd00ee4dd93 | 677 | rbuffer[rcount] = '\0'; |
mauuuuul | 0:0cd00ee4dd93 | 678 | |
mauuuuul | 0:0cd00ee4dd93 | 679 | string data; |
mauuuuul | 0:0cd00ee4dd93 | 680 | |
mauuuuul | 0:0cd00ee4dd93 | 681 | for(uint8_t i = 0; i<sizeof(rbuffer); i++) { |
mauuuuul | 0:0cd00ee4dd93 | 682 | if(rbuffer[i] == '\0')break; |
mauuuuul | 0:0cd00ee4dd93 | 683 | data += rbuffer[i]; |
mauuuuul | 0:0cd00ee4dd93 | 684 | } |
mauuuuul | 0:0cd00ee4dd93 | 685 | |
mauuuuul | 0:0cd00ee4dd93 | 686 | vector<string> res = split(data, "~"); |
mauuuuul | 0:0cd00ee4dd93 | 687 | |
mauuuuul | 0:0cd00ee4dd93 | 688 | if(sizeof(res) != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 689 | temp_data = split(res[0], ";"); |
mauuuuul | 0:0cd00ee4dd93 | 690 | |
mauuuuul | 0:0cd00ee4dd93 | 691 | if(temp_data[0] == "3" && temp_data[1] == "1") { |
mauuuuul | 0:0cd00ee4dd93 | 692 | dsp.step4(to_string(frm_data_received._key_id).c_str(),false); |
mauuuuul | 0:0cd00ee4dd93 | 693 | } else if(temp_data[0] == "3" && temp_data[1] == "0") { |
mauuuuul | 0:0cd00ee4dd93 | 694 | dsp.step0(); |
mauuuuul | 0:0cd00ee4dd93 | 695 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 696 | frm_data_received.ids = atoi(temp_data[0].c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 697 | frm_data_received.ibutton = temp_data[1]; |
mauuuuul | 0:0cd00ee4dd93 | 698 | frm_data_received._key_id = atoi(temp_data[2].c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 699 | frm_data_received.cmd_id = atoi(temp_data[3].c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 700 | |
mauuuuul | 0:0cd00ee4dd93 | 701 | |
mauuuuul | 0:0cd00ee4dd93 | 702 | printf("id = %d\r\n",frm_data_received.ids); |
mauuuuul | 0:0cd00ee4dd93 | 703 | printf("ibutton = %s\r\n",frm_data_received.ibutton.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 704 | printf("keys = %d\r\n",frm_data_received._key_id); |
mauuuuul | 0:0cd00ee4dd93 | 705 | printf("cmd = %d\r\n",frm_data_received.cmd_id); |
mauuuuul | 0:0cd00ee4dd93 | 706 | |
mauuuuul | 0:0cd00ee4dd93 | 707 | if(frm_data_received.ids== 1) { |
mauuuuul | 0:0cd00ee4dd93 | 708 | wait(1); |
mauuuuul | 0:0cd00ee4dd93 | 709 | dsp.step1(true); |
mauuuuul | 0:0cd00ee4dd93 | 710 | step = 2; |
mauuuuul | 0:0cd00ee4dd93 | 711 | } else if(frm_data_received.ids == 3) { |
mauuuuul | 0:0cd00ee4dd93 | 712 | step = 3; |
mauuuuul | 0:0cd00ee4dd93 | 713 | |
mauuuuul | 0:0cd00ee4dd93 | 714 | //dsp.step4(to_string(frm_data_received._key_id).c_str(),true); |
mauuuuul | 0:0cd00ee4dd93 | 715 | } |
mauuuuul | 0:0cd00ee4dd93 | 716 | } |
mauuuuul | 0:0cd00ee4dd93 | 717 | } |
mauuuuul | 0:0cd00ee4dd93 | 718 | } else if(rcount == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 719 | printf("Server Has Been Closed..\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 720 | |
mauuuuul | 0:0cd00ee4dd93 | 721 | isConnected = false; |
mauuuuul | 0:0cd00ee4dd93 | 722 | step = 0;// |
mauuuuul | 0:0cd00ee4dd93 | 723 | // blinking_now = 0; |
mauuuuul | 0:0cd00ee4dd93 | 724 | // real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 725 | // real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 726 | // real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 727 | // real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 728 | // real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 729 | dsp.init(); |
mauuuuul | 0:0cd00ee4dd93 | 730 | socket.close(); |
mauuuuul | 0:0cd00ee4dd93 | 731 | } |
mauuuuul | 0:0cd00ee4dd93 | 732 | |
mauuuuul | 0:0cd00ee4dd93 | 733 | if(ibutton_code != "") { |
mauuuuul | 0:0cd00ee4dd93 | 734 | string data_to_send = "3;" + ibutton_code + ";~"; |
mauuuuul | 0:0cd00ee4dd93 | 735 | printf("%s\r\n",data_to_send.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 736 | wait(1); |
mauuuuul | 0:0cd00ee4dd93 | 737 | |
mauuuuul | 0:0cd00ee4dd93 | 738 | socket.send(data_to_send.c_str(), data_to_send.length()); |
mauuuuul | 0:0cd00ee4dd93 | 739 | TCP_Ibutton_Last_Sent = data_to_send; |
mauuuuul | 0:0cd00ee4dd93 | 740 | printf("Send ibutton\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 741 | |
mauuuuul | 0:0cd00ee4dd93 | 742 | ibutton_code.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 743 | } |
mauuuuul | 0:0cd00ee4dd93 | 744 | } |
mauuuuul | 0:0cd00ee4dd93 | 745 | break; |
mauuuuul | 0:0cd00ee4dd93 | 746 | |
mauuuuul | 0:0cd00ee4dd93 | 747 | case 2: { |
mauuuuul | 0:0cd00ee4dd93 | 748 | buzz.play(1); |
mauuuuul | 0:0cd00ee4dd93 | 749 | bool restart = false; |
mauuuuul | 0:0cd00ee4dd93 | 750 | while(frm_data_received.ibutton.c_str() != ibutton_code) { |
mauuuuul | 0:0cd00ee4dd93 | 751 | uint8_t res_cek = socket.send(cek_con,sizeof(cek_con)); |
mauuuuul | 0:0cd00ee4dd93 | 752 | |
mauuuuul | 0:0cd00ee4dd93 | 753 | if(res_cek <= 0) { |
mauuuuul | 0:0cd00ee4dd93 | 754 | printf("Server Has Been Closed..\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 755 | isConnected = false; |
mauuuuul | 0:0cd00ee4dd93 | 756 | socket.close(); |
mauuuuul | 0:0cd00ee4dd93 | 757 | dsp.init(); |
mauuuuul | 0:0cd00ee4dd93 | 758 | restart = true; |
mauuuuul | 0:0cd00ee4dd93 | 759 | break; |
mauuuuul | 0:0cd00ee4dd93 | 760 | } |
mauuuuul | 0:0cd00ee4dd93 | 761 | wait(0.05); |
mauuuuul | 0:0cd00ee4dd93 | 762 | } |
mauuuuul | 0:0cd00ee4dd93 | 763 | if(restart) { |
mauuuuul | 0:0cd00ee4dd93 | 764 | continue; |
mauuuuul | 0:0cd00ee4dd93 | 765 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 766 | ibutton_code.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 767 | printf("IButton verified\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 768 | dsp.step2(to_string(frm_data_received._key_id).c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 769 | step = 3; |
mauuuuul | 0:0cd00ee4dd93 | 770 | |
mauuuuul | 0:0cd00ee4dd93 | 771 | } |
mauuuuul | 0:0cd00ee4dd93 | 772 | } |
mauuuuul | 0:0cd00ee4dd93 | 773 | break; |
mauuuuul | 0:0cd00ee4dd93 | 774 | |
mauuuuul | 0:0cd00ee4dd93 | 775 | case 3: { |
mauuuuul | 0:0cd00ee4dd93 | 776 | uint8_t res_cek = socket.send(cek_con,sizeof(cek_con)); |
mauuuuul | 0:0cd00ee4dd93 | 777 | |
mauuuuul | 0:0cd00ee4dd93 | 778 | if(res_cek <= 0) { |
mauuuuul | 0:0cd00ee4dd93 | 779 | printf("Server Has Been Closed..\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 780 | isConnected = false; |
mauuuuul | 0:0cd00ee4dd93 | 781 | socket.close(); |
mauuuuul | 0:0cd00ee4dd93 | 782 | dsp.init(); |
mauuuuul | 0:0cd00ee4dd93 | 783 | continue; |
mauuuuul | 0:0cd00ee4dd93 | 784 | } |
mauuuuul | 0:0cd00ee4dd93 | 785 | |
mauuuuul | 0:0cd00ee4dd93 | 786 | buzz.play(1); |
mauuuuul | 0:0cd00ee4dd93 | 787 | |
mauuuuul | 0:0cd00ee4dd93 | 788 | board_number = (frm_data_received._key_id - 1)%40; |
mauuuuul | 0:0cd00ee4dd93 | 789 | |
mauuuuul | 0:0cd00ee4dd93 | 790 | if(board_number>= 0 && board_number<= 7)board_number = 0; |
mauuuuul | 0:0cd00ee4dd93 | 791 | if(board_number>= 8 && board_number<= 15)board_number = 1; |
mauuuuul | 0:0cd00ee4dd93 | 792 | if(board_number>= 16 && board_number<= 23)board_number = 2; |
mauuuuul | 0:0cd00ee4dd93 | 793 | if(board_number>= 24 && board_number<= 31)board_number = 3; |
mauuuuul | 0:0cd00ee4dd93 | 794 | if(board_number>= 32 && board_number<= 39)board_number = 4; |
mauuuuul | 0:0cd00ee4dd93 | 795 | printf("KEY[board] = %d\r\n",board_number); |
mauuuuul | 0:0cd00ee4dd93 | 796 | baris = (frm_data_received._key_id - 1)/40; |
mauuuuul | 0:0cd00ee4dd93 | 797 | printf("KEY[baris] = %d\r\n",baris); |
mauuuuul | 0:0cd00ee4dd93 | 798 | kolom = (frm_data_received._key_id - 1)%8; |
mauuuuul | 0:0cd00ee4dd93 | 799 | printf("KEY[kolom] = %d\r\n",kolom); |
mauuuuul | 0:0cd00ee4dd93 | 800 | |
mauuuuul | 0:0cd00ee4dd93 | 801 | real_id = board_88[baris][kolom]; |
mauuuuul | 0:0cd00ee4dd93 | 802 | printf("Real Id = %d\r\n",real_id); |
mauuuuul | 0:0cd00ee4dd93 | 803 | |
mauuuuul | 0:0cd00ee4dd93 | 804 | Make_Prediction(board_number,baris,kolom); |
mauuuuul | 0:0cd00ee4dd93 | 805 | |
mauuuuul | 0:0cd00ee4dd93 | 806 | step = 4; |
mauuuuul | 0:0cd00ee4dd93 | 807 | |
mauuuuul | 0:0cd00ee4dd93 | 808 | } |
mauuuuul | 0:0cd00ee4dd93 | 809 | break; |
mauuuuul | 0:0cd00ee4dd93 | 810 | |
mauuuuul | 0:0cd00ee4dd93 | 811 | case 4: { |
mauuuuul | 0:0cd00ee4dd93 | 812 | uint8_t res_cek = socket.send(cek_con,sizeof(cek_con)); |
mauuuuul | 0:0cd00ee4dd93 | 813 | |
mauuuuul | 0:0cd00ee4dd93 | 814 | if(res_cek <= 0) { |
mauuuuul | 0:0cd00ee4dd93 | 815 | LCD_Step_4 = 0; |
mauuuuul | 0:0cd00ee4dd93 | 816 | printf("Server Has Been Closed..\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 817 | isConnected = false; |
mauuuuul | 0:0cd00ee4dd93 | 818 | socket.close(); |
mauuuuul | 0:0cd00ee4dd93 | 819 | dsp.init(); |
mauuuuul | 0:0cd00ee4dd93 | 820 | continue; |
mauuuuul | 0:0cd00ee4dd93 | 821 | } |
mauuuuul | 0:0cd00ee4dd93 | 822 | |
mauuuuul | 0:0cd00ee4dd93 | 823 | for(uint8_t i = 0; i<board_sum; i++) { |
mauuuuul | 0:0cd00ee4dd93 | 824 | wait_ms(100); |
mauuuuul | 0:0cd00ee4dd93 | 825 | if(board_number == i) { |
mauuuuul | 0:0cd00ee4dd93 | 826 | if(i == 0) Send_RS485(i,real_id,real_blink_id_1,true); |
mauuuuul | 0:0cd00ee4dd93 | 827 | else if(i == 1) Send_RS485(i,real_id,real_blink_id_2,true); |
mauuuuul | 0:0cd00ee4dd93 | 828 | else if(i == 2) Send_RS485(i,real_id,real_blink_id_3,true); |
mauuuuul | 0:0cd00ee4dd93 | 829 | else if(i == 3) Send_RS485(i,real_id,real_blink_id_4,true); |
mauuuuul | 0:0cd00ee4dd93 | 830 | else if(i == 4) Send_RS485(i,real_id,real_blink_id_5,true); |
mauuuuul | 0:0cd00ee4dd93 | 831 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 832 | if(i == 0) Send_RS485(i,64,real_blink_id_1,true); |
mauuuuul | 0:0cd00ee4dd93 | 833 | else if(i == 1) Send_RS485(i,64,real_blink_id_2,true); |
mauuuuul | 0:0cd00ee4dd93 | 834 | else if(i == 2) Send_RS485(i,64,real_blink_id_3,true); |
mauuuuul | 0:0cd00ee4dd93 | 835 | else if(i == 3) Send_RS485(i,64,real_blink_id_4,true); |
mauuuuul | 0:0cd00ee4dd93 | 836 | else if(i == 4) Send_RS485(i,64,real_blink_id_5,true); |
mauuuuul | 0:0cd00ee4dd93 | 837 | } |
mauuuuul | 0:0cd00ee4dd93 | 838 | |
mauuuuul | 0:0cd00ee4dd93 | 839 | printf("Data has been received successfully\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 840 | for(uint8_t a = 4; a<12; a++) { |
mauuuuul | 0:0cd00ee4dd93 | 841 | uint8_t temp_id = a; |
mauuuuul | 0:0cd00ee4dd93 | 842 | |
mauuuuul | 0:0cd00ee4dd93 | 843 | switch(i) { |
mauuuuul | 0:0cd00ee4dd93 | 844 | case 0: { |
mauuuuul | 0:0cd00ee4dd93 | 845 | Row_Board1_Now[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 846 | } |
mauuuuul | 0:0cd00ee4dd93 | 847 | break; |
mauuuuul | 0:0cd00ee4dd93 | 848 | case 1: { |
mauuuuul | 0:0cd00ee4dd93 | 849 | Row_Board2_Now[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 850 | //printf("Resp : %02X || BoardLast %d : %02X\r\n",respon_from_slave[a],i+1,Row_Board2_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 851 | } |
mauuuuul | 0:0cd00ee4dd93 | 852 | break; |
mauuuuul | 0:0cd00ee4dd93 | 853 | case 2: { |
mauuuuul | 0:0cd00ee4dd93 | 854 | Row_Board3_Now[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 855 | //printf("Resp : %02X || BoardLast %d : %02X\r\n",respon_from_slave[a],i+1,Row_Board3_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 856 | } |
mauuuuul | 0:0cd00ee4dd93 | 857 | break; |
mauuuuul | 0:0cd00ee4dd93 | 858 | case 3: { |
mauuuuul | 0:0cd00ee4dd93 | 859 | Row_Board4_Now[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 860 | //printf("Resp : %02X || BoardLast %d : %02X\r\n",respon_from_slave[a],i+1,Row_Board4_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 861 | } |
mauuuuul | 0:0cd00ee4dd93 | 862 | break; |
mauuuuul | 0:0cd00ee4dd93 | 863 | case 4: { |
mauuuuul | 0:0cd00ee4dd93 | 864 | Row_Board5_Now[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 865 | //printf("Resp : %02X || BoardLast %d : %02X\r\n",respon_from_slave[a],i+1,Row_Board5_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 866 | } |
mauuuuul | 0:0cd00ee4dd93 | 867 | break; |
mauuuuul | 0:0cd00ee4dd93 | 868 | } |
mauuuuul | 0:0cd00ee4dd93 | 869 | } |
mauuuuul | 0:0cd00ee4dd93 | 870 | } |
mauuuuul | 0:0cd00ee4dd93 | 871 | |
mauuuuul | 0:0cd00ee4dd93 | 872 | salah_ambil1 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 873 | salah_taruh1 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 874 | salah_ambil2 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 875 | salah_taruh2 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 876 | salah_ambil3 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 877 | salah_taruh3 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 878 | salah_ambil4 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 879 | salah_taruh4 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 880 | salah_ambil5 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 881 | salah_taruh5 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 882 | |
mauuuuul | 0:0cd00ee4dd93 | 883 | lst_salah.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 884 | |
mauuuuul | 0:0cd00ee4dd93 | 885 | for(uint8_t i = 0; i<board_sum; i++) { |
mauuuuul | 0:0cd00ee4dd93 | 886 | switch(i) { |
mauuuuul | 0:0cd00ee4dd93 | 887 | case 0: { |
mauuuuul | 0:0cd00ee4dd93 | 888 | string salah_1; |
mauuuuul | 0:0cd00ee4dd93 | 889 | res_cmp = 0; |
mauuuuul | 0:0cd00ee4dd93 | 890 | res_cmp = memcmp(Row_Board1_Now,Row_Board1_Predict, sizeof(Row_Board1_Now)); |
mauuuuul | 0:0cd00ee4dd93 | 891 | if(res_cmp != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 892 | for(uint8_t j = 0; j<8; j++) { |
mauuuuul | 0:0cd00ee4dd93 | 893 | if(Row_Board1_Now[j] != Row_Board1_Predict[j]) { |
mauuuuul | 0:0cd00ee4dd93 | 894 | bin_string_now = ""; |
mauuuuul | 0:0cd00ee4dd93 | 895 | bin_string_predict = ""; |
mauuuuul | 0:0cd00ee4dd93 | 896 | keys = 0; |
mauuuuul | 0:0cd00ee4dd93 | 897 | bin_string_now = Byte_to_StringBinary(Row_Board1_Now[j]); |
mauuuuul | 0:0cd00ee4dd93 | 898 | bin_string_predict = Byte_to_StringBinary(Row_Board1_Predict[j]); |
mauuuuul | 0:0cd00ee4dd93 | 899 | |
mauuuuul | 0:0cd00ee4dd93 | 900 | for (uint8_t k = 0; k < 8; k++) { |
mauuuuul | 0:0cd00ee4dd93 | 901 | if(bin_string_now[abs(k-7)] != bin_string_predict[abs(k-7)]) { |
mauuuuul | 0:0cd00ee4dd93 | 902 | keys = (40*j)+k+(8*i)+1; |
mauuuuul | 0:0cd00ee4dd93 | 903 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 904 | lst_salah.push_back(keys); |
mauuuuul | 0:0cd00ee4dd93 | 905 | salah_1 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 906 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 907 | done_1 = false; |
mauuuuul | 0:0cd00ee4dd93 | 908 | } |
mauuuuul | 0:0cd00ee4dd93 | 909 | |
mauuuuul | 0:0cd00ee4dd93 | 910 | if(bin_string_predict[abs(k-7)] == '0') { |
mauuuuul | 0:0cd00ee4dd93 | 911 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 912 | salah_taruh1 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 913 | } |
mauuuuul | 0:0cd00ee4dd93 | 914 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 915 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 916 | salah_ambil1 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 917 | |
mauuuuul | 0:0cd00ee4dd93 | 918 | } |
mauuuuul | 0:0cd00ee4dd93 | 919 | } |
mauuuuul | 0:0cd00ee4dd93 | 920 | } |
mauuuuul | 0:0cd00ee4dd93 | 921 | } |
mauuuuul | 0:0cd00ee4dd93 | 922 | } |
mauuuuul | 0:0cd00ee4dd93 | 923 | } |
mauuuuul | 0:0cd00ee4dd93 | 924 | printf("Salah_Board%d = %s\r\n",i+1,salah_1.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 925 | } else if (res_cmp == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 926 | printf("Board %d Match\r\n",i+1); |
mauuuuul | 0:0cd00ee4dd93 | 927 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 928 | salah_ambil1 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 929 | salah_taruh1 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 930 | done_1 = true; |
mauuuuul | 0:0cd00ee4dd93 | 931 | |
mauuuuul | 0:0cd00ee4dd93 | 932 | memcpy(Row_Board1_Last,Row_Board1_Now,sizeof(Row_Board1_Last)); |
mauuuuul | 0:0cd00ee4dd93 | 933 | |
mauuuuul | 0:0cd00ee4dd93 | 934 | Send_RS485(i,64,64,false); |
mauuuuul | 0:0cd00ee4dd93 | 935 | } |
mauuuuul | 0:0cd00ee4dd93 | 936 | |
mauuuuul | 0:0cd00ee4dd93 | 937 | } |
mauuuuul | 0:0cd00ee4dd93 | 938 | break; |
mauuuuul | 0:0cd00ee4dd93 | 939 | case 1: { |
mauuuuul | 0:0cd00ee4dd93 | 940 | string salah_2; |
mauuuuul | 0:0cd00ee4dd93 | 941 | res_cmp = 0; |
mauuuuul | 0:0cd00ee4dd93 | 942 | res_cmp = memcmp(Row_Board2_Now,Row_Board2_Predict, sizeof(Row_Board2_Now)); |
mauuuuul | 0:0cd00ee4dd93 | 943 | if(res_cmp != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 944 | for(uint8_t j = 0; j<8; j++) { |
mauuuuul | 0:0cd00ee4dd93 | 945 | if(Row_Board2_Now[j] != Row_Board2_Predict[j]) { |
mauuuuul | 0:0cd00ee4dd93 | 946 | bin_string_now = ""; |
mauuuuul | 0:0cd00ee4dd93 | 947 | bin_string_predict = ""; |
mauuuuul | 0:0cd00ee4dd93 | 948 | keys = 0; |
mauuuuul | 0:0cd00ee4dd93 | 949 | bin_string_now = Byte_to_StringBinary(Row_Board2_Now[j]); |
mauuuuul | 0:0cd00ee4dd93 | 950 | bin_string_predict = Byte_to_StringBinary(Row_Board2_Predict[j]); |
mauuuuul | 0:0cd00ee4dd93 | 951 | |
mauuuuul | 0:0cd00ee4dd93 | 952 | for (uint8_t k = 0; k < 8; k++) { |
mauuuuul | 0:0cd00ee4dd93 | 953 | if(bin_string_now[abs(k-7)] != bin_string_predict[abs(k-7)]) { |
mauuuuul | 0:0cd00ee4dd93 | 954 | keys = (40*j)+k+(8*i)+1; |
mauuuuul | 0:0cd00ee4dd93 | 955 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 956 | lst_salah.push_back(keys); |
mauuuuul | 0:0cd00ee4dd93 | 957 | salah_2 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 958 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 959 | done_2 = false; |
mauuuuul | 0:0cd00ee4dd93 | 960 | } |
mauuuuul | 0:0cd00ee4dd93 | 961 | |
mauuuuul | 0:0cd00ee4dd93 | 962 | if(bin_string_predict[abs(k-7)] == '0') { |
mauuuuul | 0:0cd00ee4dd93 | 963 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 964 | salah_taruh2 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 965 | } |
mauuuuul | 0:0cd00ee4dd93 | 966 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 967 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 968 | salah_ambil2 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 969 | } |
mauuuuul | 0:0cd00ee4dd93 | 970 | } |
mauuuuul | 0:0cd00ee4dd93 | 971 | } |
mauuuuul | 0:0cd00ee4dd93 | 972 | } |
mauuuuul | 0:0cd00ee4dd93 | 973 | } |
mauuuuul | 0:0cd00ee4dd93 | 974 | } |
mauuuuul | 0:0cd00ee4dd93 | 975 | printf("Salah_Board%d = %s\r\n",i+1,salah_2.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 976 | } else if (res_cmp == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 977 | printf("Board %d Match\r\n",i+1); |
mauuuuul | 0:0cd00ee4dd93 | 978 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 979 | salah_ambil2 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 980 | salah_taruh2 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 981 | done_2 = true; |
mauuuuul | 0:0cd00ee4dd93 | 982 | |
mauuuuul | 0:0cd00ee4dd93 | 983 | memcpy(Row_Board2_Last,Row_Board2_Now,sizeof(Row_Board2_Last)); |
mauuuuul | 0:0cd00ee4dd93 | 984 | |
mauuuuul | 0:0cd00ee4dd93 | 985 | Send_RS485(i,64,64,false); |
mauuuuul | 0:0cd00ee4dd93 | 986 | } |
mauuuuul | 0:0cd00ee4dd93 | 987 | } |
mauuuuul | 0:0cd00ee4dd93 | 988 | break; |
mauuuuul | 0:0cd00ee4dd93 | 989 | case 2: { |
mauuuuul | 0:0cd00ee4dd93 | 990 | string salah_3; |
mauuuuul | 0:0cd00ee4dd93 | 991 | res_cmp = 0; |
mauuuuul | 0:0cd00ee4dd93 | 992 | res_cmp = memcmp(Row_Board3_Now,Row_Board3_Predict, sizeof(Row_Board3_Now)); |
mauuuuul | 0:0cd00ee4dd93 | 993 | if(res_cmp != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 994 | for(uint8_t j = 0; j<8; j++) { |
mauuuuul | 0:0cd00ee4dd93 | 995 | if(Row_Board3_Now[j] != Row_Board3_Predict[j]) { |
mauuuuul | 0:0cd00ee4dd93 | 996 | bin_string_now = ""; |
mauuuuul | 0:0cd00ee4dd93 | 997 | bin_string_predict = ""; |
mauuuuul | 0:0cd00ee4dd93 | 998 | keys = 0; |
mauuuuul | 0:0cd00ee4dd93 | 999 | bin_string_now = Byte_to_StringBinary(Row_Board3_Now[j]); |
mauuuuul | 0:0cd00ee4dd93 | 1000 | bin_string_predict = Byte_to_StringBinary(Row_Board3_Predict[j]); |
mauuuuul | 0:0cd00ee4dd93 | 1001 | |
mauuuuul | 0:0cd00ee4dd93 | 1002 | for (uint8_t k = 0; k < 8; k++) { |
mauuuuul | 0:0cd00ee4dd93 | 1003 | if(bin_string_now[abs(k-7)] != bin_string_predict[abs(k-7)]) { |
mauuuuul | 0:0cd00ee4dd93 | 1004 | keys = (40*j)+k+(8*i)+1; |
mauuuuul | 0:0cd00ee4dd93 | 1005 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 1006 | lst_salah.push_back(keys); |
mauuuuul | 0:0cd00ee4dd93 | 1007 | salah_3 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 1008 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 1009 | done_3 = false; |
mauuuuul | 0:0cd00ee4dd93 | 1010 | } |
mauuuuul | 0:0cd00ee4dd93 | 1011 | |
mauuuuul | 0:0cd00ee4dd93 | 1012 | if(bin_string_predict[abs(k-7)] == '0') { |
mauuuuul | 0:0cd00ee4dd93 | 1013 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 1014 | salah_taruh3 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 1015 | } |
mauuuuul | 0:0cd00ee4dd93 | 1016 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 1017 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 1018 | salah_ambil3 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 1019 | } |
mauuuuul | 0:0cd00ee4dd93 | 1020 | } |
mauuuuul | 0:0cd00ee4dd93 | 1021 | } |
mauuuuul | 0:0cd00ee4dd93 | 1022 | } |
mauuuuul | 0:0cd00ee4dd93 | 1023 | } |
mauuuuul | 0:0cd00ee4dd93 | 1024 | } |
mauuuuul | 0:0cd00ee4dd93 | 1025 | printf("Salah_Board%d = %s\r\n",i+1,salah_3.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1026 | } else if (res_cmp == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1027 | printf("Board %d Match\r\n",i+1); |
mauuuuul | 0:0cd00ee4dd93 | 1028 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1029 | salah_ambil3 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1030 | salah_taruh3 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1031 | done_3 = true; |
mauuuuul | 0:0cd00ee4dd93 | 1032 | |
mauuuuul | 0:0cd00ee4dd93 | 1033 | memcpy(Row_Board3_Last,Row_Board3_Now,sizeof(Row_Board3_Last)); |
mauuuuul | 0:0cd00ee4dd93 | 1034 | |
mauuuuul | 0:0cd00ee4dd93 | 1035 | Send_RS485(i,64,64,false); |
mauuuuul | 0:0cd00ee4dd93 | 1036 | } |
mauuuuul | 0:0cd00ee4dd93 | 1037 | } |
mauuuuul | 0:0cd00ee4dd93 | 1038 | break; |
mauuuuul | 0:0cd00ee4dd93 | 1039 | case 3: { |
mauuuuul | 0:0cd00ee4dd93 | 1040 | string salah_4; |
mauuuuul | 0:0cd00ee4dd93 | 1041 | res_cmp = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1042 | res_cmp = memcmp(Row_Board4_Now,Row_Board4_Predict, sizeof(Row_Board4_Now)); |
mauuuuul | 0:0cd00ee4dd93 | 1043 | if(res_cmp != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1044 | for(uint8_t j = 0; j<8; j++) { |
mauuuuul | 0:0cd00ee4dd93 | 1045 | if(Row_Board1_Now[j] != Row_Board4_Predict[j]) { |
mauuuuul | 0:0cd00ee4dd93 | 1046 | bin_string_now = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1047 | bin_string_predict = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1048 | keys = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1049 | bin_string_now = Byte_to_StringBinary(Row_Board4_Now[j]); |
mauuuuul | 0:0cd00ee4dd93 | 1050 | bin_string_predict = Byte_to_StringBinary(Row_Board4_Predict[j]); |
mauuuuul | 0:0cd00ee4dd93 | 1051 | |
mauuuuul | 0:0cd00ee4dd93 | 1052 | for (uint8_t k = 0; k < 8; k++) { |
mauuuuul | 0:0cd00ee4dd93 | 1053 | if(bin_string_now[abs(k-7)] != bin_string_predict[abs(k-7)]) { |
mauuuuul | 0:0cd00ee4dd93 | 1054 | keys = (40*j)+k+(8*i)+1; |
mauuuuul | 0:0cd00ee4dd93 | 1055 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 1056 | lst_salah.push_back(keys); |
mauuuuul | 0:0cd00ee4dd93 | 1057 | salah_4 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 1058 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 1059 | done_4 = false; |
mauuuuul | 0:0cd00ee4dd93 | 1060 | } |
mauuuuul | 0:0cd00ee4dd93 | 1061 | |
mauuuuul | 0:0cd00ee4dd93 | 1062 | if(bin_string_predict[abs(k-7)] == '0') { |
mauuuuul | 0:0cd00ee4dd93 | 1063 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 1064 | salah_taruh4 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 1065 | } |
mauuuuul | 0:0cd00ee4dd93 | 1066 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 1067 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 1068 | salah_ambil4 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 1069 | |
mauuuuul | 0:0cd00ee4dd93 | 1070 | } |
mauuuuul | 0:0cd00ee4dd93 | 1071 | } |
mauuuuul | 0:0cd00ee4dd93 | 1072 | } |
mauuuuul | 0:0cd00ee4dd93 | 1073 | } |
mauuuuul | 0:0cd00ee4dd93 | 1074 | } |
mauuuuul | 0:0cd00ee4dd93 | 1075 | } |
mauuuuul | 0:0cd00ee4dd93 | 1076 | printf("Salah_Board%d = %s\r\n",i+1,salah_4.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1077 | } else if (res_cmp == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1078 | printf("Board %d Match\r\n",i+1); |
mauuuuul | 0:0cd00ee4dd93 | 1079 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1080 | salah_ambil4 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1081 | salah_taruh4 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1082 | done_4 = true; |
mauuuuul | 0:0cd00ee4dd93 | 1083 | |
mauuuuul | 0:0cd00ee4dd93 | 1084 | memcpy(Row_Board4_Last,Row_Board4_Now,sizeof(Row_Board4_Last)); |
mauuuuul | 0:0cd00ee4dd93 | 1085 | |
mauuuuul | 0:0cd00ee4dd93 | 1086 | Send_RS485(i,64,64,false); |
mauuuuul | 0:0cd00ee4dd93 | 1087 | } |
mauuuuul | 0:0cd00ee4dd93 | 1088 | } |
mauuuuul | 0:0cd00ee4dd93 | 1089 | break; |
mauuuuul | 0:0cd00ee4dd93 | 1090 | case 4: { |
mauuuuul | 0:0cd00ee4dd93 | 1091 | string salah_5; |
mauuuuul | 0:0cd00ee4dd93 | 1092 | res_cmp = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1093 | res_cmp = memcmp(Row_Board5_Now,Row_Board5_Predict, sizeof(Row_Board5_Now)); |
mauuuuul | 0:0cd00ee4dd93 | 1094 | if(res_cmp != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1095 | for(uint8_t j = 0; j<8; j++) { |
mauuuuul | 0:0cd00ee4dd93 | 1096 | if(Row_Board1_Now[j] != Row_Board5_Predict[j]) { |
mauuuuul | 0:0cd00ee4dd93 | 1097 | bin_string_now = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1098 | bin_string_predict = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1099 | keys = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1100 | bin_string_now = Byte_to_StringBinary(Row_Board5_Now[j]); |
mauuuuul | 0:0cd00ee4dd93 | 1101 | bin_string_predict = Byte_to_StringBinary(Row_Board5_Predict[j]); |
mauuuuul | 0:0cd00ee4dd93 | 1102 | |
mauuuuul | 0:0cd00ee4dd93 | 1103 | for (uint8_t k = 0; k < 8; k++) { |
mauuuuul | 0:0cd00ee4dd93 | 1104 | if(bin_string_now[abs(k-7)] != bin_string_predict[abs(k-7)]) { |
mauuuuul | 0:0cd00ee4dd93 | 1105 | keys = (40*j)+k+(8*i)+1; |
mauuuuul | 0:0cd00ee4dd93 | 1106 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 1107 | lst_salah.push_back(keys); |
mauuuuul | 0:0cd00ee4dd93 | 1108 | salah_5 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 1109 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 1110 | done_5 = false; |
mauuuuul | 0:0cd00ee4dd93 | 1111 | } |
mauuuuul | 0:0cd00ee4dd93 | 1112 | |
mauuuuul | 0:0cd00ee4dd93 | 1113 | if(bin_string_predict[abs(k-7)] == '0') { |
mauuuuul | 0:0cd00ee4dd93 | 1114 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 1115 | salah_taruh5 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 1116 | } |
mauuuuul | 0:0cd00ee4dd93 | 1117 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 1118 | if(keys != frm_data_received._key_id) { |
mauuuuul | 0:0cd00ee4dd93 | 1119 | salah_ambil5 += to_string(keys)+"-"; |
mauuuuul | 0:0cd00ee4dd93 | 1120 | } |
mauuuuul | 0:0cd00ee4dd93 | 1121 | } |
mauuuuul | 0:0cd00ee4dd93 | 1122 | } |
mauuuuul | 0:0cd00ee4dd93 | 1123 | } |
mauuuuul | 0:0cd00ee4dd93 | 1124 | } |
mauuuuul | 0:0cd00ee4dd93 | 1125 | } |
mauuuuul | 0:0cd00ee4dd93 | 1126 | printf("Salah_Board%d = %s\r\n",i+1,salah_5.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1127 | } else if (res_cmp == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1128 | printf("Board %d Match\r\n",i+1); |
mauuuuul | 0:0cd00ee4dd93 | 1129 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1130 | salah_ambil5 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1131 | salah_taruh5 = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1132 | done_5 = true; |
mauuuuul | 0:0cd00ee4dd93 | 1133 | |
mauuuuul | 0:0cd00ee4dd93 | 1134 | memcpy(Row_Board5_Last,Row_Board5_Now,sizeof(Row_Board5_Last)); |
mauuuuul | 0:0cd00ee4dd93 | 1135 | |
mauuuuul | 0:0cd00ee4dd93 | 1136 | Send_RS485(i,64,64,false); |
mauuuuul | 0:0cd00ee4dd93 | 1137 | } |
mauuuuul | 0:0cd00ee4dd93 | 1138 | } |
mauuuuul | 0:0cd00ee4dd93 | 1139 | break; |
mauuuuul | 0:0cd00ee4dd93 | 1140 | } |
mauuuuul | 0:0cd00ee4dd93 | 1141 | } |
mauuuuul | 0:0cd00ee4dd93 | 1142 | |
mauuuuul | 0:0cd00ee4dd93 | 1143 | salah_ambil_resultant = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1144 | salah_taruh_resultant = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1145 | printf("Size salah = %d\r\n",lst_salah.size()); |
mauuuuul | 0:0cd00ee4dd93 | 1146 | if(lst_salah.size() > 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1147 | uint8_t blink_id = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1148 | |
mauuuuul | 0:0cd00ee4dd93 | 1149 | bool ada = false; |
mauuuuul | 0:0cd00ee4dd93 | 1150 | for(uint8_t p = 0; p<lst_salah.size(); p++) printf("lst salah all%d = %d\r\n",p+1,lst_salah[p]); |
mauuuuul | 0:0cd00ee4dd93 | 1151 | |
mauuuuul | 0:0cd00ee4dd93 | 1152 | if(lst_salah_hst.size() != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1153 | |
mauuuuul | 0:0cd00ee4dd93 | 1154 | //printf("jumlah hst = %d\r\n",lst_salah_hst.size()); |
mauuuuul | 0:0cd00ee4dd93 | 1155 | for(uint8_t q = 0; q<lst_salah_hst.size(); q++) { |
mauuuuul | 0:0cd00ee4dd93 | 1156 | ada = false; |
mauuuuul | 0:0cd00ee4dd93 | 1157 | |
mauuuuul | 0:0cd00ee4dd93 | 1158 | for(uint8_t r = 0; r<lst_salah.size(); r++) { |
mauuuuul | 0:0cd00ee4dd93 | 1159 | if(lst_salah[r] == lst_salah_hst[q]) { |
mauuuuul | 0:0cd00ee4dd93 | 1160 | ada = true; |
mauuuuul | 0:0cd00ee4dd93 | 1161 | //break; |
mauuuuul | 0:0cd00ee4dd93 | 1162 | } |
mauuuuul | 0:0cd00ee4dd93 | 1163 | } |
mauuuuul | 0:0cd00ee4dd93 | 1164 | if(!ada) { |
mauuuuul | 0:0cd00ee4dd93 | 1165 | to_remove.push_back(lst_salah_hst[q]); |
mauuuuul | 0:0cd00ee4dd93 | 1166 | } |
mauuuuul | 0:0cd00ee4dd93 | 1167 | } |
mauuuuul | 0:0cd00ee4dd93 | 1168 | |
mauuuuul | 0:0cd00ee4dd93 | 1169 | if(to_remove.size() > 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1170 | for(uint8_t t = 0; t<to_remove.size(); t++) { |
mauuuuul | 0:0cd00ee4dd93 | 1171 | lst_salah_hst.erase(remove(lst_salah_hst.begin(), lst_salah_hst.end(), to_remove[t]), lst_salah_hst.end()); |
mauuuuul | 0:0cd00ee4dd93 | 1172 | } |
mauuuuul | 0:0cd00ee4dd93 | 1173 | } |
mauuuuul | 0:0cd00ee4dd93 | 1174 | |
mauuuuul | 0:0cd00ee4dd93 | 1175 | for(uint8_t w = 0; w<lst_salah.size(); w++) { |
mauuuuul | 0:0cd00ee4dd93 | 1176 | it = find (lst_salah_hst.begin(), lst_salah_hst.end(), lst_salah[w]); |
mauuuuul | 0:0cd00ee4dd93 | 1177 | if (it != lst_salah_hst.end()) { |
mauuuuul | 0:0cd00ee4dd93 | 1178 | continue; |
mauuuuul | 0:0cd00ee4dd93 | 1179 | } |
mauuuuul | 0:0cd00ee4dd93 | 1180 | lst_salah_hst.push_back(lst_salah[w]); |
mauuuuul | 0:0cd00ee4dd93 | 1181 | } |
mauuuuul | 0:0cd00ee4dd93 | 1182 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 1183 | |
mauuuuul | 0:0cd00ee4dd93 | 1184 | for(uint8_t u = 0; u<lst_salah.size(); u++) { |
mauuuuul | 0:0cd00ee4dd93 | 1185 | lst_salah_hst.push_back(lst_salah[u]); |
mauuuuul | 0:0cd00ee4dd93 | 1186 | } |
mauuuuul | 0:0cd00ee4dd93 | 1187 | } |
mauuuuul | 0:0cd00ee4dd93 | 1188 | |
mauuuuul | 0:0cd00ee4dd93 | 1189 | blink_id = lst_salah_hst[lst_salah_hst.size()-1]; |
mauuuuul | 0:0cd00ee4dd93 | 1190 | //printf("blink_id = %d\r\n",blink_id); |
mauuuuul | 0:0cd00ee4dd93 | 1191 | |
mauuuuul | 0:0cd00ee4dd93 | 1192 | uint8_t board_number_blink = (blink_id - 1)%40; |
mauuuuul | 0:0cd00ee4dd93 | 1193 | |
mauuuuul | 0:0cd00ee4dd93 | 1194 | if(board_number_blink>= 0 && board_number_blink<= 7)board_number_blink = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1195 | else if(board_number_blink>= 8 && board_number_blink<= 15)board_number_blink = 1; |
mauuuuul | 0:0cd00ee4dd93 | 1196 | else if(board_number_blink>= 16 && board_number_blink<= 23)board_number_blink = 2; |
mauuuuul | 0:0cd00ee4dd93 | 1197 | else if(board_number_blink>= 24 && board_number_blink<= 31)board_number_blink = 3; |
mauuuuul | 0:0cd00ee4dd93 | 1198 | else if(board_number_blink>= 32 && board_number_blink<= 39)board_number_blink = 4; |
mauuuuul | 0:0cd00ee4dd93 | 1199 | |
mauuuuul | 0:0cd00ee4dd93 | 1200 | //printf("board_number_blink = %d\r\n",board_number_blink); |
mauuuuul | 0:0cd00ee4dd93 | 1201 | |
mauuuuul | 0:0cd00ee4dd93 | 1202 | uint8_t baris_blink = (blink_id - 1)/40; |
mauuuuul | 0:0cd00ee4dd93 | 1203 | uint8_t kolom_blink = (blink_id - 1)%8; |
mauuuuul | 0:0cd00ee4dd93 | 1204 | |
mauuuuul | 0:0cd00ee4dd93 | 1205 | blink_id = board_88[baris_blink][kolom_blink]; |
mauuuuul | 0:0cd00ee4dd93 | 1206 | |
mauuuuul | 0:0cd00ee4dd93 | 1207 | printf("Board blink : %d,Kolom blink : %d, Baris blink : %d\r\n",board_number_blink,kolom_blink,baris_blink); |
mauuuuul | 0:0cd00ee4dd93 | 1208 | if(board_number_blink == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1209 | real_blink_id_1 = blink_id; |
mauuuuul | 0:0cd00ee4dd93 | 1210 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1211 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1212 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1213 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1214 | } else if(board_number_blink == 1) { |
mauuuuul | 0:0cd00ee4dd93 | 1215 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1216 | real_blink_id_2 = blink_id; |
mauuuuul | 0:0cd00ee4dd93 | 1217 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1218 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1219 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1220 | } else if(board_number_blink == 2) { |
mauuuuul | 0:0cd00ee4dd93 | 1221 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1222 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1223 | real_blink_id_3 = blink_id; |
mauuuuul | 0:0cd00ee4dd93 | 1224 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1225 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1226 | } else if(board_number_blink == 3) { |
mauuuuul | 0:0cd00ee4dd93 | 1227 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1228 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1229 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1230 | real_blink_id_4 = blink_id; |
mauuuuul | 0:0cd00ee4dd93 | 1231 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1232 | } else if(board_number_blink == 4) { |
mauuuuul | 0:0cd00ee4dd93 | 1233 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1234 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1235 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1236 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1237 | real_blink_id_5 = blink_id; |
mauuuuul | 0:0cd00ee4dd93 | 1238 | } |
mauuuuul | 0:0cd00ee4dd93 | 1239 | blinking_now = lst_salah_hst[lst_salah_hst.size()-1]; |
mauuuuul | 0:0cd00ee4dd93 | 1240 | salah_ambil_resultant = salah_ambil1 + salah_ambil2 + salah_ambil3 + salah_ambil4 + salah_ambil5; |
mauuuuul | 0:0cd00ee4dd93 | 1241 | salah_taruh_resultant = salah_taruh1 + salah_taruh2 + salah_taruh3 + salah_taruh4 + salah_taruh5; |
mauuuuul | 0:0cd00ee4dd93 | 1242 | |
mauuuuul | 0:0cd00ee4dd93 | 1243 | if(salah_ambil_resultant == "") salah_ambil_resultant = "0-"; |
mauuuuul | 0:0cd00ee4dd93 | 1244 | if(salah_taruh_resultant == "") salah_taruh_resultant = "0-"; |
mauuuuul | 0:0cd00ee4dd93 | 1245 | |
mauuuuul | 0:0cd00ee4dd93 | 1246 | to_sends = to_string(frm_data_received.ids) + ";" +salah_ambil_resultant+";"+salah_taruh_resultant+ ";"+to_string(blinking_now) +";~"; |
mauuuuul | 0:0cd00ee4dd93 | 1247 | |
mauuuuul | 0:0cd00ee4dd93 | 1248 | if(TCP_Data_Last_Sent.find(to_sends) == -1) { |
mauuuuul | 0:0cd00ee4dd93 | 1249 | dsp.step5(to_string(blinking_now).c_str(),true); |
mauuuuul | 0:0cd00ee4dd93 | 1250 | LCD_Step_4 = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1251 | socket.send(to_sends.c_str(), to_sends.length()); |
mauuuuul | 0:0cd00ee4dd93 | 1252 | TCP_Data_Last_Sent = to_sends; |
mauuuuul | 0:0cd00ee4dd93 | 1253 | } |
mauuuuul | 0:0cd00ee4dd93 | 1254 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 1255 | if(done_1 && done_2 && done_3 && done_4 && done_5) { |
mauuuuul | 0:0cd00ee4dd93 | 1256 | lst_salah_hst.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 1257 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1258 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1259 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1260 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1261 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1262 | blinking_now = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1263 | printf("Finish\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 1264 | salah_ambil_resultant = "0-"; |
mauuuuul | 0:0cd00ee4dd93 | 1265 | salah_taruh_resultant = "0-"; |
mauuuuul | 0:0cd00ee4dd93 | 1266 | ibutton_code.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 1267 | |
mauuuuul | 0:0cd00ee4dd93 | 1268 | to_sends = to_string(frm_data_received.ids) + ";"+salah_ambil_resultant+";"+salah_taruh_resultant+";~"; |
mauuuuul | 0:0cd00ee4dd93 | 1269 | |
mauuuuul | 0:0cd00ee4dd93 | 1270 | socket.send(to_sends.c_str(), to_sends.length()); |
mauuuuul | 0:0cd00ee4dd93 | 1271 | |
mauuuuul | 0:0cd00ee4dd93 | 1272 | to_sends = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1273 | LCD_Step_4 = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1274 | |
mauuuuul | 0:0cd00ee4dd93 | 1275 | step = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1276 | |
mauuuuul | 0:0cd00ee4dd93 | 1277 | if(frm_data_received.ids == 3) { |
mauuuuul | 0:0cd00ee4dd93 | 1278 | dsp.step4(to_string(frm_data_received._key_id).c_str(),false); |
mauuuuul | 0:0cd00ee4dd93 | 1279 | } else if(frm_data_received.ids == 1) { |
mauuuuul | 0:0cd00ee4dd93 | 1280 | dsp.step0(); |
mauuuuul | 0:0cd00ee4dd93 | 1281 | } |
mauuuuul | 0:0cd00ee4dd93 | 1282 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 1283 | real_blink_id_1 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1284 | real_blink_id_2 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1285 | real_blink_id_3 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1286 | real_blink_id_4 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1287 | real_blink_id_5 = 64; |
mauuuuul | 0:0cd00ee4dd93 | 1288 | blinking_now = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1289 | |
mauuuuul | 0:0cd00ee4dd93 | 1290 | if(LCD_Step_4 == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1291 | if(frm_data_received.ids== 1) { |
mauuuuul | 0:0cd00ee4dd93 | 1292 | dsp.step2(to_string(frm_data_received._key_id).c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1293 | wait(1); |
mauuuuul | 0:0cd00ee4dd93 | 1294 | LCD_Step_4 = 1; |
mauuuuul | 0:0cd00ee4dd93 | 1295 | } else if(frm_data_received.ids == 3) { |
mauuuuul | 0:0cd00ee4dd93 | 1296 | dsp.step4(to_string(frm_data_received._key_id).c_str(),true); |
mauuuuul | 0:0cd00ee4dd93 | 1297 | wait(1); |
mauuuuul | 0:0cd00ee4dd93 | 1298 | LCD_Step_4 = 1; |
mauuuuul | 0:0cd00ee4dd93 | 1299 | } |
mauuuuul | 0:0cd00ee4dd93 | 1300 | } |
mauuuuul | 0:0cd00ee4dd93 | 1301 | } |
mauuuuul | 0:0cd00ee4dd93 | 1302 | } |
mauuuuul | 0:0cd00ee4dd93 | 1303 | |
mauuuuul | 0:0cd00ee4dd93 | 1304 | } |
mauuuuul | 0:0cd00ee4dd93 | 1305 | break; |
mauuuuul | 0:0cd00ee4dd93 | 1306 | } |
mauuuuul | 0:0cd00ee4dd93 | 1307 | } |
mauuuuul | 0:0cd00ee4dd93 | 1308 | } |
mauuuuul | 0:0cd00ee4dd93 | 1309 | } |
mauuuuul | 0:0cd00ee4dd93 | 1310 | |
mauuuuul | 0:0cd00ee4dd93 | 1311 | int main() |
mauuuuul | 0:0cd00ee4dd93 | 1312 | { |
mauuuuul | 0:0cd00ee4dd93 | 1313 | //serial_rx_tick.attach(&RS485_Recv,0.01); |
mauuuuul | 0:0cd00ee4dd93 | 1314 | TCP_Cek_Data_Last_Sent = "2;0-;0-;~"; |
mauuuuul | 0:0cd00ee4dd93 | 1315 | ids = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1316 | board_sum = 5; |
mauuuuul | 0:0cd00ee4dd93 | 1317 | wait(0.01); |
mauuuuul | 0:0cd00ee4dd93 | 1318 | dsp.init(); |
mauuuuul | 0:0cd00ee4dd93 | 1319 | |
mauuuuul | 0:0cd00ee4dd93 | 1320 | thd_Cek_Ibutton.start(Cek_Ibutton); |
mauuuuul | 0:0cd00ee4dd93 | 1321 | thd_Buzzer.start(Cek_Salah_Buzzer); |
mauuuuul | 0:0cd00ee4dd93 | 1322 | //thd_LCD.start(Cek_LCD_State); |
mauuuuul | 0:0cd00ee4dd93 | 1323 | //thd_RS485_Recv.start(RS485_Recv); |
mauuuuul | 0:0cd00ee4dd93 | 1324 | |
mauuuuul | 0:0cd00ee4dd93 | 1325 | FindingServer(); |
mauuuuul | 0:0cd00ee4dd93 | 1326 | } |
mauuuuul | 0:0cd00ee4dd93 | 1327 | |
mauuuuul | 0:0cd00ee4dd93 | 1328 | string Byte_to_StringBinary(byte data_byte) |
mauuuuul | 0:0cd00ee4dd93 | 1329 | { |
mauuuuul | 0:0cd00ee4dd93 | 1330 | string data_temp; |
mauuuuul | 0:0cd00ee4dd93 | 1331 | for(uint8_t i = 0; i <8; i++) { |
mauuuuul | 0:0cd00ee4dd93 | 1332 | if((data_byte>>i)&0x01) { |
mauuuuul | 0:0cd00ee4dd93 | 1333 | data_temp[abs(i-7)] += '1'; |
mauuuuul | 0:0cd00ee4dd93 | 1334 | } else data_temp[abs(i-7)] += '0'; |
mauuuuul | 0:0cd00ee4dd93 | 1335 | } |
mauuuuul | 0:0cd00ee4dd93 | 1336 | return data_temp; |
mauuuuul | 0:0cd00ee4dd93 | 1337 | } |
mauuuuul | 0:0cd00ee4dd93 | 1338 | |
mauuuuul | 0:0cd00ee4dd93 | 1339 | uint8_t StringBinary_to_Byte(string data_binary) |
mauuuuul | 0:0cd00ee4dd93 | 1340 | { |
mauuuuul | 0:0cd00ee4dd93 | 1341 | uint8_t data_temp = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1342 | bitset<8> b(data_binary); |
mauuuuul | 0:0cd00ee4dd93 | 1343 | unsigned char c = ( b.to_ulong() & 0xFF); |
mauuuuul | 0:0cd00ee4dd93 | 1344 | data_temp = static_cast<uint8_t>(c); |
mauuuuul | 0:0cd00ee4dd93 | 1345 | |
mauuuuul | 0:0cd00ee4dd93 | 1346 | return data_temp; |
mauuuuul | 0:0cd00ee4dd93 | 1347 | } |
mauuuuul | 0:0cd00ee4dd93 | 1348 | |
mauuuuul | 0:0cd00ee4dd93 | 1349 | uint8_t Get_Row(uint8_t key_id) |
mauuuuul | 0:0cd00ee4dd93 | 1350 | { |
mauuuuul | 0:0cd00ee4dd93 | 1351 | uint8_t data_temp = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1352 | |
mauuuuul | 0:0cd00ee4dd93 | 1353 | data_temp = key_id/(board_sum*8); |
mauuuuul | 0:0cd00ee4dd93 | 1354 | |
mauuuuul | 0:0cd00ee4dd93 | 1355 | return data_temp; |
mauuuuul | 0:0cd00ee4dd93 | 1356 | } |
mauuuuul | 0:0cd00ee4dd93 | 1357 | |
mauuuuul | 0:0cd00ee4dd93 | 1358 | unsigned short Get_CRC_Modbus(byte data_byte[]) |
mauuuuul | 0:0cd00ee4dd93 | 1359 | { |
mauuuuul | 0:0cd00ee4dd93 | 1360 | unsigned short data_temp; |
mauuuuul | 0:0cd00ee4dd93 | 1361 | |
mauuuuul | 0:0cd00ee4dd93 | 1362 | data_temp = calculate_crc16_Modbus(reinterpret_cast<char*>(data_byte), 6); |
mauuuuul | 0:0cd00ee4dd93 | 1363 | |
mauuuuul | 0:0cd00ee4dd93 | 1364 | return data_temp; |
mauuuuul | 0:0cd00ee4dd93 | 1365 | } |
mauuuuul | 0:0cd00ee4dd93 | 1366 | byte to_send[6] = {0x00,0x03,0x14,0x15,0x01,0x00}; |
mauuuuul | 0:0cd00ee4dd93 | 1367 | void Send_RS485(uint8_t board,uint8_t key_id,uint8_t key_id_blinking,bool Cek_Respon) |
mauuuuul | 0:0cd00ee4dd93 | 1368 | { |
mauuuuul | 0:0cd00ee4dd93 | 1369 | to_send[0] = board+1; |
mauuuuul | 0:0cd00ee4dd93 | 1370 | to_send[2] = key_id; |
mauuuuul | 0:0cd00ee4dd93 | 1371 | to_send[3] = key_id_blinking; |
mauuuuul | 0:0cd00ee4dd93 | 1372 | //printf("Calculating crc : "); |
mauuuuul | 0:0cd00ee4dd93 | 1373 | unsigned short __crc = Get_CRC_Modbus(to_send); |
mauuuuul | 0:0cd00ee4dd93 | 1374 | |
mauuuuul | 0:0cd00ee4dd93 | 1375 | //printf("%02X\r\n",__crc); |
mauuuuul | 0:0cd00ee4dd93 | 1376 | memcpy(buffer_crc,(unsigned char*)&(__crc),sizeof(short)); |
mauuuuul | 0:0cd00ee4dd93 | 1377 | byte _eof = 0x0D; |
mauuuuul | 0:0cd00ee4dd93 | 1378 | |
mauuuuul | 0:0cd00ee4dd93 | 1379 | byte all_to_send[9]; |
mauuuuul | 0:0cd00ee4dd93 | 1380 | |
mauuuuul | 0:0cd00ee4dd93 | 1381 | all_to_send[0] = board+1; |
mauuuuul | 0:0cd00ee4dd93 | 1382 | all_to_send[1] = to_send[1]; |
mauuuuul | 0:0cd00ee4dd93 | 1383 | all_to_send[2] = to_send[2]; |
mauuuuul | 0:0cd00ee4dd93 | 1384 | all_to_send[3] = to_send[3]; |
mauuuuul | 0:0cd00ee4dd93 | 1385 | all_to_send[4] = to_send[4]; |
mauuuuul | 0:0cd00ee4dd93 | 1386 | all_to_send[5] = to_send[5]; |
mauuuuul | 0:0cd00ee4dd93 | 1387 | all_to_send[6] = buffer_crc[1]; |
mauuuuul | 0:0cd00ee4dd93 | 1388 | all_to_send[7] = buffer_crc[0]; |
mauuuuul | 0:0cd00ee4dd93 | 1389 | all_to_send[8] = _eof; |
mauuuuul | 0:0cd00ee4dd93 | 1390 | |
mauuuuul | 0:0cd00ee4dd93 | 1391 | Resend: |
mauuuuul | 0:0cd00ee4dd93 | 1392 | |
mauuuuul | 0:0cd00ee4dd93 | 1393 | printf("Data recv : "); |
mauuuuul | 0:0cd00ee4dd93 | 1394 | for(uint8_t i = 0; i<15; i++) { |
mauuuuul | 0:0cd00ee4dd93 | 1395 | printf("%02X ",respon_from_slave[i]); |
mauuuuul | 0:0cd00ee4dd93 | 1396 | } |
mauuuuul | 0:0cd00ee4dd93 | 1397 | printf("\r\n"); |
mauuuuul | 0:0cd00ee4dd93 | 1398 | wait(0.05); |
mauuuuul | 0:0cd00ee4dd93 | 1399 | rede = 1; |
mauuuuul | 0:0cd00ee4dd93 | 1400 | for(uint8_t i = 0; i<9; i++) { |
mauuuuul | 0:0cd00ee4dd93 | 1401 | dv.putc(all_to_send[i]); |
mauuuuul | 0:0cd00ee4dd93 | 1402 | } |
mauuuuul | 0:0cd00ee4dd93 | 1403 | |
mauuuuul | 0:0cd00ee4dd93 | 1404 | if(Cek_Respon) printf("Send Complete to %d\r\n",board+1); |
mauuuuul | 0:0cd00ee4dd93 | 1405 | |
mauuuuul | 0:0cd00ee4dd93 | 1406 | if(!Cek_Respon) { |
mauuuuul | 0:0cd00ee4dd93 | 1407 | intr_Done = true; |
mauuuuul | 0:0cd00ee4dd93 | 1408 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 1409 | //printf("Trying to received%d..\r\n",board+1); |
mauuuuul | 0:0cd00ee4dd93 | 1410 | memset(respon_from_slave, 0, sizeof respon_from_slave); |
mauuuuul | 0:0cd00ee4dd93 | 1411 | intr_Done = false; |
mauuuuul | 0:0cd00ee4dd93 | 1412 | ids = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1413 | rede = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1414 | |
mauuuuul | 0:0cd00ee4dd93 | 1415 | while(!intr_Done) { |
mauuuuul | 0:0cd00ee4dd93 | 1416 | while(dv.readable()) { |
mauuuuul | 0:0cd00ee4dd93 | 1417 | |
mauuuuul | 0:0cd00ee4dd93 | 1418 | char tempbuf = dv.getc(); |
mauuuuul | 0:0cd00ee4dd93 | 1419 | if(ids == 0 && tempbuf == 0xFF) { |
mauuuuul | 0:0cd00ee4dd93 | 1420 | |
mauuuuul | 0:0cd00ee4dd93 | 1421 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 1422 | respon_from_slave[ids] = tempbuf; |
mauuuuul | 0:0cd00ee4dd93 | 1423 | ids++; |
mauuuuul | 0:0cd00ee4dd93 | 1424 | } |
mauuuuul | 0:0cd00ee4dd93 | 1425 | } |
mauuuuul | 0:0cd00ee4dd93 | 1426 | if((respon_from_slave[0] == board+1) && (respon_from_slave[14] == 0x0D)) intr_Done = true; |
mauuuuul | 0:0cd00ee4dd93 | 1427 | else goto Resend; |
mauuuuul | 0:0cd00ee4dd93 | 1428 | } |
mauuuuul | 0:0cd00ee4dd93 | 1429 | } |
mauuuuul | 0:0cd00ee4dd93 | 1430 | } |
mauuuuul | 0:0cd00ee4dd93 | 1431 | |
mauuuuul | 0:0cd00ee4dd93 | 1432 | |
mauuuuul | 0:0cd00ee4dd93 | 1433 | void Cek_Ibutton() |
mauuuuul | 0:0cd00ee4dd93 | 1434 | { |
mauuuuul | 0:0cd00ee4dd93 | 1435 | while(1) { |
mauuuuul | 0:0cd00ee4dd93 | 1436 | ibutton.DetectiButton(); |
mauuuuul | 0:0cd00ee4dd93 | 1437 | if(ibutton.IsTaping()) |
mauuuuul | 0:0cd00ee4dd93 | 1438 | tap = true; |
mauuuuul | 0:0cd00ee4dd93 | 1439 | else |
mauuuuul | 0:0cd00ee4dd93 | 1440 | tap = false; |
mauuuuul | 0:0cd00ee4dd93 | 1441 | |
mauuuuul | 0:0cd00ee4dd93 | 1442 | if(tap != lasttap) { |
mauuuuul | 0:0cd00ee4dd93 | 1443 | lasttap = tap; |
mauuuuul | 0:0cd00ee4dd93 | 1444 | if(tap) { |
mauuuuul | 0:0cd00ee4dd93 | 1445 | string dataButton; |
mauuuuul | 0:0cd00ee4dd93 | 1446 | |
mauuuuul | 0:0cd00ee4dd93 | 1447 | dataButton.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 1448 | dataButton = ibutton.GetData(); |
mauuuuul | 0:0cd00ee4dd93 | 1449 | if(dataButton.length()== 12) { |
mauuuuul | 0:0cd00ee4dd93 | 1450 | ibutton_code = dataButton; |
mauuuuul | 0:0cd00ee4dd93 | 1451 | printf("[Data Button : %s]\r\n", dataButton.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1452 | } |
mauuuuul | 0:0cd00ee4dd93 | 1453 | } |
mauuuuul | 0:0cd00ee4dd93 | 1454 | } |
mauuuuul | 0:0cd00ee4dd93 | 1455 | } |
mauuuuul | 0:0cd00ee4dd93 | 1456 | } |
mauuuuul | 0:0cd00ee4dd93 | 1457 | |
mauuuuul | 0:0cd00ee4dd93 | 1458 | void Cek_Salah_Buzzer() |
mauuuuul | 0:0cd00ee4dd93 | 1459 | { |
mauuuuul | 0:0cd00ee4dd93 | 1460 | while(1) { |
mauuuuul | 0:0cd00ee4dd93 | 1461 | if(real_blink_id_1 != 64 || real_blink_id_2 != 64 || real_blink_id_3 != 64 || real_blink_id_4 != 64|| real_blink_id_5 != 64) { |
mauuuuul | 0:0cd00ee4dd93 | 1462 | buzz.play(3); |
mauuuuul | 0:0cd00ee4dd93 | 1463 | } |
mauuuuul | 0:0cd00ee4dd93 | 1464 | wait(0.2); |
mauuuuul | 0:0cd00ee4dd93 | 1465 | } |
mauuuuul | 0:0cd00ee4dd93 | 1466 | } |
mauuuuul | 0:0cd00ee4dd93 | 1467 | |
mauuuuul | 0:0cd00ee4dd93 | 1468 | void Cek_LCD_State() |
mauuuuul | 0:0cd00ee4dd93 | 1469 | { |
mauuuuul | 0:0cd00ee4dd93 | 1470 | while(1) { |
mauuuuul | 0:0cd00ee4dd93 | 1471 | |
mauuuuul | 0:0cd00ee4dd93 | 1472 | if(LCD_Step == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1473 | wait_ms(500); |
mauuuuul | 0:0cd00ee4dd93 | 1474 | if((step == 0 || step == 4) && blinking_now != 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1475 | dsp.step5(to_string(blinking_now).c_str(),true); |
mauuuuul | 0:0cd00ee4dd93 | 1476 | wait_ms(500); |
mauuuuul | 0:0cd00ee4dd93 | 1477 | LCD_Step = 1; |
mauuuuul | 0:0cd00ee4dd93 | 1478 | } else if(step == 0 && blinking_now == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1479 | dsp.step0(); |
mauuuuul | 0:0cd00ee4dd93 | 1480 | LCD_Step = 1; |
mauuuuul | 0:0cd00ee4dd93 | 1481 | } else if(step == 4 && blinking_now == 0) { |
mauuuuul | 0:0cd00ee4dd93 | 1482 | dsp.step2(to_string(frm_data_received._key_id).c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1483 | LCD_Step = 1; |
mauuuuul | 0:0cd00ee4dd93 | 1484 | } |
mauuuuul | 0:0cd00ee4dd93 | 1485 | } |
mauuuuul | 0:0cd00ee4dd93 | 1486 | } |
mauuuuul | 0:0cd00ee4dd93 | 1487 | } |
mauuuuul | 0:0cd00ee4dd93 | 1488 | string frames; |
mauuuuul | 0:0cd00ee4dd93 | 1489 | string First_Update() |
mauuuuul | 0:0cd00ee4dd93 | 1490 | { |
mauuuuul | 0:0cd00ee4dd93 | 1491 | frames.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 1492 | |
mauuuuul | 0:0cd00ee4dd93 | 1493 | for(uint8_t i = 0; i<board_sum; i++) { |
mauuuuul | 0:0cd00ee4dd93 | 1494 | wait_ms(50); |
mauuuuul | 0:0cd00ee4dd93 | 1495 | intr_Done = false; |
mauuuuul | 0:0cd00ee4dd93 | 1496 | ids = 0; |
mauuuuul | 0:0cd00ee4dd93 | 1497 | bool done = false; |
mauuuuul | 0:0cd00ee4dd93 | 1498 | waiting_resp = true; |
mauuuuul | 0:0cd00ee4dd93 | 1499 | Send_RS485(i,64,64,true); |
mauuuuul | 0:0cd00ee4dd93 | 1500 | |
mauuuuul | 0:0cd00ee4dd93 | 1501 | for(uint8_t a = 4; a<12; a++) { |
mauuuuul | 0:0cd00ee4dd93 | 1502 | uint8_t temp_id = a; |
mauuuuul | 0:0cd00ee4dd93 | 1503 | switch(i) { |
mauuuuul | 0:0cd00ee4dd93 | 1504 | case 0: { |
mauuuuul | 0:0cd00ee4dd93 | 1505 | Row_Board1_Last[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 1506 | //printf("%02X\r\n",Row_Board1_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 1507 | } |
mauuuuul | 0:0cd00ee4dd93 | 1508 | break; |
mauuuuul | 0:0cd00ee4dd93 | 1509 | case 1: { |
mauuuuul | 0:0cd00ee4dd93 | 1510 | Row_Board2_Last[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 1511 | //printf("%02X\r\n",Row_Board2_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 1512 | } |
mauuuuul | 0:0cd00ee4dd93 | 1513 | break; |
mauuuuul | 0:0cd00ee4dd93 | 1514 | case 2: { |
mauuuuul | 0:0cd00ee4dd93 | 1515 | Row_Board3_Last[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 1516 | //printf("%02X\r\n",Row_Board3_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 1517 | } |
mauuuuul | 0:0cd00ee4dd93 | 1518 | break; |
mauuuuul | 0:0cd00ee4dd93 | 1519 | case 3: { |
mauuuuul | 0:0cd00ee4dd93 | 1520 | Row_Board4_Last[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 1521 | //printf("%02X\r\n",Row_Board4_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 1522 | } |
mauuuuul | 0:0cd00ee4dd93 | 1523 | break; |
mauuuuul | 0:0cd00ee4dd93 | 1524 | case 4: { |
mauuuuul | 0:0cd00ee4dd93 | 1525 | Row_Board5_Last[temp_id-4] = respon_from_slave[a]; |
mauuuuul | 0:0cd00ee4dd93 | 1526 | //printf("%02X\r\n",Row_Board5_Last[temp_id-5]); |
mauuuuul | 0:0cd00ee4dd93 | 1527 | } |
mauuuuul | 0:0cd00ee4dd93 | 1528 | break; |
mauuuuul | 0:0cd00ee4dd93 | 1529 | } |
mauuuuul | 0:0cd00ee4dd93 | 1530 | } |
mauuuuul | 0:0cd00ee4dd93 | 1531 | } |
mauuuuul | 0:0cd00ee4dd93 | 1532 | string bin_string; |
mauuuuul | 0:0cd00ee4dd93 | 1533 | Frame_To_Send.ids = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1534 | Frame_To_Send.key_off = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1535 | Frame_To_Send.key_on = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1536 | string key_ids; |
mauuuuul | 0:0cd00ee4dd93 | 1537 | for (uint8_t i = 0; i < 5; i++) { |
mauuuuul | 0:0cd00ee4dd93 | 1538 | for (uint8_t j = 0; j < 8; j++) { |
mauuuuul | 0:0cd00ee4dd93 | 1539 | string bin_string = ""; |
mauuuuul | 0:0cd00ee4dd93 | 1540 | |
mauuuuul | 0:0cd00ee4dd93 | 1541 | if (i == 0) bin_string = Byte_to_StringBinary(Row_Board1_Last[j]); |
mauuuuul | 0:0cd00ee4dd93 | 1542 | if (i == 1) bin_string = Byte_to_StringBinary(Row_Board2_Last[j]); |
mauuuuul | 0:0cd00ee4dd93 | 1543 | if (i == 2) bin_string = Byte_to_StringBinary(Row_Board3_Last[j]); |
mauuuuul | 0:0cd00ee4dd93 | 1544 | if (i == 3) bin_string = Byte_to_StringBinary(Row_Board4_Last[j]); |
mauuuuul | 0:0cd00ee4dd93 | 1545 | if (i == 4) bin_string = Byte_to_StringBinary(Row_Board5_Last[j]); |
mauuuuul | 0:0cd00ee4dd93 | 1546 | |
mauuuuul | 0:0cd00ee4dd93 | 1547 | //printf("board[%d][%d] = %s\r\n",i,j,bin_string.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1548 | for (uint8_t k = 0; k < 8; k++) { |
mauuuuul | 0:0cd00ee4dd93 | 1549 | if (bin_string[abs(k-7)] == '1') { |
mauuuuul | 0:0cd00ee4dd93 | 1550 | key_ids = to_string((40*j)+k+(8*i)+1); |
mauuuuul | 0:0cd00ee4dd93 | 1551 | Frame_To_Send.key_on += (key_ids+"-"); |
mauuuuul | 0:0cd00ee4dd93 | 1552 | |
mauuuuul | 0:0cd00ee4dd93 | 1553 | } else { |
mauuuuul | 0:0cd00ee4dd93 | 1554 | key_ids = to_string((40*j)+k+(8*i)+1); |
mauuuuul | 0:0cd00ee4dd93 | 1555 | Frame_To_Send.key_off += (key_ids+"-"); |
mauuuuul | 0:0cd00ee4dd93 | 1556 | } |
mauuuuul | 0:0cd00ee4dd93 | 1557 | } |
mauuuuul | 0:0cd00ee4dd93 | 1558 | } |
mauuuuul | 0:0cd00ee4dd93 | 1559 | } |
mauuuuul | 0:0cd00ee4dd93 | 1560 | |
mauuuuul | 0:0cd00ee4dd93 | 1561 | if(Frame_To_Send.key_on == "") { |
mauuuuul | 0:0cd00ee4dd93 | 1562 | Frame_To_Send.key_on = "0-"; |
mauuuuul | 0:0cd00ee4dd93 | 1563 | } |
mauuuuul | 0:0cd00ee4dd93 | 1564 | |
mauuuuul | 0:0cd00ee4dd93 | 1565 | if(Frame_To_Send.key_off == "") { |
mauuuuul | 0:0cd00ee4dd93 | 1566 | Frame_To_Send.key_off = "0-"; |
mauuuuul | 0:0cd00ee4dd93 | 1567 | } |
mauuuuul | 0:0cd00ee4dd93 | 1568 | Frame_To_Send.ids = "4"; |
mauuuuul | 0:0cd00ee4dd93 | 1569 | |
mauuuuul | 0:0cd00ee4dd93 | 1570 | frames = Frame_To_Send.ids + ";" + Frame_To_Send.key_on + ";~"; |
mauuuuul | 0:0cd00ee4dd93 | 1571 | printf("Sent First Update : %s\r\n",frames.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1572 | return frames; |
mauuuuul | 0:0cd00ee4dd93 | 1573 | } |
mauuuuul | 0:0cd00ee4dd93 | 1574 | string data_bin_pred; |
mauuuuul | 0:0cd00ee4dd93 | 1575 | void Make_Prediction(uint8_t board_numb,uint8_t baris, uint8_t kolom) |
mauuuuul | 0:0cd00ee4dd93 | 1576 | { |
mauuuuul | 0:0cd00ee4dd93 | 1577 | printf("baris = %d\r\n",baris); |
mauuuuul | 0:0cd00ee4dd93 | 1578 | printf("kolom = %d\r\n",kolom); |
mauuuuul | 0:0cd00ee4dd93 | 1579 | |
mauuuuul | 0:0cd00ee4dd93 | 1580 | memcpy(Row_Board1_Predict,Row_Board1_Last,sizeof(Row_Board1_Predict)); |
mauuuuul | 0:0cd00ee4dd93 | 1581 | memcpy(Row_Board2_Predict,Row_Board2_Last,sizeof(Row_Board2_Predict)); |
mauuuuul | 0:0cd00ee4dd93 | 1582 | memcpy(Row_Board3_Predict,Row_Board3_Last,sizeof(Row_Board3_Predict)); |
mauuuuul | 0:0cd00ee4dd93 | 1583 | memcpy(Row_Board4_Predict,Row_Board4_Last,sizeof(Row_Board4_Predict)); |
mauuuuul | 0:0cd00ee4dd93 | 1584 | memcpy(Row_Board5_Predict,Row_Board5_Last,sizeof(Row_Board5_Predict)); |
mauuuuul | 0:0cd00ee4dd93 | 1585 | |
mauuuuul | 0:0cd00ee4dd93 | 1586 | board_numb += 1; |
mauuuuul | 0:0cd00ee4dd93 | 1587 | if(board_numb == 1) { |
mauuuuul | 0:0cd00ee4dd93 | 1588 | |
mauuuuul | 0:0cd00ee4dd93 | 1589 | data_bin_pred.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 1590 | data_bin_pred = Byte_to_StringBinary(Row_Board1_Predict[baris]); |
mauuuuul | 0:0cd00ee4dd93 | 1591 | printf("%s\r\n",data_bin_pred.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1592 | |
mauuuuul | 0:0cd00ee4dd93 | 1593 | if(frm_data_received.cmd_id == 1) { |
mauuuuul | 0:0cd00ee4dd93 | 1594 | data_bin_pred[abs(kolom-7)] = '0'; |
mauuuuul | 0:0cd00ee4dd93 | 1595 | } else if(frm_data_received.cmd_id == 2) { |
mauuuuul | 0:0cd00ee4dd93 | 1596 | data_bin_pred[abs(kolom-7)] = '1'; |
mauuuuul | 0:0cd00ee4dd93 | 1597 | } |
mauuuuul | 0:0cd00ee4dd93 | 1598 | |
mauuuuul | 0:0cd00ee4dd93 | 1599 | Row_Board1_Predict[baris] = StringBinary_to_Byte(data_bin_pred.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1600 | } else if(board_numb == 2) { |
mauuuuul | 0:0cd00ee4dd93 | 1601 | |
mauuuuul | 0:0cd00ee4dd93 | 1602 | data_bin_pred.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 1603 | data_bin_pred = Byte_to_StringBinary(Row_Board2_Predict[baris]); |
mauuuuul | 0:0cd00ee4dd93 | 1604 | printf("%s\r\n",data_bin_pred.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1605 | |
mauuuuul | 0:0cd00ee4dd93 | 1606 | if(frm_data_received.cmd_id == 1) { |
mauuuuul | 0:0cd00ee4dd93 | 1607 | data_bin_pred[abs(kolom-7)] = '0'; |
mauuuuul | 0:0cd00ee4dd93 | 1608 | } else if(frm_data_received.cmd_id == 2) { |
mauuuuul | 0:0cd00ee4dd93 | 1609 | data_bin_pred[abs(kolom-7)] = '1'; |
mauuuuul | 0:0cd00ee4dd93 | 1610 | } |
mauuuuul | 0:0cd00ee4dd93 | 1611 | |
mauuuuul | 0:0cd00ee4dd93 | 1612 | Row_Board2_Predict[baris] = StringBinary_to_Byte(data_bin_pred.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1613 | } else if(board_numb == 3) { |
mauuuuul | 0:0cd00ee4dd93 | 1614 | data_bin_pred.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 1615 | data_bin_pred = Byte_to_StringBinary(Row_Board3_Predict[baris]); |
mauuuuul | 0:0cd00ee4dd93 | 1616 | printf("%s\r\n",data_bin_pred.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1617 | |
mauuuuul | 0:0cd00ee4dd93 | 1618 | if(frm_data_received.cmd_id == 1) { |
mauuuuul | 0:0cd00ee4dd93 | 1619 | data_bin_pred[abs(kolom-7)] = '0'; |
mauuuuul | 0:0cd00ee4dd93 | 1620 | } else if(frm_data_received.cmd_id == 2) { |
mauuuuul | 0:0cd00ee4dd93 | 1621 | data_bin_pred[abs(kolom-7)] = '1'; |
mauuuuul | 0:0cd00ee4dd93 | 1622 | } |
mauuuuul | 0:0cd00ee4dd93 | 1623 | |
mauuuuul | 0:0cd00ee4dd93 | 1624 | Row_Board3_Predict[baris] = StringBinary_to_Byte(data_bin_pred.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1625 | } else if(board_numb == 4) { |
mauuuuul | 0:0cd00ee4dd93 | 1626 | data_bin_pred.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 1627 | data_bin_pred = Byte_to_StringBinary(Row_Board4_Predict[baris]); |
mauuuuul | 0:0cd00ee4dd93 | 1628 | printf("%s\r\n",data_bin_pred.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1629 | |
mauuuuul | 0:0cd00ee4dd93 | 1630 | if(frm_data_received.cmd_id == 1) { |
mauuuuul | 0:0cd00ee4dd93 | 1631 | data_bin_pred[abs(kolom-7)] = '0'; |
mauuuuul | 0:0cd00ee4dd93 | 1632 | } else if(frm_data_received.cmd_id == 2) { |
mauuuuul | 0:0cd00ee4dd93 | 1633 | data_bin_pred[abs(kolom-7)] = '1'; |
mauuuuul | 0:0cd00ee4dd93 | 1634 | } |
mauuuuul | 0:0cd00ee4dd93 | 1635 | |
mauuuuul | 0:0cd00ee4dd93 | 1636 | Row_Board4_Predict[baris] = StringBinary_to_Byte(data_bin_pred.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1637 | } else if(board_numb == 5) { |
mauuuuul | 0:0cd00ee4dd93 | 1638 | data_bin_pred.clear(); |
mauuuuul | 0:0cd00ee4dd93 | 1639 | data_bin_pred = Byte_to_StringBinary(Row_Board5_Predict[baris]); |
mauuuuul | 0:0cd00ee4dd93 | 1640 | printf("%s\r\n",data_bin_pred.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1641 | |
mauuuuul | 0:0cd00ee4dd93 | 1642 | if(frm_data_received.cmd_id == 1) { |
mauuuuul | 0:0cd00ee4dd93 | 1643 | data_bin_pred[abs(kolom-7)] = '0'; |
mauuuuul | 0:0cd00ee4dd93 | 1644 | } else if(frm_data_received.cmd_id == 2) { |
mauuuuul | 0:0cd00ee4dd93 | 1645 | data_bin_pred[abs(kolom-7)] = '1'; |
mauuuuul | 0:0cd00ee4dd93 | 1646 | } |
mauuuuul | 0:0cd00ee4dd93 | 1647 | |
mauuuuul | 0:0cd00ee4dd93 | 1648 | Row_Board5_Predict[baris] = StringBinary_to_Byte(data_bin_pred.c_str()); |
mauuuuul | 0:0cd00ee4dd93 | 1649 | } |
mauuuuul | 0:0cd00ee4dd93 | 1650 | } |