Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            int common_port_9601 = 5000;
            //int common_port_9601 = 9601;
            int common_port_9602 = 9602;


            ReaderManager.addReader(common_port_9601, "9601");
            ReaderManager.addReader(common_port_9602, "9602");



            Action <int> StartUDPListener = (port) =>
            {
                TagPool.AddParser(port, TagInfo.GetParseRawTagDataFunc(port, TagPool.AddTagRange), true);
                UDPServer.StartUDPServer(port,
                                         (_port, _data) =>
                {
                    TagPool.GetRawDataParser(_port)(_data);
                });
            };

            StartUDPListener(common_port_9601);
            StartUDPListener(common_port_9602);

            StartWebSocketServer(9701);

            StartIntervalCheck(10000);



            string line;

            READ_LINE : line = Console.ReadLine();
            if (line == "ignoreMisreading")
            {
                Console.WriteLine("Input State:  y   or   n ?");
                string state = Console.ReadLine();
                if (state.ToLower() == "y")
                {
                    TagPool.SetIgnoreMisreading(true);
                    Console.WriteLine("Current Ignore Misreading State:  true");
                }
                if (state.ToLower() == "n")
                {
                    TagPool.SetIgnoreMisreading(false);
                    Console.WriteLine("Current Ignore Misreading State:  false");
                }
                goto READ_LINE;
            }
            else
            {
                goto READ_LINE;
            }

            //****************************************
            //Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void ReportEventChangedTag()
        {
            List <TagInfo>          tags = TagPool.GetAllEventChangedTags();
            List <SubscriberClient> list = new List <SubscriberClient>(ClientList);

            foreach (SubscriberClient socket in list)
            {
                List <int>     ports      = ReaderManager.getPortsByName(socket.subscribedReaderList);
                List <TagInfo> filtedTags = tags.Where((_ti) => { return(ports.Contains(_ti.port)); }).ToList <TagInfo>();
                string         json       = JsonConvert.SerializeObject(filtedTags);
                socket.client.Send(json);
            }
        }
Ejemplo n.º 3
0
        static void StartIntervalCheck(int interval, Func <bool> predictor = null)
        {
            System.Timers.Timer timer = new System.Timers.Timer(interval);
            timer.Elapsed += (sender, e) =>
            {
                TagPool.ResetExistsState();
                ReportEventChangedTag();
#if APP_DEBUG
                //Console.WriteLine("***************************************");
                //List<TagInfo> tags = TagPool.GetAllEventChangedTags();
                //List<TagInfo> tags = TagPool.GetAllExistsTags();
                //PrintTagInfo(tags);
                //Console.WriteLine("***************************************");
                //Console.WriteLine();
#endif
            };

            timer.Enabled = true;
        }
Ejemplo n.º 4
0
        static void StartWebSocketServer(int _websocketPort)
        {
            string          url    = "ws://localhost:" + _websocketPort.ToString();
            WebSocketServer server = new WebSocketServer(url);

            server.Start(socket =>
            {
                string originurl = socket.ConnectionInfo.Host + socket.ConnectionInfo.Path;
                socket.OnOpen    = () =>
                {
                    Console.WriteLine(originurl + " connected");

                    if (socket.ConnectionInfo.Path == "/Client")
                    {
                        addClient(socket, ClientList);
                        Debug.WriteLine("Client ++  => " + ClientList.Count.ToString());
                    }
                };
                socket.OnClose = () =>
                {
                    Console.WriteLine(originurl + " closed");
                    removeClient(socket, ClientList);
                };
                socket.OnMessage = message =>
                {
                    Debug.WriteLine("OnMessage => " + message);
                    try
                    {
                        MessageInfo mi = JsonConvert.DeserializeObject <MessageInfo>(message) as MessageInfo;
                        if (mi != null)
                        {
                            List <TagInfo> tags;
                            string json;
                            switch (mi.command)
                            {
                            case MessageInfo.GET_ALL_TAGS:
                                tags = TagPool.GetAllExistsTags();
                                json = JsonConvert.SerializeObject(tags);
                                socket.Send(json);
                                break;

                            case MessageInfo.GET_SUBSCRIBE_READER_TAGS:
                                SubscriberClient sc = getClientInfo(socket, ClientList);
                                tags = TagPool.GetExistsTags(ReaderManager.getPortsByName(sc.subscribedReaderList));
                                json = JsonConvert.SerializeObject(tags);
                                socket.Send(json);
                                break;

                            case MessageInfo.SUBSCRIBE_READER:
                                Debug.WriteLine("subscribe => " + mi.content);

                                string[] reader = mi.content.Split(',');
                                if (reader.Length > 0)
                                {
                                    updateClientSubscribedReaderList(socket, ClientList, reader.ToList <string>());
                                }
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }


                    /*
                     * [{"port":9601,"bThisTagExists":true,"antennaID":"04","tagType":"","epc":"300833B2DDD906C001010101","antReadCountList":[{"antID":"04","count":0}],"milliSecond":0,"Event":"tagNew"},{"port":9601,"bThisTagExists":true,"antennaID":"02","tagType":"","epc":"300833B2DDD906C001010102","antReadCountList":[{"antID":"02","count":0}],"milliSecond":0,"Event":"tagNew"}]
                     * */
                };
                socket.OnError = (error) =>
                {
                    Debug.WriteLine("OnError => " + error.Data);
                    removeClient(socket, ClientList);
                };
            });
        }