void init_client(int bankid, int clientid)
{
    if (bankid < 1 || clientid < 1)
    {
        printf("illegal client info input\n");
        return;
    }
    bank_id = bankid;
    client_id = clientid;

    /*get the current client's information from the config file */
    /* in client_read_conf.cpp */
    get_client_need_info();

    /* init server address */
    bzero(&ser_addr, sizeof(ser_addr));
    ser_addr.sin_family = AF_INET;

    /* init master address */
    bzero(&ma_addr, sizeof(ma_addr));
    ma_addr.sin_family = AF_INET;

    if ((send_head_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    {
        printf("Error opening head_fd socket\n");
        exit(1);
    }
    if ((send_tail_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    {
        printf("Error opening tail_fd socket\n");
        exit(1);
    }
    if ((send_master_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    {
        printf("Error opening master_fd socket\n");
        exit(1);
    }
    /*when client login, tell master its own bank_id, ip, port
    to get head, tail servers' info*/
    send_master();
}
Exemple #2
0
// switch to master mode and send something, return to slave mode when done.
extern void i2c_tx(u8 chip, u32 addr, u8 addr_len, u32 data_len, void* data) {
  while( twi_is_busy() ) {;;}
  status = init_master();
  print_dbg("\r\nI2C init (master) : ");
  if(status==TWI_SUCCESS) { print_dbg("SUCCESS"); } else { print_dbg("FAIL: "); print_dbg_hex(status); }   
  print_dbg("\r\n chip addr: ");
  print_dbg_hex(chip);
  print_dbg(", mem addr: ");
  print_dbg_hex(addr);
  print_dbg(", addr len: ");
  print_dbg_hex(addr_len);
  print_dbg(", data len: ");
  print_dbg_hex(data_len);
  print_dbg(", data (1st 4 bytes): ");
  print_dbg_hex(*((u32*)(data)));

  status = send_master(chip, addr, addr_len, data_len, data);
  print_dbg("\r\nI2C tx (master) : ");
  if(status==TWI_SUCCESS) { print_dbg("SUCCESS"); } else { print_dbg("FAIL: "); print_dbg_hex(status); }   
  while( twi_is_busy() ) {;;}
  status = init_slave();
  print_dbg("\r\nI2C init (slave) : ");
  if(status==TWI_SUCCESS) { print_dbg("SUCCESS"); } else { print_dbg("FAIL: "); print_dbg_hex(status);}   
}