Ejemplo n.º 1
0
        private dynamic readRegs()
        {
            log.info("Got request for reading DSP registers");
            try {
                string          body       = this.getJsonBody();
                StringReader    memeReader = new StringReader(body);
                JsonTextReader  memer      = new JsonTextReader(memeReader);
                JsonSerializer  serializer = new JsonSerializer();
                RegReadRequest  r          = serializer.Deserialize <RegReadRequest>(memer);
                RegReadResponse resp       = controller.readRegs(r);

                if (r.desc == String.Empty)
                {
                    log.info($"Got register read request with no description");
                }
                else
                {
                    log.info($"Got register read request with description: {r.desc}");
                }

                log.info($"Reading registers:");
                log.info(r.ToString());

                log.info($"Returning values:");
                log.info(resp.ToString());
                string output = JsonConvert.SerializeObject(resp);
                var    hurr   = Encoding.UTF8.GetBytes(output);

                return(new Response
                {
                    ContentType = "application/json",
                    Contents = s => s.Write(hurr, 0, hurr.Length)
                });
            }
            catch (Exception e) {
                log.err("read regs malformed request");
                Console.WriteLine(e);
                return(500);
            }
            log.ok("Registers read successful");
            return(200);
        }