next up previous contents
Next: 10.1.2 k-bus.h Up: 10.1 Header-Dateien Previous: 10.1 Header-Dateien

10.1.1 can-ir.h

/*****************************************************************************/
/* File:        can-ir.h                                                     */
/* Author:      Christopher Odenbach                                         */
/* Date:        April 1999                                                   */
/* Description: Include file for use of the CAN-IR-Module                    */
/*****************************************************************************/

#ifndef CAN_IR_H
#define CAN_IR_H

/*
 * includes
 *
 * these includes are needed for the module
 *
 */

#include "bios.h"
#include "usercr.h"
#include "math.h"
#include "stdlib.h"
#include "stdio.h"
#include "string.h"




/* global variables */

/* DON'T USE THESE VARIABLES IN YOUR PROGRAM ! */
static  unsigned char   data[8];        // the buffer
static  uint8   sender;                 // the sender
static  uint8   length;                 // the size of the message
static  boolean ir_ready = FALSE;       // the flag for the process

/* YOU MAY USE THESE VARIABLES */
static  char    robot_ID[32];           // the list of existing robots
static  uint8   robnr;                  // the number of existing robots



/*
 * send_IR
 *
 * just send any string up to 8 characters to a robot from A to Z
 *
 */

void send_IR (char to, char *data)

{
        uint8   length, receiver, i;

        length = strlen (data);
        receiver = (int)to - 65;

        var_put_extension(2,((length - 1)<<5) | receiver);
        for (i=0; i < length; i++) {
                tim_suspend_task(1);                                    /* we need here about 100 µs    */
                var_put_extension(3,data[i]);
        }
}



/*
 * receive_IR
 *
 * just define a routine named receive_IR in the shown way
 * to make your program react to a received message
 *
 */

void receive_IR(uint8 sender, uint8 length, uint8 *data);



/*
 * process_IR_data
 *
 * this process has to be started with tim_new_task()
 * it takes over the received data and handles commands like
 * logins etc.
 *
 */

void process_IR_data()
{
  uint8 i;
  unsigned char local_data[8];  /* the buffer                   */
  uint8 local_sender;           /* the sender                   */
  uint8 local_length;           /* the size of the message      */

  boolean exists;

  for (i=0; i<32; i++) robot_ID[i]=0x00;

  for(;;) {
    do {
      tim_switch_fast();
    } while (!ir_ready);

    var_disable_irq();
    local_sender = (char)((int)sender + 65);
    local_length = length;
    for (i=0; i> 5) + 1;
  sender = (status & 0x1F);
  for (i=0; i



Christopher Odenbach
1999-06-01