
#include <stdio.h>
#ifdef WIN32
#include <conio.h>
#include <windows.h>
#endif

#ifdef WIN32
#include <winsock2.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h> /* close */
#include <netdb.h> /* gethostbyname */
#include <fcntl.h>
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define closesocket(s) close(s)
typedef int SOCKET;
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct sockaddr SOCKADDR;
typedef struct in_addr IN_ADDR;
#define getch getchar
#endif

#include "remote_socket_client.h"
//link with ws2_32

void f(int v){
    printf ("!!! Event:%04X !!!\n",v);
}

int main (int argc, char* argv[]){

    int val;
    char perip;
    char mode;
    Remote_Client remote;

/*    while(1){
        if (kbhit())
            printf ("%x\n",getch());
    }*/

    remote_init("127.0.0.1",&remote);

    remote.event_callback = &f;

    do{
        printf ("\nPeriph:");
        perip=getch();
        printf ("%c\n",perip);
        printf("\nMode:");
        mode=getch();
        printf("%c\n",mode);
        if (mode==':'){
            printf ("Val:");
            scanf("%d",&val);
            remote_write(&remote,perip,val);
        }
        if (mode=='?'){
            val=remote_read(&remote,perip);
            printf ("\n%c:-> %d",perip,val);
        }
    }while(perip!='.');
    remote_close(&remote);
    return 0;
}
