Skip to content

Commit

Permalink
sipf-std-client_nrf9160 v0.3.x 対応
Browse files Browse the repository at this point in the history
- $$RXコマンド応答のパラメータ順入れ替えに対応
  • Loading branch information
f-okuhara committed Nov 17, 2021
1 parent a0c2d34 commit 8a935c7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 12 deletions.
6 changes: 5 additions & 1 deletion sipf-std-m5stack/sipf-std-m5stack.ino
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ void setup() {
return;
}

if (SipfGetFwVersion() != 0) {
M5.Lcd.printf("SipfGetFwVersion(): FAILED\r\n");
}

M5.Lcd.printf("Setting auth mode...");
if (SipfSetAuthMode(0x01) == 0) {
M5.Lcd.printf(" OK\n");
Expand Down Expand Up @@ -303,7 +307,7 @@ void loop() {
M5.Lcd.printf("remain=%d, qty=%d\r\n", remain, qty);
//obj
for (int i = 0; i < ret; i++) {
M5.Lcd.printf("obj[%d]:type=0x%02x, tag=0x%02x, len=%d, value=", i, objs[i].type, objs[i].tag_id, objs[i].value_len);
M5.Lcd.printf("obj[%d]:tag=0x%02x, type=0x%02x, len=%d, value=", i, objs[i].tag_id, objs[i].type, objs[i].value_len);
uint8_t *p_value = objs[i].value;
SipfObjPrimitiveType v;
switch (objs[i].type) {
Expand Down
61 changes: 50 additions & 11 deletions sipf-std-m5stack/sipf_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include <stdio.h>
#include <string.h>

static char cmd[256];
static char cmd[512];
static uint32_t fw_version;

//UARTの受信バッファを読み捨てる
void SipfClientFlushReadBuff(void)
Expand Down Expand Up @@ -215,6 +216,31 @@ int SipfSetAuthInfo(char *user_name, char *password)
return 0;
}

/**
* Fwバージョンを取得
*/
int SipfGetFwVersion(void)
{
uint8_t v = 0;
if (sipfSendR(0xf1, &v) != 0) {
return -1;
}
fw_version = (uint32_t)v << 24; // MAJOR
if (sipfSendR(0xf2, &v) != 0) {
return -1;
}
fw_version |= (uint32_t)v << 16;// MINOR
if (sipfSendR(0xf3, &v) != 0) {
return -1;
}
fw_version |= (uint32_t)v; // RELEASE下位
if (sipfSendR(0xf4, &v) != 0) {
return -1;
}
fw_version |= (uint32_t)v << 8; // RELEASE上位

return 0;
}

int SipfSetGnss(bool is_active) {
int len;
Expand Down Expand Up @@ -620,16 +646,29 @@ int SipfCmdRx(uint8_t *otid, uint64_t *user_send_datetime_ms, uint64_t *sipf_rec
}

SipfObjObject *obj = &obj_list[cnt++];
// TYPE
if (utilHexToUint8(&cmd[0], &obj->type) == -1) {
// HEXから変換できなかった
return -1;
}
// TAG_ID
if (utilHexToUint8(&cmd[3], &obj->tag_id) == -1) {
// HEXから変換できなかった
return -1;
}
if (fw_version >= 0x00030001) {
// TAG_ID
if (utilHexToUint8(&cmd[0], &obj->tag_id) == -1) {
// HEXから変換できなかった
return -1;
}
// TYPE
if (utilHexToUint8(&cmd[3], &obj->type) == -1) {
// HEXから変換できなかった
return -1;
}
} else {
// TYPE
if (utilHexToUint8(&cmd[0], &obj->type) == -1) {
// HEXから変換できなかった
return -1;
}
// TAG_ID
if (utilHexToUint8(&cmd[3], &obj->tag_id) == -1) {
// HEXから変換できなかった
return -1;
}
}
// VALUE_LEN
if (utilHexToUint8(&cmd[6], &obj->value_len) == -1) {
// HEXから変換できなかった
Expand Down
2 changes: 2 additions & 0 deletions sipf-std-m5stack/sipf_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ typedef struct {
int SipfSetAuthMode(uint8_t mode);
int SipfSetAuthInfo(char *user_name, char *password);

int SipfGetFwVersion(void);

int SipfCmdTx(uint8_t tag_id, SipfObjTypeId type, uint8_t *value, uint8_t value_len, uint8_t *otid);
int SipfCmdRx(uint8_t *otid, uint64_t *user_send_datetime_ms, uint64_t *sipf_recv_datetime_ms, uint8_t *remain, uint8_t *obj_cnt, SipfObjObject *obj_list, uint8_t obj_list_sz);

Expand Down

0 comments on commit 8a935c7

Please sign in to comment.