Erlang/OTP Forums

Author Message

<  Open Telecom Platform (OTP)  ~  Automatic function call in gen_fsm

Dinesh Rajpoot
Posted: Thu Oct 07, 2010 7:35 am Reply with quote
Joined: 11 Jun 2010 Posts: 5 Location: mumbai
hi all,
I am using gen_fsm to create centralized autonomous parking system.The name sounds big but actually what I am doing is just parking the bots in the free slots available.
The gen_fsm has 3 states i.e. receive, find, and update.
Initial state is receive where it waits for Data sent by bot.
if Data is 'r'(parking request) then fsm should go to find state and call function find_slot or if Data is '1'(bot has parked in slot 1) then update the status of slot '1' to occupied.

Code:
receive({check, Data}, State) ->
      case Data of
         'r' ->
             {next_state, find, State}, find_slot();
%%This is wrong but I need such behaviour....
          '1' ->
             {next_state, update. State}, update_slot(1);
         .....
find({find_slot}, State) ->
         ....code for finding slot...

update({update_slot, Slot}, State) ->
        .....code for updating slot.....

find_slot() ->
     gen_fsm:send_event(?SERVER, {find_slot}).

update_slot(Slot) ->
   gen_fsm:send_event(?SERVER, {update_slot, Slot}).


Can Someone tell me how to achieve such behaviour.

"change state to next_state and call a function in next_state"


Thanks and Regards
View user's profile Send private message
jwatte
Posted: Sat Oct 09, 2010 4:41 am Reply with quote
User Joined: 10 Feb 2010 Posts: 34
Is this homework?

Anyway, if you want to model a FSM, then your model is wrong, or at least wrong-ish.

I suggest modeling each parking spot as a FSM that has two states (empty/taken), and each bot as a FSM that has N+1 states (in parking slot 1..N, or in the open).

An alternative is to model your FSM with (N+1)*N*(N-1) ... states, corresponding to the occupancy or not of each parking slot. (I e, slot 1 can be open, have bot 1, have bot 1, ...; slot 2 can be open or have any bot that's not in slot 1, ...)
View user's profile Send private message
nike air max
Posted: Thu Jan 05, 2012 1:50 am Reply with quote
Guest
ugg canada advancement movement image color contacts certainly they are a assortment that will not genuinely customize the colors from the eyes.

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum