Weiter gehts
This commit is contained in:
parent
d4fd23bab2
commit
59485950c2
@ -8,6 +8,7 @@ namespace Matomat
|
|||||||
class Automat
|
class Automat
|
||||||
{
|
{
|
||||||
private User user;
|
private User user;
|
||||||
|
private bool shutdown = false;
|
||||||
internal void doJob(int userId, long codeId)
|
internal void doJob(int userId, long codeId)
|
||||||
{
|
{
|
||||||
user = findUser(userId);
|
user = findUser(userId);
|
||||||
@ -20,5 +21,10 @@ namespace Matomat
|
|||||||
{
|
{
|
||||||
return new User(userId);
|
return new User(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal bool die()
|
||||||
|
{
|
||||||
|
return shutdown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ namespace Matomat
|
|||||||
{
|
{
|
||||||
internal long getCodeID()
|
internal long getCodeID()
|
||||||
{
|
{
|
||||||
|
Console.ReadKey();
|
||||||
return 1234567890123;
|
return 1234567890123;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24
Matomat/Factory.cs
Normal file
24
Matomat/Factory.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Matomat
|
||||||
|
{
|
||||||
|
class Factory
|
||||||
|
{
|
||||||
|
static LCDDisplay lcd_i = null;
|
||||||
|
internal static LCDDisplay getLCDDisplay()
|
||||||
|
{
|
||||||
|
if (lcd_i == null)
|
||||||
|
lcd_i = Factory._createLCDDisplay();
|
||||||
|
return lcd_i;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static LCDDisplay _createLCDDisplay()
|
||||||
|
{
|
||||||
|
LCDDisplay lcd = LCDDisplay.getInstance("lpd1");
|
||||||
|
return lcd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
Matomat/Helper.cs
Normal file
25
Matomat/Helper.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Matomat
|
||||||
|
{
|
||||||
|
class Helper
|
||||||
|
{
|
||||||
|
internal static double Serialize(string text)
|
||||||
|
{
|
||||||
|
Stream stream = new MemoryStream(255);
|
||||||
|
IFormatter formatter = new BinaryFormatter();
|
||||||
|
formatter.Serialize(stream, text);
|
||||||
|
stream.Position = 0;
|
||||||
|
byte[] bytes = new byte[(int)stream.Length];
|
||||||
|
stream.Read(bytes, 0, (int)stream.Length);
|
||||||
|
return BitConverter.ToDouble(bytes, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,19 +2,123 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
|
||||||
namespace Matomat
|
namespace Matomat
|
||||||
{
|
{
|
||||||
class LCDDisplay
|
class LCDDisplay
|
||||||
{
|
{
|
||||||
internal static void print(string text)
|
private class instance
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
public LCDDisplay lCDDisplay;
|
||||||
|
public double signature;
|
||||||
|
|
||||||
|
public instance(LCDDisplay lCDDisplay, double signature)
|
||||||
|
{
|
||||||
|
this.lCDDisplay = lCDDisplay;
|
||||||
|
this.signature = signature;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private class Message
|
||||||
|
{
|
||||||
|
public string text;
|
||||||
|
public Status status;
|
||||||
|
public int time;
|
||||||
|
|
||||||
|
public Message(string text, Status status, int time)
|
||||||
|
{
|
||||||
|
this.text = text;
|
||||||
|
this.status = status;
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static List<instance> instances;
|
||||||
|
private string port;
|
||||||
|
private Queue<Message> messages;
|
||||||
|
private volatile bool _shouldStop;
|
||||||
|
|
||||||
|
public LCDDisplay(string port)
|
||||||
|
{
|
||||||
|
this.port = port;
|
||||||
|
messages = new Queue<Message>();
|
||||||
|
Thread workerThread = new Thread(this.DoWork);
|
||||||
|
workerThread.Start();
|
||||||
|
while (!workerThread.IsAlive);
|
||||||
|
}
|
||||||
|
public void DoWork()
|
||||||
|
{
|
||||||
|
Message m;
|
||||||
|
DateTime timeout = new DateTime();
|
||||||
|
while (!_shouldStop)
|
||||||
|
{
|
||||||
|
Thread.Sleep(1);
|
||||||
|
if (messages.Count != 0)
|
||||||
|
{
|
||||||
|
if (timeout.Ticks < DateTime.Now.Ticks)
|
||||||
|
{
|
||||||
|
m = messages.Dequeue();
|
||||||
|
timeout = DateTime.Now.AddSeconds(m.time);
|
||||||
|
display(m.text, m.status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void print(string text, int time)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void display(string text, Status status)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
Console.WriteLine(text);
|
||||||
|
}
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
OK,
|
||||||
|
Warn,
|
||||||
|
Error
|
||||||
|
}
|
||||||
|
internal void print(string text)
|
||||||
|
{
|
||||||
|
this.anzeige(text, Status.OK, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void anzeige(string text, Status status, int time)
|
||||||
|
{
|
||||||
|
Message m = new Message(text, status, time);
|
||||||
|
messages.Enqueue(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void print(string text, int time)
|
||||||
|
{
|
||||||
|
this.anzeige(text, Status.OK, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void print(string text, Status status)
|
||||||
|
{
|
||||||
|
this.anzeige(text, status, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void print(string text, Status status, int time)
|
||||||
|
{
|
||||||
|
this.anzeige(text, status, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static LCDDisplay getInstance(string port)
|
||||||
|
{
|
||||||
|
if (instances == null)
|
||||||
|
instances = new List<instance>();
|
||||||
|
double signature = Helper.Serialize(port);
|
||||||
|
foreach (instance i in instances)
|
||||||
|
{
|
||||||
|
if (i.signature == signature)
|
||||||
|
return i.lCDDisplay;
|
||||||
|
}
|
||||||
|
instance instance = new instance(new LCDDisplay(port),signature);
|
||||||
|
instances.Add(instance);
|
||||||
|
return instance.lCDDisplay;
|
||||||
|
}
|
||||||
|
public void RequestStop()
|
||||||
|
{
|
||||||
|
_shouldStop = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Automat.cs" />
|
<Compile Include="Automat.cs" />
|
||||||
<Compile Include="BarcodeReader.cs" />
|
<Compile Include="BarcodeReader.cs" />
|
||||||
|
<Compile Include="Factory.cs" />
|
||||||
|
<Compile Include="Helper.cs" />
|
||||||
<Compile Include="LCDDisplay.cs" />
|
<Compile Include="LCDDisplay.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
@ -9,6 +9,7 @@ namespace Matomat
|
|||||||
{
|
{
|
||||||
internal int getCardID()
|
internal int getCardID()
|
||||||
{
|
{
|
||||||
|
Console.ReadKey();
|
||||||
return 0x1234;
|
return 0x1234;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,13 @@ namespace Matomat
|
|||||||
|
|
||||||
internal bool vaild()
|
internal bool vaild()
|
||||||
{
|
{
|
||||||
|
LCDDisplay lcd = Factory.getLCDDisplay();
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
LCDDisplay.print("User wurde nich gefunden",5);
|
lcd.print("User wurde nich gefunden",LCDDisplay.Status.Error,5);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,22 +11,25 @@ namespace Matomat
|
|||||||
private RFIDReader rfid;
|
private RFIDReader rfid;
|
||||||
private BarcodeReader barcode;
|
private BarcodeReader barcode;
|
||||||
private Automat automat;
|
private Automat automat;
|
||||||
|
private LCDDisplay lcd;
|
||||||
public Worker()
|
public Worker()
|
||||||
{
|
{
|
||||||
rfid = new RFIDReader();
|
rfid = new RFIDReader();
|
||||||
barcode = new BarcodeReader();
|
barcode = new BarcodeReader();
|
||||||
automat = new Automat();
|
automat = new Automat();
|
||||||
|
lcd = Factory.getLCDDisplay();
|
||||||
}
|
}
|
||||||
public void DoWork()
|
public void DoWork()
|
||||||
{
|
{
|
||||||
while (!_shouldStop)
|
while (!_shouldStop)
|
||||||
{
|
{
|
||||||
LCDDisplay.print("Bitte Sudierendenausweis über den RFID Leser halten.");
|
lcd.print("Bitte Sudierendenausweis über den RFID Leser halten.");
|
||||||
int userId = rfid.getCardID();
|
int userId = rfid.getCardID();
|
||||||
LCDDisplay.print("Bitte Produkt / Code über den Barcodeleser halten.");
|
lcd.print("Bitte Produkt / Code über den Barcodeleser halten.");
|
||||||
long codeId = barcode.getCodeID();
|
long codeId = barcode.getCodeID();
|
||||||
automat.doJob(userId, codeId);
|
automat.doJob(userId, codeId);
|
||||||
|
if (automat.die())
|
||||||
|
RequestStop();
|
||||||
}
|
}
|
||||||
Console.WriteLine("worker thread: terminating gracefully.");
|
Console.WriteLine("worker thread: terminating gracefully.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user