#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include "system.h"
#include "packet.h"
#include "uart.h"
#include "LedUtils.h"
char CardHost[16] = "192.168.1.99";
int com_port=1;
void doprint(BYTE* buffer, DWORD size)
{
/
DWORD i;
printf("------------------------------------------\n");
for (i=1; i<=size; i++)
{
printf("0x%0.2X,", buffer[i-1]);
if ((i % 8)==0) printf(" ");
if ((i % 16)==0) printf("\n");
}
printf("\n----------------------------------------\n");
/
}
void net_send(BYTE* stream)
{
DWORD size;
BYTE buffer[6144];
SOCKET s;
DWORD i, K;
char ip[16];
WORD port;
s=InitSocket(9011);
//----generate and send the begin packet----
size=DoBeginPacket(buffer, 0);
SocketWrite(s, buffer, size, CardHost, 6666);
Sleep(100);
size=SocketRead(s, buffer, 6144, ip, &port);
if (size>0) printf("==>begin packet ok\n\n"); else printf("==>begin packet time out\n\n");
//----generate and send the data packet----
// first, get the count of data packet
K=GetDataPacketCount(stream);
// second, generate and send the data packet one by one
for (i=1; i<=K; i++)
{
size=DoDataPacket(stream, i, buffer, 0);
SocketWrite(s, buffer, size, CardHost, 6666);
Sleep(100);
size=SocketRead(s, buffer, 6144, ip, &port);
if (size>0) printf("==>data packet %d ok\n\n", i); else printf("==>data packet %d time out\n\n", i);
}
//----generate and send the end packet----
size=DoEndPacket(buffer, K+1, 0);
SocketWrite(s, buffer, size, CardHost, 6666);
Sleep(100);
size=SocketRead(s, buffer, 6144, ip, &port);
if (size>0) printf("==>end packet ok\n\n"); else printf("==>end packet time out\n\n");
CloseSocket(s);
}
void com_send(BYTE* stream)
{
DWORD size;
BYTE buffer[6144];
DWORD i, K;
TDeviceInfo dev;
uart_Initialize(com_port);
//----generate and send the begin packet----
size=DoBeginPacket(buffer, 0);
uart_Write(buffer, size, NULL);
Sleep(100);
size=uart_Read(buffer, 6144, &dev);
if (size>0) printf("==>begin packet ok\n\n"); else printf("==>begin packet time out\n\n");
//----generate and send the data packet----
// first, get the count of data packet
K=GetDataPacketCount(stream);
// second, generate and send the data packet one by one
for (i=1; i<=K; i++)
{
size=DoDataPacket(stream, i, buffer, 0);
uart_Write(buffer, size, NULL);
Sleep(100);
size=uart_Read(buffer, 6144, &dev);
if (size>0) printf("==>data packet %d ok\n\n", i); else printf("==>data packet %d time out\n\n", i);
}
//----generate and send the end packet----
size=DoEndPacket(buffer, K+1, 0);
uart_Write(buffer, size, NULL);
Sleep(100);
size=uart_Read(buffer, 6144, &dev);
if (size>0) printf("==>end packet ok\n\n"); else printf("==>end packet time out\n\n");
uart_Destroy();
}
void demo_string()
{
BYTE stream[65536];
char str1[]="HELLO WORLD!";
char str2[]="你好";
//genrate the display program data
//this is a demo that there are two text display in the screen
//one display in the rect (0, 0, 256, 16), another display in the rect (0, 16, 256, 32)
// /---------------\
// | HELLOW WORLD! |
// | hellow world! |
// \---------------/
MakeRoot(stream);
AddChapter(0x7fffffff, PLAY_MODE_WAIT);
AddRegion(0, 0, 256, 32);
AddLeaf(0x7fffffff, PLAY_MODE_WAIT);
AddString(0, 0, 256, 16, str1, FONT_SET_16, RGB(255,255,0), 1, 0, 2, 0, 0, 0, 5000); //display in yellow
AddString(0, 16, 256, 16, str2, FONT_SET_16, RGB(0,255,0), 1, 0, 2, 0, 0, 0, 5000); //display in green
//send to screen
//net_send(stream); //this is the network (udp)
com_send(stream); //this is the rs232
}
void main(void)
{
while (1)
{
demo_string();
Sleep(5000);
}
}