Nemeus NIS-UL

24 views
Skip to first unread message

Toni Juola

unread,
Feb 26, 2019, 8:12:15 AM2/26/19
to LoRaWAN Server Users
Hi!

Can someone guide me what is wrong with this function, written in Erlang? LoRaWAN won't accept it:

fun(Fields, <<Mask_bit0:1, Mask_bit1:1, Mask_bit2:1, Mask_bit3:1, Mask_bit4:1, Mask_bit5:1, Mask_bit6:1, Mask_bit7:1, Data/binary>>) ->
if
 Mask_bit0 == 0 -> Nb_meas = 0;
 Mask_bit0 -> Nb_meas => binary_part(Data, {0,1});
 Mask_bit1 -> if
             Nb_meas == 0 -> Fields#{usonic_dist0 => binary_part(Data, {0,2})};
        Nb_meas == 1 -> Fields#{usonic_dist0 => binary_part(Data, {1,2})}, Vindx = 3;
             Nb_meas == 2 -> Fields#{usonic_dist0 => binary_part(Data, {1,2}), usonic_dist1 => binary_part(Data, {3,2})}, Vindx = 5;
             Nb_meas == 3 -> Fields#{usonic_dist0 => binary_part(Data, {1,2}), usonic_dist1 => binary_part(Data, {3,2}), usonic_dist2 => binary_part(Data, {5,2})}, Vindx = 7;
           end.
   (Fields, _) ->
        Fields
Mask_bit2 -> if
             Nb_meas == 0 -> Fields#{voltage0 => binary_part(Data, {2,2})};
        Nb_meas == 1 -> Fields#{voltage0 => binary_part(Data, {Vindx,2})}, Tindx = 5;
             Nb_meas == 2 -> Fields#{voltage0 => binary_part(Data, {Vindx,2}), voltage1 => binary_part(Data, {Vindx+2,2})}, Tindx = 9;
             Nb_meas == 3 -> Fields#{voltage0 => binary_part(Data, {Vindx,2}), voltage1 => binary_part(Data, {Vindx+2,2}), voltage2 => binary_part(Data, {Vindx+4,2})}, Tindx = 13;
           end.
  (Fields, _) ->
        Fields
Mask_bit3 -> if
        Nb_meas == 0 -> Fields#{temperature0 => binary_part(Data, {4, 1})};
        Nb_meas == 1 -> Fields#{temperature0 => binary_part(Data, {Tindx, 1})};
             Nb_meas == 2 -> Fields#{temperature0 => binary_part(Data, {Tindx,1}), temperature1 => binary_part(Data, {Tindx+1,1})};
             Nb_meas == 3 -> Fields#{temperature0 => binary_part(Data, {Tindx,1}), temperature1 => binary_part(Data, {Tindx+1,1}), temperature2 => binary_part(Data, {Tindx+1,1})};
           end.
end.
 (Fields, _) ->
        Fields
end.


BR,

Stonde

Petr Gotthard

unread,
Feb 26, 2019, 9:17:22 AM2/26/19
to Toni Juola, LoRaWAN Server Users

Hi.

 

There are many things wrong with this code. At least:

·         Dot within the function. Dot is an end of the function. Therefore, there can be only one dot, at the very end of the entire function.

·         Weird Vindx assignments (or those are meant as conditions?) There are no assignments in erlang.

 

Plus, the use of “if” to check values is suboptiomal. It would be better to use “case” instead.

 

 

Petr

--
You received this message because you are subscribed to the Google Groups "LoRaWAN Server Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lorawan-serve...@googlegroups.com.
To post to this group, send email to lorawan...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lorawan-server/1a091606-7984-4dcb-b4e0-76dac04c4390%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Александр Тищенко

unread,
Feb 27, 2019, 11:36:41 AM2/27/19
to Petr Gotthard, Toni Juola, LoRaWAN Server Users
As Petr said, there is quite a lot of things that are wrong here. Even nesting is not proper, considering the topmost if and the bottom end which span multiple function clauses. May be it will be easier to help you out if you will just explain the protocol/meaning of the bits and pieces you are trying to process - there are many ways to achieve the solution.

With best regards
Alexander Tishchenko



вт, 26 февр. 2019 г. в 17:17, Petr Gotthard <petr.g...@centrum.cz>:
Reply all
Reply to author
Forward
0 new messages