Skip to content

Queuetest update #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ BasedOnStyle: Chromium
IndentWidth: 4
AllowShortFunctionsOnASingleLine: None
BreakBeforeBraces: Allman
# BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBinaryOperators: None
BreakBeforeBinaryOperators: NonAssignment
# BreakBeforeBinaryOperators: None
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ clean:
@make -C src clean

format:
find src/ -maxdepth 1 -iname *.h -o -iname *.c | xargs clang-format -i
find src/ -iname *.h -o -iname *.c | xargs clang-format -i
13 changes: 6 additions & 7 deletions src/examples/dhcpclient/src/dhcpc.c
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
#include <netinet/in.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>

#include <ufsm.h>

#include "dhcpc.h"
#include "dhcp_client_fsm.h"
#include "dhcpc.h"

static struct ufsm_queue *q;
static struct ufsm_queue* q;
static int s_fd;

void dhcpc_enable_broadcast(const char *ifacename)
void dhcpc_enable_broadcast(const char* ifacename)
{
s_fd = socket(AF_PACKET, SOCK_RAW, IPPROTO_RAW);

if (s_fd == -1)
printf ("Could not open raw socket\n");
printf("Could not open raw socket\n");
}

void dhcpc_bcast_request(void)
{

}

void dhcpc_reset(struct ufsm_queue *queue)
void dhcpc_reset(struct ufsm_queue* queue)
{
q = queue;
ufsm_queue_put(q, READY);
Expand Down
4 changes: 2 additions & 2 deletions src/examples/dhcpclient/src/dhcpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <ufsm.h>

void dhcpc_enable_broadcast(const char *ifacename);
void dhcpc_enable_broadcast(const char* ifacename);
void dhcpc_bcast_request(void);
void dhcpc_reset(struct ufsm_queue *queue);
void dhcpc_reset(struct ufsm_queue* queue);

#endif
102 changes: 51 additions & 51 deletions src/examples/dhcpclient/src/dhcpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,68 @@
*
*/

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <linux/if_packet.h>
#include <net/ethernet.h>
#include <pthread.h>
#include <stdio.h>
#include <sys/socket.h>
#include <ufsm.h>
#include <unistd.h>

#include "dhcp_client_fsm.h"
#include "dhcpc.h"

static struct ufsm_machine *m = NULL;
static struct ufsm_queue *q = NULL;
static struct ufsm_machine* m = NULL;
static struct ufsm_queue* q = NULL;
static pthread_mutex_t queue_lock;
static pthread_mutex_t event_loop_lock;
static char *ifacename = NULL;
static char* ifacename = NULL;

#define MSG(x...) printf(" | Message | " x)

/* Debug functions */
static void debug_transition (struct ufsm_transition *t)
static void debug_transition(struct ufsm_transition* t)
{

printf (" | Transition | %s {%s} --> %s {%s}\n", t->source->name,
ufsm_state_kinds[t->source->kind],
t->dest->name,
ufsm_state_kinds[t->dest->kind]);
printf(" | Transition | %s {%s} --> %s {%s}\n",
t->source->name,
ufsm_state_kinds[t->source->kind],
t->dest->name,
ufsm_state_kinds[t->dest->kind]);
}

static void debug_enter_region(struct ufsm_region *r)
static void debug_enter_region(struct ufsm_region* r)
{
printf (" | R enter | %s, H=%i\n", r->name, r->has_history);
printf(" | R enter | %s, H=%i\n", r->name, r->has_history);
}

static void debug_leave_region(struct ufsm_region *r)
static void debug_leave_region(struct ufsm_region* r)
{
printf (" | R exit | %s, H=%i\n", r->name, r->has_history);
printf(" | R exit | %s, H=%i\n", r->name, r->has_history);
}

static void debug_event(uint32_t ev)
{
printf (" %-3i| |\n",ev);
printf(" %-3i| |\n", ev);
}

static void debug_action(struct ufsm_action *a)
static void debug_action(struct ufsm_action* a)
{
printf (" | Action | %s()\n",a->name);
printf(" | Action | %s()\n", a->name);
}

static void debug_guard(struct ufsm_guard *g, bool result)
static void debug_guard(struct ufsm_guard* g, bool result)
{
printf (" | Guard | %s() = %i\n", g->name, result);
printf(" | Guard | %s() = %i\n", g->name, result);
}

static void debug_enter_state(struct ufsm_state *s)
static void debug_enter_state(struct ufsm_state* s)
{
printf (" | S enter | %s {%s}\n", s->name,ufsm_state_kinds[s->kind]);
printf(" | S enter | %s {%s}\n", s->name, ufsm_state_kinds[s->kind]);
}

static void debug_exit_state(struct ufsm_state *s)
static void debug_exit_state(struct ufsm_state* s)
{
printf (" | S exit | %s {%s}\n", s->name,ufsm_state_kinds[s->kind]);
printf(" | S exit | %s {%s}\n", s->name, ufsm_state_kinds[s->kind]);
}

/* uFSM actions/guards */
Expand All @@ -79,17 +79,17 @@ void dhcp_stop_timers(void)

void dhcp_disable_broadcast(void)
{
MSG ("Broadcast disable\n");
MSG("Broadcast disable\n");
}

void dhcp_enable_socket(void)
{
MSG ("Socket enable\n");
MSG("Socket enable\n");
}

void dhcp_send_request(void)
{
MSG ("Send request\n");
MSG("Send request\n");
}

void dhcp_display_result(void)
Expand All @@ -98,7 +98,7 @@ void dhcp_display_result(void)

void dhcp_disable_socket(void)
{
MSG ("Disable socket\n");
MSG("Disable socket\n");
}

void dhcp_enable_broadcast(void)
Expand All @@ -120,9 +120,8 @@ void dhcp_set_timers(void)

void dhcp_reset(void)
{
MSG ("DHCP Reset\n");
MSG("DHCP Reset\n");
dhcpc_reset(q);

}

void dhcp_select_offer(void)
Expand Down Expand Up @@ -150,7 +149,6 @@ void dhcp_collect_reply(void)
{
}


/* Help functions */

void dhcp_run_eventloop(void)
Expand All @@ -168,39 +166,40 @@ void dhcp_unlock_queue(void)
pthread_mutex_unlock(&queue_lock);
}

void * q_test (void *arg)
void* q_test(void* arg)
{
while (true)
{
ufsm_queue_put(q,DHCPACK);
ufsm_queue_put(q, DHCPACK);
sleep(1);
}
}

int main(int argc, char **argv)
int main(int argc, char** argv)
{
bool running = true;
uint32_t err = UFSM_OK;
uint32_t ev = 0;

printf ("uFSM dhcp client demo\n");
printf("uFSM dhcp client demo\n");

if (argc < 2) {
printf ("Usage: dhcpclient <network interface>\n");
if (argc < 2)
{
printf("Usage: dhcpclient <network interface>\n");
return 0;
}

ifacename = argv[1];

if (pthread_mutex_init (&queue_lock, NULL) != 0)
if (pthread_mutex_init(&queue_lock, NULL) != 0)
{
printf ("Error: Could not initialise queue lock\n");
printf("Error: Could not initialise queue lock\n");
return -1;
}

if (pthread_mutex_init (&event_loop_lock, NULL) != 0)
if (pthread_mutex_init(&event_loop_lock, NULL) != 0)
{
printf ("Error: Could not initialise event loop lock\n");
printf("Error: Could not initialise event loop lock\n");
return -1;
}

Expand All @@ -220,25 +219,28 @@ int main(int argc, char **argv)
q->lock = &dhcp_lock_queue;
q->unlock = &dhcp_unlock_queue;

printf (" EV | OP | Details\n");
printf(" EV | OP | Details\n");
ufsm_init_machine(m);

pthread_t t;
//pthread_create(&t, NULL, &q_test, NULL);
// pthread_create(&t, NULL, &q_test, NULL);

while (running)
{
pthread_mutex_lock(&event_loop_lock);
err = ufsm_queue_get(q, &ev);

if (err == UFSM_OK) {
if (err == UFSM_OK)
{
pthread_mutex_unlock(&event_loop_lock);

err = ufsm_process(m, ev);
if (err != UFSM_OK)
MSG ("Error: %s\n", ufsm_errors[err]);
} else {
MSG ("Eventloop: No more events to process, sleeping...\n");
MSG("Error: %s\n", ufsm_errors[err]);
}
else
{
MSG("Eventloop: No more events to process, sleeping...\n");
}
}

Expand All @@ -247,5 +249,3 @@ int main(int argc, char **argv)

return 0;
}


11 changes: 5 additions & 6 deletions src/examples/simple/simple.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#include <ufsm.h>
#include <stdio.h>
#include <ufsm.h>
#include "ufsm_demo_fsm.h"

void led_on(void)
{
printf ("LED ON\n");
printf("LED ON\n");
}

void led_off(void)
{
printf ("LED OFF\n");
printf("LED OFF\n");
}

int main(int argc, char **argv)
int main(int argc, char** argv)
{
struct ufsm_machine *m = get_StateMachine1();
struct ufsm_machine* m = get_StateMachine1();

ufsm_init_machine(m);

Expand All @@ -30,4 +30,3 @@ int main(int argc, char **argv)

return 0;
}

15 changes: 15 additions & 0 deletions src/tests/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
BasedOnStyle: Chromium
IndentWidth: 4
AllowShortFunctionsOnASingleLine: All
BreakBeforeBraces: Allman
# BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBinaryOperators: None
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
BinPackArguments: false
BinPackParameters: false
AlignAfterOpenBracket: Align
PenaltyBreakAssignment: 100
PenaltyBreakBeforeFirstCallParameter: 1000

Loading