Depot Pertamina / Mbed 2 deprecated Gate_FRDM

Dependencies:   EthernetInterface MbedJSONValue SDFileSystem mbed-rtos mbed

Fork of Gate_Aidik_FRDM_v2 by Depot Pertamina

Committer:
irsanjul
Date:
Tue Feb 28 06:55:23 2017 +0000
Revision:
1:021273f6b9f4
Parent:
0:fbb75122015f
aaa

Who changed what in which revision?

UserRevisionLine numberNew contents of line
irsanjul 1:021273f6b9f4 1 /*
irsanjul 1:021273f6b9f4 2 FRDM v4 menggunakan board v2 yang dimodif lednya.
irsanjul 1:021273f6b9f4 3 Led ga pake digital inout, diganti jadi digitalout.
irsanjul 1:021273f6b9f4 4 */
irsanjul 1:021273f6b9f4 5
irsanjul 0:fbb75122015f 6 #include "mbed.h"
irsanjul 0:fbb75122015f 7 #include "EthernetInterface.h"
irsanjul 1:021273f6b9f4 8 //#include "SDFileSystem.h"
irsanjul 1:021273f6b9f4 9 #include "MbedJSONValue.h"
irsanjul 1:021273f6b9f4 10 #include <sstream>
irsanjul 1:021273f6b9f4 11 #include <iostream>
irsanjul 1:021273f6b9f4 12 #include <fstream>
irsanjul 0:fbb75122015f 13
irsanjul 0:fbb75122015f 14 #define IP_CONF_PORT 50004
irsanjul 0:fbb75122015f 15
irsanjul 0:fbb75122015f 16 #define ijo 0
irsanjul 0:fbb75122015f 17 #define merah 1
irsanjul 0:fbb75122015f 18
irsanjul 1:021273f6b9f4 19 UDPSocket sock, ip_conf, trx_ser;
irsanjul 1:021273f6b9f4 20 Endpoint multi, server;
irsanjul 1:021273f6b9f4 21
irsanjul 1:021273f6b9f4 22 //SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
irsanjul 0:fbb75122015f 23
irsanjul 1:021273f6b9f4 24 DigitalOut Stdby_R(LED2), Sopir_R(LED3), Res_R(LED1), MT_R(LED4);
irsanjul 1:021273f6b9f4 25 DigitalOut Std_G(PTC5), Std_R(PTC7), Spr_G(PTC0), Spr_R(PTC9), Mt_G(PTC8), Mt_R(PTC1), Pow(PTB19);
irsanjul 1:021273f6b9f4 26 DigitalOut Gate(PTB9), Sleep(PTA1), Reset(PTB23, 1);
irsanjul 1:021273f6b9f4 27 DigitalInOut iBtn(PTB18);
irsanjul 0:fbb75122015f 28 DigitalIn print_er(PTC2), print_done(PTB2);
irsanjul 0:fbb75122015f 29
irsanjul 0:fbb75122015f 30 Serial dbg(USBTX, USBRX);
irsanjul 1:021273f6b9f4 31 Serial printer(PTC17, PTC16);
irsanjul 0:fbb75122015f 32
irsanjul 1:021273f6b9f4 33 char IP[16], SUBNET[16], GATEWAY[16], MCAST[16], IDX[4];
irsanjul 0:fbb75122015f 34 char PortListen[6], PortSend[6], PortHeartB[6];
irsanjul 0:fbb75122015f 35 int BAUD = 19200;
irsanjul 0:fbb75122015f 36
irsanjul 0:fbb75122015f 37 int width, TICK = 0;
irsanjul 0:fbb75122015f 38 unsigned char ID[8], idx, idy, id_addr = 0x33, ix, er_tmp1 = 0, er_tmp2 = 0,
irsanjul 1:021273f6b9f4 39 sprmt = 0;
irsanjul 1:021273f6b9f4 40 char text[26], ch, rx_buff[6], tx_buff[7],
irsanjul 1:021273f6b9f4 41 _hex[17] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
irsanjul 1:021273f6b9f4 42 'C', 'D', 'E', 'F' };
irsanjul 0:fbb75122015f 43
irsanjul 0:fbb75122015f 44 void Standby(bool warna, bool nyala) {
irsanjul 0:fbb75122015f 45 switch (nyala) {
irsanjul 0:fbb75122015f 46 case 0:
irsanjul 0:fbb75122015f 47 if (warna == ijo) {
irsanjul 0:fbb75122015f 48 Stdby_R = 0; // led 2
irsanjul 0:fbb75122015f 49 Std_G.write(0);
irsanjul 0:fbb75122015f 50 } else if (warna == merah) {
irsanjul 0:fbb75122015f 51 Std_R.write(0);
irsanjul 0:fbb75122015f 52 }
irsanjul 0:fbb75122015f 53 break;
irsanjul 0:fbb75122015f 54 case 1:
irsanjul 0:fbb75122015f 55 if (warna == ijo) {
irsanjul 0:fbb75122015f 56 Stdby_R = 1;
irsanjul 0:fbb75122015f 57 Std_G.write(1);
irsanjul 0:fbb75122015f 58 } else if (warna == merah) {
irsanjul 0:fbb75122015f 59 Std_R.write(1);
irsanjul 0:fbb75122015f 60 }
irsanjul 0:fbb75122015f 61 break;
irsanjul 0:fbb75122015f 62 }
irsanjul 0:fbb75122015f 63 }
irsanjul 0:fbb75122015f 64
irsanjul 0:fbb75122015f 65 void Sopir(bool warna, bool nyala) {
irsanjul 0:fbb75122015f 66 switch (nyala) {
irsanjul 0:fbb75122015f 67 case 0:
irsanjul 0:fbb75122015f 68 if (warna == ijo) {
irsanjul 0:fbb75122015f 69 Sopir_R = 0; // led 3
irsanjul 0:fbb75122015f 70 Spr_G.write(0);
irsanjul 0:fbb75122015f 71 } else if (warna == merah) {
irsanjul 0:fbb75122015f 72 Spr_R.write(0);
irsanjul 0:fbb75122015f 73 }
irsanjul 0:fbb75122015f 74 break;
irsanjul 0:fbb75122015f 75 case 1:
irsanjul 0:fbb75122015f 76 if (warna == ijo) {
irsanjul 0:fbb75122015f 77 Sopir_R = 1;
irsanjul 0:fbb75122015f 78 Spr_G.write(1);
irsanjul 0:fbb75122015f 79 } else if (warna == merah) {
irsanjul 0:fbb75122015f 80 Spr_R.write(1);
irsanjul 0:fbb75122015f 81 }
irsanjul 0:fbb75122015f 82 break;
irsanjul 0:fbb75122015f 83 }
irsanjul 0:fbb75122015f 84 }
irsanjul 0:fbb75122015f 85
irsanjul 0:fbb75122015f 86 void eMTy(bool warna, bool nyala) {
irsanjul 0:fbb75122015f 87 switch (nyala) {
irsanjul 0:fbb75122015f 88 case 0:
irsanjul 0:fbb75122015f 89 if (warna == ijo) {
irsanjul 0:fbb75122015f 90 MT_R = 0; // led 4
irsanjul 0:fbb75122015f 91 Mt_G.write(0);
irsanjul 0:fbb75122015f 92 } else if (warna == merah) {
irsanjul 0:fbb75122015f 93 Mt_R.write(0);
irsanjul 0:fbb75122015f 94 }
irsanjul 0:fbb75122015f 95 break;
irsanjul 0:fbb75122015f 96 case 1:
irsanjul 0:fbb75122015f 97 if (warna == ijo) {
irsanjul 0:fbb75122015f 98 MT_R = 1;
irsanjul 0:fbb75122015f 99 Mt_G.write(1);
irsanjul 0:fbb75122015f 100 } else if (warna == merah) {
irsanjul 0:fbb75122015f 101 Mt_R.write(1);
irsanjul 0:fbb75122015f 102 }
irsanjul 0:fbb75122015f 103 break;
irsanjul 0:fbb75122015f 104 }
irsanjul 0:fbb75122015f 105 }
irsanjul 1:021273f6b9f4 106
irsanjul 1:021273f6b9f4 107
irsanjul 1:021273f6b9f4 108 string open_file(const char *location)
irsanjul 1:021273f6b9f4 109 {
irsanjul 1:021273f6b9f4 110 string rtn = "\0";
irsanjul 1:021273f6b9f4 111
irsanjul 1:021273f6b9f4 112 // dbg.printf("OPEN FILE %s\r\n", location);
irsanjul 1:021273f6b9f4 113 ifstream stream(location, std::ifstream::binary);
irsanjul 1:021273f6b9f4 114
irsanjul 1:021273f6b9f4 115 if ( !stream.is_open() ) {
irsanjul 1:021273f6b9f4 116 dbg.printf("File Opening Error\n\r");
irsanjul 1:021273f6b9f4 117 stream.close();
irsanjul 1:021273f6b9f4 118 }
irsanjul 1:021273f6b9f4 119 else
irsanjul 1:021273f6b9f4 120 {
irsanjul 1:021273f6b9f4 121 stream.seekg(0,stream.end);
irsanjul 1:021273f6b9f4 122 int len = stream.tellg();
irsanjul 1:021273f6b9f4 123 stream.seekg(0,stream.beg);
irsanjul 1:021273f6b9f4 124
irsanjul 1:021273f6b9f4 125 char *_stream = new char [len];
irsanjul 1:021273f6b9f4 126
irsanjul 1:021273f6b9f4 127 stream.read(_stream,len);
irsanjul 1:021273f6b9f4 128 _stream[len] = '\0';
irsanjul 1:021273f6b9f4 129
irsanjul 1:021273f6b9f4 130 rtn += _stream;
irsanjul 1:021273f6b9f4 131 stream.close();
irsanjul 1:021273f6b9f4 132 delete [] _stream;
irsanjul 0:fbb75122015f 133 }
irsanjul 1:021273f6b9f4 134
irsanjul 1:021273f6b9f4 135 return rtn;
irsanjul 1:021273f6b9f4 136 }
irsanjul 1:021273f6b9f4 137
irsanjul 1:021273f6b9f4 138 bool mbed_config_init()
irsanjul 1:021273f6b9f4 139 {
irsanjul 1:021273f6b9f4 140 dbg.printf("Masuk mbed config init\r\n");
irsanjul 1:021273f6b9f4 141
irsanjul 1:021273f6b9f4 142 MbedJSONValue config_json;
irsanjul 1:021273f6b9f4 143 string dataSet = open_file("/sd/IPCONF.TXT");
irsanjul 1:021273f6b9f4 144 dbg.printf("isi file :\r\n%s\r\n", dataSet.c_str());
irsanjul 1:021273f6b9f4 145
irsanjul 1:021273f6b9f4 146 if(dataSet.size() > 1)
irsanjul 1:021273f6b9f4 147 {
irsanjul 1:021273f6b9f4 148 string err;
irsanjul 1:021273f6b9f4 149 parse(config_json, dataSet.c_str(), dataSet.c_str() + strlen(dataSet.c_str()), &err);
irsanjul 1:021273f6b9f4 150 if(err.size() > 0)
irsanjul 1:021273f6b9f4 151 {
irsanjul 1:021273f6b9f4 152 dbg.printf("res error? %s\r\n", err.c_str());
irsanjul 1:021273f6b9f4 153 return false;
irsanjul 1:021273f6b9f4 154 }
irsanjul 1:021273f6b9f4 155 else
irsanjul 1:021273f6b9f4 156 {
irsanjul 1:021273f6b9f4 157 const char *ip_temp = config_json["IP"].get<string>().c_str();
irsanjul 1:021273f6b9f4 158 const char *sub_temp = config_json["SUBNET"].get<string>().c_str();
irsanjul 1:021273f6b9f4 159 const char *gate_temp = config_json["GATEWAY"].get<string>().c_str();
irsanjul 1:021273f6b9f4 160 const char *mcast_temp = config_json["MCAST"].get<string>().c_str();
irsanjul 1:021273f6b9f4 161 const char *idx_temp = config_json["IDX"].get<string>().c_str();
irsanjul 1:021273f6b9f4 162 // PortListen = config_json["PortListen"].get<int>();
irsanjul 1:021273f6b9f4 163 // PortSend = config_json["PortSend"].get<int>();
irsanjul 1:021273f6b9f4 164 // PortHeartB = config_json["PortHeartBit"].get<int>();
irsanjul 1:021273f6b9f4 165 BAUD = config_json["BAUD"].get<int>();
irsanjul 1:021273f6b9f4 166
irsanjul 1:021273f6b9f4 167 sprintf(IP,"%s", ip_temp);
irsanjul 1:021273f6b9f4 168 sprintf(SUBNET, "%s", sub_temp);
irsanjul 1:021273f6b9f4 169 sprintf(GATEWAY, "%s", gate_temp);
irsanjul 1:021273f6b9f4 170 sprintf(MCAST, "%s", mcast_temp);
irsanjul 1:021273f6b9f4 171 sprintf(IDX, "%s", idx_temp);
irsanjul 1:021273f6b9f4 172
irsanjul 1:021273f6b9f4 173 dbg.printf("IP Device = %s\r\n", IP);
irsanjul 1:021273f6b9f4 174 dbg.printf("Subnet = %s\r\n", SUBNET);
irsanjul 1:021273f6b9f4 175 dbg.printf("Gateway = %s\r\n", GATEWAY);
irsanjul 1:021273f6b9f4 176 dbg.printf("Multicast IP = %s\r\n", MCAST);
irsanjul 1:021273f6b9f4 177 // dbg.printf("Server to mBed = %d\r\n", PortListen);
irsanjul 1:021273f6b9f4 178 // dbg.printf("mBed to Multicast = %d\r\n", PortSend);
irsanjul 1:021273f6b9f4 179 // dbg.printf("HeartBeat Port = %d\r\n", PortHeartB);
irsanjul 1:021273f6b9f4 180 dbg.printf("device IDX = %s\r\n", IDX);
irsanjul 1:021273f6b9f4 181 dbg.printf("Serial Baudrate = %d\r\n", BAUD);
irsanjul 1:021273f6b9f4 182
irsanjul 1:021273f6b9f4 183 return true;
irsanjul 0:fbb75122015f 184 }
irsanjul 1:021273f6b9f4 185 }
irsanjul 1:021273f6b9f4 186 else
irsanjul 1:021273f6b9f4 187 {
irsanjul 1:021273f6b9f4 188 dbg.printf("Config is not found\r\n");
irsanjul 1:021273f6b9f4 189 return false;
irsanjul 1:021273f6b9f4 190 }
irsanjul 0:fbb75122015f 191 }
irsanjul 0:fbb75122015f 192
irsanjul 0:fbb75122015f 193 unsigned char reset(void) {
irsanjul 0:fbb75122015f 194 for (idx = 0; idx < 8; idx++) {
irsanjul 0:fbb75122015f 195 ID[idx] = 0;
irsanjul 0:fbb75122015f 196 }
irsanjul 0:fbb75122015f 197 ix = 0;
irsanjul 0:fbb75122015f 198 iBtn.output();
irsanjul 0:fbb75122015f 199 iBtn.write(0);
irsanjul 0:fbb75122015f 200 wait_us(480);
irsanjul 0:fbb75122015f 201 iBtn.write(1);
irsanjul 0:fbb75122015f 202 iBtn.mode(PullUp);
irsanjul 0:fbb75122015f 203 iBtn.input();
irsanjul 0:fbb75122015f 204
irsanjul 0:fbb75122015f 205 for (int i = 0; i < 180; i++) {
irsanjul 0:fbb75122015f 206 wait_us(1);
irsanjul 0:fbb75122015f 207 if (iBtn == 0) {
irsanjul 0:fbb75122015f 208 ix = 1;
irsanjul 0:fbb75122015f 209 }
irsanjul 0:fbb75122015f 210 }
irsanjul 0:fbb75122015f 211 wait_us(1);
irsanjul 0:fbb75122015f 212 if (ix == 0) {
irsanjul 0:fbb75122015f 213 return 0;
irsanjul 0:fbb75122015f 214 } else
irsanjul 0:fbb75122015f 215 return 1;
irsanjul 0:fbb75122015f 216 }
irsanjul 0:fbb75122015f 217
irsanjul 0:fbb75122015f 218 int write() {
irsanjul 0:fbb75122015f 219 iBtn.output();
irsanjul 0:fbb75122015f 220 iBtn.write(1);
irsanjul 0:fbb75122015f 221 for (idx = 0; idx < 8; idx++) {
irsanjul 0:fbb75122015f 222 for (int i = 0; i < 35; i++) {
irsanjul 0:fbb75122015f 223 wait_us(1);
irsanjul 0:fbb75122015f 224 if (i >= 2) {
irsanjul 0:fbb75122015f 225 iBtn.write((id_addr >> idx) & 1);
irsanjul 0:fbb75122015f 226 } else
irsanjul 0:fbb75122015f 227 iBtn.write(0);
irsanjul 0:fbb75122015f 228 }
irsanjul 0:fbb75122015f 229 iBtn.write(1);
irsanjul 0:fbb75122015f 230 }
irsanjul 0:fbb75122015f 231 wait_us(2);
irsanjul 0:fbb75122015f 232 return 0;
irsanjul 0:fbb75122015f 233 }
irsanjul 0:fbb75122015f 234
irsanjul 0:fbb75122015f 235 int read() {
irsanjul 0:fbb75122015f 236 iBtn.output();
irsanjul 0:fbb75122015f 237 iBtn.write(1);
irsanjul 0:fbb75122015f 238 for (idx = 0; idx < 8; idx++) {
irsanjul 0:fbb75122015f 239 for (idy = 0; idy < 8; idy++) {
irsanjul 0:fbb75122015f 240 width = 0;
irsanjul 0:fbb75122015f 241 iBtn.output();
irsanjul 0:fbb75122015f 242 iBtn.write(0);
irsanjul 0:fbb75122015f 243 wait_us(1);
irsanjul 0:fbb75122015f 244 iBtn.input();
irsanjul 0:fbb75122015f 245 for (int i = 0; i < 35; i++) {
irsanjul 0:fbb75122015f 246 wait_us(1);
irsanjul 0:fbb75122015f 247 if (iBtn.read()) {
irsanjul 0:fbb75122015f 248 width++;
irsanjul 0:fbb75122015f 249 }
irsanjul 0:fbb75122015f 250 }
irsanjul 0:fbb75122015f 251 if (width > 25) {
irsanjul 0:fbb75122015f 252 ID[idx] |= (1 << idy);
irsanjul 0:fbb75122015f 253 }
irsanjul 0:fbb75122015f 254 }
irsanjul 0:fbb75122015f 255 }
irsanjul 0:fbb75122015f 256
irsanjul 0:fbb75122015f 257 for (idx = 0; idx < 8; idx++) {
irsanjul 1:021273f6b9f4 258 text[((7 - idx) * 2) + 7] = _hex[ID[idx] & 0x0f];
irsanjul 1:021273f6b9f4 259 text[((7 - idx) * 2) + 6] = _hex[(ID[idx] >> 4) & 0x0f];
irsanjul 0:fbb75122015f 260 }
irsanjul 1:021273f6b9f4 261 string str;
irsanjul 1:021273f6b9f4 262 size_t found1;
irsanjul 0:fbb75122015f 263 str += text;
irsanjul 0:fbb75122015f 264
irsanjul 0:fbb75122015f 265 found1 = str.find("FFFFFFFFFF");
irsanjul 0:fbb75122015f 266 if(found1 == std::string::npos)
irsanjul 0:fbb75122015f 267 {
irsanjul 0:fbb75122015f 268 found1 = str.find("000000000000");
irsanjul 0:fbb75122015f 269 if(found1 == std::string::npos)
irsanjul 0:fbb75122015f 270 {
irsanjul 0:fbb75122015f 271 dbg.printf(text);
irsanjul 0:fbb75122015f 272 dbg.printf("\r\n");
irsanjul 0:fbb75122015f 273 }
irsanjul 0:fbb75122015f 274 }
irsanjul 0:fbb75122015f 275 return 0;
irsanjul 0:fbb75122015f 276 }
irsanjul 0:fbb75122015f 277
irsanjul 0:fbb75122015f 278 int cmpstr(const char *str, const char *sub) {
irsanjul 0:fbb75122015f 279 int length = strlen(sub);
irsanjul 0:fbb75122015f 280 if (length == 0)
irsanjul 0:fbb75122015f 281 return 0;
irsanjul 0:fbb75122015f 282 int count = 0;
irsanjul 0:fbb75122015f 283 for (str = strstr(str, sub); str; str = strstr(str + length, sub))
irsanjul 0:fbb75122015f 284 ++count;
irsanjul 0:fbb75122015f 285 return count;
irsanjul 0:fbb75122015f 286 }
irsanjul 0:fbb75122015f 287
irsanjul 0:fbb75122015f 288 void Hartbit(unsigned char std) {
irsanjul 0:fbb75122015f 289 char hb_buff[20], hb_num[10];
irsanjul 0:fbb75122015f 290 static int hb;
irsanjul 0:fbb75122015f 291 hb_buff[0] = IDX[0];
irsanjul 0:fbb75122015f 292 hb_buff[1] = IDX[1];
irsanjul 0:fbb75122015f 293 hb_buff[2] = IDX[2];
irsanjul 0:fbb75122015f 294 hb_buff[3] = IDX[3];
irsanjul 0:fbb75122015f 295
irsanjul 0:fbb75122015f 296 multi.set_address(MCAST, atoi(PortHeartB));
irsanjul 0:fbb75122015f 297 hb++;
irsanjul 0:fbb75122015f 298
irsanjul 0:fbb75122015f 299 switch (std) {
irsanjul 0:fbb75122015f 300 case 0:
irsanjul 0:fbb75122015f 301 //Standby(0, 1);
irsanjul 0:fbb75122015f 302 if (hb < 375) {
irsanjul 0:fbb75122015f 303 Sopir(0, 1);
irsanjul 0:fbb75122015f 304 } else if ((hb >= 375) && (hb < 750)) {
irsanjul 0:fbb75122015f 305 Sopir(0, 0);
irsanjul 0:fbb75122015f 306 } else if ((hb >= 750) && (hb < 1125)) {
irsanjul 0:fbb75122015f 307 Sopir(0, 1);
irsanjul 0:fbb75122015f 308 } else if ((hb >= 1125) && (hb < 1500))
irsanjul 0:fbb75122015f 309 Sopir(0, 0);
irsanjul 0:fbb75122015f 310 if (hb >= 1500) {
irsanjul 0:fbb75122015f 311 sprintf(hb_num, "%d", TICK);
irsanjul 0:fbb75122015f 312 strcat(hb_buff, hb_num);
irsanjul 0:fbb75122015f 313 sock.sendTo(multi, hb_buff, sizeof(hb_buff));
irsanjul 0:fbb75122015f 314 hb = 0;
irsanjul 0:fbb75122015f 315 TICK++;
irsanjul 0:fbb75122015f 316 }
irsanjul 0:fbb75122015f 317 break;
irsanjul 0:fbb75122015f 318 case 1:
irsanjul 0:fbb75122015f 319 Standby(0, 0);
irsanjul 0:fbb75122015f 320 Standby(0, 1);
irsanjul 0:fbb75122015f 321 if (hb < 750) {
irsanjul 0:fbb75122015f 322 Standby(0, 1);
irsanjul 0:fbb75122015f 323 } else if ((hb >= 750) && (hb < 1500)) {
irsanjul 0:fbb75122015f 324 Standby(0, 0);
irsanjul 0:fbb75122015f 325 } else if ((hb >= 1500) && (hb < 2250)) {
irsanjul 0:fbb75122015f 326 Standby(0, 1);
irsanjul 0:fbb75122015f 327 } else if ((hb >= 2250) && (hb < 3000))
irsanjul 0:fbb75122015f 328 Standby(0, 0);
irsanjul 0:fbb75122015f 329 if (hb >= 3000) {
irsanjul 0:fbb75122015f 330 sprintf(hb_num, "%d", TICK);
irsanjul 0:fbb75122015f 331 strcat(hb_buff, hb_num);
irsanjul 0:fbb75122015f 332 sock.sendTo(multi, hb_buff, sizeof(hb_buff));
irsanjul 0:fbb75122015f 333 hb = 0;
irsanjul 0:fbb75122015f 334 TICK++;
irsanjul 0:fbb75122015f 335 }
irsanjul 0:fbb75122015f 336
irsanjul 0:fbb75122015f 337 break;
irsanjul 0:fbb75122015f 338 case 2:
irsanjul 0:fbb75122015f 339 Standby(0, 1);
irsanjul 0:fbb75122015f 340 if (hb >= 7000) {
irsanjul 0:fbb75122015f 341 sprintf(hb_num, "%d", TICK);
irsanjul 0:fbb75122015f 342 strcat(hb_buff, hb_num);
irsanjul 0:fbb75122015f 343 sock.sendTo(multi, hb_buff, sizeof(hb_buff));
irsanjul 0:fbb75122015f 344 hb = 0;
irsanjul 0:fbb75122015f 345 TICK++;
irsanjul 0:fbb75122015f 346 }
irsanjul 0:fbb75122015f 347 break;
irsanjul 0:fbb75122015f 348 }
irsanjul 0:fbb75122015f 349 }
irsanjul 0:fbb75122015f 350
irsanjul 0:fbb75122015f 351 int openForce() {
irsanjul 0:fbb75122015f 352 int n = sock.receiveFrom(server, rx_buff, sizeof(rx_buff));
irsanjul 0:fbb75122015f 353
irsanjul 0:fbb75122015f 354 if (n != 0) {
irsanjul 0:fbb75122015f 355 if ((rx_buff[1] == 'V') && (rx_buff[3] == '5')) {
irsanjul 0:fbb75122015f 356 eMTy(0, 0);
irsanjul 0:fbb75122015f 357 Sopir(0, 0);
irsanjul 0:fbb75122015f 358 wait(1);
irsanjul 0:fbb75122015f 359 Gate = 1; //BYPASS
irsanjul 0:fbb75122015f 360 wait_ms(1500); //BYPASS
irsanjul 0:fbb75122015f 361 Gate = 0; //BYPASS
irsanjul 0:fbb75122015f 362 sprmt = 0;
irsanjul 0:fbb75122015f 363 tx_buff[4] = 'P';
irsanjul 0:fbb75122015f 364 tx_buff[5] = '0';
irsanjul 0:fbb75122015f 365 tx_buff[6] = '0';
irsanjul 0:fbb75122015f 366 multi.set_address(MCAST, atoi(PortSend));
irsanjul 0:fbb75122015f 367 sock.sendTo(multi, tx_buff, sizeof(tx_buff));
irsanjul 0:fbb75122015f 368 } else if (rx_buff[1] == 'R') {
irsanjul 0:fbb75122015f 369 tx_buff[4] = 'P';
irsanjul 0:fbb75122015f 370 tx_buff[5] = '0';
irsanjul 0:fbb75122015f 371 tx_buff[6] = '0';
irsanjul 0:fbb75122015f 372 sprmt = 0;
irsanjul 0:fbb75122015f 373 multi.set_address(MCAST, atoi(PortSend));
irsanjul 0:fbb75122015f 374 sock.sendTo(multi, tx_buff, sizeof(tx_buff));
irsanjul 0:fbb75122015f 375 eMTy(0, 0);
irsanjul 0:fbb75122015f 376 Sopir(0, 0);
irsanjul 0:fbb75122015f 377 Gate = 0;
irsanjul 0:fbb75122015f 378 }
irsanjul 0:fbb75122015f 379 } else {
irsanjul 0:fbb75122015f 380 return 0;
irsanjul 0:fbb75122015f 381 }
irsanjul 0:fbb75122015f 382 return 0;
irsanjul 0:fbb75122015f 383 }
irsanjul 0:fbb75122015f 384
irsanjul 0:fbb75122015f 385 int set_IP() {
irsanjul 0:fbb75122015f 386 char ptr_data;
irsanjul 0:fbb75122015f 387 //server.set_address(SERVER,ER_SEND_PORT);
irsanjul 0:fbb75122015f 388 //char print_rx_buff[128];
irsanjul 1:021273f6b9f4 389 char conf_buff[1024] = { 0 };
irsanjul 1:021273f6b9f4 390 // char print_init[20] = { 0x1b, 0x40, 0x1b, 0x54,
irsanjul 1:021273f6b9f4 391 // 0x1b, 0x57, 0x00, 0x1b, 0x77, 0x00, 0x12, 0x1b, 0x43, 0x00, 0x06,
irsanjul 1:021273f6b9f4 392 // 0x1b, 0x6c, 0x01, 0x12 }
irsanjul 1:021273f6b9f4 393 //
irsanjul 0:fbb75122015f 394 int n = ip_conf.receiveFrom(server, conf_buff, sizeof(conf_buff));
irsanjul 0:fbb75122015f 395 if (n >= 0) {
irsanjul 0:fbb75122015f 396 //printf("Packet from \"%s\": %s\n", server.get_address(), conf_buff);
irsanjul 0:fbb75122015f 397 if (conf_buff[0] == '^') {
irsanjul 0:fbb75122015f 398 if (conf_buff[1] == 'R') {
irsanjul 0:fbb75122015f 399 Reset = 0;
irsanjul 0:fbb75122015f 400 } else if (conf_buff[1] == 'S') {
irsanjul 0:fbb75122015f 401 Sleep = 1;
irsanjul 0:fbb75122015f 402 Gate = 0;
irsanjul 0:fbb75122015f 403
irsanjul 0:fbb75122015f 404 int stop = 0;
irsanjul 0:fbb75122015f 405 while(stop != 1)
irsanjul 0:fbb75122015f 406 {
irsanjul 1:021273f6b9f4 407 Spr_G = 0;
irsanjul 1:021273f6b9f4 408 Mt_G = 0;
irsanjul 1:021273f6b9f4 409 Std_G = 0;
irsanjul 0:fbb75122015f 410
irsanjul 0:fbb75122015f 411 ip_conf.receiveFrom(server, conf_buff, sizeof(conf_buff));
irsanjul 0:fbb75122015f 412
irsanjul 0:fbb75122015f 413 if (conf_buff[0] == '^')
irsanjul 0:fbb75122015f 414 {
irsanjul 0:fbb75122015f 415 if (conf_buff[1] == 'W')
irsanjul 0:fbb75122015f 416 {
irsanjul 0:fbb75122015f 417 stop = 1;
irsanjul 0:fbb75122015f 418 Sleep = 0;
irsanjul 0:fbb75122015f 419 }
irsanjul 0:fbb75122015f 420 else if (conf_buff[1] == 'R')
irsanjul 0:fbb75122015f 421 {
irsanjul 0:fbb75122015f 422 stop = 0;
irsanjul 0:fbb75122015f 423 }
irsanjul 0:fbb75122015f 424 else if (conf_buff[1] == 'S')
irsanjul 0:fbb75122015f 425 {
irsanjul 0:fbb75122015f 426 stop = 0;
irsanjul 0:fbb75122015f 427 }
irsanjul 0:fbb75122015f 428 else stop = 0;
irsanjul 0:fbb75122015f 429 }
irsanjul 0:fbb75122015f 430 else if (conf_buff[0] == '2') stop = 0;
irsanjul 0:fbb75122015f 431
irsanjul 0:fbb75122015f 432 else stop = 0;
irsanjul 0:fbb75122015f 433 }
irsanjul 0:fbb75122015f 434 //sock.close(true);
irsanjul 0:fbb75122015f 435 } else if (conf_buff[1] == 'W') {
irsanjul 0:fbb75122015f 436 Sleep = 0;
irsanjul 0:fbb75122015f 437 //sock.bind(atoi(PortListen));
irsanjul 0:fbb75122015f 438 }
irsanjul 0:fbb75122015f 439 } else if (conf_buff[0] == 0x0f) {
irsanjul 1:021273f6b9f4 440 // printer.printf("%s", print_init);
irsanjul 1:021273f6b9f4 441 printer.printf("%s", conf_buff);
irsanjul 0:fbb75122015f 442 ptr_data = *strchr(conf_buff, 0x1d);
irsanjul 0:fbb75122015f 443 if (ptr_data != NULL) {
irsanjul 0:fbb75122015f 444 tx_buff[4] = 'D';
irsanjul 0:fbb75122015f 445 tx_buff[5] = '0';
irsanjul 0:fbb75122015f 446 tx_buff[6] = '1';
irsanjul 0:fbb75122015f 447 multi.set_address(MCAST, atoi(PortSend));
irsanjul 0:fbb75122015f 448 sock.sendTo(multi, tx_buff, sizeof(tx_buff));
irsanjul 0:fbb75122015f 449 dbg.printf("Printer Done\r\n");
irsanjul 0:fbb75122015f 450 }
irsanjul 0:fbb75122015f 451 } else
irsanjul 0:fbb75122015f 452 return 0;
irsanjul 0:fbb75122015f 453 } else {
irsanjul 0:fbb75122015f 454 return 0;
irsanjul 0:fbb75122015f 455 }
irsanjul 0:fbb75122015f 456 return 0;
irsanjul 0:fbb75122015f 457 }
irsanjul 0:fbb75122015f 458
irsanjul 0:fbb75122015f 459 void flush(void)
irsanjul 0:fbb75122015f 460 {
irsanjul 0:fbb75122015f 461 int chk;
irsanjul 0:fbb75122015f 462 do
irsanjul 0:fbb75122015f 463 {
irsanjul 0:fbb75122015f 464 char flush_buff[1024] = { 0 };
irsanjul 0:fbb75122015f 465 chk = ip_conf.receiveFrom(server, flush_buff, sizeof(flush_buff));
irsanjul 0:fbb75122015f 466 //clear flush_buff
irsanjul 0:fbb75122015f 467 for(int i = 0; i <sizeof(flush_buff); i++)
irsanjul 0:fbb75122015f 468 {
irsanjul 0:fbb75122015f 469 flush_buff[i] = '\0';
irsanjul 0:fbb75122015f 470 }
irsanjul 0:fbb75122015f 471 }while (chk > 0);
irsanjul 0:fbb75122015f 472 }
irsanjul 0:fbb75122015f 473
irsanjul 0:fbb75122015f 474 void Set_IP_Manual()
irsanjul 0:fbb75122015f 475 {
irsanjul 1:021273f6b9f4 476 sprintf(IP,"192.168.1.14");
irsanjul 0:fbb75122015f 477 sprintf(SUBNET, "255.255.255.0");
irsanjul 1:021273f6b9f4 478 sprintf(GATEWAY, "192.168.1.1");
irsanjul 0:fbb75122015f 479 sprintf(MCAST, "224.1.1.8");
irsanjul 0:fbb75122015f 480 sprintf(PortListen, "50007");
irsanjul 0:fbb75122015f 481 sprintf(PortSend, "50001");
irsanjul 0:fbb75122015f 482 sprintf(PortHeartB, "50003");
irsanjul 0:fbb75122015f 483 sprintf(IDX, "GI01");
irsanjul 0:fbb75122015f 484 BAUD = 19200;
irsanjul 0:fbb75122015f 485
irsanjul 0:fbb75122015f 486 dbg.printf("IP Device = %s\r\n", IP);
irsanjul 0:fbb75122015f 487 dbg.printf("Subnet = %s\r\n", SUBNET);
irsanjul 0:fbb75122015f 488 dbg.printf("Gateway = %s\r\n", GATEWAY);
irsanjul 0:fbb75122015f 489 dbg.printf("Multicast IP = %s\r\n", MCAST);
irsanjul 0:fbb75122015f 490 dbg.printf("Server to mBed = %s\r\n", PortListen);
irsanjul 0:fbb75122015f 491 dbg.printf("mBed to Multicast = %s\r\n", PortSend);
irsanjul 0:fbb75122015f 492 dbg.printf("HeartBeat Port = %s\r\n", PortHeartB);
irsanjul 0:fbb75122015f 493 dbg.printf("device IDX = %s\r\n", IDX);
irsanjul 1:021273f6b9f4 494 dbg.printf("Printer Baud = %d\r\n", BAUD);
irsanjul 0:fbb75122015f 495 }
irsanjul 0:fbb75122015f 496
irsanjul 0:fbb75122015f 497 int main(void) {
irsanjul 1:021273f6b9f4 498 // mkdir("/sd/", 0777);
irsanjul 0:fbb75122015f 499
irsanjul 1:021273f6b9f4 500 // mbed_config_init(); // Digunakan jika setting ip melalui micro sd
irsanjul 0:fbb75122015f 501 Set_IP_Manual(); // Digunakan jika setting ip secara manual
irsanjul 0:fbb75122015f 502
irsanjul 1:021273f6b9f4 503 printer.baud(BAUD);
irsanjul 1:021273f6b9f4 504 dbg.baud(9600);
irsanjul 0:fbb75122015f 505 dbg.printf("System Start \r\n");
irsanjul 0:fbb75122015f 506
irsanjul 0:fbb75122015f 507 EthernetInterface eth;
irsanjul 0:fbb75122015f 508 eth.init(IP, SUBNET, GATEWAY);
irsanjul 0:fbb75122015f 509 int n = eth.connect();
irsanjul 0:fbb75122015f 510 if (!n) {
irsanjul 0:fbb75122015f 511 dbg.printf("Ethernet is not connect");
irsanjul 0:fbb75122015f 512 } else
irsanjul 0:fbb75122015f 513 dbg.printf("Ethernet is connect");
irsanjul 0:fbb75122015f 514
irsanjul 0:fbb75122015f 515 ip_conf.bind(IP_CONF_PORT);
irsanjul 0:fbb75122015f 516 ip_conf.set_blocking(false, 0);
irsanjul 0:fbb75122015f 517 server.set_address(MCAST, 50002);
irsanjul 0:fbb75122015f 518
irsanjul 0:fbb75122015f 519 sock.bind(atoi(PortListen));
irsanjul 0:fbb75122015f 520
irsanjul 0:fbb75122015f 521 sock.set_blocking(false, 0);
irsanjul 0:fbb75122015f 522
irsanjul 0:fbb75122015f 523 text[0] = 2;
irsanjul 0:fbb75122015f 524 text[1] = IDX[0];
irsanjul 0:fbb75122015f 525 text[2] = IDX[1];
irsanjul 0:fbb75122015f 526 text[3] = IDX[2];
irsanjul 0:fbb75122015f 527 text[4] = IDX[3];
irsanjul 0:fbb75122015f 528 text[22] = '0';
irsanjul 0:fbb75122015f 529 text[23] = '0';
irsanjul 0:fbb75122015f 530 text[24] = 3;
irsanjul 0:fbb75122015f 531 unsigned char tmp, sndrcv = 0, tmpx = 0;
irsanjul 0:fbb75122015f 532 int timeout = 0;
irsanjul 0:fbb75122015f 533
irsanjul 0:fbb75122015f 534 dbg.printf("Device Ready\r\n");
irsanjul 0:fbb75122015f 535
irsanjul 0:fbb75122015f 536 tx_buff[0] = IDX[0];
irsanjul 0:fbb75122015f 537 tx_buff[1] = IDX[1];
irsanjul 0:fbb75122015f 538 tx_buff[2] = IDX[2];
irsanjul 0:fbb75122015f 539 tx_buff[3] = IDX[3];
irsanjul 0:fbb75122015f 540 tx_buff[4] = 'R';
irsanjul 0:fbb75122015f 541 tx_buff[5] = '0';
irsanjul 0:fbb75122015f 542
irsanjul 0:fbb75122015f 543 multi.set_address(MCAST, atoi(PortSend));
irsanjul 0:fbb75122015f 544 sock.sendTo(multi, tx_buff, sizeof(tx_buff));
irsanjul 0:fbb75122015f 545
irsanjul 0:fbb75122015f 546 eMTy(ijo, 0);
irsanjul 0:fbb75122015f 547 eMTy(merah, 0);
irsanjul 0:fbb75122015f 548 Sopir(ijo, 0);
irsanjul 0:fbb75122015f 549 Sopir(merah, 0);
irsanjul 0:fbb75122015f 550 Standby(ijo, 0);
irsanjul 0:fbb75122015f 551 Standby(merah, 0);
irsanjul 0:fbb75122015f 552 Res_R = 1;
irsanjul 0:fbb75122015f 553
irsanjul 0:fbb75122015f 554 flush(); // clear ethernet port
irsanjul 0:fbb75122015f 555
irsanjul 0:fbb75122015f 556 while (true) {
irsanjul 0:fbb75122015f 557 for (idx = 0; idx < 6; idx++) {
irsanjul 0:fbb75122015f 558 rx_buff[idx] = 0;
irsanjul 0:fbb75122015f 559 }
irsanjul 0:fbb75122015f 560
irsanjul 0:fbb75122015f 561 switch (sndrcv) {
irsanjul 0:fbb75122015f 562 case 0: {
irsanjul 0:fbb75122015f 563 tmp = reset();
irsanjul 0:fbb75122015f 564
irsanjul 0:fbb75122015f 565 if (tmp == 1) {
irsanjul 0:fbb75122015f 566 if (tmpx == 0) {
irsanjul 0:fbb75122015f 567 if (sprmt == 0) {
irsanjul 0:fbb75122015f 568 Sopir(0, 1);
irsanjul 0:fbb75122015f 569 } else {
irsanjul 0:fbb75122015f 570 eMTy(0, 1);
irsanjul 0:fbb75122015f 571 }
irsanjul 0:fbb75122015f 572 wait_ms(70);
irsanjul 0:fbb75122015f 573 reset();
irsanjul 0:fbb75122015f 574 write();
irsanjul 0:fbb75122015f 575 read();
irsanjul 0:fbb75122015f 576 if (sprmt == 0) {
irsanjul 0:fbb75122015f 577 Sopir(0, 0);
irsanjul 0:fbb75122015f 578 text[5] = 'S';
irsanjul 0:fbb75122015f 579 } else {
irsanjul 0:fbb75122015f 580 eMTy(0, 0);
irsanjul 0:fbb75122015f 581 text[5] = 'M';
irsanjul 0:fbb75122015f 582 }
irsanjul 0:fbb75122015f 583 if (cmpstr(text, "F") < 10) {
irsanjul 0:fbb75122015f 584 multi.set_address(MCAST, atoi(PortSend));
irsanjul 0:fbb75122015f 585 sock.sendTo(multi, text, sizeof(text));
irsanjul 0:fbb75122015f 586 sndrcv = 1;
irsanjul 0:fbb75122015f 587 }
irsanjul 0:fbb75122015f 588 }
irsanjul 0:fbb75122015f 589 }
irsanjul 0:fbb75122015f 590
irsanjul 0:fbb75122015f 591 if (sprmt == 0) {
irsanjul 0:fbb75122015f 592 if (sndrcv == 1) {
irsanjul 0:fbb75122015f 593 Hartbit(2);
irsanjul 0:fbb75122015f 594 } else
irsanjul 0:fbb75122015f 595 Hartbit(1);
irsanjul 0:fbb75122015f 596 } else if (sprmt == 1)
irsanjul 0:fbb75122015f 597 Hartbit(0);
irsanjul 0:fbb75122015f 598
irsanjul 0:fbb75122015f 599 tmpx = tmp;
irsanjul 0:fbb75122015f 600 openForce();
irsanjul 0:fbb75122015f 601 break;
irsanjul 0:fbb75122015f 602 }
irsanjul 0:fbb75122015f 603 case 1: {
irsanjul 0:fbb75122015f 604 sock.bind(atoi(PortListen));
irsanjul 0:fbb75122015f 605
irsanjul 0:fbb75122015f 606 int n = sock.receiveFrom(server, rx_buff, sizeof(rx_buff));
irsanjul 0:fbb75122015f 607 if (n != 0) {
irsanjul 0:fbb75122015f 608 dbg.printf("Packet from \"%s\": %s\n", server.get_address(),
irsanjul 0:fbb75122015f 609 rx_buff);
irsanjul 0:fbb75122015f 610 if ((rx_buff[1] == 'V') && (rx_buff[3] == '3')) {
irsanjul 0:fbb75122015f 611 sndrcv = 0;
irsanjul 0:fbb75122015f 612 Sopir(0, 1);
irsanjul 0:fbb75122015f 613 sprmt = 1;
irsanjul 0:fbb75122015f 614 tx_buff[4] = 'O';
irsanjul 0:fbb75122015f 615 tx_buff[5] = 'K';
irsanjul 0:fbb75122015f 616 tx_buff[6] = '!';
irsanjul 0:fbb75122015f 617 multi.set_address(MCAST, atoi(PortSend));
irsanjul 0:fbb75122015f 618 sock.sendTo(multi, tx_buff, sizeof(tx_buff));
irsanjul 0:fbb75122015f 619 dbg.printf("Data S Valid..\r\n");
irsanjul 0:fbb75122015f 620 } else if ((rx_buff[1] == 'A') && (rx_buff[3] == '3')) {
irsanjul 0:fbb75122015f 621 sndrcv = 0;
irsanjul 0:fbb75122015f 622 Sopir(0, 0);
irsanjul 0:fbb75122015f 623 eMTy(0, 1);
irsanjul 0:fbb75122015f 624 wait_ms(200);
irsanjul 0:fbb75122015f 625 eMTy(0, 0);
irsanjul 0:fbb75122015f 626 sprmt = 0;
irsanjul 0:fbb75122015f 627 tx_buff[4] = 'O';
irsanjul 0:fbb75122015f 628 tx_buff[5] = 'K';
irsanjul 0:fbb75122015f 629 tx_buff[6] = '!';
irsanjul 0:fbb75122015f 630 multi.set_address(MCAST, atoi(PortSend));
irsanjul 0:fbb75122015f 631 sock.sendTo(multi, tx_buff, sizeof(tx_buff));
irsanjul 0:fbb75122015f 632 dbg.printf("Data S Not Valid, but M valid, reset!!!!\r\n");
irsanjul 0:fbb75122015f 633 } else if ((rx_buff[1] == 'V') && (rx_buff[3] == '4')) {
irsanjul 0:fbb75122015f 634 Sopir(0, 1);
irsanjul 0:fbb75122015f 635 eMTy(0, 1);
irsanjul 0:fbb75122015f 636 wait_ms(500);
irsanjul 0:fbb75122015f 637 /*
irsanjul 0:fbb75122015f 638 Lakukan perubahan disini menyangkut dengan:
irsanjul 0:fbb75122015f 639 - delay lebih lama
irsanjul 0:fbb75122015f 640 - sprmt yang ditambah
irsanjul 0:fbb75122015f 641 */
irsanjul 0:fbb75122015f 642 tx_buff[4] = 'O';
irsanjul 0:fbb75122015f 643 tx_buff[5] = 'K';
irsanjul 0:fbb75122015f 644 tx_buff[6] = '!';
irsanjul 0:fbb75122015f 645 multi.set_address(MCAST, atoi(PortSend));
irsanjul 0:fbb75122015f 646 sock.sendTo(multi, tx_buff, sizeof(tx_buff));
irsanjul 0:fbb75122015f 647 dbg.printf("Data M Valid..\r\n");
irsanjul 0:fbb75122015f 648 } else if ((rx_buff[1] == 'A') && (rx_buff[3] == '4')) {
irsanjul 0:fbb75122015f 649 sndrcv = 0;
irsanjul 0:fbb75122015f 650 if (sprmt == 0) {
irsanjul 0:fbb75122015f 651 Sopir(0, 0);
irsanjul 0:fbb75122015f 652 } else {
irsanjul 0:fbb75122015f 653 Sopir(0, 1);
irsanjul 0:fbb75122015f 654 }
irsanjul 0:fbb75122015f 655 eMTy(0, 0);
irsanjul 0:fbb75122015f 656 tx_buff[4] = 'O';
irsanjul 0:fbb75122015f 657 tx_buff[5] = 'K';
irsanjul 0:fbb75122015f 658 tx_buff[6] = '!';
irsanjul 0:fbb75122015f 659 multi.set_address(MCAST, atoi(PortSend));
irsanjul 0:fbb75122015f 660 sock.sendTo(multi, tx_buff, sizeof(tx_buff));
irsanjul 0:fbb75122015f 661 dbg.printf("Data M Not Valid, refresh!!!!\r\n");
irsanjul 0:fbb75122015f 662 } else if (rx_buff[1] == 'R') {
irsanjul 0:fbb75122015f 663 sndrcv = 0;
irsanjul 0:fbb75122015f 664 Sopir(0, 0);
irsanjul 0:fbb75122015f 665 eMTy(0, 0);
irsanjul 0:fbb75122015f 666 sprmt = 0;
irsanjul 0:fbb75122015f 667 tx_buff[4] = 'O';
irsanjul 0:fbb75122015f 668 tx_buff[5] = 'K';
irsanjul 0:fbb75122015f 669 tx_buff[6] = '!';
irsanjul 0:fbb75122015f 670 multi.set_address(MCAST, atoi(PortSend));
irsanjul 0:fbb75122015f 671 sock.sendTo(multi, tx_buff, sizeof(tx_buff));
irsanjul 0:fbb75122015f 672 dbg.printf("All Data Not Valid, reset!!!!\r\n");
irsanjul 0:fbb75122015f 673 }
irsanjul 0:fbb75122015f 674 } else {
irsanjul 0:fbb75122015f 675 timeout++;
irsanjul 0:fbb75122015f 676 if (timeout >= 12000) {
irsanjul 0:fbb75122015f 677 sndrcv = 0;
irsanjul 0:fbb75122015f 678 timeout = 0;
irsanjul 0:fbb75122015f 679 }
irsanjul 0:fbb75122015f 680 }
irsanjul 0:fbb75122015f 681 Stdby_R = 1;
irsanjul 0:fbb75122015f 682 openForce();
irsanjul 0:fbb75122015f 683 break;
irsanjul 0:fbb75122015f 684 }
irsanjul 0:fbb75122015f 685 }
irsanjul 0:fbb75122015f 686
irsanjul 0:fbb75122015f 687 // membaca perintah dari server dari port 5004
irsanjul 0:fbb75122015f 688 set_IP();
irsanjul 0:fbb75122015f 689
irsanjul 0:fbb75122015f 690 // cek printer
irsanjul 0:fbb75122015f 691 if (!print_er) {
irsanjul 0:fbb75122015f 692 er_tmp2 = 0;
irsanjul 0:fbb75122015f 693 if (er_tmp1 < 3) {
irsanjul 0:fbb75122015f 694 tx_buff[4] = 'X';
irsanjul 0:fbb75122015f 695 tx_buff[5] = '0';
irsanjul 0:fbb75122015f 696 tx_buff[6] = '1';
irsanjul 0:fbb75122015f 697 multi.set_address(MCAST, atoi(PortSend));
irsanjul 0:fbb75122015f 698 dbg.printf("Printer Error\r\n");
irsanjul 0:fbb75122015f 699 sock.sendTo(multi, tx_buff, sizeof(tx_buff));
irsanjul 0:fbb75122015f 700 } else
irsanjul 0:fbb75122015f 701 er_tmp1 = 5;
irsanjul 0:fbb75122015f 702 er_tmp1++;
irsanjul 0:fbb75122015f 703 } else if (print_er) {
irsanjul 0:fbb75122015f 704 er_tmp1 = 0;
irsanjul 0:fbb75122015f 705 if (er_tmp2 < 3) {
irsanjul 0:fbb75122015f 706 tx_buff[4] = 'N';
irsanjul 0:fbb75122015f 707 tx_buff[5] = '0';
irsanjul 0:fbb75122015f 708 tx_buff[6] = '1';
irsanjul 0:fbb75122015f 709 dbg.printf("Printer Fixed\r\n");
irsanjul 0:fbb75122015f 710 multi.set_address(MCAST, atoi(PortSend));
irsanjul 0:fbb75122015f 711 sock.sendTo(multi, tx_buff, sizeof(tx_buff));
irsanjul 0:fbb75122015f 712 } else
irsanjul 0:fbb75122015f 713 er_tmp2 = 5;
irsanjul 0:fbb75122015f 714 er_tmp2++;
irsanjul 0:fbb75122015f 715 }
irsanjul 0:fbb75122015f 716 }
irsanjul 0:fbb75122015f 717 }