LinuxCNC 命令更新
while (!done) {
// read command
if (0 != emcCommandBuffer->peek()) {
// got a new command, so clear out errors
taskPlanError = 0;
taskExecuteError = 0;
}
emcCommandBuffer->peek()->|
Description: nml.cc
NMLTYPE NML::peek()
{
error_type = NML_NO_ERROR;
if (fast_mode) {
cms->peek();
switch (cms->status) {
case CMS_READ_OLD:
return (0);
case CMS_READ_OK:
if (((NMLmsg *) cms->subdiv_data)->type <= 0 && !cms->isserver) {
rcs_print_error
("NML: New data recieved but type of %d is invalid.\n",
(int)((NMLmsg *) cms->subdiv_data)->type);
return -1;
}
return (((NMLmsg *) cms->subdiv_data)->type);
default:
set_error();
return -1;
}
}
if (NULL == cms) {
if (error_type != NML_INVALID_CONFIGURATION) {
error_type = NML_INVALID_CONFIGURATION;
rcs_print_error("NML::peek: CMS not configured.\n");
}
return (-1);
}
if (cms->is_phantom) {
if (NULL != phantom_peek) {
return ((*phantom_peek) ());
} else {
return (0);
}
}
if (!cms->force_raw) {
cms->set_mode(CMS_READ);
}
cms->peek();
if (!cms->force_raw) {
if (cms->status == CMS_READ_OK) {
if (-1 == format_output()) {
error_type = NML_FORMAT_ERROR;
return (-1);
}
}
}
switch (cms->status) {
case CMS_READ_OLD:
return (0);
case CMS_READ_OK:
if (((NMLmsg *) cms->subdiv_data)->type <= 0 && !cms->isserver) {
rcs_print_error
("NML: New data recieved but type of %d is invalid.\n",
(int)((NMLmsg *) cms->subdiv_data)->type);
return -1;
}
return (((NMLmsg *) cms->subdiv_data)->type);
default:
set_error();
return -1;
}
}
cms->peek()
* Description: cms.cc
CMS_STATUS CMS::peek()
{
internal_access_type = CMS_PEEK_ACCESS;
status = CMS_STATUS_NOT_SET;
blocking_timeout = 0;
main_access(data);
return (status);
}
* Description: shmem.cc
main_access(data) :
/* Access the shared memory buffer. */
CMS_STATUS SHMEM::main_access(void *_local)
{
/* Check pointers. */
if (shm == NULL) {
second_read = 0;
return (status = CMS_MISC_ERROR);
}
if (bsem == NULL && not_zero(blocking_timeout)) {
rcs_print_error
("No blocking semaphore available. Can not call blocking_read(%f).\n",
blocking_timeout);
second_read = 0;
return (status = CMS_NO_BLOCKING_SEM_ERROR);
}
mao.read_only = ((internal_access_type == CMS_CHECK_IF_READ_ACCESS) ||
(internal_access_type == CMS_PEEK_ACCESS) ||
(internal_access_type == CMS_READ_ACCESS));
switch (mutex_type) {
case NO_MUTEX:
break;
case MAO_MUTEX:
case MAO_MUTEX_W_OS_SEM:
switch (mem_get_access(&mao)) {
case -1:
rcs_print_error("SHMEM: Can't take semaphore\n");
second_read = 0;
return (status = CMS_MISC_ERROR);
case -2:
if (timeout > 0) {
rcs_print_error("SHMEM: Timed out waiting for semaphore.\n");
rcs_print_error("buffer = %s, timeout = %lf sec.\n",
BufferName, timeout);
}
second_read = 0;
return (status = CMS_TIMED_OUT);
default:
break;
}
toggle_bit = mao.toggle_bit;
break;
case OS_SEM_MUTEX:
if (sem == NULL) {
second_read = 0;
return (status = CMS_MISC_ERROR);
}
switch (sem->wait()) {
case -1:
rcs_print_error("SHMEM: Can't take semaphore\n");
second_read = 0;
return (status = CMS_MISC_ERROR);
case -2:
if (timeout > 0) {
rcs_print_error("SHMEM: Timed out waiting for semaphore.\n");
rcs_print_error("buffer = %s, timeout = %lf sec.\n",
BufferName, timeout);
}
second_read = 0;
return (status = CMS_TIMED_OUT);
default:
break;
}
break;
case NO_INTERRUPTS_MUTEX:
rcs_print_error("Interrupts can not be disabled.\n");
second_read = 0;
return (status = CMS_MISC_ERROR);
break;
case NO_SWITCHING_MUTEX:
rcs_print_error("Interrupts can not be disabled.\n");
return (status = CMS_MISC_ERROR);
break;
default:
rcs_print_error("SHMEM: Invalid mutex type.(%d)\n", mutex_type);
second_read = 0;
return (status = CMS_MISC_ERROR);
break;
}
if (second_read > 0 && enable_diagnostics) {
disable_diag_store = 1;
}
/* Perform access function. */
internal_access(shm->addr, size, _local);
disable_diag_store = 0;
if (NULL != bsem &&
(internal_access_type == CMS_WRITE_ACCESS
|| internal_access_type == CMS_WRITE_IF_READ_ACCESS)) {
bsem->flush();
}
switch (mutex_type) {
case NO_MUTEX:
break;
case MAO_MUTEX:
case MAO_MUTEX_W_OS_SEM:
mem_release_access(&mao);
break;
case OS_SEM_MUTEX:
sem->post();
break;
case NO_INTERRUPTS_MUTEX:
rcs_print_error("Can not restore interrupts.\n");
break;
case NO_SWITCHING_MUTEX:
rcs_print_error("Can not restore interrupts.\n");
break;
}
switch (internal_access_type) {
case CMS_READ_ACCESS:
if (NULL != bsem && status == CMS_READ_OLD &&
(blocking_timeout > 1e-6 || blocking_timeout < -1E-6)) {
if (second_read > 10 && total_subdivisions <= 1) {
status = CMS_MISC_ERROR;
rcs_print_error
("CMS: Blocking semaphore error. The semaphore wait has returned %d times but there is still no new data.\n",
second_read);
second_read = 0;
return (status);
}
second_read++;
bsem->timeout = blocking_timeout;
int bsem_ret = bsem->wait();
if (bsem_ret == -2) {
status = CMS_TIMED_OUT;
second_read = 0;
return (status);
}
if (bsem_ret == -1) {
rcs_print_error("CMS: Blocking semaphore error.\n");
status = CMS_MISC_ERROR;
second_read = 0;
return (status);
}
main_access(_local);
}
break;
case CMS_WRITE_ACCESS:
case CMS_WRITE_IF_READ_ACCESS:
break;
default:
break;
}
second_read = 0;
return (status);
}