Prusa MINI Firmware overview
marlin_client.c File Reference
#include "marlin_client.h"
#include <stdarg.h>
#include <string.h>
#include "dbg.h"
#include "app.h"
#include "bsod.h"
#include "cmsis_os.h"
#include "stm32f4xx_hal.h"

Classes

struct  _marlin_client_t
 

Macros

#define DBG   _dbg1
 
#define DBG_REQ(...)
 
#define DBG_EVT   DBG
 
#define DBG_EVT_MSK   (MARLIN_EVT_MSK_ALL & ~MARLIN_EVT_MSK(MARLIN_EVT_Acknowledge))
 
#define DBG_VAR(...)
 

Typedefs

typedef struct _marlin_client_t marlin_client_t
 

Functions

void _wait_server_started (void)
 
void _send_request_to_server (uint8_t client_id, const char *request)
 
uint32_t _wait_ack_from_server (uint8_t client_id)
 
void _process_client_message (marlin_client_t *client, variant8_t msg)
 
marlin_client_t_client_ptr (void)
 
marlin_vars_tmarlin_client_init (void)
 
void marlin_client_shdn (void)
 
void marlin_client_loop (void)
 
int marlin_processing (void)
 
int marlin_busy (void)
 
uint32_t marlin_command (void)
 
void marlin_stop_processing (void)
 
void marlin_start_processing (void)
 
int marlin_motion (void)
 
int marlin_wait_motion (uint32_t timeout)
 
void marlin_gcode (const char *gcode)
 
int marlin_gcode_printf (const char *format,...)
 
void marlin_gcode_push_front (const char *gcode)
 
int marlin_event (uint8_t evt_id)
 
int marlin_event_set (uint8_t evt_id)
 
int marlin_event_clr (uint8_t evt_id)
 
uint64_t marlin_events (void)
 
int marlin_change (uint8_t var_id)
 
int marlin_change_set (uint8_t var_id)
 
int marlin_change_clr (uint8_t var_id)
 
uint64_t marlin_changes (void)
 
int marlin_error (uint8_t err_id)
 
int marlin_error_set (uint8_t err_id)
 
int marlin_error_clr (uint8_t err_id)
 
uint64_t marlin_errors (void)
 
variant8_t marlin_get_var (uint8_t var_id)
 
variant8_t marlin_set_var (uint8_t var_id, variant8_t val)
 
marlin_vars_tmarlin_vars (void)
 
marlin_vars_tmarlin_update_vars (uint64_t msk)
 
uint8_t marlin_get_gqueue (void)
 
uint8_t marlin_get_gqueue_max (void)
 
uint8_t marlin_get_pqueue (void)
 
uint8_t marlin_get_pqueue_max (void)
 
float marlin_set_target_nozzle (float val)
 
float marlin_set_target_bed (float val)
 
float marlin_set_z_offset (float val)
 
uint8_t marlin_set_fan_speed (uint8_t val)
 
uint16_t marlin_set_print_speed (uint16_t val)
 
uint16_t marlin_set_flow_factor (uint16_t val)
 
uint8_t marlin_set_wait_heat (uint8_t val)
 
uint8_t marlin_set_wait_user (uint8_t val)
 
void marlin_do_babysteps_Z (float offs)
 
void marlin_settings_save (void)
 
void marlin_settings_load (void)
 
void marlin_manage_heater (void)
 
void marlin_quick_stop (void)
 
void marlin_print_abort (void)
 
void marlin_print_pause (void)
 
void marlin_print_resume (void)
 
void marlin_park_head (void)
 
uint8_t marlin_message_received (void)
 
host_prompt_type_t marlin_host_prompt_type (void)
 
uint8_t marlin_host_button_count (void)
 
host_prompt_button_t marlin_host_button_type (uint8_t index)
 
void marlin_host_button_click (host_prompt_button_t button)
 
int marlin_reheating (void)
 

Variables

osThreadId marlin_client_task [MARLIN_MAX_CLIENTS]
 
osMessageQId marlin_client_queue [MARLIN_MAX_CLIENTS]
 
marlin_client_t marlin_client [MARLIN_MAX_CLIENTS]
 
uint8_t marlin_clients = 0
 
osThreadId marlin_server_task
 
osMessageQId marlin_server_queue
 
osSemaphoreId marlin_server_sema
 

Macro Definition Documentation

◆ DBG

#define DBG   _dbg1

◆ DBG_REQ

#define DBG_REQ (   ...)

◆ DBG_EVT

#define DBG_EVT   DBG

◆ DBG_EVT_MSK

◆ DBG_VAR

#define DBG_VAR (   ...)

Typedef Documentation

◆ marlin_client_t

Function Documentation

◆ _wait_server_started()

void _wait_server_started ( void  )
564  {
565  while (marlin_server_task == 0)
566  osDelay(1);
567 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _send_request_to_server()

void _send_request_to_server ( uint8_t  client_id,
const char *  request 
)
570  {
571  int ret = 0;
572  int len = strlen(request);
573  osMessageQId queue = 0;
574  int i;
576  if ((queue = marlin_server_queue) != 0) // queue valid
577  {
579  while (ret == 0) {
580  if (osMessageAvailableSpace(queue) >= (uint32_t)(len + 1)) // check available space
581  {
582  osMessagePut(queue, '0' + client_id, osWaitForever); // one character client id
583  for (i = 0; i < len; i++) // loop over every characters
584  osMessagePut(queue, request[i], osWaitForever); //
585  if ((i > 0) && (request[i - 1] != '\n')) // automatically terminate with '\n'
587  ret = 1;
588  } else {
590  osDelay(10);
592  }
593  }
594  }
596  DBG_REQ("CL%c: REQ %s", '0' + client_id, request);
597  //return ret;
598 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _wait_ack_from_server()

uint32_t _wait_ack_from_server ( uint8_t  client_id)
601  {
602  while ((marlin_client[client_id].events & MARLIN_EVT_MSK(MARLIN_EVT_Acknowledge)) == 0) {
604  if (marlin_client[client_id].last_count == 0)
605  osDelay(10);
606  }
608  return marlin_client[client_id].ack;
609 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _process_client_message()

void _process_client_message ( marlin_client_t client,
variant8_t  msg 
)
612  {
613  char var_str[16];
614  uint8_t id = msg.usr8 & MARLIN_USR8_MSK_ID;
615  if (msg.usr8 & MARLIN_USR8_VAR_FLG) // variable change received
616  {
617  marlin_vars_set_var(&(client->vars), id, msg);
618  client->changes |= ((uint64_t)1 << id);
619  marlin_vars_value_to_str(&(client->vars), id, var_str);
620 #ifdef DBG_VAR_MSK
621  if (DBG_VAR_MSK & ((uint64_t)1 << id))
622 #endif //DBG_VAR_MSK
623  DBG_VAR("CL%c: VAR %s %s", '0' + client->id, marlin_vars_get_name(id), var_str);
624  } else if (msg.type == VARIANT8_USER) // event received
625  {
626  client->events |= ((uint64_t)1 << id);
627  switch (id) {
628  case MARLIN_EVT_MeshUpdate: {
629  uint8_t x = msg.usr16 & 0xff;
630  uint8_t y = msg.usr16 >> 8;
631  float z = msg.flt;
632  client->mesh.z[x + client->mesh.xc * y] = z;
633  } break;
635  marlin_host_prompt_decode(msg.ui32, &(client->prompt));
636  break;
638  client->flags |= MARLIN_CFLG_PROCESS;
639  break;
641  client->flags &= ~MARLIN_CFLG_PROCESS;
642  break;
643  case MARLIN_EVT_Busy:
644  client->flags |= MARLIN_CFLG_BUSY;
645  break;
646  case MARLIN_EVT_Ready:
647  client->flags &= ~MARLIN_CFLG_BUSY;
648  break;
649  case MARLIN_EVT_Error:
650  client->errors |= MARLIN_ERR_MSK(msg.ui32);
651  break;
653  client->command = msg.ui32;
654  break;
656  client->command = MARLIN_CMD_NONE;
657  break;
658  case MARLIN_EVT_Message:
659  client->flags |= MARLIN_CFLG_MESSAGE;
660  break;
661  case MARLIN_EVT_Reheat:
662  client->reheating = (uint8_t)msg.ui32;
663  break;
665  client->ack = msg.ui32;
666  break;
667  }
668 #ifdef DBG_EVT_MSK
669  if (DBG_EVT_MSK & ((uint64_t)1 << id))
670 #endif
671  switch (id) {
672  // Event MARLIN_EVT_MeshUpdate - ui32 is float z, ui16 low byte is x index, high byte y index
673  case MARLIN_EVT_MeshUpdate: {
674  uint8_t x = msg.usr16 & 0xff;
675  uint8_t y = msg.usr16 >> 8;
676  float z = msg.flt;
677  DBG_EVT("CL%c: EVT %s %d %d %.3f", '0' + client->id, marlin_events_get_name(id),
678  x, y, (double)z);
679  x = x;
680  y = y;
681  z = z; //prevent warning
682  } break;
683  // Event MARLIN_EVT_CommandBegin/End - ui32 is encoded command
686  DBG_EVT("CL%c: EVT %s %c%u", '0' + client->id, marlin_events_get_name(id),
687  (msg.ui32 >> 16) & 0xff, msg.ui32 & 0xffff);
688  break;
689  // Event MARLIN_EVT_Acknowledge - ui32 is result (not used in this time)
690  case MARLIN_EVT_Reheat:
692  DBG_EVT("CL%c: EVT %s %lu", '0' + client->id, marlin_events_get_name(id), msg.ui32);
693  break;
694  // Other events and events without arguments
695  default:
696  DBG_EVT("CL%c: EVT %s", '0' + client->id, marlin_events_get_name(id));
697  break;
698  }
699  }
700 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _client_ptr()

marlin_client_t * _client_ptr ( void  )
703  {
704  osThreadId taskHandle = osThreadGetId();
705  int client_id;
706  for (client_id = 0; client_id < MARLIN_MAX_CLIENTS; client_id++)
707  if (taskHandle == marlin_client_task[client_id])
708  return marlin_client + client_id;
709  return 0;
710 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_client_init()

marlin_vars_t* marlin_client_init ( void  )
84  {
85  int client_id;
86  marlin_client_t *client = 0;
89  for (client_id = 0; client_id < MARLIN_MAX_CLIENTS; client_id++)
90  if (marlin_client_task[client_id] == 0)
91  break;
92  if (client_id < MARLIN_MAX_CLIENTS) {
93  client = marlin_client + client_id;
94  memset(client, 0, sizeof(marlin_client_t));
95  osMessageQDef(clientQueue, 32, uint32_t);
96  marlin_client_queue[client_id] = osMessageCreate(osMessageQ(clientQueue), NULL);
97  client->id = client_id;
98  client->flags = 0;
99  client->events = 0;
100  client->changes = 0;
101  marlin_clients++;
103  client->errors = 0;
104  client->mesh.xc = 4;
105  client->mesh.yc = 4;
106  client->command = MARLIN_CMD_NONE;
107  client->reheating = 0;
108  marlin_client_task[client_id] = osThreadGetId();
109  }
111  return (client) ? &(client->vars) : 0;
112 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_client_shdn()

void marlin_client_shdn ( void  )
114  {
115  //TODO
116 }

◆ marlin_client_loop()

void marlin_client_loop ( void  )
118  {
119  uint16_t count = 0;
120  osEvent ose;
121  variant8_t msg;
122  int client_id;
123  marlin_client_t *client;
125  osThreadId taskHandle = osThreadGetId();
126  for (client_id = 0; client_id < MARLIN_MAX_CLIENTS; client_id++)
127  if (taskHandle == marlin_client_task[client_id])
128  break;
129  if (client_id >= MARLIN_MAX_CLIENTS)
130  return;
131  client = marlin_client + client_id;
132  if ((queue = marlin_client_queue[client_id]) != 0)
133  while ((ose = osMessageGet(queue, 0)).status == osEventMessage) {
134  if (client->flags & MARLIN_CFLG_LOWHIGH) {
135  *(((uint32_t *)(&msg)) + 1) = ose.value.v; //store high dword
136  _process_client_message(client, msg); //call handler
137  count++;
138  } else
139  *(((uint32_t *)(&msg)) + 0) = ose.value.v; //store low dword
140  client->flags ^= MARLIN_CFLG_LOWHIGH; //flip flag
141  }
142  client->last_count = count;
143 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_processing()

int marlin_processing ( void  )
145  {
146  marlin_client_t *client = _client_ptr();
147  if (client)
148  return (client->flags & MARLIN_CFLG_PROCESS) ? 1 : 0;
149  return 0;
150 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_busy()

int marlin_busy ( void  )
152  {
153  marlin_client_t *client = _client_ptr();
154  if (client)
155  return (client->flags & MARLIN_CFLG_BUSY) ? 1 : 0;
156  return 0;
157 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_command()

uint32_t marlin_command ( void  )
159  {
160  marlin_client_t *client = _client_ptr();
161  if (client)
162  return client->command;
163  return MARLIN_CMD_NONE;
164 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_stop_processing()

void marlin_stop_processing ( void  )
166  {
167  marlin_client_t *client = _client_ptr();
168  if (client == 0)
169  return;
170  _send_request_to_server(client->id, "!stop");
171  _wait_ack_from_server(client->id);
172 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_start_processing()

void marlin_start_processing ( void  )
174  {
175  marlin_client_t *client = _client_ptr();
176  if (client == 0)
177  return;
178  _send_request_to_server(client->id, "!start");
179  _wait_ack_from_server(client->id);
180 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_motion()

int marlin_motion ( void  )
182  {
184  return (vars->motion) ? 1 : 0;
185 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_wait_motion()

int marlin_wait_motion ( uint32_t  timeout)
187  {
189  uint32_t tick = HAL_GetTick();
190  while ((vars->motion == 0) && ((HAL_GetTick() - tick) < timeout))
192  return (vars->motion) ? 1 : 0;
193 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_gcode()

void marlin_gcode ( const char *  gcode)
195  {
196  char request[MARLIN_MAX_REQUEST];
197  marlin_client_t *client = _client_ptr();
198  if (client == 0)
199  return;
200  strcpy(request, "!g ");
201  strcat(request, gcode);
202  _send_request_to_server(client->id, request);
203  _wait_ack_from_server(client->id);
204 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_gcode_printf()

int marlin_gcode_printf ( const char *  format,
  ... 
)
206  {
207  int ret;
208  char request[MARLIN_MAX_REQUEST];
209  marlin_client_t *client = _client_ptr();
210  if (client == 0)
211  return 0;
212  strcpy(request, "!g ");
213  va_list ap;
214  va_start(ap, format);
215  ret = vsprintf(request + 3, format, ap);
216  va_end(ap);
217  _send_request_to_server(client->id, request);
218  _wait_ack_from_server(client->id);
219  return ret;
220 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_gcode_push_front()

void marlin_gcode_push_front ( const char *  gcode)
222  {
223  char request[MARLIN_MAX_REQUEST];
224  marlin_client_t *client = _client_ptr();
225  if (client == 0)
226  return;
227  snprintf(request, MARLIN_MAX_REQUEST, "!ig %p", gcode);
228  _send_request_to_server(client->id, request);
229  _wait_ack_from_server(client->id);
230 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_event()

int marlin_event ( uint8_t  evt_id)
232  {
233  int ret = 0;
234  marlin_client_t *client = _client_ptr();
235  uint64_t msk = (uint64_t)1 << evt_id;
236  if (client)
237  ret = (client->events & msk) ? 1 : 0;
238  return ret;
239 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_event_set()

int marlin_event_set ( uint8_t  evt_id)
241  {
242  int ret = 0;
243  marlin_client_t *client = _client_ptr();
244  uint64_t msk = (uint64_t)1 << evt_id;
245  if (client) {
246  ret = (client->events & msk) ? 1 : 0;
247  client->events |= msk;
248  }
249  return ret;
250 }
Here is the call graph for this function:

◆ marlin_event_clr()

int marlin_event_clr ( uint8_t  evt_id)
252  {
253  int ret = 0;
254  marlin_client_t *client = _client_ptr();
255  uint64_t msk = (uint64_t)1 << evt_id;
256  if (client) {
257  ret = (client->events & msk) ? 1 : 0;
258  client->events &= ~msk;
259  }
260  return ret;
261 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_events()

uint64_t marlin_events ( void  )
263  {
264  marlin_client_t *client = _client_ptr();
265  return (client) ? client->events : 0;
266 }
Here is the call graph for this function:

◆ marlin_change()

int marlin_change ( uint8_t  var_id)
268  {
269  int ret = 0;
270  marlin_client_t *client = _client_ptr();
271  uint64_t msk = (uint64_t)1 << var_id;
272  if (client)
273  ret = (client->changes & msk) ? 1 : 0;
274  return ret;
275 }
Here is the call graph for this function:

◆ marlin_change_set()

int marlin_change_set ( uint8_t  var_id)
277  {
278  int ret = 0;
279  marlin_client_t *client = _client_ptr();
280  uint64_t msk = (uint64_t)1 << var_id;
281  if (client) {
282  ret = (client->changes & msk) ? 1 : 0;
283  client->changes |= msk;
284  }
285  return ret;
286 }
Here is the call graph for this function:

◆ marlin_change_clr()

int marlin_change_clr ( uint8_t  var_id)
288  {
289  int ret = 0;
290  marlin_client_t *client = _client_ptr();
291  uint64_t msk = (uint64_t)1 << var_id;
292  if (client) {
293  ret = (client->changes & msk) ? 1 : 0;
294  client->changes &= ~msk;
295  }
296  return ret;
297 }
Here is the call graph for this function:

◆ marlin_changes()

uint64_t marlin_changes ( void  )
299  {
300  marlin_client_t *client = _client_ptr();
301  return (client) ? client->changes : 0;
302 }
Here is the call graph for this function:

◆ marlin_error()

int marlin_error ( uint8_t  err_id)
304  {
305  int ret = 0;
306  marlin_client_t *client = _client_ptr();
307  uint64_t msk = (uint64_t)1 << err_id;
308  if (client)
309  ret = (client->errors & msk) ? 1 : 0;
310  return ret;
311 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_error_set()

int marlin_error_set ( uint8_t  err_id)
313  {
314  int ret = 0;
315  marlin_client_t *client = _client_ptr();
316  uint64_t msk = (uint64_t)1 << err_id;
317  if (client) {
318  ret = (client->errors & msk) ? 1 : 0;
319  client->errors |= msk;
320  }
321  return ret;
322 }
Here is the call graph for this function:

◆ marlin_error_clr()

int marlin_error_clr ( uint8_t  err_id)
324  {
325  int ret = 0;
326  marlin_client_t *client = _client_ptr();
327  uint64_t msk = (uint64_t)1 << err_id;
328  if (client) {
329  ret = (client->errors & msk) ? 1 : 0;
330  client->errors &= ~msk;
331  }
332  return ret;
333 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_errors()

uint64_t marlin_errors ( void  )
335  {
336  marlin_client_t *client = _client_ptr();
337  return (client) ? client->errors : 0;
338 }
Here is the call graph for this function:

◆ marlin_get_var()

variant8_t marlin_get_var ( uint8_t  var_id)
340  {
341  marlin_client_t *client = _client_ptr();
342  return (client) ? marlin_vars_get_var(&(client->vars), var_id) : variant8_empty();
343 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_set_var()

variant8_t marlin_set_var ( uint8_t  var_id,
variant8_t  val 
)
345  {
346  variant8_t retval = variant8_empty();
347  char request[MARLIN_MAX_REQUEST];
348  int n;
349  marlin_client_t *client = _client_ptr();
350  if (client) {
351  retval = marlin_vars_get_var(&(client->vars), var_id);
352  marlin_vars_set_var(&(client->vars), var_id, val);
353  n = sprintf(request, "!var %s ", marlin_vars_get_name(var_id));
354  marlin_vars_value_to_str(&(client->vars), var_id, request + n);
355  _send_request_to_server(client->id, request);
356  _wait_ack_from_server(client->id);
357  }
358  return retval;
359 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_vars()

marlin_vars_t* marlin_vars ( void  )
361  {
362  marlin_client_t *client = _client_ptr();
363  if (client)
364  return &(client->vars);
365  return 0;
366 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_update_vars()

marlin_vars_t* marlin_update_vars ( uint64_t  msk)
368  {
369  char request[MARLIN_MAX_REQUEST];
370  marlin_client_t *client = _client_ptr();
371  if (client == 0)
372  return 0;
374  client->changes &= ~msk;
375  sprintf(request, "!update %" PRIu64, msk);
376  _send_request_to_server(client->id, request);
377  _wait_ack_from_server(client->id);
378  return &(client->vars);
379 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_get_gqueue()

uint8_t marlin_get_gqueue ( void  )
381  {
383 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_get_gqueue_max()

uint8_t marlin_get_gqueue_max ( void  )
385  {
386  //TODO: variable gqueue_max should be part of marlin_consts structure transmited from server
387  //Marlin/queue, BUFSIZE - 1
388  return 8 - 1;
389 }

◆ marlin_get_pqueue()

uint8_t marlin_get_pqueue ( void  )
391  {
393 }
Here is the call graph for this function:

◆ marlin_get_pqueue_max()

uint8_t marlin_get_pqueue_max ( void  )
395  {
396  //TODO: variable pqueue_max should be part of marlin_consts structure transmited from server
397  //Marlin/planner, BLOCK_BUFFER_SIZE - 1
398  return 16 - 1;
399 }

◆ marlin_set_target_nozzle()

float marlin_set_target_nozzle ( float  val)
401  {
403 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_set_target_bed()

float marlin_set_target_bed ( float  val)
405  {
407 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_set_z_offset()

float marlin_set_z_offset ( float  val)
409  {
411 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_set_fan_speed()

uint8_t marlin_set_fan_speed ( uint8_t  val)
413  {
415 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_set_print_speed()

uint16_t marlin_set_print_speed ( uint16_t  val)
417  {
419 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_set_flow_factor()

uint16_t marlin_set_flow_factor ( uint16_t  val)
421  {
423 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_set_wait_heat()

uint8_t marlin_set_wait_heat ( uint8_t  val)
425  {
427 }
Here is the call graph for this function:

◆ marlin_set_wait_user()

uint8_t marlin_set_wait_user ( uint8_t  val)
429  {
431 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_do_babysteps_Z()

void marlin_do_babysteps_Z ( float  offs)
433  {
434  char request[MARLIN_MAX_REQUEST];
435  marlin_client_t *client = _client_ptr();
436  if (client == 0)
437  return;
438  sprintf(request, "!babystep_Z %.4f", (double)offs);
439  _send_request_to_server(client->id, request);
440  _wait_ack_from_server(client->id);
441 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_settings_save()

void marlin_settings_save ( void  )
443  {
444  marlin_client_t *client = _client_ptr();
445  if (client == 0)
446  return;
447  _send_request_to_server(client->id, "!save");
448  _wait_ack_from_server(client->id);
449 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_settings_load()

void marlin_settings_load ( void  )
451  {
452  marlin_client_t *client = _client_ptr();
453  if (client == 0)
454  return;
455  _send_request_to_server(client->id, "!load");
456  _wait_ack_from_server(client->id);
457 }
Here is the call graph for this function:

◆ marlin_manage_heater()

void marlin_manage_heater ( void  )
459  {
460  marlin_client_t *client = _client_ptr();
461  if (client == 0)
462  return;
463  _send_request_to_server(client->id, "!updt");
464  _wait_ack_from_server(client->id);
465 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_quick_stop()

void marlin_quick_stop ( void  )
467  {
468  marlin_client_t *client = _client_ptr();
469  if (client == 0)
470  return;
471  _send_request_to_server(client->id, "!qstop");
472  _wait_ack_from_server(client->id);
473 }
Here is the call graph for this function:

◆ marlin_print_abort()

void marlin_print_abort ( void  )
475  {
476  marlin_client_t *client = _client_ptr();
477  if (client == 0)
478  return;
479  _send_request_to_server(client->id, "!pabort");
480  _wait_ack_from_server(client->id);
481 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_print_pause()

void marlin_print_pause ( void  )
483  {
484  marlin_client_t *client = _client_ptr();
485  if (client == 0)
486  return;
487  _send_request_to_server(client->id, "!ppause");
488  _wait_ack_from_server(client->id);
489 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_print_resume()

void marlin_print_resume ( void  )
491  {
492  marlin_client_t *client = _client_ptr();
493  if (client == 0)
494  return;
495  _send_request_to_server(client->id, "!presume");
496  _wait_ack_from_server(client->id);
497 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_park_head()

void marlin_park_head ( void  )
499  {
500  marlin_client_t *client = _client_ptr();
501  if (client == 0)
502  return;
503  _send_request_to_server(client->id, "!park");
504  _wait_ack_from_server(client->id);
505 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_message_received()

uint8_t marlin_message_received ( void  )
507  {
508  marlin_client_t *client = _client_ptr();
509  if (client == 0)
510  return 0;
511  if (client->flags & MARLIN_CFLG_MESSAGE) {
512  client->flags &= ~MARLIN_CFLG_MESSAGE;
513  return 1;
514  } else
515  return 0;
516 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_host_prompt_type()

host_prompt_type_t marlin_host_prompt_type ( void  )
521  {
522  marlin_client_t *client = _client_ptr();
523  if (client)
524  return client->prompt.type;
525  return HOST_PROMPT_None;
526 }
Here is the call graph for this function:

◆ marlin_host_button_count()

uint8_t marlin_host_button_count ( void  )
528  {
529  marlin_client_t *client = _client_ptr();
530  if (client)
531  return client->prompt.button_count;
532  return 0;
533 }
Here is the call graph for this function:

◆ marlin_host_button_type()

host_prompt_button_t marlin_host_button_type ( uint8_t  index)
535  {
536  marlin_client_t *client = _client_ptr();
537  if (client && (index < client->prompt.button_count))
538  return client->prompt.button[index];
539  return HOST_PROMPT_BTN_None;
540 }
Here is the call graph for this function:

◆ marlin_host_button_click()

void marlin_host_button_click ( host_prompt_button_t  button)
542  {
543  char request[MARLIN_MAX_REQUEST];
544  marlin_client_t *client = _client_ptr();
545  if (client == 0)
546  return;
547  sprintf(request, "!hclick %d", (int)button);
548  _send_request_to_server(client->id, request);
549  _wait_ack_from_server(client->id);
550 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ marlin_reheating()

int marlin_reheating ( void  )
553  {
554  marlin_client_t *client = _client_ptr();
555  if (client)
556  return client->reheating;
557  return 0;
558 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ marlin_client_task

osThreadId marlin_client_task[MARLIN_MAX_CLIENTS]

◆ marlin_client_queue

osMessageQId marlin_client_queue[MARLIN_MAX_CLIENTS]

◆ marlin_client

◆ marlin_clients

uint8_t marlin_clients = 0

◆ marlin_server_task

osThreadId marlin_server_task

◆ marlin_server_queue

osMessageQId marlin_server_queue

◆ marlin_server_sema

osSemaphoreId marlin_server_sema
MARLIN_MAX_CLIENTS
#define MARLIN_MAX_CLIENTS
Definition: config.h:96
_marlin_client_t::flags
uint16_t flags
Definition: marlin_client.c:41
MARLIN_ERR_MSK
#define MARLIN_ERR_MSK(e_id)
Definition: marlin_errors.h:13
osMessageAvailableSpace
uint32_t osMessageAvailableSpace(osMessageQId queue_id)
Get the available space in a message queue.
Definition: cmsis_os.c:1658
variant8_ui8
variant8_t variant8_ui8(uint8_t ui8)
Definition: variant8.c:18
marlin_vars_get_name
const char * marlin_vars_get_name(uint8_t var_id)
Definition: marlin_vars.c:36
_wait_ack_from_server
uint32_t _wait_ack_from_server(uint8_t client_id)
Definition: marlin_client.c:601
osThreadId
TaskHandle_t osThreadId
Definition: cmsis_os.h:283
DBG_VAR
#define DBG_VAR(...)
Definition: marlin_client.c:23
osSemaphoreWait
int32_t osSemaphoreWait(osSemaphoreId semaphore_id, uint32_t millisec)
Wait until a Semaphore token becomes available.
Definition: cmsis_os.c:822
queue
GCodeQueue queue
Definition: queue.cpp:28
marlin_vars_get_var
variant8_t marlin_vars_get_var(marlin_vars_t *vars, uint8_t var_id)
Definition: marlin_vars.c:50
g29_auto.gcode
list gcode
Definition: g29_auto.py:44
_variant8_t::ui16
uint16_t ui16
Definition: variant8.h:34
MARLIN_VAR_FLOWFACT
#define MARLIN_VAR_FLOWFACT
Definition: marlin_vars.h:26
MARLIN_VAR_MOTION
#define MARLIN_VAR_MOTION
Definition: marlin_vars.h:8
_marlin_host_prompt_t::button
host_prompt_button_t button[HOST_PROMPT_MAX_BUTTONS]
Definition: marlin_host.h:49
marlin_server_task
osThreadId marlin_server_task
Definition: marlin_server.cpp:88
_variant8_t::ui8
uint8_t ui8
Definition: variant8.h:36
MARLIN_VAR_FANSPEED
#define MARLIN_VAR_FANSPEED
Definition: marlin_vars.h:24
marlin_get_var
variant8_t marlin_get_var(uint8_t var_id)
Definition: marlin_client.c:340
marlin_vars_value_to_str
void marlin_vars_value_to_str(marlin_vars_t *vars, uint8_t var_id, char *str)
Definition: marlin_vars.c:183
VARIANT8_USER
#define VARIANT8_USER
Definition: variant8.h:16
i
uint8_t i
Definition: screen_test_graph.c:72
_variant8_t::type
uint8_t type
Definition: variant8.h:25
MARLIN_VAR_TTEM_BED
#define MARLIN_VAR_TTEM_BED
Definition: marlin_vars.h:22
_marlin_client_t::reheating
uint8_t reheating
Definition: marlin_client.c:51
_marlin_host_prompt_t::type
host_prompt_type_t type
Definition: marlin_host.h:47
DBG_EVT
#define DBG_EVT
Definition: marlin_client.c:18
marlin_events_get_name
const char * marlin_events_get_name(uint8_t evt_id)
Definition: marlin_events.c:40
_marlin_client_t::command
uint32_t command
Definition: marlin_client.c:49
_marlin_mesh_t::xc
uint8_t xc
Definition: marlin_events.h:104
marlin_client_loop
void marlin_client_loop(void)
Definition: marlin_client.c:118
osThreadGetId
osThreadId osThreadGetId(void)
Return the thread ID of the current running thread.
Definition: cmsis_os.c:283
_variant8_t::usr16
uint16_t usr16
Definition: variant8.h:27
NULL
#define NULL
Definition: usbd_def.h:53
marlin_client
marlin_client_t marlin_client[MARLIN_MAX_CLIENTS]
Definition: marlin_client.c:62
osMessageQId
QueueHandle_t osMessageQId
Definition: cmsis_os.h:303
MARLIN_USR8_VAR_FLG
#define MARLIN_USR8_VAR_FLG
Definition: marlin_vars.h:59
MARLIN_CFLG_LOWHIGH
#define MARLIN_CFLG_LOWHIGH
Definition: marlin_client.h:14
osMessageGet
osEvent osMessageGet(osMessageQId queue_id, uint32_t millisec)
Get a Message or Wait for a Message from a Queue.
Definition: cmsis_os.c:1145
osDelay
osStatus osDelay(uint32_t millisec)
Wait for Timeout (Time Delay)
Definition: cmsis_os.c:365
HOST_PROMPT_None
Definition: marlin_host.h:18
marlin_server_queue
osMessageQId marlin_server_queue
Definition: marlin_server.cpp:89
HAL_GetTick
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
Definition: stm32f4xx_hal.c:339
variant8_ui16
variant8_t variant8_ui16(uint16_t ui16)
Definition: variant8.c:30
MARLIN_VAR_WAITUSER
#define MARLIN_VAR_WAITUSER
Definition: marlin_vars.h:28
MARLIN_EVT_Reheat
#define MARLIN_EVT_Reheat
Definition: marlin_events.h:37
MARLIN_USR8_MSK_ID
#define MARLIN_USR8_MSK_ID
Definition: marlin_vars.h:60
osEvent
Definition: cmsis_os.h:395
_variant8_t
Definition: variant8.h:24
DBG_REQ
#define DBG_REQ(...)
Definition: marlin_client.c:16
marlin_host_prompt_decode
void marlin_host_prompt_decode(uint32_t ui32, marlin_host_prompt_t *prompt)
Definition: marlin_host.c:56
HOST_PROMPT_BTN_None
Definition: marlin_host.h:26
_variant8_t::flt
float flt
Definition: variant8.h:31
marlin_set_var
variant8_t marlin_set_var(uint8_t var_id, variant8_t val)
Definition: marlin_client.c:345
MARLIN_EVT_CommandEnd
#define MARLIN_EVT_CommandEnd
Definition: marlin_events.h:34
_marlin_host_prompt_t::button_count
uint8_t button_count
Definition: marlin_host.h:48
MARLIN_MAX_REQUEST
#define MARLIN_MAX_REQUEST
Definition: config.h:97
_marlin_client_t
Definition: marlin_client.c:39
MARLIN_VAR_PQUEUE
#define MARLIN_VAR_PQUEUE
Definition: marlin_vars.h:10
_process_client_message
void _process_client_message(marlin_client_t *client, variant8_t msg)
Definition: marlin_client.c:612
MARLIN_EVT_StopProcessing
#define MARLIN_EVT_StopProcessing
Definition: marlin_events.h:29
MARLIN_EVT_CommandBegin
#define MARLIN_EVT_CommandBegin
Definition: marlin_events.h:33
marlin_client_task
osThreadId marlin_client_task[MARLIN_MAX_CLIENTS]
Definition: marlin_client.c:59
MARLIN_VAR_GQUEUE
#define MARLIN_VAR_GQUEUE
Definition: marlin_vars.h:9
osMessagePut
osStatus osMessagePut(osMessageQId queue_id, uint32_t info, uint32_t millisec)
Put a Message to a Queue.
Definition: cmsis_os.c:1113
osEventMessage
function completed; message event occurred.
Definition: cmsis_os.h:237
MARLIN_EVT_Message
#define MARLIN_EVT_Message
Definition: marlin_events.h:36
MARLIN_VAR_WAITHEAT
#define MARLIN_VAR_WAITHEAT
Definition: marlin_vars.h:27
marlin_vars_set_var
void marlin_vars_set_var(marlin_vars_t *vars, uint8_t var_id, variant8_t var)
Definition: marlin_vars.c:105
MARLIN_CFLG_STARTED
#define MARLIN_CFLG_STARTED
Definition: marlin_client.h:11
_client_ptr
marlin_client_t * _client_ptr(void)
Definition: marlin_client.c:703
_marlin_client_t::events
uint64_t events
Definition: marlin_client.c:42
osWaitForever
#define osWaitForever
wait forever timeout value
Definition: cmsis_os.h:230
MARLIN_CFLG_BUSY
#define MARLIN_CFLG_BUSY
Definition: marlin_client.h:13
_marlin_client_t::errors
uint64_t errors
Definition: marlin_client.c:47
marlin_update_vars
marlin_vars_t * marlin_update_vars(uint64_t msk)
Definition: marlin_client.c:368
MARLIN_EVT_MeshUpdate
#define MARLIN_EVT_MeshUpdate
Definition: marlin_events.h:24
variant8_empty
variant8_t variant8_empty(void)
Definition: variant8.c:10
uint8_t
const uint8_t[]
Definition: 404_html.c:3
_marlin_mesh_t::z
float z[MARLIN_MAX_MESH_POINTS]
Definition: marlin_events.h:103
MARLIN_VAR_MSK
#define MARLIN_VAR_MSK(v_id)
Definition: marlin_vars.h:35
_marlin_client_t::prompt
marlin_host_prompt_t prompt
Definition: marlin_client.c:50
MARLIN_VAR_PRNSPEED
#define MARLIN_VAR_PRNSPEED
Definition: marlin_vars.h:25
MARLIN_EVT_HostPrompt
#define MARLIN_EVT_HostPrompt
Definition: marlin_events.h:26
_send_request_to_server
void _send_request_to_server(uint8_t client_id, const char *request)
Definition: marlin_client.c:570
_marlin_client_t::ack
uint32_t ack
Definition: marlin_client.c:45
_marlin_client_t::changes
uint64_t changes
Definition: marlin_client.c:43
_marlin_mesh_t::yc
uint8_t yc
Definition: marlin_events.h:105
marlin_server_sema
osSemaphoreId marlin_server_sema
Definition: marlin_server.cpp:90
_marlin_client_t::id
uint8_t id
Definition: marlin_client.c:40
status
static status_t status
Definition: filament_sensor.c:37
_marlin_client_t::vars
marlin_vars_t vars
Definition: marlin_client.c:44
MARLIN_EVT_Ready
#define MARLIN_EVT_Ready
Definition: marlin_events.h:31
marlin_clients
uint8_t marlin_clients
Definition: marlin_client.c:63
_marlin_vars_t
Definition: marlin_vars.h:77
MARLIN_EVT_StartProcessing
#define MARLIN_EVT_StartProcessing
Definition: marlin_events.h:28
_wait_server_started
void _wait_server_started(void)
Definition: marlin_client.c:564
osMessageCreate
osMessageQId osMessageCreate(const osMessageQDef_t *queue_def, osThreadId thread_id)
Create and Initialize a Message Queue.
Definition: cmsis_os.c:1086
osMessageQ
#define osMessageQ(name)
Access a Message Queue Definition.
Definition: cmsis_os.h:829
_variant8_t::usr8
uint8_t usr8
Definition: variant8.h:26
MARLIN_CMD_NONE
#define MARLIN_CMD_NONE
Definition: marlin_events.h:50
MARLIN_CFLG_MESSAGE
#define MARLIN_CFLG_MESSAGE
Definition: marlin_client.h:15
MARLIN_EVT_Error
#define MARLIN_EVT_Error
Definition: marlin_events.h:32
MARLIN_EVT_MSK
#define MARLIN_EVT_MSK(e_id)
Definition: marlin_events.h:42
DBG_EVT_MSK
#define DBG_EVT_MSK
Definition: marlin_client.c:20
MARLIN_VAR_TTEM_NOZ
#define MARLIN_VAR_TTEM_NOZ
Definition: marlin_vars.h:21
osEvent::value
union osEvent::@54 value
event value
_variant8_t::ui32
uint32_t ui32
Definition: variant8.h:32
MARLIN_EVT_Busy
#define MARLIN_EVT_Busy
Definition: marlin_events.h:30
MARLIN_EVT_Acknowledge
#define MARLIN_EVT_Acknowledge
Definition: marlin_events.h:38
variant8_flt
variant8_t variant8_flt(float flt)
Definition: variant8.c:48
MARLIN_CFLG_PROCESS
#define MARLIN_CFLG_PROCESS
Definition: marlin_client.h:12
_marlin_client_t::last_count
uint16_t last_count
Definition: marlin_client.c:46
osEvent::v
uint32_t v
message as 32-bit value
Definition: cmsis_os.h:398
_marlin_client_t::mesh
marlin_mesh_t mesh
Definition: marlin_client.c:48
marlin_client_queue
osMessageQId marlin_client_queue[MARLIN_MAX_CLIENTS]
Definition: marlin_client.c:60
MARLIN_VAR_Z_OFFSET
#define MARLIN_VAR_Z_OFFSET
Definition: marlin_vars.h:23
_marlin_vars_t::motion
uint8_t motion
Definition: marlin_vars.h:78
osSemaphoreRelease
osStatus osSemaphoreRelease(osSemaphoreId semaphore_id)
Release a Semaphore token.
Definition: cmsis_os.c:862
osMessageQDef
#define osMessageQDef(name, queue_sz, type)
Create a Message Queue Definition.
Definition: cmsis_os.h:818