Go to the source code of this file.
Defines | |
#define | DISTANCE_READINGS_TO_AVERAGE 3 |
#define | MAX_TIMEOUT_IN_MS 500 |
#define | MAX_DATA_BYTES 246 |
#define | device "/dev/tts/2" |
#define | PXA_INT0 8 |
#define | OUT 0 |
#define | STX 2 |
#define | ETX 3 |
#define | LRF_PORT "/dev/tts/2" |
#define | HKO_POLY 0x1021 |
Functions | |
int | kb_lrf_OpenComPort (void) |
void | kb_lrf_FlushSerPort (int LRF_DeviceHandle) |
unsigned char | kb_lrf_lsb_to_msb (unsigned char lsb) |
unsigned short | kb_lrf_GenerateCRC (unsigned char *buf, int count) |
int | kb_lrf_GetDataFromLRF (int LRF_DeviceHandle, int TotalBytes) |
int | kb_lrf_SendCommand (int LRF_DeviceHandle, char *LRF_Command, int LRF_CommandLength) |
int | kb_lrf_AcquireCertifiedCode (int LRF_DeviceHandle) |
int | kb_lrf_CertifyLink (int LRF_DeviceHandle) |
void | kb_lrf_pwrOn (void) |
void | kb_lrf_pwrOff (void) |
int | kb_lrf_Init (char *LRF_DeviceName) |
void | kb_lrf_Close (int LRF_DeviceHandle) |
int | kb_lrf_FetchDistanceFromLRF (int LRF_DeviceHandle) |
int | kb_lrf_GetDistances (int LRF_DeviceHandle) |
Variables | |
unsigned short | calcTable [] |
unsigned char | kb_lrf_Data [MAX_DATA_BYTES] |
unsigned short | kb_lrf_DistanceData [121] |
unsigned short | kb_lrf_DistanceDataSensor [121] |
unsigned long | kb_lrf_DistanceDataSum [121] |
int | kb_lrf_DistanceGoodCounter [121] |
unsigned short | CertifiedCode |
Support for KoreBot Led Range Finder.
Definition in file kb_lrf.c.
#define device "/dev/tts/2" |
Definition at line 34 of file kb_lrf.c.
Referenced by knet_i2c_init(), koa_lrf_task(), lrfinit(), and lrfmeasure().
#define DISTANCE_READINGS_TO_AVERAGE 3 |
#define ETX 3 |
#define HKO_POLY 0x1021 |
kb_lrf_lsb_to_msb reverts Lsb to Msb on a byte
lsb | byte to reverse bits on |
Definition at line 224 of file kb_lrf.c.
Referenced by kb_lrf_GenerateCRC().
#define LRF_PORT "/dev/tts/2" |
#define MAX_DATA_BYTES 246 |
Definition at line 32 of file kb_lrf.c.
Referenced by kb_lrf_GetDataFromLRF(), and kb_lrf_SendCommand().
#define MAX_TIMEOUT_IN_MS 500 |
Definition at line 31 of file kb_lrf.c.
Referenced by kb_lrf_GetDataFromLRF(), and kb_lrf_SendCommand().
#define PXA_INT0 8 |
Definition at line 36 of file kb_lrf.c.
Referenced by gpioinit(), kb_lrf_Init(), kb_lrf_pwrOff(), and kb_lrf_pwrOn().
#define STX 2 |
int kb_lrf_AcquireCertifiedCode | ( | int | LRF_DeviceHandle | ) |
kb_lrf_AcquireCertifiedCode does receive certification code from LRF
LRF_DeviceHandle | Handle to the lrf port which as been openned by kb_lrf_openComPort or kb_lrf_init |
Definition at line 582 of file kb_lrf.c.
References CertifiedCode, KB_DEBUG, KB_ERROR, KB_ERROR_LRFNOCERT, KB_ERROR_LRFNODATA, kb_lrf_Data, kb_lrf_GenerateCRC(), kb_lrf_GetDataFromLRF(), and kb_lrf_SendCommand().
Referenced by kb_lrf_GetDistances(), and kb_lrf_Init().
int kb_lrf_CertifyLink | ( | int | LRF_DeviceHandle | ) |
kb_lrf_CertifyLink does checking that link is still valid, caution, this function need to be called regulary, below 3 seconds
LRF_DeviceHandle | Handle to the lrf port which as been openned by kb_lrf_openComPort or kb_lrf_init |
Definition at line 618 of file kb_lrf.c.
References CertifiedCode, KB_DEBUG, KB_ERROR, KB_ERROR_LRFNOCERT, KB_ERROR_LRFNODATA, kb_lrf_Data, kb_lrf_GetDataFromLRF(), and kb_lrf_SendCommand().
Referenced by kb_lrf_GetDistances(), and kb_lrf_Init().
void kb_lrf_Close | ( | int | LRF_DeviceHandle | ) |
kb_lrf_Close does powering off the LRF, the close the port device
LRF_DeviceHandle | Handle to the lrf port which as been openned by kb_lrf_openComPort or kb_lrf_init |
Definition at line 720 of file kb_lrf.c.
References kb_lrf_pwrOff().
Referenced by handle_kill().
int kb_lrf_FetchDistanceFromLRF | ( | int | LRF_DeviceHandle | ) |
kb_lrf_FetchDistanceFromLRF is a medium level function that does whole mechanism send the command, then receive back the data from LRF,
LRF_DeviceHandle | Handle to the lrf port which as been openned by kb_lrf_openComPort or kb_lrf_init |
Definition at line 738 of file kb_lrf.c.
References KB_ERROR, KB_ERROR_LRFCMDTX, KB_ERROR_LRFDATARX, KB_ERROR_LRFDISTRX, kb_lrf_Data, kb_lrf_DistanceDataSensor, kb_lrf_GetDataFromLRF(), and kb_lrf_SendCommand().
Referenced by kb_lrf_GetDistances().
void kb_lrf_FlushSerPort | ( | int | LRF_DeviceHandle | ) |
kb_lrf_FlushSerPort "erases" the serial port buffer.
LRF_DeviceHandle | Handle to the port which is returned by kb_lrf_OpenComPort |
Definition at line 198 of file kb_lrf.c.
References fd_set1.
Referenced by kb_lrf_SendCommand().
unsigned short kb_lrf_GenerateCRC | ( | unsigned char * | buf, | |
int | count | |||
) |
kb_lrf_GenerateCRC does generating CCIT CRC for a given byte array and for a given array lenght
buf | Pointer to the array that need to be CRCed | |
count | Size of the array passed as buf |
Definition at line 250 of file kb_lrf.c.
References HKO_POLY, and kb_lrf_lsb_to_msb().
Referenced by kb_lrf_AcquireCertifiedCode(), kb_lrf_GetDataFromLRF(), and kb_lrf_SendCommand().
int kb_lrf_GetDataFromLRF | ( | int | LRF_DeviceHandle, | |
int | TotalBytes | |||
) |
kb_lrf_GetDataFromLRF does receiving some datas from the LRF sensor data is stored in the global 121 bytes arrays
datasheet is saying there is 121 measures which all are 16 bits wide each measure is the distance in millimeters from the sensor and measure 0 means it is at -18 degrees ( inverse clockwise ) and mesure 121 means it is at +198 degrees ( inverse clockwise )
LRF_DeviceHandle | Handle to the lrf port which as been openned by kb_lrf_openComPort or kb_lrf_init | |
TotalBytes | Number of bytes that should be received |
Definition at line 329 of file kb_lrf.c.
References calcTable, ETX, KB_DEBUG, KB_ERROR, KB_ERROR_LRFNOETX, KB_ERROR_LRFNOSTX, kb_lrf_Data, kb_lrf_GenerateCRC(), MAX_DATA_BYTES, MAX_TIMEOUT_IN_MS, and STX.
Referenced by kb_lrf_AcquireCertifiedCode(), kb_lrf_CertifyLink(), and kb_lrf_FetchDistanceFromLRF().
int kb_lrf_GetDistances | ( | int | LRF_DeviceHandle | ) |
kb_lrf_GetDistances is a high level function that does whole mechanism certify the link, get some distances, averages then receive back the data from LRF,
LRF_DeviceHandle | Handle to the lrf port which as been openned by kb_lrf_openComPort or kb_lrf_init |
Definition at line 787 of file kb_lrf.c.
References DISTANCE_READINGS_TO_AVERAGE, KB_ERROR, KB_ERROR_LRFNOCERT, kb_lrf_AcquireCertifiedCode(), kb_lrf_CertifyLink(), kb_lrf_DistanceData, kb_lrf_DistanceDataSensor, kb_lrf_DistanceDataSum, kb_lrf_DistanceGoodCounter, and kb_lrf_FetchDistanceFromLRF().
Referenced by koa_lrf_task(), and lrfmeasure().
int kb_lrf_Init | ( | char * | LRF_DeviceName | ) |
kb_lrf_Init does openning port, turn power on the LRF then certify the link,
Definition at line 669 of file kb_lrf.c.
References KB_ERROR, KB_ERROR_OPENLRF, kb_gpio_dir(), kb_gpio_function(), kb_gpio_init(), kb_init(), kb_lrf_AcquireCertifiedCode(), kb_lrf_CertifyLink(), kb_lrf_OpenComPort(), kb_lrf_pwrOn(), OUT, and PXA_INT0.
Referenced by koa_lrf_task(), lrfinit(), and lrfmeasure().
unsigned char kb_lrf_lsb_to_msb | ( | unsigned char | lsb | ) |
int kb_lrf_OpenComPort | ( | void | ) |
kb_lrf_OpenComPort opens the serial port which is LRF card port ( /dev/tts/2 ).
none |
Definition at line 163 of file kb_lrf.c.
References KB_ERROR, KB_ERROR_OPENLRF, and LRF_PORT.
Referenced by kb_lrf_Init().
void kb_lrf_pwrOff | ( | void | ) |
kb_lrf_pwrOff does enabling 12 => 24V converter thus powering LRF module
Definition at line 657 of file kb_lrf.c.
References kb_gpio_clear(), and PXA_INT0.
Referenced by kb_lrf_Close(), and lrfoff().
void kb_lrf_pwrOn | ( | void | ) |
kb_lrf_pwrOn does enabling 12 => 24V converter thus powering LRF module
Definition at line 648 of file kb_lrf.c.
References kb_gpio_set(), and PXA_INT0.
Referenced by kb_lrf_Init(), and lrfon().
int kb_lrf_SendCommand | ( | int | LRF_DeviceHandle, | |
char * | LRF_Command, | |||
int | LRF_CommandLength | |||
) |
kb_lrf_SendCommand does sending a command to the LRF, checkout the link before as well
LRF_DeviceHandle | Handle to the lrf port which as been openned by kb_lrf_openComPort or kb_lrf_init | |
LRF_Command | Buffer containing the command to send | |
LRF_CommandLength | Lenght of the command to send |
Definition at line 471 of file kb_lrf.c.
References calcTable, fd_set1, KB_DEBUG, KB_ERROR, KB_ERROR_LRFDATA2BIG, KB_ERROR_LRFNODATA, KB_ERROR_LRFSENDDATA, kb_lrf_FlushSerPort(), kb_lrf_GenerateCRC(), MAX_DATA_BYTES, and MAX_TIMEOUT_IN_MS.
Referenced by kb_lrf_AcquireCertifiedCode(), kb_lrf_CertifyLink(), and kb_lrf_FetchDistanceFromLRF().
unsigned short calcTable[] |
Initial value:
{ 0x0000, 0x0002, 0x0003, 0x0004, 0x0006, 0x0007, 0x0008, 0x000A, 0x000B, 0x000C, 0x000E, 0x000F, 0x0010, 0x0012, 0x0013, 0x0014, 0x0016, 0x0017, 0x0018, 0x001A, 0x001B, 0x001C, 0x001E, 0x001F, 0x0020, 0x0022, 0x0023, 0x0024, 0x0026, 0x0027, 0x0028, 0x002A, 0x002B, 0x002C, 0x002E, 0x002F, 0x0030, 0x0032, 0x0033, 0x0034, 0x0036, 0x0037, 0x0038, 0x003A, 0x003B, 0x003C, 0x003E, 0x003F, 0x0040, 0x0042, 0x0043, 0x0044, 0x0046, 0x0047, 0x0048, 0x004A, 0x004B, 0x004C, 0x004E, 0x004F, 0x0050, 0x0052, 0x0053, 0x0054, 0x0056, 0x0057, 0x0058, 0x005A, 0x005B, 0x005C, 0x005E, 0x005F, 0x0060, 0x0062, 0x0063, 0x0064, 0x0066, 0x0067, 0x0068, 0x006A, 0x006B, 0x006C, 0x006E, 0x006F, 0x0070, 0x0072, 0x0073, 0x0074, 0x0076, 0x0077, 0x0078, 0x007A, 0x007B, 0x007C, 0x007E, 0x007F, 0x0080, 0x0082, 0x0083, 0x0084, 0x0086, 0x0087, 0x0088, 0x008A, 0x008B, 0x008C, 0x008E, 0x008F, 0x0090, 0x0092, 0x0093, 0x0094, 0x0096, 0x0097, 0x0098, 0x009A, 0x009B, 0x009C, 0x009E, 0x009F, 0x00A0, 0x00A2, 0x00A3, 0x00A4, 0x00A6, 0x00A7, 0x00A8, 0x00AA, 0x00AB, 0x00AC, 0x00AE, 0x00AF, 0x00B0, 0x00B2, 0x00B3, 0x00B4, 0x00B6, 0x00B7, 0x00B8, 0x00BA, 0x00BB, 0x00BC, 0x00BE, 0x00BF, 0x00C0, 0x00C2, 0x00C3, 0x00C4, 0x00C6, 0x00C7, 0x00C8, 0x00CA, 0x00CB, 0x00CC, 0x00CE, 0x00CF, 0x00D0, 0x00D2, 0x00D3, 0x00D4, 0x00D6, 0x00D7, 0x00D8, 0x00DA, 0x00DB, 0x00DC, 0x00DE, 0x00DF, 0x00E0, 0x00E2, 0x00E3, 0x00E4, 0x00E6, 0x00E7, 0x00E8, 0x00EA, 0x00EB, 0x00EC, 0x00EE, 0x00EF, 0x00F0, 0x00F2, 0x00F3, 0x00F4, 0x00F6, 0x00F7, 0x00F8, 0x00FA, 0x00FB, 0x00FC, 0x00FE, 0x00FF, 0x0100, 0x0102, 0x0103, 0x0104, 0x0106, 0x0107, 0x0108, 0x010A, 0x010B, 0x010C, 0x010E, 0x010F, 0x0110, 0x0112, 0x0113, 0x0114, 0x0116, 0x0117, 0x0118, 0x011A, 0x011B, 0x011C, 0x011E, 0x011F, 0x0120, 0x0122, 0x0123, 0x0124, 0x0126, 0x0127, 0x0128, 0x012A, 0x012B, 0x012C, 0x012E, 0x012F, 0x0130, 0x0132, 0x0133, 0x0134, 0x0136, 0x0137, 0x0138, 0x013A, 0x013B, 0x013C, 0x013E, 0x013F, 0x0140, 0x0142, 0x0143, 0x0144, 0x0146, 0x0147, 0x0148, 0x014A, 0x014B, 0x014C, 0x014E, 0x014F, 0x0150, 0x0152, 0x0153 }
Definition at line 40 of file kb_lrf.c.
Referenced by kb_lrf_GetDataFromLRF(), and kb_lrf_SendCommand().
unsigned short CertifiedCode |
Definition at line 86 of file kb_lrf.c.
Referenced by kb_lrf_AcquireCertifiedCode(), and kb_lrf_CertifyLink().
unsigned char kb_lrf_Data[MAX_DATA_BYTES] |
Definition at line 78 of file kb_lrf.c.
Referenced by kb_lrf_AcquireCertifiedCode(), kb_lrf_CertifyLink(), kb_lrf_FetchDistanceFromLRF(), and kb_lrf_GetDataFromLRF().
unsigned short kb_lrf_DistanceData[121] |
Definition at line 80 of file kb_lrf.c.
Referenced by kb_lrf_GetDistances(), koa_lrf_task(), and lrfmeasure().
unsigned short kb_lrf_DistanceDataSensor[121] |
Definition at line 82 of file kb_lrf.c.
Referenced by kb_lrf_FetchDistanceFromLRF(), and kb_lrf_GetDistances().
unsigned long kb_lrf_DistanceDataSum[121] |
int kb_lrf_DistanceGoodCounter[121] |