Project

General

Profile

Revision 1609

wl updates: compile issues

View differences:

xbee.c
45 45
// TODO: convert all int references to int16_t syntax (see stdint.h)
46 46

  
47 47
/* I/O Functions */
48
static int8_t xbee_send(uint8_t* buf, uint16_t size);
49 48
static int8_t xbee_send_string(unsigned char* c);
50 49

  
51 50
/* Command Mode Functions */
......
53 52
static int xbee_exit_command_mode(void);
54 53
static int xbee_enter_api_mode(void);
55 54
static int xbee_exit_api_mode(void);
56
static int xbee_wait_for_string(char* s, int len);
55
static int xbee_wait_for_string(char* s, uint16_t len);
57 56
static int xbee_wait_for_ok(void);
58 57

  
59 58
/* API Mode Functions */
60 59
static int xbee_handle_packet(uint8_t* packet, uint16_t len);
61 60
static int xbee_handle_at_command_response(uint16_t command, uint8_t result, uint8_t len);
62 61
static int xbee_handle_at_command_response(uint16_t command, uint8_t result, uint8_t len);
63
static void xbee_handle_status(char status);
64
static int xbee_verify_checksum(char* packet, int len);
65
static char xbee_compute_checksum(char* packet, int len);
66
static int xbee_send_frame(char* buf, int len);
67
int xbee_send_read_at_command(char* command);
68
static int xbee_send_modify_at_command(char* command, char* value);
62
static void xbee_handle_status(uint8_t status);
63
static int xbee_verify_checksum(uint8_t* packet, uint16_t len);
64
static char xbee_compute_checksum(uint8_t* packet, uint16_t len);
65
static int xbee_send_frame(uint8_t* buf, int len);
66
int xbee_send_read_at_command(uint8_t* command);
67
static int xbee_send_modify_at_command(uint8_t* command, uint8_t* value, uint8_t len);
69 68

  
70 69
/* Buffer Manipulation Functions */
71 70
int8_t xbee_basic_buf_add(uint8_t *ptr, uint8_t byte);
......
137 136
  uint16_t len=0;
138 137
  
139 138
  // check that we're in API mode
140
  if (xbee_status&0x03 == XBEE_API_OFF || apitype != XBEE_FRAME_START) {
139
  if ((xbee_status&0x03) == XBEE_API_OFF || apitype != XBEE_FRAME_START) {
141 140
    // not in API mode
142
    if (xbee_status&0xC0) == XBEE_COMMAND_WAIT) {
141
    if ((xbee_status&0xC0) == XBEE_COMMAND_WAIT) {
143 142
      // get rest of command and put in basic buf
144 143
      xbee_basic_buf[0] = apitype;
145 144
      if (xbee_basic_buf[i] != '\r') {
......
175 174
  switch(apitype) {
176 175
  case XBEE_FRAME_AT_COMMAND_RESPONSE:
177 176
    // AT command response
178
    if (xbee_status&0xC0 == XBEE_COMMAND_RESPONSE)
177
    if ((xbee_status&0xC0) == XBEE_COMMAND_RESPONSE)
179 178
      return; // we're currently processing a command, so drop the incoming one
180 179
    uint16_t atcommand=0;
181 180
    uint8_t ptr=basic_buf_last;
......
202 201
    break;
203 202
  case XBEE_FRAME_TX_STATUS:
204 203
    // TX status
205
    uint8_t frameid=0;
204
    if (0) { WL_DEBUG_PRINT("test"); } // why do I need this statement?
205
    uint8_t frame_id = 0;
206 206
    while(i<len) {
207 207
      if (FLAG) {
208 208
        if (i==1)
209
          frameid = PORT;
209
          frame_id = PORT;
210 210
        else {
211
          ackhandle(frameid,PORT); // handle the status
211
          ackhandle(frame_id,PORT); // handle the status
212 212
          break;
213 213
        }
214 214
        i++;
......
1082 1082
  int16_t i=0;
1083 1083
  // change status to command wait
1084 1084
  xbee_status = (xbee_status&0x3F)|XBEE_COMMAND_WAIT;
1085
  xbee_send_modify_at_command("ID",id); // send command to set the channel
1085
  xbee_send_modify_at_command("ID",id,2); // send command to set the channel
1086 1086
  // wait for up to 30 ms
1087 1087
  while(xbee_status&0xC0 != XBEE_COMMAND_RESPONSE && i++ < 10000) {
1088 1088
    delay_us(1); // wait 3us
......
1146 1146
  int16_t i=0;
1147 1147
  // change status to command wait
1148 1148
  xbee_status = (xbee_status&0x3F)|XBEE_COMMAND_WAIT;
1149
  xbee_send_modify_at_command("CH",channel); // send command to set the channel
1149
  xbee_send_modify_at_command("CH",channel,1); // send command to set the channel
1150 1150
  // wait for up to 30 ms
1151
  while(xbee_status&0xC0 != XBEE_COMMAND_RESPONSE && i++ < 10000) {
1151
  while((xbee_status&0xC0) != XBEE_COMMAND_RESPONSE && i++ < 10000) {
1152 1152
    delay_us(1); // wait 3us
1153 1153
  }
1154
  if (i < 1000 && xbee_command[0] == 'O' && xbee_command[1] == 'K') {
1154
  if (i < 1000 && xbee_command[0] == 'O' && xbee_command[1] == 'K')
1155 1155
    i = WL_SUCCESS;
1156 1156
  else
1157 1157
    i = WL_ERROR_XBEE_COMMAND; // set error code
......
1168 1168
 **/
1169 1169
int8_t xbee_get_channel(void)
1170 1170
{
1171
  if (xbee_status&0xC0 == XBEE_COMMAND_WAIT
1172
    || xbee_status&0xC0 == XBEE_COMMAND_RESPONSE)
1171
  if ((xbee_status&0xC0) == XBEE_COMMAND_WAIT
1172
    || (xbee_status&0xC0) == XBEE_COMMAND_RESPONSE)
1173 1173
    return WL_ERROR_XBEE_COMMAND; // can't do command right now
1174 1174
  
1175 1175
  int16_t i=0;
......
1177 1177
  xbee_status = (xbee_status&0x3F)|XBEE_COMMAND_WAIT;
1178 1178
  xbee_send_read_at_command("ID"); // send command to get the channel
1179 1179
  // wait for up to 30 ms
1180
  while(xbee_status&0xC0 != XBEE_COMMAND_RESPONSE && i++ < 10000) {
1180
  while((xbee_status&0xC0) != XBEE_COMMAND_RESPONSE && i++ < 10000) {
1181 1181
    delay_us(1); // wait 3us
1182 1182
  }
1183
  if (i < 1000 && xbee_command[0] == 'C' && xbee_command[1] == 'H') {
1183
  if (i < 1000 && xbee_command[0] == 'C' && xbee_command[1] == 'H')
1184 1184
    i = xbee_command[2]; // get channel
1185 1185
  else
1186 1186
    i = WL_ERROR_XBEE_COMMAND; // set error code
......
1197 1197
 **/
1198 1198
uint16_t xbee_get_address(void)
1199 1199
{
1200
  if (xbee_status&0xC0 == XBEE_COMMAND_WAIT
1201
    || xbee_status&0xC0 == XBEE_COMMAND_RESPONSE)
1200
  if ((xbee_status&0xC0) == XBEE_COMMAND_WAIT
1201
    || (xbee_status&0xC0) == XBEE_COMMAND_RESPONSE)
1202 1202
    return WL_ERROR_XBEE_COMMAND_16BIT; // can't do command right now
1203 1203
  
1204 1204
  uint16_t i=0;
......
1206 1206
  xbee_status = (xbee_status&0x3F)|XBEE_COMMAND_WAIT;
1207 1207
  xbee_send_read_at_command("MY"); // send command to get the address
1208 1208
  // wait for up to 30 ms
1209
  while(xbee_status&0xC0 != XBEE_COMMAND_RESPONSE && i++ < 10000) {
1209
  while((xbee_status&0xC0) != XBEE_COMMAND_RESPONSE && i++ < 10000) {
1210 1210
    delay_us(1); // wait 3us
1211 1211
  }
1212
  if (i < 1000 && xbee_command[0] == 'M' && xbee_command[1] == 'Y') {
1212
  if (i < 1000 && xbee_command[0] == 'M' && xbee_command[1] == 'Y')
1213 1213
    i = (xbee_command[2]<<8)+xbee_command[3]; // get address
1214 1214
  else
1215 1215
    i = WL_ERROR_XBEE_COMMAND_16BIT; // set error code

Also available in: Unified diff