示例#1
0
文件: action.c 项目: s-cherepanov/elk
void Action_Hook (Widget w, XtPointer client_data, char *name, XEvent *ep,
                  char **argv, int *argc) {
    ACTION *ap;
    Object args, params, tail;
    register int i;
    GC_Node3;

    for (ap = actions; ap; ap = ap->next) {
        if (strcmp (ap->name, name))
            continue;
        args = params = tail = Null;
        GC_Link3 (args, params, tail);
        params = P_Make_List (Make_Integer (*argc), Null);
        for (i = 0, tail = params; i < *argc; tail = Cdr (tail), i++) {
            Object tmp;

            tmp = Make_String (argv[i], strlen (argv[i]));
            Car (tail) = tmp;
        }
        args = Cons (params, Null);
        params = Get_Event_Args (ep);
        args = Cons (Copy_List (params), args);
        Destroy_Event_Args (params);
        args = Cons (Make_Widget_Foreign (w), args);
        (void)Funcall (Get_Function (ap->num), args, 0);
        GC_Unlink;
    }
}
void ReadPackage() {
  unsigned char c,cif;
  if (Serial.available() < 0) { // no new data
      return;
      /*
       delay(50);
      printf("... \n");
      if (SerialAvailable() == 0) {
          ProtocolError = Timeout_Error;
          printf("Timeout\n");
          return;
      }
      */
  }
  while(Serial.available () > 0 && ((InBfTopPointer+1) % sizeof(InputBuffer)) != InBfBtmPointer  ) {
      // while there is data and buffer not full
    InputBuffer[InBfTopPointer] = Serial.read(); //Load InputBuffer with received packets
    InBfTopPointer++;  InBfTopPointer %=sizeof(InputBuffer);
  }
  while(InBfBtmPointer != InBfTopPointer)  { // while not empty
    c = InputBuffer[InBfBtmPointer];
    InBfBtmPointer++; InBfBtmPointer %=sizeof(InputBuffer);;
    cif = c&0x80; // Start or "End" Frame Char
    if(cif==0) {
      Read_Num = 0;
      Read_Package_Length = 0;
    }
    if(cif==0||Read_Num>0) {
      Read_Package_Buffer[Read_Num] = c;
      Read_Num++;
      if(Read_Num==2)
      {
        cif = c>>5;
        cif = cif&0x03;
        Read_Package_Length = 4 + cif;
        c = 0;
      }
      if(Read_Num==Read_Package_Length)
      {
        ProtocolError = Get_Function();
        Read_Num = 0;
        Read_Package_Length = 0;
        if (ProtocolError != In_Progress) {
//            InBfBtmPointer = InBfTopPointer = 0;
            return;
        }
      }
    }