Tuesday, March 10, 2015

Space Engineers and stone removal

This is one of those cases where the editor just isn't wide enough. Attached is some code that I wrote for a friend because I know some C#. It is for the starting miner ship, but it's not completely functional because it does not sort all items to the connector. You need a second connector to dump waste. I only had a basic understanding of the game's systems. Good luck!
Code:
 void Main() 
 { 
    var blockTerminal = new List<IMyTerminalBlock>();
    var blockProduction = new List<IMyTerminalBlock>();  
    
    GridTerminalSystem.GetBlocksOfType<IMyCargoContainer>(blockTerminal); 
    GridTerminalSystem.GetBlocksOfType<IMyProductionBlock>(blockProduction); 
    
    //now get the Wastedump connector.  You need to use an object that can eject stuff 
    IMyShipConnector wasteboxport = GridTerminalSystem.GetBlockWithName("Connector") as IMyShipConnector;    
    var wastebox = wasteboxport as Sandbox.ModAPI.InterfacesIMyInventoryOwner;     //this is the transfer target
    
    blockTerminal.AddRange(blockProduction);  //merge lists, notice the "AddRange" due to the class type
    blockTerminal.Add(wasteboxport);  //merge lists, note the "Add"


    int i_counterBlockTerminal;
    int i_counter_source;
    int i_counter_inventory;
    
    if(blockTerminal.Count==0)
    {
    ;;
    }else
    {
        for (i_counterBlockTerminal=0; i_counterBlockTerminal<blockTerminal.Count; i_counterBlockTerminal++)//loop through each block
        {
            var inventory_source = blockTerminal[i_counterBlockTerminal] as Sandbox.ModAPI.InterfacesIMyInventoryOwner; 
       //         throw new Exception("inventory_source.InventoryCount: "+inventory_source.InventoryCount);
            for(i_counter_source=0; i_counter_source<inventory_source.InventoryCount; i_counter_source++)//loop through each item of the selected block            
            {       // also, because inventory is of type IMyInventoryOwner, I had to make the "Count" method InventoryCount
                   var inventory_items = inventory_source.GetInventory(i_counter_source).GetItems(); 
                   // throw new Exception("inventory_items.Count: "+inventory_items.Count);
                for(i_counter_inventory=0; i_counter_inventory<inventory_items.Count; i_counter_inventory++) 
                {
                    var item_name = inventory_items[i_counter_inventory].ToString().Split('x');   //need to split the "amount x name" string
                    //throw new Exception("blockTerminal["+i_counterBlockTerminal+"]inventory_source["+i_counter_source+"]: "+item_name[0]);
                    string item_type = item_name[1];
                    if (item_type.Contains(@"Ingot/Stone") || item_type.Contains(@"Ore/Stone"))
                    {
                        //move everything into the waste connector
                        //throw new Exception("item_type: "+item_type);
                        inventory_source.GetInventory(i_counter_source).TransferItemTo(wastebox.GetInventory(0), i_counter_inventory, null, true, null); 
                    }  
                }

            }
        }
        //the end of moving things to the connector
        wasteboxport.GetActionWithName("ThrowOut").Apply(wasteboxport); 
    }
 }

Monday, March 31, 2014

Cadence and tunneling ports

Cadence periodically changes ports. There is a "base" connection port, and then some client ports. I recently helped a friend tunnel their license server connection so that he could push rectangles in the coffee shop.

As an example, the license port is specified:
CDS_LIC_FILE=5280@ecelinsrv3.ece.gatech.edu
However, Cadence opens a bunch of client ports, so you need to forward more than just the primary port. In the end, the forwarding script (tun.sh) looked like:
#!/bin/sh
ssh -C -2 -f -N -g \
-L 5280:ecelinsrv3.ece.gatech.edu:5280 \
-L 32801:ecelinsrv3.ece.gatech.edu:32801 \
-L 32815:ecelinsrv3.ece.gatech.edu:32815 \
ecelinsrv9.ece.gatech.edu
The higher number ports you need to find with:
netstat -tulpn
It will list groups of TCP ports, and add those to the script until you get a successful tunneling of the license. In my case, 32801 and 32815 where the secondary ports to forward that day. It is also worth noting that these seem to change every once in awhile, so if you cannot get a license, you will need to update the port list.

Monday, January 6, 2014

Computer Scientists are pretty much worthless when it comes to conserving anything.

Bits are equal to power. Let's say that I want a simple tool to get a file, in this case "wget". One would think that it would be simple to compile it, or get it; however, here's the build dependency list:
gnutls libtasn1 nettle p11-kit desktop-file-utils glib2 libffi perl5 perl5.12 gdbm popt libxslt libxml2 xz libgcrypt libgpg-error pcre
Perl? I don't want Perl. I can see how libgcrypt and a few others are in there. I get to eat up flash write cycles, power, time just because someone decided to include perl.

Program packages should be as small as possible. This is important in an energy constrained environment or just as a function of time.

Tuesday, December 24, 2013

removing the password from PDF files.

PDF files with passwords really do not make much sense. You can remove the PDF password easily, and for free. You just need ghostscript installed.
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=PDFnopass.pdf -c .setpdfwrite -f PDFwithPASSWORD.pdf

Sunday, October 27, 2013

Cross platform Makefile

I needed to change my Makefile to output different target information based on the Operating System. This turned out more difficult than I thought since Windows doesn't have uname. I asked some friends, and the gave me some code snippets. To start with find the OSCLASS and OSNAME.
ifeq ($(OS),Windows_NT)
    OSCLASS = windows
    OSNAME=windows
else
    OSCLASS = unix
    UNAME_S := $(shell uname -s)
    ifeq ($(UNAME_S),Linux)
     OSNAME = linux
    endif
    ifeq ($(UNAME_S),Darwin)
        OSNAME = osx
    endif
endif
You can then do switches based upon the compiling OS. The biggest one was that I needed to output to a file. The problem with files that would write to both windows and unix is that the shell commands are different, so I need to address the differences in commands.
ifeq ($(OSCLASS),unix)
    FIXDIR = $1
    COMMANDCAT = cat
else
    FIXDIR = $(subst /,\,$1)
    COMMANDCAT = type
endif
Windows uses "type", whereas unix uses "cat". I then also fix the \ issue to go from the the unix / to the windows \ with the FIXDIR command. When I type "make test", the following will output the contents of info/chunk2.txt and append it to installer/test.inf.
test:
  $(COMMANDCAT) $(call FIXDIR,info/chunk2.txt >> installer/test.inf)
In unix, you will get: cat info/chunk2.txt >> installer/test.inf
In Windows, you get: type info\chunk2.txt >> installer\test.inf

Tuesday, October 15, 2013

Referencing datasheets in BIBTEX.

The CD4007 inverter pair is referenced as far back as papers from the early 1970's.  It's a great IC for teaching, but I really had to think of how to reference it using bibtex. I decided to go with the MISC tag.

@misc{CD4007,
    author={Texas Instruments},
    title={CD4007UB},
    url={http://www.ti.com/lit/ds/symlink/cd4007ub.pdf},
    note={original document from Harris Semiconductor},
    publisher={Texas Instruments},
    year={2012}
}

UPDATE:
Of course, once I decide on a method, I come up with a better method. Include:
\usepackage{url}
in your TEX document, and then you can have a prettier entry.
@misc{CD4007,
  author={Texas Instruments},
  title={CD4007UB},
  howpublished = "\url{http://www.ti.com/lit/ds/symlink/cd4007ub.pdf}",
  note={original document from Harris Semiconductor},
  publisher={Texas Instruments},
  year={2012}
}