+---
+-- This is only meant to be used when errors occur
+function oops(err)
+ prlog("ERROR: ",err)
+ return nil,err
+end
+
+
+-- Perhaps this will be moved to a separate library at one point
+local utils = {
+ --- Writes an eml-file.
+ -- @param uid - the uid of the tag. Used in filename
+ -- @param blockData. Assumed to be on the format {'\0\1\2\3,'\b\e\e\f' ...,
+ -- that is, blockData[row] contains a string with the actual data, not ascii hex representation
+ -- return filename if all went well,
+ -- @reurn nil, error message if unsuccessfull
+ writeDumpFile = function(uid, blockData)
+ local destination = string.format("%s.eml", uid)
+ local file = io.open(destination, "w")
+ if file == nil then
+ return nil, string.format("Could not write to file %s", destination)
+ end
+ local rowlen = string.len(blockData[1])
+
+ for i,block in ipairs(blockData) do
+ if rowlen ~= string.len(block) then
+ prlog(string.format("WARNING: Dumpdata seems corrupted, line %d was not the same length as line 1",i))
+ end
+
+ local formatString = string.format("H%d", string.len(block))
+ local _,hex = bin.unpack(formatString,block)
+ file:write(hex)
+ file:write(0x0A) -- Line feed
+ end
+ file:close()
+ return destination
+ end,
+}
+
+
+