Decode incoming Sislog messages

Found out recently that messages coming from Sislog can either be encoded properly or encoded in GSM 03.38 Portuguese.  So we have to inspect the message content and decode if it's GSM.
did this come from somewhere or did you author it?