diff --git a/service/printer.go b/service/printer.go index fb16b6a..5356f9e 100644 --- a/service/printer.go +++ b/service/printer.go @@ -1,6 +1,7 @@ package service import ( + "encoding/hex" "git.anomalous.dev/57_Wolve/uberbringer/config" fifo "github.com/foize/go.fifo" "github.com/justinmichaelvieira/escpos" @@ -8,49 +9,6 @@ import ( "net" ) -type Queue struct { - Data []Item `json:"data"` -} - -type QueueItem struct { - JobID string - SequenceNumber int - Type int - Bold bool - Size int - Text string -} - -// constructor function -func (std *QueueItem) fillDefaults() { - - // setting default values - // if no values present - if std.JobID == "" { - std.JobID = "000000000000000000" - } - - if std.SequenceNumber == 0 { - std.SequenceNumber = 0 - } - - if std.Type == 0 { - std.Type = 0 - } - - if std.Bold == false { - std.Bold = false - } - - if std.Size == 0 { - std.Size = 1 - } - - if std.Text == "" { - std.Text = "NULL" - } -} - func newPrintJob(input DataStruct, queue *fifo.Queue) { var byteLength int @@ -92,7 +50,7 @@ func printJobCreate(input DataStruct, queue *fifo.Queue) { for i, item := range input.Data { var SeqNum = i + 1 tml.Printf("[" + config.Project + "]: Job #" + input.JobID + " - creating command " + string(SeqNum) + "\n") - if item.Type <= 0 || item.Type > 5 { + if item.Type <= 0 || item.Type > 6 { tml.Printf("[" + config.Project + "]: Job #" + input.JobID + " bad type\n") return } else if item.Size <= 0 || item.Size > 16 { @@ -115,6 +73,22 @@ func printJobCreate(input DataStruct, queue *fifo.Queue) { case 5: // New Line X amount of times p.LineFeedD(uint8(item.Size)) + case 6: + // Decode Base64Raw Input + /* + base64_decoded, err := base64.StdEncoding.DecodeString(item.Text) + if err != nil { + tml.Printf("[" + config.Project + "]: Job #" + input.JobID + " base64 decode failed\n") + return + } + */ + hex_decoded, err := hex.DecodeString(item.Text) + if err != nil { + tml.Printf("[" + config.Project + "]: Job #" + input.JobID + " hex decode failed\n") + return + } + + p.WriteRaw([]byte(hex_decoded)) } tml.Printf("[" + config.Project + "]: Job #" + input.JobID + " good type\n") diff --git a/service/webserver.go b/service/webserver.go index c82487f..cc0a3ab 100644 --- a/service/webserver.go +++ b/service/webserver.go @@ -16,6 +16,10 @@ import ( "git.anomalous.dev/57_Wolve/uberbringer/snowflake" ) +type Queue struct { + Data []Item `json:"data"` +} + type InputData struct { Data []Item `json:"data"` }