
/* handle control messages */
void handle_msg()
{
    // assume messages are at most 8 words for now
    __declspec(gp_reg) unsigned int i;
    __declspec(gp_reg) unsigned int message[8];
    __declspec(gp_reg) onl_api_ctrl_msg_hdr hdr;

    __declspec(local_mem) char msgstr[28];
    __declspec(local_mem) char pkt_count_str[28];
    __declspec(local_mem) char hello_str[6] = "hello\0";
    __declspec(local_mem) char yo_str[3] = "yo\0";
    __declspec(local_mem) char getcnt_str[10] = "get count\0";

    for(i=0; i<8; ++i) { message[i] = 0; }

    dl_source_message(msgFromBlock, message);

    hdr.value = message[0];
    if( hdr.type != CM_CONTROLMSG )	return;
    {
      return;
    }
    if(hdr.response_requested != 1)
    {
      return;
    }

    onl_api_intarr2str(&message[1], msgstr);

    if(strncmp_lmem(msgstr, hello_str, 5) == 0)
    {
      if(onl_api_str2intarr(yo_str, &message[1]) < 0)
      {
        return;
      }
    }
    else if(strncmp_lmem(msgstr, getcnt_str, 9) == 0)
    {
      onl_api_int2str(pkt_count, pkt_count_str);
      if(onl_api_str2intarr(pkt_count_str, &message[1]) < 0)
      {
        return;
      } 
    }
    // else just return the message that was sent

    hdr.type = CM_CONTROLMSGRSP;
    hdr.response_requested = 0;
    hdr.num_words = 7;
    message[0] = hdr.value;

    dl_sink_message(msgNextBlock, message);
}

