SCOM Serial Communication Protocol
0.5.2
|
Various utils. More...
#include "hal.h"
#include "scom.h"
#include "scom_filtering.h"
#include "scom_frame_type_filter.h"
#include <string.h>
Go to the source code of this file.
Macros | |
#define | HAL_LOG_CHANNEL SCOM |
#define | HAL_LOG_SUBCHANNEL UTIL |
Functions | |
SCOMResult | SCOM_GetIdentity (SCOMDataLinkDesc *const scom, SCOMIdentity *const identity) |
SCOMResult | SCOM_WaitForDevice (SCOMDataLink scom, uint32_t expectedDeviceClass, uint32_t expectedDeviceClassMask, uint32_t probeInterval, uint32_t timeout, SCOMIdentity *identity) |
unsigned int | SCOM_ScanAndRun (void(*initProc)(IODevice iodevice, const char *deviceName), bool(*userProc)(SCOMDataLink scom, SCOMIdentity *identity, const char *deviceName), uint32_t responseTimeout) |
Various utils.
Definition in file scom_utils.c.
#define HAL_LOG_CHANNEL SCOM |
Definition at line 10 of file scom_utils.c.
#define HAL_LOG_SUBCHANNEL UTIL |
Definition at line 11 of file scom_utils.c.
SCOMResult SCOM_GetIdentity | ( | SCOMDataLinkDesc *const | scom, |
SCOMIdentity *const | identity | ||
) |
Definition at line 23 of file scom_utils.c.
References SCOMFrameTypeMatchFilter::filter, SCOM_COMMUNICATION_ERROR, SCOM_DeinitializeFrameTypeMatchFilter(), SCOM_ERROR, SCOM_FILTER_ERROR, SCOM_FILTER_LIST_FULL, SCOM_FRAMETYPE_IDENTIFY, SCOM_InitializeFrameTypeMatchFilter(), SCOM_InsertFilter(), SCOM_RemoveFilter(), SCOM_RESULT_ERROR, SCOM_RESULT_OK, SCOM_SendFrame(), SCOM_SetupFrameTypeMatchFilter(), SCOM_TX_FRAME_BUFFER_OVERRUN, and SCOM_WaitForFrameTypeFilter().
unsigned int SCOM_ScanAndRun | ( | void(*)(IODevice iodevice, const char *deviceName) | initProc, |
bool(*)(SCOMDataLink scom, SCOMIdentity *identity, const char *deviceName) | userProc, | ||
uint32_t | responseTimeout | ||
) |
Scans all available serial ports using IOSerial interface. Tries to open each serial port. If successful runs the user initialization procedure (initProc) and then tries to connect using SCOM protocol. If successful, gets the identity information from the remote device and runs user procedure (userProc). The user procedure can then interact with the device. If the user procedure returns true, the device will be counted as a "valid" device. The counter is returned as a result of this function. If no user procedure is provided, all SCOM devices are counted as "valid".
This utility is handy for running tasks across all SCOM devices connected to a computer.
[in] | initProc | initialization procedure run for all successfully opened serial ports, prior to SCOM communication |
[in] | userProc | user-defined procedure run for all successfully identified SCOM devices |
[in] | responseTimeout | maximum time waiting for response from SCOM device during scanning |
Definition at line 134 of file scom_utils.c.
References SCOM_Create(), SCOM_CreateFrameBuffer(), SCOM_Deinit(), SCOM_DeinitFiltering(), SCOM_Destroy(), SCOM_Init(), SCOM_InitFiltering(), SCOM_RESULT_OK, SCOM_RunFilteringThread(), SCOM_RunProcessingThread(), SCOM_StopFilteringThread(), SCOM_StopProcessingThread(), and SCOM_WaitForDevice().
SCOMResult SCOM_WaitForDevice | ( | SCOMDataLink | scom, |
uint32_t | expectedDeviceClass, | ||
uint32_t | expectedDeviceClassMask, | ||
uint32_t | probeInterval, | ||
uint32_t | timeout, | ||
SCOMIdentity * | identity | ||
) |
Waits for a given SCOM device, trying to identify it and match against a given DeviceClass.
This function periodically sends identification requests to the device every given probe interval. These requests do not require ACK, so that in case of no response no error is reported. If identification response is received, the remote DeviceClass from the response is compared against the expected DeviceClass. This comparison is additionally masked, so that only required bits are compared. The function exits when the compare yields match or when given timeout occurs. Both the interval and timeout are expressed in SCOM clock time units.
[in] | scom | SCOM descriptor (requires initialized SCOM object with enabled filtering) |
[in] | expectedDeviceClass | expected value of the DeviceClass identification parameter |
[in] | expectedDeviceClassMask | mask used when comparing the received DeviceClass with the expected |
[in] | probeInterval | time interval between consecutive identify requests |
[in] | timeout | maximum time waiting for a matching identity |
[out] | identity | place to store the retrieved remote device identity - only available if matched DeviceClass has been found |
SCOM_RESULT_OK | when the identity of the remote device was successfully retrieved |
SCOM_NO_DEVICE | when no matching remote device was detected |
Definition at line 64 of file scom_utils.c.
References SCOMDataLinkDesc::clockSource, HAL_PACKED::deviceClass, SCOMFrameTypeMatchFilter::filter, SCOM_DeinitializeFrameTypeMatchFilter(), SCOM_ERROR, SCOM_FILTER_ERROR, SCOM_FILTER_LIST_FULL, SCOM_FRAMETYPE_IDENTIFY, SCOM_InitializeFrameTypeMatchFilter(), SCOM_InsertFilter(), SCOM_NO_DEVICE, SCOM_RemoveFilter(), SCOM_RESULT_OK, SCOM_SendFrameWithoutAck(), SCOM_SetupFrameTypeMatchFilter(), and SCOM_WaitForFrameTypeFilter().
Referenced by SCOM_ScanAndRun().