Ejemplo n.º 1
0
        /// <summary>
        /// Send a command to SENTIO, collect the response.
        /// Use this function for SENTIO remote commands
        /// </summary>
        /// <param name="cmd">The command to send</param>
        /// <param name="errc">Error code</param>
        /// <param name="stat">A status code (i.e. last die, last sub site)</param>
        /// <param name="cmdId">Command ID. Only used by asynchronous remote commands</param>
        /// <param name="msg">remote command return string</param>
        public static void Send(string cmd, out RemoteCommandResult errc, out RemoteCommandStatus stat, out int cmdId, out string msg)
        {
            errc  = RemoteCommandResult.NoError;
            stat  = RemoteCommandStatus.None;
            cmdId = -1;
            msg   = "";

            Send(cmd);
            var resp = Readline();
            var tok  = resp.Split(",");

            if (tok.Length < 3)
            {
                throw new InvalidOperationException("Invalid Response Format!");
            }

            // SENTIO's error code consists of an error code and a status code!
            var errcOrig = uint.Parse(tok[0]);

            errc  = (RemoteCommandResult)(errcOrig & 0b1111111111); // the lowermost 10 bits cvontain the error code
            stat  = (RemoteCommandStatus)(errcOrig >> 10);          // the uppermost bits contain status codes
            cmdId = int.Parse(tok[1]);

            // Collect the remaining arguments and join them back together
            msg = string.Join(",", tok.Skip(2).ToArray());
            Console.WriteLine($"Remote command Response: errc={errc},stat={stat},cmdId={cmdId}: resp=\"{msg}\"");
        }
Ejemplo n.º 2
0
 static void CheckSentioResp(RemoteCommandResult errc, string msg)
 {
     if (errc != RemoteCommandResult.NoError)
     {
         throw new Exception($"Remote command error {errc}: {msg}");
     }
 }