Subversion Repositories NedoOS

Rev

Rev 2338 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
1452 Kulich 1
#include <stdlib.h>
1434 Kulich 2
#include <stdio.h>
3
#include <string.h>
4
#include <oscalls.h>
1452 Kulich 5
#include <osfs.h>
1434 Kulich 6
#include <intrz80.h>
2337 kulich 7
// #include <graphic.h>
2117 kulich 8
#include <../common/terminal.c>
1434 Kulich 9
#include <tcp.h>
2236 kulich 10
//
2187 kulich 11
#define true 1
12
#define false 0
13
 
2046 kulich 14
unsigned int RBR_THR = 0xf8ef;
15
unsigned int IER = 0xf9ef;
16
unsigned int IIR_FCR = 0xfaef;
17
unsigned int LCR = 0xfbef;
18
unsigned int MCR = 0xfcef;
19
unsigned int LSR = 0xfdef;
20
unsigned int MSR = 0xfeef;
21
unsigned int SR = 0xffef;
22
unsigned int divider = 1;
2041 kulich 23
unsigned char comType = 0;
2048 kulich 24
unsigned int espType = 32;
2022 kulich 25
 
2224 kulich 26
unsigned char picture[15000];
27
unsigned char netbuf[6912];
2337 kulich 28
unsigned char curPath[128];
2193 kulich 29
 
2187 kulich 30
unsigned char minRating[] = "0000000000";
1698 kulich 31
struct fileStruct
32
{
33
  long picId;
34
  unsigned int picYear;
35
  unsigned long totalAmount;
2250 kulich 36
  unsigned int httpErr;
1698 kulich 37
  unsigned char picRating[8];
38
  unsigned char picName[256];
39
  unsigned char picType[64];
40
  unsigned char authorIds[64];
41
  unsigned char authorTitle[64];
42
  unsigned char authorRealName[64];
1811 kulich 43
  unsigned char afn[128];
44
  unsigned char pfn[128];
1810 kulich 45
  unsigned char fileName[128];
1698 kulich 46
} curFileStruct;
2023 kulich 47
 
2187 kulich 48
struct window
49
{
50
  unsigned char x;
51
  unsigned char y;
52
  unsigned char w;
53
  unsigned char h;
54
  unsigned char text;
55
  unsigned char back;
56
  unsigned char tittle[80];
57
} curWin;
58
 
2107 kulich 59
struct sockaddr_in dnsaddress;
60
struct sockaddr_in targetadr;
61
struct readstructure readStruct;
62
 
2344 kulich 63
unsigned char ver[] = "4.5";
2050 kulich 64
const unsigned char sendOk[] = "SEND OK";
65
const unsigned char gotWiFi[] = "WIFI GOT IP";
66
unsigned char buffer[] = "0000000000";
67
unsigned char userAgent[] = " HTTP/1.1\r\nHost: zxart.ee\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE5.01; NedoOS; GetPic)\r\n\r\n\0";
2107 kulich 68
unsigned char zxart[] = "zxart.ee";
2067 kulich 69
unsigned char keypress, verbose, randomPic, slideShow, netDriver;
2050 kulich 70
 
1462 Kulich 71
unsigned long contLen;
2050 kulich 72
unsigned long count = 0;
1961 kulich 73
unsigned int headlng;
1921 kulich 74
unsigned int slideShowTime = 0;
2022 kulich 75
unsigned int loaded;
1590 kulich 76
 
2067 kulich 77
unsigned char crlf[2] = {13, 10};
78
unsigned char cmd[512];
79
unsigned char link[512];
80
unsigned char fileIdChar[10];
81
 
2179 kulich 82
void clearStatus(void)
83
{
84
}
85
 
2005 kulich 86
void emptyKeys(void)
1919 kulich 87
{
2224 kulich 88
  unsigned char loop = 0, key;
1919 kulich 89
  do
90
  {
2193 kulich 91
    key = OS_GETKEY();
2005 kulich 92
    if (loop > 64)
93
    {
94
      break;
95
    }
96
    loop++;
97
  } while (key != 0);
1919 kulich 98
}
99
 
2283 kulich 100
unsigned char delayLongKey(unsigned long counter)
101
{
102
  unsigned long start, finish, key;
103
  counter = counter / 20;
104
  if (counter < 1)
105
  {
106
    counter = 1;
107
  }
108
  start = time();
109
  finish = start + counter;
110
 
111
  while (start < finish)
112
  {
113
    start = time();
114
    key = OS_GETKEY();
115
    if (key != 0)
116
    {
117
      return key;
118
    }
119
    YIELD();
120
  }
121
  return 32;
122
}
123
 
2193 kulich 124
void spaces(unsigned char number)
125
{
126
  while (number > 0)
127
  {
128
    putchar(' ');
129
    number--;
130
  }
131
}
2197 kulich 132
void quit(void)
133
{
134
  OS_CLS(0);
135
  OS_SETGFX(-1);
136
  exit(0);
137
}
2271 kulich 138
/*
2224 kulich 139
void infoBox(struct window w, const char *message)
2193 kulich 140
{
141
  unsigned char wcount, tempx, tittleStart;
142
 
143
  w.h++;
144
  OS_SETXY(w.x, w.y - 1);
145
  BDBOX(w.x, w.y, w.w + 1, w.h, w.back, 32);
146
  OS_SETXY(w.x, w.y);
147
  OS_SETCOLOR(w.text);
148
  putchar(201);
149
  for (wcount = 0; wcount < w.w; wcount++)
150
  {
151
    putchar(205);
152
  }
153
  putchar(187);
154
  OS_SETXY(w.x, w.y + w.h);
155
  putchar(200);
156
  for (wcount = 0; wcount < w.w; wcount++)
157
  {
158
    putchar(205);
159
  }
160
  putchar(188);
161
 
162
  tempx = w.x + w.w + 1;
163
  for (wcount = 1; wcount < w.h; wcount++)
164
  {
165
    OS_SETXY(w.x, w.y + wcount);
166
    putchar(186);
167
    OS_SETXY(tempx, w.y + wcount);
168
    putchar(186);
169
  }
170
  tittleStart = w.x + (w.w / 2) - (strlen(w.tittle) / 2);
171
  OS_SETXY(tittleStart, w.y);
172
  printf("[%s]", w.tittle);
173
 
174
  OS_SETXY(w.x + 1, w.y + 1);
175
  OS_SETCOLOR(w.back);
176
  tittleStart = w.x + (w.w / 2) - (strlen(message) / 2);
177
  OS_SETXY(tittleStart, w.y + 1);
178
  printf("%s", message);
179
}
2271 kulich 180
*/
1915 kulich 181
void printHelp(void)
182
{
2193 kulich 183
  OS_SETCOLOR(67);
1925 kulich 184
  printf("   GETPIC [%s] zxart.ee picture viewer for nedoNET\n\r", ver);
2193 kulich 185
  OS_SETCOLOR(6);
1925 kulich 186
  printf("-------------------------------------------------------\n\r");
1915 kulich 187
  printf(" ࠢ:\n\r");
1921 kulich 188
  printf(" 'ESC' - 室  ணࠬ;\n\r");
189
  printf(" '<-'  'B'  ᫥ ⨭;\n\r");
190
  printf(" '->'  '஡'    ⨭\n\r");
191
  printf(" 'J' 릮   㪠   ⨭\n\r");
192
  printf(" 'I' ᬮ ࠭ ଠ樨  ⨭\n\r");
193
  printf(" 'S' ࠭ ⨭    ⥪ \n\r");
194
  printf(" 'V'  뢮 ଠ  \n\r");
195
  printf(" 'R' 室  ०  砩 ⨭  ३⨭ 4+\n\r");
1961 kulich 196
  printf(" 'A' 室  ०  ᫠-\n\r");
2195 kulich 197
  printf(" 'D' ४祭 ० ZXNETUSB/ESP-COM\n\r");
198
  printf(" 'T' த⥫쭮  ᫠  int- \n\r");
2208 kulich 199
  printf(" 'M'  ३⨭  砩 ந. \n\r");
1921 kulich 200
  printf(" 'H'  ࠢ筠 ଠ\n\r");
1925 kulich 201
  printf("-----------------  ------------------\n\r");
2193 kulich 202
  OS_SETCOLOR(70);
2005 kulich 203
  keypress = getchar();
2193 kulich 204
  OS_CLS(0);
1915 kulich 205
}
2187 kulich 206
 
1651 kulich 207
void delay(unsigned long counter)
208
{
209
  unsigned long start, finish;
210
  counter = counter / 20;
211
  if (counter < 1)
212
  {
213
    counter = 1;
214
  }
215
  start = time();
216
  finish = start + counter;
217
 
218
  while (start < finish)
219
  {
220
    start = time();
221
  }
222
}
223
 
2117 kulich 224
///////////////////////////
2179 kulich 225
#include <../common/esp-com.c>
2117 kulich 226
#include <../common/network.c>
227
//////////////////////////
2110 kulich 228
 
2224 kulich 229
int testOperation2(const char *process, int socket)
2208 kulich 230
{
231
  if (socket < 0)
232
  {
233
    printf("%s: [ERROR:", process);
234
    errorPrint(-socket);
235
    printf("]\r\n");
236
    YIELD();
237
    return -socket;
238
  }
239
  return 1;
240
}
241
 
2117 kulich 242
int cutHeader(unsigned int todo)
2022 kulich 243
{
1961 kulich 244
  unsigned char *count1;
2022 kulich 245
 
2250 kulich 246
  curFileStruct.httpErr = httpError();
247
  if (curFileStruct.httpErr != 200)
2022 kulich 248
  {
2250 kulich 249
    clearStatus();
250
    printf("HTTP response:[%u]", curFileStruct.httpErr);
251
    return 0;
2022 kulich 252
  }
1961 kulich 253
  count1 = strstr(netbuf, "Content-Length:");
254
  if (count1 == NULL)
1462 Kulich 255
  {
2250 kulich 256
    clearStatus();
257
    printf("contLen not found");
1618 kulich 258
    contLen = 0;
2250 kulich 259
    curFileStruct.httpErr = 999; // bad kostil
260
    return 0;
1462 Kulich 261
  }
2250 kulich 262
  contLen = atol(count1 + 15);
263
  // printf("Content-Length: %lu \n\r", contLen);
1618 kulich 264
 
1961 kulich 265
  count1 = strstr(netbuf, "\r\n\r\n");
266
  if (count1 == NULL)
1618 kulich 267
  {
2250 kulich 268
    clearStatus();
269
    printf("end of header not found\r\n");
1618 kulich 270
  }
1452 Kulich 271
  else
272
  {
1961 kulich 273
    headlng = ((unsigned int)count1 - (unsigned int)netbuf + 4);
2067 kulich 274
    // printf("header %u bytes\r\n", headlng);
1452 Kulich 275
  }
2078 kulich 276
  return todo - headlng;
2022 kulich 277
}
1462 Kulich 278
 
2198 kulich 279
char *str_replace(char *dst, int num, const char *str, const char *orig, const char *rep)
2022 kulich 280
{
2193 kulich 281
  const char *ptr;
282
  size_t len1 = strlen(orig);
283
  size_t len2 = strlen(rep);
284
  char *tmp = dst;
285
 
286
  num -= 1;
287
  while ((ptr = strstr(str, orig)) != NULL)
288
  {
289
    num -= (ptr - str) + len2;
290
    if (num < 1)
291
      break;
292
 
293
    strncpy(dst, str, (size_t)(ptr - str));
294
    dst += ptr - str;
295
    strncpy(dst, rep, len2);
296
    dst += len2;
297
    str = ptr + len1;
298
  }
299
 
300
  for (; (*dst = *str) && (num > 0); --num)
301
  {
302
    ++dst;
303
    ++str;
304
  }
305
  return tmp;
306
}
307
 
308
char fillPictureEsp(void)
309
{
2271 kulich 310
  unsigned char sizeLink;
311
  unsigned long downloaded;
312
  unsigned char byte, countl;
313
  unsigned int todo;
314
  const unsigned char *count1;
2250 kulich 315
  unsigned char firstPacket;
2022 kulich 316
  strcpy(link, netbuf);
317
  sizeLink = strlen(link);
2052 kulich 318
  do
319
  {
320
    sendcommand("AT+CIPSTART=\"TCP\",\"zxart.ee\",80");
321
    getAnswer2(); // CONNECT or ERROR or link is not valid
322
    count1 = strstr(netbuf, "CONNECT");
323
  } while (count1 == NULL);
2048 kulich 324
 
2179 kulich 325
  getAnswer2();                                   // OK
326
  sprintf(netbuf, "AT+CIPSEND=%u", sizeLink + 2); // second CRLF in send command
327
  sendcommand(netbuf);
2050 kulich 328
  getAnswer2();
329
  do
2022 kulich 330
  {
331
    byte = uart_readBlock();
2107 kulich 332
    // putchar(byte);
2050 kulich 333
  } while (byte != '>');
2022 kulich 334
  sendcommand(link);
2224 kulich 335
  countl = 0;
2050 kulich 336
  do
2048 kulich 337
  {
2050 kulich 338
    byte = uart_readBlock();
2224 kulich 339
    if (byte == sendOk[countl])
2050 kulich 340
    {
2224 kulich 341
      countl++;
2050 kulich 342
    }
343
    else
344
    {
2224 kulich 345
      countl = 0;
2050 kulich 346
    }
2224 kulich 347
  } while (countl < strlen(sendOk));
2050 kulich 348
  uart_readBlock(); // CR
349
  uart_readBlock(); // LF
2022 kulich 350
  downloaded = 0;
2250 kulich 351
  firstPacket = true;
2022 kulich 352
  do
353
  {
354
    headlng = 0;
2179 kulich 355
    todo = recvHead();
2344 kulich 356
 
357
    if (!getdataEsp(todo))
358
    {
359
      OS_CLS(0);
360
      puts("[getdataEsp]Downloading timeout. Exit!");
361
      delayLongKey(5000);
362
      exit(0);
363
    }
364
 
2250 kulich 365
    if (firstPacket)
2022 kulich 366
    {
2179 kulich 367
      todo = cutHeader(todo);
2250 kulich 368
      firstPacket = false;
369
      if (curFileStruct.httpErr != 200)
370
      {
371
        sendcommand("AT+CIPCLOSE");
372
        getAnswer2(); // CLOSED
373
        getAnswer2(); // OK
374
        return false;
375
      }
2022 kulich 376
    }
2193 kulich 377
 
378
    if (downloaded + todo > sizeof(picture))
379
    {
380
      printf("dataBuffer overrun... %u reached \n\r", downloaded + todo);
381
      return false;
382
    }
2179 kulich 383
    memcpy(picture + downloaded, netbuf + headlng, todo);
384
    downloaded = downloaded + todo;
2078 kulich 385
  } while (downloaded < contLen);
2022 kulich 386
  sendcommand("AT+CIPCLOSE");
2224 kulich 387
  getAnswer2(); // CLOSED or ERROR
388
  count1 = strstr(netbuf, "CLOSED");
389
  if (count1 != NULL)
390
  {
391
    getAnswer2(); // OK
392
  }
2193 kulich 393
  return true;
2022 kulich 394
}
2187 kulich 395
 
2193 kulich 396
char fillPictureNet(void)
2022 kulich 397
{
2117 kulich 398
  int todo;
2179 kulich 399
  unsigned int downloaded = 0;
2250 kulich 400
  unsigned char firstPacket;
2193 kulich 401
  char socket, retry;
402
  picture[0] = 0;
403
  retry = 3;
404
  socket = OpenSock(AF_INET, SOCK_STREAM);
2208 kulich 405
  if (testOperation2("OS_NETSOCKET", socket) != 1)
406
  {
407
    getchar();
408
    quit();
409
  }
2193 kulich 410
  todo = netConnect(socket, retry);
2208 kulich 411
  if (testOperation2("OS_NETCONNECT", todo) != 1)
412
  {
413
    getchar();
414
    quit();
415
  }
2193 kulich 416
  todo = tcpSend(socket, (unsigned int)&netbuf, strlen(netbuf), retry);
2208 kulich 417
  if (testOperation2("OS_WIZNETWRITE", todo) != 1)
418
  {
419
    getchar();
420
    quit();
421
  }
2250 kulich 422
  firstPacket = true;
2179 kulich 423
  do
1618 kulich 424
  {
1961 kulich 425
    headlng = 0;
2193 kulich 426
    todo = tcpRead(socket, retry);
2179 kulich 427
    testOperation("OS_WIZNETREAD", todo); // Quit if too many retries
428
 
2250 kulich 429
    if (firstPacket)
1618 kulich 430
    {
1698 kulich 431
      todo = cutHeader(todo);
2250 kulich 432
      firstPacket = false;
433
      if (curFileStruct.httpErr != 200)
434
      {
435
        netShutDown(socket, 0);
436
        return false;
437
      }
1452 Kulich 438
    }
1679 kulich 439
 
2179 kulich 440
    if (downloaded + todo > sizeof(picture))
1452 Kulich 441
    {
2179 kulich 442
      printf("dataBuffer overrun... %u reached \n\r", downloaded + todo);
2193 kulich 443
      return false;
1452 Kulich 444
    }
2179 kulich 445
    memcpy(picture + downloaded, netbuf + headlng, todo);
446
    downloaded = downloaded + todo;
447
  } while (downloaded != contLen);
2193 kulich 448
 
1968 kulich 449
  netShutDown(socket, 0);
2193 kulich 450
  picture[downloaded + 1] = 0;
451
  return true;
1452 Kulich 452
}
2187 kulich 453
 
1831 kulich 454
void nameRepair(unsigned char *pfn, unsigned int tfnSize)
455
{
1434 Kulich 456
 
1831 kulich 457
  str_replace(pfn, tfnSize, pfn, "\\", "_");
458
  str_replace(pfn, tfnSize, pfn, "/", "_");
459
  str_replace(pfn, tfnSize, pfn, ":", "_");
460
  str_replace(pfn, tfnSize, pfn, "*", "_");
461
  str_replace(pfn, tfnSize, pfn, "?", "_");
462
  str_replace(pfn, tfnSize, pfn, "<", "_");
463
  str_replace(pfn, tfnSize, pfn, ">", "_");
464
  str_replace(pfn, tfnSize, pfn, "|", "_");
465
  str_replace(pfn, tfnSize, pfn, " ", "_");
466
  str_replace(pfn, tfnSize, pfn, "&#039;", "'");
467
  str_replace(pfn, tfnSize, pfn, "&amp;", "&");
468
  str_replace(pfn, tfnSize, pfn, "&quot;", "'");
469
  str_replace(pfn, tfnSize, pfn, "&gt;", ")");
470
  str_replace(pfn, tfnSize, pfn, "&lt;", "(");
471
  str_replace(pfn, tfnSize, pfn, "\"", "'");
472
}
473
 
474
void stringRepair(unsigned char *pfn, unsigned int tSize)
475
{
476
  str_replace(pfn, tSize, pfn, "&#039;", "'");
477
  str_replace(pfn, tSize, pfn, "&amp;", "&");
478
  str_replace(pfn, tSize, pfn, "&gt;", ">");
479
  str_replace(pfn, tSize, pfn, "&lt;", "<");
480
  str_replace(pfn, tSize, pfn, "&quot;", "\"");
481
  str_replace(pfn, tSize, pfn, "\\/", "/");
482
}
483
 
1998 kulich 484
void ncReplace(void)
1452 Kulich 485
{
1998 kulich 486
  unsigned char len;
1997 kulich 487
  for (len = 0; len < strlen(curFileStruct.afn); len++)
488
  {
2338 kulich 489
    if ((curFileStruct.afn[len] < ' ') || (curFileStruct.afn[len] > 0xf1) || (curFileStruct.afn[len] > 0xb0 && curFileStruct.afn[len] < 0xdf))
1997 kulich 490
    {
491
      curFileStruct.afn[len] = '_';
492
    }
493
  }
494
 
495
  for (len = 0; len < strlen(curFileStruct.pfn); len++)
496
  {
2338 kulich 497
    if ((curFileStruct.pfn[len] < ' ') || (curFileStruct.pfn[len] > 0xef) || (curFileStruct.pfn[len] > 0xb0 && curFileStruct.pfn[len] < 0xdf))
1997 kulich 498
    {
499
      curFileStruct.pfn[len] = '_';
500
    }
501
  }
1998 kulich 502
}
1997 kulich 503
 
1998 kulich 504
unsigned char savePic(unsigned long fileId)
505
{
506
  FILE *fp2;
507
  unsigned char afnSize, tfnSize;
508
 
509
  afnSize = sizeof(curFileStruct.afn) - 1;
510
  tfnSize = sizeof(curFileStruct.pfn) - 1;
511
 
512
  strcpy(curFileStruct.afn, curFileStruct.authorTitle);
513
  nameRepair(curFileStruct.afn, afnSize);
514
 
515
  strcpy(curFileStruct.pfn, curFileStruct.picName);
516
  nameRepair(curFileStruct.pfn, tfnSize);
2338 kulich 517
 
1998 kulich 518
  ncReplace();
519
 
1827 kulich 520
  sprintf(curFileStruct.fileName, "%s-%s-%ld.scr", curFileStruct.afn, curFileStruct.pfn, fileId);
1831 kulich 521
  if (strlen(curFileStruct.fileName) > 62)
1825 kulich 522
  {
1831 kulich 523
    sprintf(fileIdChar, "-%ld", fileId);
524
    str_replace(curFileStruct.fileName, sizeof(curFileStruct.fileName) - 1, curFileStruct.fileName, fileIdChar, "");
525
    curFileStruct.fileName[50] = '\0';
526
    strcat(curFileStruct.fileName, fileIdChar);
527
    strcat(curFileStruct.fileName, ".scr");
1825 kulich 528
  }
1824 kulich 529
  OS_SETSYSDRV();
1925 kulich 530
  OS_MKDIR("../downloads");        // Create if not exist
1824 kulich 531
  OS_MKDIR("../downloads/getpic"); // Create if not exist
1831 kulich 532
  OS_CHDIR("../downloads/getpic");
1810 kulich 533
  fp2 = OS_CREATEHANDLE(curFileStruct.fileName, 0x80);
1452 Kulich 534
  if (((int)fp2) & 0xff)
535
  {
1976 kulich 536
    printf("%s creating error\r\n", curFileStruct.fileName);
1810 kulich 537
    getchar();
2197 kulich 538
    quit();
1452 Kulich 539
  }
540
  OS_WRITEHANDLE(picture, fp2, 6912);
541
  OS_CLOSEHANDLE(fp2);
542
  return 0;
543
}
544
 
1459 Kulich 545
int pos(unsigned char *s, unsigned char *c, unsigned int n, unsigned int startPos)
546
{
1618 kulich 547
  unsigned int i, j;
548
  unsigned int lenC, lenS;
549
 
550
  for (lenC = 0; c[lenC]; lenC++)
551
    ;
552
  for (lenS = 0; s[lenS]; lenS++)
553
    ;
554
 
555
  for (i = startPos; i <= lenS - lenC; i++)
556
  {
557
    for (j = 0; s[i + j] == c[j]; j++)
558
      ;
559
 
560
    if (j - lenC == 1 && i == lenS - lenC && !(n - 1))
561
      return i;
562
    if (j == lenC)
563
      if (n - 1)
564
        n--;
565
      else
566
        return i;
567
  }
568
  return -1;
1459 Kulich 569
}
570
 
1618 kulich 571
const char *parseJson(unsigned char *property)
572
{
573
  unsigned int w, lng, lngp1, findEnd, listPos;
574
  unsigned char terminator;
575
  int n;
2283 kulich 576
  // n = -1;
577
  //  netbuf[0] = '\0';
1618 kulich 578
  n = pos(picture, property, 1, 0);
579
  if (n == -1)
580
  {
1976 kulich 581
    strcpy(netbuf, "-");
1810 kulich 582
    // printf("Property %s not found", property);
1618 kulich 583
    return netbuf;
584
  }
585
  lng = n - 1 + strlen(property);
586
  if (picture[lng] == ':')
587
  {
2199 kulich 588
    terminator = 0;
1618 kulich 589
  }
590
  if (picture[lng] == '\"')
591
  {
592
    terminator = '\"';
593
  }
594
  if (picture[lng] == '[')
595
  {
596
    terminator = ']';
597
  }
1459 Kulich 598
 
1618 kulich 599
  findEnd = 1;
600
  lngp1 = lng + 1;
1459 Kulich 601
 
602
  while (42)
1452 Kulich 603
  {
1618 kulich 604
 
605
    if ((picture[lngp1 + findEnd] == ','))
606
    {
2199 kulich 607
      if (terminator == 0)
1618 kulich 608
      {
609
        break;
610
      }
611
      if ((picture[lng + findEnd] == terminator))
612
      {
613
        findEnd--;
614
        break;
615
      }
616
    }
617
    findEnd++;
1452 Kulich 618
  }
1618 kulich 619
  listPos = 0;
620
  for (w = lngp1; w < findEnd + lngp1; w++)
621
  {
622
    netbuf[listPos] = picture[w];
623
    listPos++;
624
  }
2198 kulich 625
  netbuf[listPos] = 0;
1618 kulich 626
  return netbuf;
1452 Kulich 627
}
2187 kulich 628
 
1452 Kulich 629
void convert866(void)
630
{
631
  unsigned int lng, targetPos, w, q = 0;
2224 kulich 632
  unsigned char bufferl[8], one, two;
1452 Kulich 633
  unsigned int decVal;
1618 kulich 634
  lng = strlen(netbuf);
1452 Kulich 635
  targetPos = lng + 1;
636
 
1618 kulich 637
  while (q < lng)
1452 Kulich 638
  {
1618 kulich 639
    one = netbuf[q];
640
    two = netbuf[q + 1];
641
    if (one == 92 && two == 117)
642
    {
643
      q = q + 2;
644
      for (w = 0; w < 4; w++)
645
      {
2224 kulich 646
        bufferl[w] = netbuf[q + w];
1618 kulich 647
      }
648
      q = q + 4;
2224 kulich 649
      bufferl[4] = '\0';
650
      decVal = (unsigned int)strtol(bufferl, NULL, 16);
1434 Kulich 651
 
1618 kulich 652
      if (decVal < 1088)
653
      {
654
        decVal = decVal - 912;
655
      }
656
      if (decVal > 1087)
657
      {
658
        decVal = decVal - 864;
659
      }
660
      if (decVal == 1025)
661
      {
662
        decVal = 240;
663
      }
664
      if (decVal == 1105)
665
      {
666
        decVal = 241;
667
      }
1997 kulich 668
 
1618 kulich 669
      netbuf[targetPos] = decVal;
670
    }
671
    else
672
    {
673
      netbuf[targetPos] = netbuf[q];
674
      q++;
675
    }
676
    targetPos++;
677
  }
1979 kulich 678
  netbuf[targetPos] = 0;
1618 kulich 679
 
1452 Kulich 680
  for (w = lng + 1; w < targetPos + 1; w++)
681
  {
1618 kulich 682
    netbuf[w - lng - 1] = netbuf[w];
683
  }
684
}
1452 Kulich 685
 
1972 kulich 686
long processJson(unsigned long startPos, unsigned char limit, unsigned char queryNum)
1452 Kulich 687
{
2193 kulich 688
  unsigned int tSize;
2271 kulich 689
  const unsigned char *count1;
690
  unsigned char result;
1701 kulich 691
  switch (queryNum)
692
  {
693
  case 0:
2179 kulich 694
    sprintf(netbuf, "GET /api/export:zxPicture/filter:zxPictureType=standard/limit:%u/start:%lu/order:date,desc%s", limit, startPos, userAgent);
1701 kulich 695
    break;
1822 kulich 696
  case 1:
2187 kulich 697
    sprintf(netbuf, "GET /api/types:zxPicture/export:zxPicture/language:eng/start:0/limit:1/order:rand/filter:zxPictureMinRating=%s;zxPictureType=standard%s", minRating, userAgent);
1821 kulich 698
    break;
1810 kulich 699
  case 99: // GET /jsonElementData/elementId:182798
2179 kulich 700
    sprintf(netbuf, "GET /jsonElementData/elementId:%lu%s", startPos, userAgent);
1810 kulich 701
    break;
1701 kulich 702
  }
2193 kulich 703
 
704
  switch (netDriver)
1972 kulich 705
  {
2193 kulich 706
  case 0:
707
    result = fillPictureNet();
708
    break;
709
  case 1:
710
    result = fillPictureEsp();
711
    break;
1972 kulich 712
  }
2198 kulich 713
 
2250 kulich 714
  if (!result)
715
  {
716
    return -1;
717
  }
718
 
2193 kulich 719
  count1 = strstr(picture, "responseStatus\":\"success");
720
  if (count1 == NULL)
721
  {
722
    OS_CLS(0);
723
    OS_SETCOLOR(66);
724
    puts("Picture[]:");
725
    puts(picture);
726
    puts("---------------");
727
    printf("PROCESS JSON: [ERROR: Bad responseStatus.] [Query:%u][Pic:%lu]\r\n", queryNum, startPos);
728
    YIELD();
729
    getchar();
730
    return -1;
731
  }
1618 kulich 732
 
1972 kulich 733
  count1 = strstr(picture, "\"id\":");
734
  if (count1 == NULL)
1452 Kulich 735
  {
2198 kulich 736
    parseJson("\"totalAmount\":");
737
 
738
    if (atol(netbuf) == 0)
739
    {
740
      return -3;
741
    }
742
 
743
    if (netbuf[0] != '-')
744
    {
745
      return -4;
746
    }
2193 kulich 747
    OS_CLS(0);
748
    OS_SETCOLOR(66);
749
    puts("Picture[]:");
750
    puts(picture);
751
    puts("---------------");
2005 kulich 752
    printf("PROCESS JSON: [ERROR: ID not found.] [Query:%u][Pic:%lu]\r\n", queryNum, startPos);
1618 kulich 753
    YIELD();
1701 kulich 754
    return -2;
1452 Kulich 755
  }
2199 kulich 756
  netbuf[0] = 0;
1701 kulich 757
 
2199 kulich 758
  switch (queryNum)
1701 kulich 759
  {
2199 kulich 760
  case 0:
761
  case 1:
1701 kulich 762
    parseJson("\"id\":");
763
    curFileStruct.picId = atol(netbuf);
764
    parseJson(",\"title\":\"");
765
    convert866();
766
    strcpy(curFileStruct.picName, netbuf);
1810 kulich 767
    tSize = sizeof(curFileStruct.picName);
1831 kulich 768
    stringRepair(curFileStruct.picName, tSize);
1810 kulich 769
 
1701 kulich 770
    parseJson(",\"type\":\"");
771
    strcpy(curFileStruct.picType, netbuf);
772
    parseJson("\"rating\":\"");
773
    strcpy(curFileStruct.picRating, netbuf);
774
    parseJson("\"year\":\"");
775
    curFileStruct.picYear = atoi(netbuf);
776
    parseJson("\"totalAmount\":");
777
    curFileStruct.totalAmount = atol(netbuf);
778
    parseJson("\"authorIds\":[");
779
    strcpy(curFileStruct.authorIds, netbuf);
2199 kulich 780
    break;
2344 kulich 781
  case 99: // Author info
1701 kulich 782
    parseJson(",\"title\":\"");
783
    convert866();
784
    strcpy(curFileStruct.authorTitle, netbuf);
785
    parseJson(",\"realName\":\"");
786
    convert866();
787
    strcpy(curFileStruct.authorRealName, netbuf);
2199 kulich 788
    break;
1701 kulich 789
  }
1698 kulich 790
  return curFileStruct.picId;
1452 Kulich 791
}
1436 Kulich 792
 
1701 kulich 793
void printData(void)
794
{
2193 kulich 795
  OS_SETCOLOR(70);
1701 kulich 796
  printf(" #: ");
2193 kulich 797
  OS_SETCOLOR(71);
1701 kulich 798
  printf("%lu", count);
2193 kulich 799
  OS_SETCOLOR(70);
1701 kulich 800
  printf(" ID: ");
2193 kulich 801
  OS_SETCOLOR(71);
1701 kulich 802
  printf("%lu ", curFileStruct.picId);
2193 kulich 803
  OS_SETCOLOR(70);
1701 kulich 804
  printf(" Total Pics: ");
2193 kulich 805
  OS_SETCOLOR(71);
1976 kulich 806
  printf("%lu\r\n", curFileStruct.totalAmount);
2193 kulich 807
  OS_SETCOLOR(70);
1810 kulich 808
  printf(" Author: ");
2193 kulich 809
  OS_SETCOLOR(69);
1810 kulich 810
  printf("%s\r\n", curFileStruct.authorTitle);
2193 kulich 811
  OS_SETCOLOR(70);
1701 kulich 812
  printf(" TITLE: ");
2193 kulich 813
  OS_SETCOLOR(67);
1701 kulich 814
  printf("%s\r\n", curFileStruct.picName);
2193 kulich 815
  OS_SETCOLOR(70);
1701 kulich 816
  printf(" RATING: ");
2193 kulich 817
  OS_SETCOLOR(71);
1701 kulich 818
  printf("%s", curFileStruct.picRating);
2193 kulich 819
  OS_SETCOLOR(70);
1701 kulich 820
  printf(" YEAR: ");
2193 kulich 821
  OS_SETCOLOR(71);
1976 kulich 822
  printf("%u\r\n", curFileStruct.picYear);
2193 kulich 823
  OS_SETCOLOR(70);
1701 kulich 824
  printf(" AuthorsIDs ");
2193 kulich 825
  OS_SETCOLOR(71);
1701 kulich 826
  printf("%s", curFileStruct.authorIds);
2193 kulich 827
  OS_SETCOLOR(70);
1701 kulich 828
  printf(" Real name: ");
2193 kulich 829
  OS_SETCOLOR(71);
1976 kulich 830
  printf("%s\r\n", curFileStruct.authorRealName);
2193 kulich 831
  OS_SETCOLOR(69);
1976 kulich 832
  printf("\r\n");
2197 kulich 833
  printf("\r\n");
834
 
835
  OS_SETCOLOR(70);
836
 
837
  OS_SETCOLOR(70);
838
  printf(" Query: ");
839
  OS_SETCOLOR(71);
840
  if (randomPic)
841
  {
842
    printf("Random pic with %s+ rating\r\n", minRating);
843
  }
844
  else
845
  {
846
    puts("Sequental from newest");
847
  }
848
  OS_SETCOLOR(70);
849
  printf(" Mode : ");
850
  OS_SETCOLOR(71);
851
 
852
  if (slideShow)
853
  {
854
    printf("Slide-show, %u ints \r\n", slideShowTime);
855
  }
856
  else
857
  {
858
    puts("Manual show");
859
  }
860
 
2193 kulich 861
  // YIELD();
1701 kulich 862
}
2187 kulich 863
 
2224 kulich 864
unsigned char inputBox(struct window w, const char *prefilled)
2187 kulich 865
{
866
  unsigned char wcount, tempx, tittleStart;
867
  unsigned char byte, counter;
868
  w.h++;
2193 kulich 869
  OS_SETXY(w.x, w.y - 1);
870
  BDBOX(w.x, w.y, w.w + 1, w.h, w.back, 32);
871
  OS_SETXY(w.x, w.y);
872
  OS_SETCOLOR(w.text);
2187 kulich 873
  putchar(201);
874
  for (wcount = 0; wcount < w.w; wcount++)
875
  {
876
    putchar(205);
877
  }
878
  putchar(187);
2193 kulich 879
  OS_SETXY(w.x, w.y + w.h);
2187 kulich 880
  putchar(200);
881
  for (wcount = 0; wcount < w.w; wcount++)
882
  {
883
    putchar(205);
884
  }
885
  putchar(188);
886
 
887
  tempx = w.x + w.w + 1;
888
  for (wcount = 1; wcount < w.h; wcount++)
889
  {
2193 kulich 890
    OS_SETXY(w.x, w.y + wcount);
2187 kulich 891
    putchar(186);
2193 kulich 892
    OS_SETXY(tempx, w.y + wcount);
2187 kulich 893
    putchar(186);
894
  }
895
  tittleStart = w.x + (w.w / 2) - (strlen(w.tittle) / 2);
2193 kulich 896
  OS_SETXY(tittleStart, w.y);
2187 kulich 897
  printf("[%s]", w.tittle);
2193 kulich 898
  OS_SETXY(w.x + 1, w.y + 1);
899
  OS_SETCOLOR(w.back);
900
  putchar(219);
2187 kulich 901
 
902
  cmd[0] = 0;
903
 
904
  counter = strlen(prefilled);
905
  if (counter != 0)
906
  {
907
    strcpy(cmd, prefilled);
908
    goto skipKeys;
909
  }
910
 
911
  do
912
  {
2193 kulich 913
    byte = OS_GETKEY();
2187 kulich 914
    if (byte != 0)
915
    {
916
      switch (byte)
917
      {
918
      case 0x08:
919
        if (counter > 0)
920
        {
921
          counter--;
922
          cmd[counter] = 0;
923
        }
924
        break;
925
      case 0x0d:
926
 
927
        if (counter == 0)
928
        {
929
          return false;
930
        }
931
        else
932
        {
933
          return true;
934
        }
935
 
936
      case 31:
937
        break;
938
      case 250:
939
        break;
940
      case 249:
941
        break;
942
      case 248:
943
        break;
944
      case 251: // Right
945
        break;
946
      case 252: // Del
2193 kulich 947
        OS_SETXY(w.x + 1, w.y + 1);
2187 kulich 948
        spaces(counter + 1);
949
        cmd[0] = 0;
950
        counter = 0;
951
        break;
952
      case 27:
953
        cmd[0] = 0;
954
        return false;
955
      default:
956
        if (counter < w.w - 1)
957
        {
958
          cmd[counter] = byte;
959
          counter++;
960
          cmd[counter] = 0;
961
        }
962
        break;
963
      }
964
    skipKeys:
2193 kulich 965
      OS_SETXY(w.x + 1, w.y + 1);
2187 kulich 966
      printf("%s", cmd);
2193 kulich 967
      putchar(219);
968
      if (byte == 0x08)
969
      {
970
        putchar(' ');
971
      }
2187 kulich 972
    }
973
    YIELD();
974
  } while (42);
975
  return false;
976
}
977
 
2193 kulich 978
void safeKeys(unsigned char keypress)
1452 Kulich 979
{
2193 kulich 980
  switch (keypress)
981
  {
982
  case 27:
983
    OS_SETCOLOR(70);
984
    printf("Good bye...\r\n");
985
    delayLong(500);
2197 kulich 986
    quit();
2193 kulich 987
    break;
988
  case 'j':
989
  case 'J':
990
    curWin.w = 13;
991
    curWin.x = 80 / 2 - curWin.w / 2 - 2;
992
    curWin.y = 11;
993
    curWin.h = 1;
994
    curWin.text = 103;
995
    curWin.back = 103;
2195 kulich 996
    strcpy(curWin.tittle, "# of pic:");
2193 kulich 997
    if (inputBox(curWin, ""))
998
    {
999
      sscanf(cmd, "%lu", &count);
1000
      if (count > curFileStruct.totalAmount - 1)
1001
      {
1002
        count = curFileStruct.totalAmount - 1;
1003
      }
1004
    }
1005
    break;
2195 kulich 1006
  case 't':
1007
  case 'T':
1008
    curWin.w = 20;
1009
    curWin.x = 80 / 2 - curWin.w / 2 - 2;
1010
    curWin.y = 11;
1011
    curWin.h = 1;
1012
    curWin.text = 103;
1013
    curWin.back = 103;
1014
    strcpy(curWin.tittle, "Slide time(ints)");
1015
    if (inputBox(curWin, ""))
1016
    {
1017
      sscanf(cmd, "%u", &slideShowTime);
1018
      OS_CLS(0);
1019
      OS_SETCOLOR(70);
1020
      printf("Slide duration set to %u ints.", slideShowTime);
1021
      delayLong(500);
1022
    }
2197 kulich 1023
    break;
2193 kulich 1024
  case 'v':
1025
  case 'V':
1026
    verbose = !verbose;
2022 kulich 1027
 
2193 kulich 1028
    if (verbose == 0)
1029
    {
1030
      BOX(1, 1, 80, 25, 40, ' ');
1031
      AT(1, 1);
1032
    }
1033
    break;
1034
  case 'h':
1035
  case 'H':
1036
    printHelp();
1037
    break;
1038
  case 'r':
1039
  case 'R':
1040
    randomPic = !randomPic;
1041
    OS_SETCOLOR(70);
1042
    if (verbose == 1)
1043
    {
1044
      if (randomPic == 1)
1045
      {
1046
        printf("    Random mode enabled...\r\n");
1047
        count = 0;
1048
        delayLong(500);
1049
      }
1050
      else
1051
      {
1052
        printf("    Sequental mode enabled...\r\n");
1053
        count = 0;
1054
        delayLong(500);
1055
      }
1056
    }
1057
    break;
1058
  case 'a':
1059
  case 'A':
1060
    slideShow = !slideShow;
1061
    OS_SETCOLOR(70);
1062
    if (slideShow == 1)
1063
    {
1064
      if (verbose == 1)
1065
        printf("    SlideShow mode enabled...\r\n\r\n");
2194 kulich 1066
      slideShowTime = 150;
2193 kulich 1067
      delayLong(500);
1068
    }
1069
    else
1070
    {
1071
      if (verbose == 1)
1072
        printf("    Manual mode enabled...\r\n\r\n");
1073
      slideShowTime = 0;
1074
      delayLong(500);
1075
    }
1076
    break;
1077
  case 'd':
1078
  case 'D':
1079
    netDriver = !netDriver;
1080
    OS_SETCOLOR(70);
1081
    if (netDriver == 1)
1082
    {
1083
      printf("    ESP-COM mode enabled...\r\n");
1084
      loadEspConfig();
1085
      uart_init(divider);
1086
      espReBoot();
1087
      printf("    ESP-COM inited...\r\n");
1088
      delayLong(500);
1089
    }
1090
    else
1091
    {
1092
      if (verbose == 1)
1093
        printf("    NedoNET mode enabled...");
1094
      delayLong(500);
1095
    }
1096
    break;
1097
  case 'm':
1098
  case 'M':
1099
    curWin.w = 22;
1100
    curWin.x = 80 / 2 - curWin.w / 2 - 2;
1101
    curWin.y = 1;
1102
    curWin.h = 1;
1103
    curWin.text = 103;
1104
    curWin.back = 103;
1105
    strcpy(curWin.tittle, "쭠 業:");
1646 kulich 1106
 
2193 kulich 1107
    if (inputBox(curWin, ""))
1108
    {
1109
      char counter;
1110
      for (counter = 0; counter < strlen(cmd); counter++)
1111
      {
1112
        if ((((cmd[counter] < '0') || (cmd[counter] > '9'))) && cmd[counter] != '.')
1113
        {
1114
          counter = 0;
1115
          break;
1116
        }
1117
      }
1118
      if (counter != 0)
1119
      {
1120
        strncpy(minRating, cmd, 5);
1121
        count = 0;
1122
      }
1123
    }
1124
  default:
1125
    break;
1126
  }
1127
}
1128
 
2337 kulich 1129
char readParamFromIni(void)
1130
{
1131
  FILE *fpini;
1132
  unsigned char *count1;
1133
  const char currentNetwork[] = "currentNetwork";
1134
  unsigned char curNet = 0;
1135
 
1136
  OS_GETPATH((unsigned int)&curPath);
1137
  OS_SETSYSDRV();
1138
  OS_CHDIR("/");
1139
  OS_CHDIR("ini");
1140
 
1141
  fpini = OS_OPENHANDLE("network.ini", 0x80);
1142
  if (((int)fpini) & 0xff)
1143
  {
1144
    clearStatus();
1145
    printf("network.ini not found.\r\n");
1146
    getchar();
1147
    return false;
1148
  }
1149
 
1150
  OS_READHANDLE(netbuf, fpini, sizeof(netbuf) - 1);
1151
  OS_CLOSEHANDLE(fpini);
1152
 
1153
  count1 = strstr(netbuf, currentNetwork);
1154
  if (count1 != NULL)
1155
  {
1156
    sscanf(count1 + strlen(currentNetwork) + 1, "%u", &curNet);
1157
  }
1158
 
1159
  OS_CHDIR(curPath);
1160
  return curNet;
1161
}
1162
 
2193 kulich 1163
void init(void)
1164
{
1165
  OS_SETSYSDRV();
1166
  OS_MKDIR("../downloads");        // Create if not exist
1167
  OS_MKDIR("../downloads/getpic"); // Create if not exist
1168
  OS_CHDIR("../downloads/getpic");
1169
 
1619 kulich 1170
  count = 0;
1702 kulich 1171
  verbose = 1;
1821 kulich 1172
  randomPic = 0;
1921 kulich 1173
  slideShow = 0;
2187 kulich 1174
  strcpy(minRating, "4.0");
1646 kulich 1175
 
2117 kulich 1176
  targetadr.family = AF_INET;
1177
  targetadr.porth = 00;
1178
  targetadr.portl = 80;
1179
  targetadr.b1 = 217; // D9
1180
  targetadr.b2 = 146; // 92
1181
  targetadr.b3 = 69;  // 45
1182
  targetadr.b4 = 13;  // 0D
2337 kulich 1183
 
1184
  netDriver = readParamFromIni();
1185
 
1186
  if (netDriver == 0)
1187
  {
1188
    get_dns();
1189
    clearStatus();
1190
    dnsResolve("zxart.ee");
1191
  }
1192
 
1193
  if (netDriver == 1)
1194
  {
1195
    loadEspConfig();
1196
    uart_init(divider);
1197
    espReBoot();
2338 kulich 1198
    OS_CLS(0);
2337 kulich 1199
  }
2193 kulich 1200
}
2117 kulich 1201
 
2283 kulich 1202
unsigned char viewScreen6912c(unsigned int bufAdr)
1203
{
1204
  unsigned char key;
1205
  OS_SETBORDER(0);
1206
  OS_SETGFX(0x83);
1207
  SETPG32KHIGH(OS_GETSCR0() >> 8);
1208
  memcpy((unsigned char *)(0xc000), (unsigned char *)(bufAdr), 6912);
1209
 
1210
  if (slideShowTime != 0)
1211
  {
1212
    key = delayLongKey(slideShowTime * 20);
1213
  }
1214
  else
1215
  {
1216
    key = getchar();
1217
  }
1218
  OS_SETGFX(0x86);
1219
  return key;
1220
}
1221
 
2193 kulich 1222
C_task main(void)
1223
{
1224
  long iddqd, idkfa;
1225
  char result;
1226
 
1227
  OS_HIDEFROMPARENT();
1228
  OS_SETGFX(0x86);
1229
  OS_CLS(0);
1230
 
1231
  init();
1232
 
1824 kulich 1233
  printHelp();
1925 kulich 1234
  safeKeys(keypress);
1459 Kulich 1235
 
1618 kulich 1236
start:
2005 kulich 1237
  keypress = 0;
1821 kulich 1238
  switch (randomPic)
1239
  {
1240
  case 0:
2050 kulich 1241
 
1821 kulich 1242
    iddqd = processJson(count, 1, 0);
1243
    break;
1244
  case 1:
1245
    iddqd = processJson(0, 1, 1);
1246
    break;
1247
  }
1248
 
2198 kulich 1249
  OS_SETCOLOR(70);
2250 kulich 1250
 
2198 kulich 1251
  switch (iddqd)
1252
  {
1253
  case -3: // return 0 pictures
1254
    strcpy(minRating, "1.0");
2250 kulich 1255
    printf("[%u]No picture is returned in query. Minimal rating is set to %s\r\n", curFileStruct.httpErr, minRating);
2198 kulich 1256
    delayLong(500);
1257
    goto start;
1258
  case -4: // return xxxx picture, but empty body.
2250 kulich 1259
    printf("[%u]Empty body is returned. Next picture, please.(%ld)...\r\n", curFileStruct.httpErr, iddqd);
2198 kulich 1260
    delayLong(500);
1261
    count++;
1262
    goto start;
2250 kulich 1263
  case -1: // return HTTP error != 200
1264
    printf("[%u]Error getting pic info. Next picture, please(%ld)...\r\n", curFileStruct.httpErr, iddqd);
2193 kulich 1265
    count++;
2250 kulich 1266
    delayLong(500);
2193 kulich 1267
    goto start;
1701 kulich 1268
  }
1972 kulich 1269
 
1975 kulich 1270
  if (verbose == 1)
1810 kulich 1271
  {
1975 kulich 1272
    idkfa = processJson(atol(curFileStruct.authorIds), 0, 99);
1273
    if (idkfa < 0)
1274
    {
2271 kulich 1275
      printf("[%u]Error can't parse authorIds(%s). Next picture, please...\r\n", curFileStruct.httpErr, curFileStruct.authorIds);
1975 kulich 1276
      count++;
2250 kulich 1277
      delayLong(500);
1975 kulich 1278
      goto start;
1279
    }
1702 kulich 1280
  }
2005 kulich 1281
  if (strcmp(curFileStruct.picType, "standard") != 0)
1618 kulich 1282
  {
2271 kulich 1283
    printf("[%u]Error format '%s' not supported. Next picture, please.\n\r", curFileStruct.httpErr, curFileStruct.picType);
2250 kulich 1284
    delayLong(500);
1618 kulich 1285
    count++;
1286
    goto start;
1287
  }
2271 kulich 1288
  sprintf(netbuf, "GET /file/id:%ld%s", iddqd, userAgent);
2193 kulich 1289
  switch (netDriver)
2022 kulich 1290
  {
2193 kulich 1291
  case 0:
1292
    result = fillPictureNet();
1293
    break;
1294
  case 1:
1295
    result = fillPictureEsp();
1296
    break;
2022 kulich 1297
  }
1298
 
2257 kulich 1299
  if (result == -1) // return HTTP error != 200
2250 kulich 1300
  {
2271 kulich 1301
    printf("[%u]Error getting pic. Next picture, please...\r\n", curFileStruct.httpErr);
2250 kulich 1302
    count++;
1303
    delayLong(500);
1304
    goto start;
1305
  }
1306
 
2005 kulich 1307
review:
2193 kulich 1308
  OS_CLS(0);
1309
  YIELD();
2283 kulich 1310
  // keypress = viewScreen6912((unsigned int)&picture, slideShowTime);
1311
  keypress = viewScreen6912c((unsigned int)&picture);
2005 kulich 1312
  emptyKeys();
1313
 
1925 kulich 1314
  ///// Keys only for pictures
1618 kulich 1315
  if (keypress == 's' || keypress == 'S')
1316
  {
1317
    savePic(iddqd);
2193 kulich 1318
    printf("%s saved.", curFileStruct.fileName);
1319
    delayLong(500);
1618 kulich 1320
    count++;
1321
  }
2193 kulich 1322
 
1323
  if (keypress == 248 || keypress == 'b' || keypress == 'B')
1618 kulich 1324
  {
1325
    if (count > 0)
1326
    {
1327
      count--;
1328
    }
1329
  }
2193 kulich 1330
  if (keypress == 251 || keypress == 32)
1618 kulich 1331
  {
1332
    count++;
1919 kulich 1333
    goto start;
1618 kulich 1334
  }
2193 kulich 1335
  if (keypress == 'i' || keypress == 'I')
1824 kulich 1336
  {
2193 kulich 1337
    printData();
2283 kulich 1338
    while (OS_GETKEY() == 0)
1339
    {
1340
    }
1824 kulich 1341
    goto review;
1342
  }
1925 kulich 1343
  safeKeys(keypress);
1618 kulich 1344
  goto start;
1459 Kulich 1345
}