Question
Following code has Error(Specifically the def parse part). Please fix the error run the code and give me the updated correct code using ONLY ELIXIR
Following code has Error(Specifically the "def parse" part). Please fix the error run the code and give me the updated correct code using ONLY ELIXIR LANGUAGE. Than you
defmodule Eligius.Parser do
@separator >
alias Eligius.ELK.{Replies, Utils}
def parse(data, buff) do
case :binary.split(data, @separator) |> extract_payload do
{:ok, message, [""]} -> {:ok, message, []}
{:ok, message, new_buffer} -> {:ok, message, new_buffer}
{:error, error_type, new_buffer} -> {:error, error_type, new_buffer}
end
end
defp extract_payload([msg | next] = data) do
encoded_length = String.slice(msg, 0, 2) |> String.to_integer(16)
payload = String.slice(msg, 0, encoded_length)
csum = String.slice(msg, -2, 2) |> String.to_integer(16)
sum = payload |> :binary.bin_to_list() |> Enum.sum() |> Integer.mod(256)
if Utils.validate_csum(csum, payload) do
payload |> parse_message() |> Tuple.append(next)
else
{:error, :checksum_invalid, next}
end
end
defp parse_message(str) do
case String.slice(str, 2, 2) do
"XK" -> Replies.ethernet_test(str)
"KC" -> Replies.keypad_keychange_update(str)
"LW" -> Replies.temperature_data(str)
"ST" -> Replies.requested_temperature(str)
_ -> {:error, str}
end
end
end
Preview File Edit View Go Tools window Help ? 16% H. Wed 1:43 AM a ELK-MIL RS232 PROTOCOL-Ver-1,84.paf (page 43 of 68) Q Search Zoom Share Highlight Rotate Markup ELK-M1-RS232-PROTOCOL .ver. 1 4.31 Request Temperatures (ST This request command allows automation equipment to read temperatures of the temperature probes connected to zones 1 to 16, Keypad temperature from the sensor in cach LCD keypad, and Thermostat temperatures. Each Group can have upto 16 temperature sensors Version 4.2.8 and later sends automatic temperature updates out Port 0 when any temperature device parameter changes 41 cx Internsh...tion.doc 4.31.1 Request Temperature format (st) 09 -Length as ASCII ex at - Reque t tmperature Conard - Requested Group (ASCIE)-temperature probe 1-Keypads, "2" -Thermostats NN - Which device in the group to be returned (2 decimal 00 -Euture uae ASCII digits, 1 based. ie. "16" . device 16 NY Samiha Riham - Checksu Example: 09st00100BF Temperature Probe, Device 01 Example:09st10100BE Keypad Temperature, Device 01 Example: 09st20100BD Themostat, Device 01 Samiha Riham Resume...er Letter Microsoft O 4.31.2 Reply With Requested Temperature (ST) Reply format: c -Length as ASCII hex 42 84.pd er : Raply tepeASCI tenpezature probe 1"-Keypada, "2"-Thermostats AsCII digits, based) ie. "16 - device 16 Group 0 - Bubtraet 60 Erom the Terperature Probe data Group 1 - Subtzact 40 from the Keypad Temperature data.This Which device in the group to be returned (2 Samiha Cover Letter Micro Power DDD- Temperature in ASCII decimal connected to zone tenperature data for near minim-60 degreesF allowa Eor near minium-40 degreesF Samiha Resume uture uce Microsoft Example 1: oCST001135005C Temperature Probe, Zone 01, Retumed value 135, subtract 60 for 75 degrees F. Maximum temperature Probe Zone 150 F. Zone 01 programmed as Temperature 0 Exampie 2: OCST1021050058 Keyped Temperature, Keypad 02, Reurned value 105, 43 subtract 40 for 65 degrees F Microsoft 01, Returned value 072 Preview File Edit View Go Tools window Help ? 16% H. Wed 1:43 AM a ELK-MIL RS232 PROTOCOL-Ver-1,84.paf (page 43 of 68) Q Search Zoom Share Highlight Rotate Markup ELK-M1-RS232-PROTOCOL .ver. 1 4.31 Request Temperatures (ST This request command allows automation equipment to read temperatures of the temperature probes connected to zones 1 to 16, Keypad temperature from the sensor in cach LCD keypad, and Thermostat temperatures. Each Group can have upto 16 temperature sensors Version 4.2.8 and later sends automatic temperature updates out Port 0 when any temperature device parameter changes 41 cx Internsh...tion.doc 4.31.1 Request Temperature format (st) 09 -Length as ASCII ex at - Reque t tmperature Conard - Requested Group (ASCIE)-temperature probe 1-Keypads, "2" -Thermostats NN - Which device in the group to be returned (2 decimal 00 -Euture uae ASCII digits, 1 based. ie. "16" . device 16 NY Samiha Riham - Checksu Example: 09st00100BF Temperature Probe, Device 01 Example:09st10100BE Keypad Temperature, Device 01 Example: 09st20100BD Themostat, Device 01 Samiha Riham Resume...er Letter Microsoft O 4.31.2 Reply With Requested Temperature (ST) Reply format: c -Length as ASCII hex 42 84.pd er : Raply tepeASCI tenpezature probe 1"-Keypada, "2"-Thermostats AsCII digits, based) ie. "16 - device 16 Group 0 - Bubtraet 60 Erom the Terperature Probe data Group 1 - Subtzact 40 from the Keypad Temperature data.This Which device in the group to be returned (2 Samiha Cover Letter Micro Power DDD- Temperature in ASCII decimal connected to zone tenperature data for near minim-60 degreesF allowa Eor near minium-40 degreesF Samiha Resume uture uce Microsoft Example 1: oCST001135005C Temperature Probe, Zone 01, Retumed value 135, subtract 60 for 75 degrees F. Maximum temperature Probe Zone 150 F. Zone 01 programmed as Temperature 0 Exampie 2: OCST1021050058 Keyped Temperature, Keypad 02, Reurned value 105, 43 subtract 40 for 65 degrees F Microsoft 01, Returned value 072
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started