?login_element?

Subversion Repositories NedoOS

Rev

Rev 2103 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <oscalls.h>
  5. #include <osfs.h>
  6. #include <intrz80.h>
  7. #include <tcp.h>
  8. #include <../common/terminal.c>
  9.  
  10. FILE *fp1;
  11.  
  12. unsigned int RBR_THR = 0xf8ef;
  13. unsigned int IER = 0xf9ef;
  14. unsigned int IIR_FCR = 0xfaef;
  15. unsigned int LCR = 0xfbef;
  16. unsigned int MCR = 0xfcef;
  17. unsigned int LSR = 0xfdef;
  18. unsigned int MSR = 0xfeef;
  19. unsigned int SR = 0xffef;
  20. unsigned int divider = 1;
  21. unsigned char comType = 0;
  22. unsigned int espType = 32;
  23.  
  24. unsigned char netbuf[1024];
  25. unsigned char tempbuf[256];
  26. unsigned int netDriver = 32768;
  27.  
  28. unsigned char ver[] = "0.2";
  29. const unsigned char sendOk[] = "SEND OK";
  30. const unsigned char gotWiFi[] = "WIFI GOT IP";
  31. unsigned char buffer[] = "0000000000";
  32.  
  33. unsigned long contLen;
  34. unsigned long count = 0;
  35. unsigned int headlng;
  36. unsigned int slideShowTime = 0;
  37. unsigned int loaded;
  38.  
  39. unsigned char crlf[2] = {13, 10};
  40. unsigned char cmd[512];
  41. unsigned char link[512];
  42.  
  43. struct sockaddr_in targetadr;
  44. struct readstructure readStruct;
  45.  
  46. void delay(unsigned long counter)
  47. {
  48.   unsigned long start, finish;
  49.   counter = counter / 20;
  50.   if (counter < 1)
  51.   {
  52.     counter = 1;
  53.   }
  54.   start = time();
  55.   finish = start + counter;
  56.  
  57.   while (start < finish)
  58.   {
  59.     start = time();
  60.   }
  61. }
  62.  
  63. void errorPrint(unsigned int error)
  64. {
  65.   switch (error)
  66.   {
  67.   case 2:
  68.     printf("02 SHUT_RDWR");
  69.     break;
  70.   case 4:
  71.     printf("04 ERR_INTR");
  72.     break;
  73.   case 23:
  74.     printf("23 ERR_NFILE");
  75.     break;
  76.   case 35:
  77.     printf("35 ERR_EAGAIN");
  78.     break;
  79.   case 37:
  80.     printf("37 ERR_ALREADY");
  81.     break;
  82.   case 38:
  83.     printf("38 ERR_NOTSOCK");
  84.     break;
  85.   case 40:
  86.     printf("40 ERR_EMSGSIZE");
  87.     break;
  88.   case 41:
  89.     printf("41 ERR_PROTOTYPE");
  90.     break;
  91.   case 47:
  92.     printf("47 ERR_AFNOSUPPORT");
  93.     break;
  94.   case 53:
  95.     printf("53 ERR_ECONNABORTED");
  96.     break;
  97.   case 54:
  98.     printf("54 ERR_CONNRESET");
  99.     break;
  100.   case 57:
  101.     printf("57 ERR_NOTCONN");
  102.     break;
  103.   case 65:
  104.     printf("65 ERR_HOSTUNREACH");
  105.     break;
  106.   default:
  107.     printf("%u UNKNOWN ERROR", error);
  108.     break;
  109.   }
  110. }
  111.  
  112. signed char OpenSock(unsigned char family, unsigned char protocol)
  113. {
  114.   signed char socket;
  115.   unsigned int todo;
  116.   todo = OS_NETSOCKET((family << 8) + protocol);
  117.   if (todo > 32767)
  118.   {
  119.     printf("OS_NETSOCKET: [ERROR:");
  120.     errorPrint(todo & 255);
  121.     printf("] Press any key.");
  122.     getchar();
  123.     exit(0);
  124.   }
  125.   else
  126.   {
  127.     socket = ((todo & 65280) >> 8);
  128.     // printf("OS_NETSOCKET: Socket #%d created\n\r", socket);
  129.   }
  130.   return socket;
  131. }
  132.  
  133. signed char netShutDown(signed char socket, unsigned char type)
  134. {
  135.   unsigned int todo;
  136.   todo = OS_NETSHUTDOWN(socket, type);
  137.   if (todo > 32767)
  138.   {
  139.     printf("OS_NETSHUTDOWN: [ERROR:");
  140.     errorPrint(todo & 255);
  141.     return -1;
  142.   }
  143.   else
  144.   {
  145.     // printf("Socket #%d closed.\n\r", socket);
  146.   }
  147.   return 1;
  148. }
  149.  
  150. unsigned char netConnect(signed char socket)
  151. {
  152.   unsigned int todo;
  153.  
  154.   todo = OS_NETCONNECT(socket, &targetadr);
  155.  
  156.   if (todo > 32767)
  157.   {
  158.     printf("OS_NETCONNECT ERROR:");
  159.     errorPrint(todo & 255);
  160.     puts("]");
  161.     YIELD();
  162.     netShutDown(socket, 0);
  163.     exit(0);
  164.   }
  165.   else
  166.   {
  167.     //  puts("Connected to printer.");
  168.   }
  169.   return 1;
  170. }
  171.  
  172. unsigned int tcpSend(signed char socket, unsigned int messageadr, unsigned int size)
  173. {
  174.   unsigned char retry = 10;
  175.   unsigned int todo;
  176.   readStruct.socket = socket;
  177.   readStruct.BufAdr = messageadr;
  178.   readStruct.bufsize = size;
  179.   readStruct.protocol = SOCK_STREAM;
  180.   while (retry > 0)
  181.   {
  182.     todo = OS_WIZNETWRITE(&readStruct);
  183.     if (todo > 32767)
  184.     {
  185.       printf("OS_WIZNETWRITE: [ERROR:");
  186.       errorPrint(todo & 255);
  187.       printf("] [Retry:%u] [Pic:%lu]\r\n", retry, count);
  188.       YIELD();
  189.       retry--;
  190.     }
  191.     else
  192.     {
  193.       // printf("OS_WIZNETWRITE: %u bytes written. \n\r", todo);
  194.       return todo;
  195.     }
  196.   }
  197.  
  198.   getchar();
  199.   exit(0);
  200.   return todo;
  201. }
  202.  
  203. unsigned int tcpRead(signed char socket)
  204. {
  205.   unsigned char retry = 10;
  206.   unsigned int todo;
  207.  
  208.   readStruct.socket = socket;
  209.   readStruct.BufAdr = (unsigned int)&netbuf;
  210.   readStruct.bufsize = sizeof(netbuf);
  211.   readStruct.protocol = SOCK_STREAM;
  212.  
  213.   while (retry > 0)
  214.   {
  215.     todo = OS_WIZNETREAD(&readStruct);
  216.  
  217.     if (todo > 32767)
  218.     {
  219.       if ((todo & 255) != ERR_EAGAIN)
  220.       {
  221.         printf("OS_WIZNETREAD: [ERROR:");
  222.         errorPrint(todo & 255);
  223.         printf("] [Retry:%u] [Pic:%lu]\r\n", retry, count);
  224.         YIELD();
  225.         retry--;
  226.       }
  227.     }
  228.     else
  229.     {
  230.       // printf("OS_WIZNETREAD: %u bytes read. \n\r", todo);
  231.       return todo;
  232.     }
  233.   }
  234.   getchar();
  235.   exit(0);
  236.   return todo;
  237. }
  238. /*
  239. ////////////////////////ESP32 PROCEDURES//////////////////////
  240. void uart_write(unsigned char data)
  241. {
  242.   unsigned char status;
  243.   switch (comType)
  244.   {
  245.   case 0:
  246.   case 2:
  247.     while ((input(LSR) & 64) == 0)
  248.     {
  249.     }
  250.     output(RBR_THR, data);
  251.     break;
  252.   case 1:
  253.     disable_interrupt();
  254.     do
  255.     {
  256.       input(0x55fe);          // Переход в режим команд
  257.       status = input(0x42fe); // Команда прочесть статус
  258.     } while ((status & 64) == 0); // Проверяем 6 бит
  259.  
  260.     input(0x55fe);               // Переход в режим команд
  261.     input(0x03fe);               // Команда записать в порт
  262.     input((data << 8) | 0x00fe); // Записываем data в порт
  263.     enable_interrupt();
  264.     break;
  265.   }
  266. }
  267.  
  268. void uart_setrts(unsigned char mode)
  269. {
  270.   switch (comType)
  271.   {
  272.   case 0:
  273.     switch (mode)
  274.     {
  275.     case 1:
  276.       output(MCR, 2);
  277.       break;
  278.     case 0:
  279.       output(MCR, 0);
  280.       break;
  281.     default:
  282.       disable_interrupt();
  283.       output(MCR, 2);
  284.       output(MCR, 0);
  285.       enable_interrupt();
  286.       break;
  287.     }
  288.   case 1:
  289.     switch (mode)
  290.     {
  291.     case 1:
  292.       disable_interrupt();
  293.       input(0x55fe); // Переход в режим команд
  294.       input(0x43fe); // Команда установить статус
  295.       input(0x03fe); // Устанавливаем готовность DTR и RTS
  296.       enable_interrupt();
  297.       break;
  298.     case 0:
  299.       disable_interrupt();
  300.       input(0x55fe); // Переход в режим команд
  301.       input(0x43fe); // Команда установить статус
  302.       input(0x00fe); // Снимаем готовность DTR и RTS
  303.       enable_interrupt();
  304.       break;
  305.     default:
  306.       disable_interrupt();
  307.       input(0x55fe); // Переход в режим команд
  308.       input(0x43fe); // Команда установить статус
  309.       input(0x03fe); // Устанавливаем готовность DTR и RTS
  310.  
  311.       input(0x55fe); // Переход в режим команд
  312.       input(0x43fe); // Команда установить статус
  313.       input(0x00fe); // Снимаем готовность DTR и RTS
  314.       enable_interrupt();
  315.       break;
  316.     }
  317.   case 2:
  318.     break;
  319.   }
  320. }
  321.  
  322. void uart_init(unsigned char divisor)
  323. {
  324.   switch (comType)
  325.   {
  326.   case 0:
  327.   case 2:
  328.     output(MCR, 0x00);        // Disable input
  329.     output(IIR_FCR, 0x87);    // Enable fifo 8 level, and clear it
  330.     output(LCR, 0x83);        // 8n1, DLAB=1
  331.     output(RBR_THR, divisor); // 115200 (divider 1-115200, 3 - 38400)
  332.     output(IER, 0x00);        // (divider 0). Divider is 16 bit, so we get (#0002 divider)
  333.     output(LCR, 0x03);        // 8n1, DLAB=0
  334.     output(IER, 0x00);        // Disable int
  335.     output(MCR, 0x2f);        // Enable AFE
  336.     break;
  337.   case 1:
  338.     disable_interrupt();
  339.     input(0x55fe);
  340.     input(0xc3fe);
  341.     input((divisor << 8) | 0x00fe);
  342.     enable_interrupt();
  343.     break;
  344.   }
  345. }
  346.  
  347. unsigned char uart_hasByte(void)
  348. {
  349.   unsigned char queue;
  350.   switch (comType)
  351.   {
  352.   case 0:
  353.   case 2:
  354.     return (1 & input(LSR));
  355.   case 1:
  356.     disable_interrupt();
  357.     input(0x55fe);         // Переход в режим команд
  358.     queue = input(0xc2fe); // Получаем количество байт в приемном буфере
  359.     enable_interrupt();
  360.     return queue;
  361.   }
  362.   return 255;
  363. }
  364.  
  365. unsigned char uart_read(void)
  366. {
  367.   unsigned char data;
  368.   switch (comType)
  369.   {
  370.   case 0:
  371.   case 2:
  372.     return input(RBR_THR);
  373.   case 1:
  374.     disable_interrupt();
  375.     input(0x55fe);        // Переход в режим команд
  376.     data = input(0x02fe); // Команда прочесть из порта
  377.     enable_interrupt();
  378.     return data;
  379.   }
  380.   return 255;
  381. }
  382.  
  383. unsigned char uart_readBlock(void)
  384. {
  385.   unsigned char data;
  386.   switch (comType)
  387.   {
  388.   case 0:
  389.     while (uart_hasByte() == 0)
  390.     {
  391.       uart_setrts(2);
  392.     }
  393.     return input(RBR_THR);
  394.   case 1:
  395.     while (uart_hasByte() == 0)
  396.     {
  397.       uart_setrts(2);
  398.     }
  399.     disable_interrupt();
  400.     input(0x55fe);        // Переход в режим команд
  401.     data = input(0x02fe); // Команда прочесть из порта
  402.     enable_interrupt();
  403.     return data;
  404.   case 2:
  405.     while (uart_hasByte() == 0)
  406.     {
  407.     }
  408.     return input(RBR_THR);
  409.   }
  410.   return 255;
  411. }
  412.  
  413. void uart_flush(void)
  414. {
  415.   unsigned int count;
  416.   for (count = 0; count < 6000; count++)
  417.   {
  418.     disable_interrupt();
  419.     uart_setrts(1);
  420.     enable_interrupt();
  421.     uart_read();
  422.   }
  423.   printf("\r\nBuffer cleared.\r\n");
  424. }
  425. void getdataEsp(unsigned int counted)
  426. {
  427.   unsigned int counter;
  428.   for (counter = 0; counter < counted; counter++)
  429.   {
  430.     netbuf[counter] = uart_readBlock();
  431.   }
  432.   netbuf[counter] = 0;
  433. }
  434.  
  435. void sendcommand(char *commandline)
  436. {
  437.   unsigned int count, cmdLen;
  438.   cmdLen = strlen(commandline);
  439.   for (count = 0; count < cmdLen; count++)
  440.   {
  441.     uart_write(commandline[count]);
  442.   }
  443.   uart_write('\r');
  444.   uart_write('\n');
  445.   // printf("Sended:[%s] \r\n", commandline);
  446. }
  447.  
  448. unsigned char getAnswer2(void)
  449. {
  450.   unsigned char readbyte;
  451.   unsigned int curPos = 0;
  452.   do
  453.   {
  454.     readbyte = uart_readBlock();
  455.     // putdec(readbyte);
  456.   } while (((readbyte == 0x0a) || (readbyte == 0x0d)));
  457.  
  458.   netbuf[curPos] = readbyte;
  459.   curPos++;
  460.   do
  461.   {
  462.     readbyte = uart_readBlock();
  463.     netbuf[curPos] = readbyte;
  464.     curPos++;
  465.   } while (readbyte != 0x0d);
  466.   netbuf[curPos - 1] = 0;
  467.   uart_readBlock(); // 0xa
  468.   // printf("Answer:[%s]\r\n", netbuf);
  469.   //   getchar();
  470.   return curPos;
  471. }
  472.  
  473. void espReBoot(void)
  474. {
  475.   unsigned char byte, count;
  476.   uart_flush();
  477.   sendcommand("AT+RST");
  478.   printf("Resetting ESP...");
  479.   count = 0;
  480.   do
  481.   {
  482.     byte = uart_readBlock();
  483.     if (byte == gotWiFi[count])
  484.     {
  485.       count++;
  486.     }
  487.     else
  488.     {
  489.       count = 0;
  490.     }
  491.   } while (count < strlen(gotWiFi));
  492.   uart_readBlock(); // CR
  493.   uart_readBlock(); // LF
  494.   puts("Reset complete.");
  495.  
  496.   sendcommand("ATE0");
  497.   do
  498.   {
  499.     byte = uart_readBlock();
  500.   } while (byte != 'K'); // OK
  501.   // puts("Answer:[OK]");
  502.   uart_readBlock(); // CR
  503.   uart_readBlock(); // LN
  504.  
  505.   sendcommand("AT+CIPCLOSE");
  506.   getAnswer2();
  507.   sendcommand("AT+CIPDINFO=0");
  508.   getAnswer2();
  509.   sendcommand("AT+CIPMUX=0");
  510.   getAnswer2();
  511.   sendcommand("AT+CIPSERVER=0");
  512.   getAnswer2();
  513.   sendcommand("AT+CIPRECVMODE=0");
  514.   getAnswer2();
  515. }
  516. unsigned int recvHead(void)
  517. {
  518.   unsigned char byte, dataRead = 0;
  519.   do
  520.   {
  521.     byte = uart_readBlock();
  522.   } while (byte != ',');
  523.  
  524.   dataRead = 0;
  525.   do
  526.   {
  527.     byte = uart_readBlock();
  528.     netbuf[dataRead] = byte;
  529.     dataRead++;
  530.   } while (byte != ':');
  531.   netbuf[dataRead] = 0;
  532.   loaded = atoi(netbuf); // <actual_len>
  533.   // printf("\r\n loaded %u\r\n", loaded);
  534.   return loaded;
  535. }
  536.  
  537. // in netbuf data to send
  538. unsigned int fillPictureEsp(void)
  539. {
  540.   unsigned char sizeLink = 0;
  541.   unsigned long downloaded = 0;
  542.   unsigned char byte, count = 0, try = 0;
  543.   unsigned int dataSize = 0;
  544.   unsigned char skipHeader = 0;
  545.   unsigned char *count1;
  546.  
  547.   strcpy(link, netbuf);
  548.   sizeLink = strlen(link);
  549.   try = 0;
  550.   do
  551.   {
  552.     try++;
  553.     if (try > 1)
  554.     {
  555.       printf("----->Retry:%u\r\n", try);
  556.       delay(1000);
  557.     }
  558.     sendcommand("AT+CIPSTART=\"TCP\",\"zxart.ee\",80");
  559.     getAnswer2(); // CONNECT or ERROR or link is not valid
  560.     count1 = strstr(netbuf, "CONNECT");
  561.   } while (count1 == NULL);
  562.  
  563.   getAnswer2(); // OK
  564.  
  565.   strcpy(cmd, "AT+CIPSEND=");
  566.   sprintf(netbuf, "%u", sizeLink + 2); // second CRLF in send command
  567.  
  568.   strcat(cmd, netbuf);
  569.   sendcommand(cmd);
  570.   getAnswer2();
  571.   do
  572.   {
  573.     byte = uart_readBlock();
  574.     // putchar(byte);
  575.   } while (byte != '>');
  576.   sendcommand(link);
  577.  
  578.   count = 0;
  579.  
  580.   do
  581.   {
  582.     byte = uart_readBlock();
  583.     if (byte == sendOk[count])
  584.     {
  585.       count++;
  586.     }
  587.     else
  588.     {
  589.       count = 0;
  590.     }
  591.   } while (count < strlen(sendOk));
  592.   uart_readBlock(); // CR
  593.   uart_readBlock(); // LF
  594.   skipHeader = 0;
  595.   downloaded = 0;
  596.   do
  597.   {
  598.     headlng = 0;
  599.     dataSize = recvHead();
  600.     getdataEsp(dataSize); // Requested size
  601.     if (skipHeader == 0)
  602.     {
  603.       dataSize = cutHeader(dataSize);
  604.       skipHeader = 1;
  605.     }
  606.     downloaded = downloaded + dataSize;
  607.     memcpy(picture + downloaded - dataSize, netbuf + headlng, dataSize);
  608.   } while (downloaded < contLen);
  609.   sendcommand("AT+CIPCLOSE");
  610.   getAnswer2(); // CLOSED
  611.   getAnswer2(); // OK
  612.   return 0;
  613. }
  614.  
  615. void loadEspConfig(void)
  616. {
  617.   unsigned char curParam[256];
  618.   unsigned char res;
  619.   FILE *espcom;
  620.   OS_SETSYSDRV();
  621.   OS_CHDIR("browser");
  622.   espcom = OS_OPENHANDLE("espcom.ini", 0x80);
  623.   if (((int)espcom) & 0xff)
  624.   {
  625.     printf("mrfesp.ini opening error\r\n");
  626.     return;
  627.   }
  628.  
  629.   OS_READHANDLE(curParam, espcom, 256);
  630.  
  631.   res = sscanf(curParam, "%x %x %x %x %x %x %x %x %u %u %u", &RBR_THR, &IER, &IIR_FCR, &LCR, &MCR, &LSR, &MSR, &SR, &divider, &comType, &espType);
  632.   puts("Config loaded:");
  633.   if (comType == 1)
  634.   {
  635.     puts("     Controller base port: 0x55fe");
  636.   }
  637.   else
  638.   {
  639.     printf("     RBR_THR:0x%4x\r\n     IER    :0x%4x\r\n     IIR_FCR:0x%4x\r\n     LCR    :0x%4x\r\n", RBR_THR, IER, IIR_FCR, LCR);
  640.     printf("     MCR    :0x%4x\r\n     LSR    :0x%4x\r\n     MSR    :0x%4x\r\n     SR     :0x%4x\r\n", MCR, LSR, MSR, SR);
  641.   }
  642.   printf("     DIVIDER:  %4u\r\n     TYPE   :  %4u\r\n     ESP    : %u\r\n", divider, comType, espType);
  643.  
  644.   switch (comType)
  645.   {
  646.   case 0:
  647.     puts("     (16550 like w/o AFC)");
  648.     break;
  649.   case 1:
  650.     puts("     (ATM Turbo 2+)");
  651.     break;
  652.   case 2:
  653.     puts("     (16550 with AFC)");
  654.   default:
  655.     puts("     (Unknown type)");
  656.     break;
  657.   }
  658. }
  659.  
  660. ////////////////////////ESP32 PROCEDURES//////////////////////
  661. */
  662. void convert866(void)
  663. {
  664.   unsigned int lng, targetPos, w, q = 0;
  665.   unsigned char buffer[8], one, two;
  666.   unsigned int decVal;
  667.   lng = strlen(netbuf);
  668.   targetPos = lng + 1;
  669.  
  670.   while (q < lng)
  671.   {
  672.     one = netbuf[q];
  673.     two = netbuf[q + 1];
  674.     if (one == 92 && two == 117)
  675.     {
  676.       q = q + 2;
  677.       for (w = 0; w < 4; w++)
  678.       {
  679.         buffer[w] = netbuf[q + w];
  680.       }
  681.       q = q + 4;
  682.       buffer[4] = '\0';
  683.       decVal = (unsigned int)strtol(buffer, NULL, 16);
  684.  
  685.       if (decVal < 1088)
  686.       {
  687.         decVal = decVal - 912;
  688.       }
  689.       if (decVal > 1087)
  690.       {
  691.         decVal = decVal - 864;
  692.       }
  693.       if (decVal == 1025)
  694.       {
  695.         decVal = 240;
  696.       }
  697.       if (decVal == 1105)
  698.       {
  699.         decVal = 241;
  700.       }
  701.  
  702.       netbuf[targetPos] = decVal;
  703.     }
  704.     else
  705.     {
  706.       netbuf[targetPos] = netbuf[q];
  707.       q++;
  708.     }
  709.     targetPos++;
  710.   }
  711.   netbuf[targetPos] = 0;
  712.  
  713.   for (w = lng + 1; w < targetPos + 1; w++)
  714.   {
  715.     netbuf[w - lng - 1] = netbuf[w];
  716.   }
  717. }
  718.  
  719. void loadParm(void)
  720. {
  721.   FILE *params;
  722.   unsigned char param[256];
  723.   unsigned int ip16[6];
  724.   unsigned int porthl;
  725.  
  726.   OS_GETPATH((unsigned int)&tempbuf);
  727.   OS_SETSYSDRV();
  728.   OS_CHDIR("../ini");
  729.   params = OS_OPENHANDLE("netprint.ini", 0x80);
  730.   if (((int)params) & 0xff)
  731.   {
  732.     printf("ini/netprint.ini opening error\r\n");
  733.     exit(0);
  734.   }
  735.  
  736.   OS_READHANDLE(param, params, 256);
  737.   OS_CLOSEHANDLE(params);
  738.   OS_CHDIR(tempbuf);
  739.  
  740.   if (sscanf(param, "%d.%d.%d.%d:%d.%d", ip16, ip16 + 1, ip16 + 2, ip16 + 3, ip16 + 4, ip16 + 5) == 6)
  741.   {
  742.     targetadr.b1 = ip16[0];
  743.     targetadr.b2 = ip16[1];
  744.     targetadr.b3 = ip16[2];
  745.     targetadr.b4 = ip16[3];
  746.     porthl = ip16[4];
  747.     targetadr.porth = porthl >> 8;
  748.     targetadr.portl = porthl;
  749.     netDriver = ip16[5];
  750.   }
  751.   else
  752.   {
  753.     printf("Wrong parameter\r\n");
  754.     exit(0);
  755.   }
  756.   targetadr.family = AF_INET;
  757.   ATRIB(97);
  758.   printf("Printer adress: %d.%d.%d.%d:%d ", targetadr.b1, targetadr.b2, targetadr.b3, targetadr.b4, porthl);
  759.  
  760.   switch (netDriver)
  761.   {
  762.   case 0:
  763.     printf("thru NedoNet\r\n");
  764.     break;
  765.   case 1:
  766.     printf("thru EspCom\r\n");
  767.     break;
  768.   }
  769.   ATRIB(37);
  770. }
  771.  
  772. C_task main(int argc, char *argv[])
  773. {
  774.   unsigned char socket;
  775.   unsigned int todo;
  776.   unsigned long progress = 0;
  777.  
  778.   os_initstdio();
  779.   ATRIB(93);
  780.   printf("Network RAW printing utillity version:%s\r\n", ver);
  781.   ATRIB(37);
  782.  
  783.   if (argc < 2)
  784.   {
  785.     puts("Error: File name required.");
  786.     exit(0);
  787.   }
  788.  
  789.   loadParm();
  790.  
  791.   fp1 = OS_OPENHANDLE(argv[1], 0x80);
  792.  
  793.   if (((int)fp1) & 0xff)
  794.   {
  795.     printf("Error: %s opening error\r\n", argv[1]);
  796.     exit(0);
  797.   }
  798.   ATRIB(93);
  799.   socket = OpenSock(AF_INET, SOCK_STREAM);
  800.   netConnect(socket);
  801.   do
  802.   {
  803.     todo = OS_READHANDLE(netbuf, fp1, sizeof(netbuf));
  804.     progress = progress + todo;
  805.     printf("Bytes sended: %lu...     \r", progress);
  806.     tcpSend(socket, (unsigned int)&netbuf, todo);
  807.   } while (todo != 0 && errno == 0);
  808.   OS_CLOSEHANDLE(fp1);
  809.   netShutDown(socket, 0);
  810.  
  811.   ATRIB(37);
  812.   ATRIB(40);
  813.   printf("\r\n");
  814.   exit(0);
  815. }
  816.